Postie - Version 1.9.38

Version Description

(2019-07-27) = * Fix bug where filtering out an attachment prevented other attachments from being processed

Download this release

Release Info

Developer WayneAllen
Plugin Icon 128x128 Postie
Version 1.9.38
Comparing to
See all releases

Code changes from version 1.9.37 to 1.9.38

Files changed (7) hide show
  1. docs/Changes.txt +3 -0
  2. docs/Postie.txt +1 -1
  3. docs/TODO.txt +6 -6
  4. postie-filters.php +92 -77
  5. postie.class.php +2 -2
  6. postie.php +3 -3
  7. readme.txt +4 -1
docs/Changes.txt CHANGED
@@ -35,6 +35,9 @@ All script, style and body tags are stripped from html emails.
35
  Attachments are now processed in the order they were attached.
36
 
37
  == CHANGELOG ==
 
 
 
38
  = 1.9.37 (2019-06-20) =
39
  * Update logging to output encoding info
40
  * Fix bug where non-image titles are blank
35
  Attachments are now processed in the order they were attached.
36
 
37
  == CHANGELOG ==
38
+ = 1.9.38 (2019-07-27) =
39
+ * Fix bug where filtering out an attachment prevented other attachments from being processed
40
+
41
  = 1.9.37 (2019-06-20) =
42
  * Update logging to output encoding info
43
  * Fix bug where non-image titles are blank
docs/Postie.txt CHANGED
@@ -7,7 +7,7 @@ Tags: e-mail, email, post-by-email
7
  Requires PHP: 5.3
8
  Requires at least: 4.0
9
  Tested up to: 5.2
10
- Stable tag: 1.9.37
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
7
  Requires PHP: 5.3
8
  Requires at least: 4.0
9
  Tested up to: 5.2
10
+ Stable tag: 1.9.38
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
docs/TODO.txt CHANGED
@@ -12,22 +12,22 @@ Comment not being created when subject contains category command []. I.e. listse
12
  Comment not being created when subject contains fomat or type. I.e. re: image//Image subject
13
 
14
  Other
15
- detect links to enbedable content and remove anchor tag <a href="https://youtube.com?...">https://youtube.com</a>
16
  Process single email at a time and don't delete unless successful
17
- Change all "filters" to "addons" and allow them to be disabled (i.e. turn off processing for "date:"
18
  Add default comment status (like post status) wp_set_comment_status
19
- Send post confirmation email to: add list of individual admins (lisa@kellys.org)
 
 
 
20
  provide a location for custom icons. update docs about location.
21
  "yoast" style admin sidebar - see clicky by yoast
22
  check multiple email accounts
23
  allow other roles access to manual check like "Roles That Can Post"
24
- Test server port combination by opening a socket connection to see if any service responds. (via ajax call)
25
  For IMAP mailboxes allow the user to choose the folder.
26
  Check to see if post already exists. Store hash in custom field.
27
- Verify that WP is honoring the wp_set_current_user() call. I.e. if the user is not an "author" role can they publish?
28
  Add Message-ID header value to custom field (postie_message_id?) to both posts and comments.
29
  Use In-Reply-To/Message-ID header value as a better way to detect replies
30
- date: tag is being detected in body when not wanted
31
  dynamically determine video size (height/width) - https://code.google.com/p/phpvideotoolkit/
32
  readme tips http://wp.smashingmagazine.com/2011/11/23/improve-wordpress-plugins-readme-txt/
33
  review http://codex.wordpress.org/Settings_API
12
  Comment not being created when subject contains fomat or type. I.e. re: image//Image subject
13
 
14
  Other
15
+ Google Sign-In https://developers.google.com/identity/sign-in/web/sign-in
16
  Process single email at a time and don't delete unless successful
17
+ detect links to embeddable content and remove anchor tag <a href="https://youtube.com?...">https://youtube.com</a>
18
  Add default comment status (like post status) wp_set_comment_status
19
+ Test server port combination by opening a socket connection to see if any service responds. (via ajax call)
20
+ date: tag is being detected in body when not wanted
21
+
22
+ Change all "filters" to "addons" and allow them to be disabled (i.e. turn off processing for "date:"
23
  provide a location for custom icons. update docs about location.
24
  "yoast" style admin sidebar - see clicky by yoast
25
  check multiple email accounts
26
  allow other roles access to manual check like "Roles That Can Post"
 
27
  For IMAP mailboxes allow the user to choose the folder.
28
  Check to see if post already exists. Store hash in custom field.
 
29
  Add Message-ID header value to custom field (postie_message_id?) to both posts and comments.
30
  Use In-Reply-To/Message-ID header value as a better way to detect replies
 
31
  dynamically determine video size (height/width) - https://code.google.com/p/phpvideotoolkit/
32
  readme tips http://wp.smashingmagazine.com/2011/11/23/improve-wordpress-plugins-readme-txt/
33
  review http://codex.wordpress.org/Settings_API
postie-filters.php CHANGED
@@ -28,54 +28,62 @@ function filter_AttachmentTemplates($content, $mimeDecodedEmail, $post_id, $conf
28
 
29
  DebugEcho("filter_AttachmentTemplates: # attachments: " . count($mimeDecodedEmail['attachment']));
30
  foreach ($mimeDecodedEmail['attachment'] as $attachment) {
31
- DebugEcho("filter_AttachmentTemplates: image: " . $attachment['wp_filename']);
32
- $skip = ($featuredimageid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
33
- if (!$skip) {
34
- if (!$addimages && $attachment['primary'] == 'image') {
35
- DebugEcho("filter_AttachmentTemplates: skip image " . $attachment['wp_filename']);
36
- } else {
37
- $template = $attachment['template'];
38
- DebugEcho("filter_AttachmentTemplates: pre filter '$template'");
39
- if ($config['images_append']) {
40
- DebugEcho("filter_AttachmentTemplates: pre postie_place_media_after");
41
- $template = apply_filters('postie_place_media_after', $template, $attachment['wp_id']);
42
  } else {
43
- DebugEcho("filter_AttachmentTemplates: pre postie_place_media_before");
44
- $template = apply_filters('postie_place_media_before', $template, $attachment['wp_id']);
 
 
 
 
 
 
 
 
 
 
 
45
  }
46
- DebugEcho("filter_AttachmentTemplates: post filter '$template'");
47
- $template = mb_str_replace('{CAPTION}', '', $template);
48
- DebugEcho("filter_AttachmentTemplates: post caption '$template'");
49
- $html .= $template;
50
  }
51
  } else {
52
- DebugEcho("filter_AttachmentTemplates: skip attachment " . $attachment['wp_filename']);
53
  }
54
  }
55
 
56
  DebugEcho("filter_AttachmentTemplates: # inline: " . count($mimeDecodedEmail['inline']));
57
  DebugEcho("filter_AttachmentTemplates: # related: " . count($mimeDecodedEmail['related']));
58
  foreach (array_merge($mimeDecodedEmail['inline'], $mimeDecodedEmail['related']) as $attachment) {
59
- DebugEcho("filter_AttachmentTemplates: image: " . $attachment['wp_filename']);
60
- $skip = ($featuredimageid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
61
- if (!$skip) {
62
- if (!$addimages && $attachment['primary'] == 'image') {
63
- DebugEcho("filter_AttachmentTemplates: skip image (alt) " . $attachment['wp_filename']);
64
- } else {
65
- $template = $attachment['template'];
66
- if ($config['images_append']) {
67
- DebugEcho("filter_AttachmentTemplates: pre postie_place_media_after");
68
- $template = apply_filters('postie_place_media_after', $template, $attachment['wp_id']);
69
  } else {
70
- DebugEcho("filter_AttachmentTemplates: pre postie_place_media_before");
71
- $template = apply_filters('postie_place_media_before', $template, $attachment['wp_id']);
 
 
 
 
 
 
 
 
 
72
  }
73
- $template = mb_str_replace('{CAPTION}', '', $template);
74
- DebugEcho("filter_AttachmentTemplates: post filter (alt) '$template'");
75
- $html .= $template;
76
  }
77
  } else {
78
- DebugEcho("filter_AttachmentTemplates: skip attachment (alt) " . $attachment['wp_filename']);
79
  }
80
  }
81
 
@@ -108,8 +116,7 @@ function filter_AttachmentTemplates($content, $mimeDecodedEmail, $post_id, $conf
108
 
109
  $imagecount = 0;
110
  foreach (array_merge($mimeDecodedEmail['attachment'], $mimeDecodedEmail['inline'], $mimeDecodedEmail['related']) as $attachment) {
111
- DebugEcho("filter_AttachmentTemplates: attachment mime primary: {$attachment['primary']}");
112
- if ($attachment['primary'] == 'image' && $attachment['exclude'] == false) {
113
  $imagecount++;
114
  }
115
  }
@@ -394,9 +401,13 @@ function filter_ReplaceImageCIDs($content, &$email) {
394
  foreach ($email['related'] as $cid => &$attachment) {
395
  if (false !== stripos($content, $cid)) {
396
  DebugEcho("filter_ReplaceImageCIDs: CID: $cid");
397
- $fileid = $attachment['wp_id'];
398
- $url = wp_get_attachment_url($fileid);
399
- $content = str_replace($cid, $url, $content);
 
 
 
 
400
  $attachment['exclude'] = true;
401
  } else {
402
  DebugEcho("filter_ReplaceImageCIDs: CID not found: $cid");
@@ -473,48 +484,52 @@ function filter_ReplaceImagePlaceHolders($content, &$email, $config, $post_id, $
473
  }
474
 
475
  function filter_ReplaceImagePlaceHolders_worker($content, &$attachment, $imagePattern, $startIndex, $currentIndex) {
476
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: " . $attachment['wp_filename']);
477
-
478
- if (empty($attachment['template'])) {
479
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: no template");
480
- return $content;
481
- }
482
 
483
- $matches = array();
484
- $pparts = explode('%', $imagePattern);
485
- if (count($pparts) != 2) {
486
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: invalid image pattern: $imagePattern");
487
- return $content;
488
- }
489
- $pattern = '/' . $pparts[0] . (string) ($startIndex + $currentIndex) . '\s?(caption=[\'"]?(.*?)[\'"]?)?' . $pparts[1] . '/iu';
490
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: pattern: $pattern");
491
- preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
492
- //DebugEcho($content);
493
- DebugDump($matches);
494
- foreach ($matches as $match) {
495
- $attachment['exclude'] = true;
496
- $imageTemplate = $attachment['template'];
497
-
498
- $caption = '';
499
- if (count($match) > 2) {
500
- $caption = trim($match[2]);
501
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: caption: '$caption'");
502
  }
503
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: parameterize templete: $imageTemplate");
504
- $imageTemplate = mb_str_replace('{CAPTION}', htmlspecialchars($caption, ENT_QUOTES), $imageTemplate);
505
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: captioned template: $imageTemplate");
506
-
507
- if (!empty($caption)) {
508
- $img = get_post($attachment['wp_id']);
509
- $img->post_excerpt = $caption;
510
- wp_update_post($img);
511
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: caption added to metadata");
512
  }
513
- $imageTemplate = apply_filters('postie_place_media', $imageTemplate, $attachment['wp_id']);
514
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: post postie_place_media: '$imageTemplate'");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
515
 
516
- $content = str_ireplace($match[0], $imageTemplate, $content);
517
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: post replace: $content");
 
 
 
518
  }
519
  return $content;
520
  }
28
 
29
  DebugEcho("filter_AttachmentTemplates: # attachments: " . count($mimeDecodedEmail['attachment']));
30
  foreach ($mimeDecodedEmail['attachment'] as $attachment) {
31
+ if (isset($attachment['wp_filename'])) {
32
+ DebugEcho("filter_AttachmentTemplates: image: " . $attachment['wp_filename']);
33
+ $skip = ($featuredimageid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
34
+ if (!$skip) {
35
+ if (!$addimages && $attachment['primary'] == 'image') {
36
+ DebugEcho("filter_AttachmentTemplates: skip image " . $attachment['wp_filename']);
 
 
 
 
 
37
  } else {
38
+ $template = $attachment['template'];
39
+ DebugEcho("filter_AttachmentTemplates: pre filter '$template'");
40
+ if ($config['images_append']) {
41
+ DebugEcho("filter_AttachmentTemplates: pre postie_place_media_after");
42
+ $template = apply_filters('postie_place_media_after', $template, $attachment['wp_id']);
43
+ } else {
44
+ DebugEcho("filter_AttachmentTemplates: pre postie_place_media_before");
45
+ $template = apply_filters('postie_place_media_before', $template, $attachment['wp_id']);
46
+ }
47
+ DebugEcho("filter_AttachmentTemplates: post filter '$template'");
48
+ $template = mb_str_replace('{CAPTION}', '', $template);
49
+ DebugEcho("filter_AttachmentTemplates: post caption '$template'");
50
+ $html .= $template;
51
  }
52
+ } else {
53
+ DebugEcho("filter_AttachmentTemplates: skip attachment " . $attachment['wp_filename']);
 
 
54
  }
55
  } else {
56
+ DebugEcho("filter_AttachmentTemplates: skipped attachment " . $attachment['filename']);
57
  }
58
  }
59
 
60
  DebugEcho("filter_AttachmentTemplates: # inline: " . count($mimeDecodedEmail['inline']));
61
  DebugEcho("filter_AttachmentTemplates: # related: " . count($mimeDecodedEmail['related']));
62
  foreach (array_merge($mimeDecodedEmail['inline'], $mimeDecodedEmail['related']) as $attachment) {
63
+ if (isset($attachment['wp_filename'])) {
64
+ DebugEcho("filter_AttachmentTemplates: image: " . $attachment['wp_filename']);
65
+ $skip = ($featuredimageid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
66
+ if (!$skip) {
67
+ if (!$addimages && $attachment['primary'] == 'image') {
68
+ DebugEcho("filter_AttachmentTemplates: skip image (alt) " . $attachment['wp_filename']);
 
 
 
 
69
  } else {
70
+ $template = $attachment['template'];
71
+ if ($config['images_append']) {
72
+ DebugEcho("filter_AttachmentTemplates: pre postie_place_media_after");
73
+ $template = apply_filters('postie_place_media_after', $template, $attachment['wp_id']);
74
+ } else {
75
+ DebugEcho("filter_AttachmentTemplates: pre postie_place_media_before");
76
+ $template = apply_filters('postie_place_media_before', $template, $attachment['wp_id']);
77
+ }
78
+ $template = mb_str_replace('{CAPTION}', '', $template);
79
+ DebugEcho("filter_AttachmentTemplates: post filter (alt) '$template'");
80
+ $html .= $template;
81
  }
82
+ } else {
83
+ DebugEcho("filter_AttachmentTemplates: skip attachment (alt) " . $attachment['wp_filename']);
 
84
  }
85
  } else {
86
+ DebugEcho("filter_AttachmentTemplates: skip attachment (removed by filter) " . $attachment['filename']);
87
  }
88
  }
89
 
116
 
117
  $imagecount = 0;
118
  foreach (array_merge($mimeDecodedEmail['attachment'], $mimeDecodedEmail['inline'], $mimeDecodedEmail['related']) as $attachment) {
119
+ if (isset($attachment['primary']) && $attachment['primary'] == 'image' && $attachment['exclude'] == false) {
 
120
  $imagecount++;
121
  }
122
  }
401
  foreach ($email['related'] as $cid => &$attachment) {
402
  if (false !== stripos($content, $cid)) {
403
  DebugEcho("filter_ReplaceImageCIDs: CID: $cid");
404
+ if (isset($attachment['wp_id'])) {
405
+ $fileid = $attachment['wp_id'];
406
+ $url = wp_get_attachment_url($fileid);
407
+ $content = str_replace($cid, $url, $content);
408
+ } else {
409
+ DebugEcho("filter_ReplaceImageCIDs: skipping {$attachment['filename']}");
410
+ }
411
  $attachment['exclude'] = true;
412
  } else {
413
  DebugEcho("filter_ReplaceImageCIDs: CID not found: $cid");
484
  }
485
 
486
  function filter_ReplaceImagePlaceHolders_worker($content, &$attachment, $imagePattern, $startIndex, $currentIndex) {
487
+ if (isset($attachment['wp_filename'])) {
488
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: " . $attachment['wp_filename']);
 
 
 
 
489
 
490
+ if (empty($attachment['template'])) {
491
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: no template");
492
+ return $content;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
493
  }
494
+
495
+ $matches = array();
496
+ $pparts = explode('%', $imagePattern);
497
+ if (count($pparts) != 2) {
498
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: invalid image pattern: $imagePattern");
499
+ return $content;
 
 
 
500
  }
501
+ $pattern = '/' . $pparts[0] . (string) ($startIndex + $currentIndex) . '\s?(caption=[\'"]?(.*?)[\'"]?)?' . $pparts[1] . '/iu';
502
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: pattern: $pattern");
503
+ preg_match_all($pattern, $content, $matches, PREG_SET_ORDER);
504
+ //DebugEcho($content);
505
+ DebugDump($matches);
506
+ foreach ($matches as $match) {
507
+ $attachment['exclude'] = true;
508
+ $imageTemplate = $attachment['template'];
509
+
510
+ $caption = '';
511
+ if (count($match) > 2) {
512
+ $caption = trim($match[2]);
513
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: caption: '$caption'");
514
+ }
515
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: parameterize templete: $imageTemplate");
516
+ $imageTemplate = mb_str_replace('{CAPTION}', htmlspecialchars($caption, ENT_QUOTES), $imageTemplate);
517
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: captioned template: $imageTemplate");
518
+
519
+ if (!empty($caption)) {
520
+ $img = get_post($attachment['wp_id']);
521
+ $img->post_excerpt = $caption;
522
+ wp_update_post($img);
523
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: caption added to metadata");
524
+ }
525
+ $imageTemplate = apply_filters('postie_place_media', $imageTemplate, $attachment['wp_id']);
526
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: post postie_place_media: '$imageTemplate'");
527
 
528
+ $content = str_ireplace($match[0], $imageTemplate, $content);
529
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: post replace: $content");
530
+ }
531
+ } else {
532
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: skipping {$attachment['filename']}");
533
  }
534
  return $content;
535
  }
postie.class.php CHANGED
@@ -206,12 +206,12 @@ class Postie {
206
 
207
  if ($this->is_banned_filename($attachment['filename'], $config['banned_files_list'])) {
208
  DebugEcho("save_attachments_worker: skipping banned filename " . $attachment['filename']);
209
- break;
210
  }
211
 
212
  if (false === apply_filters('postie_include_attachment', true, $attachment)) {
213
  DebugEcho("save_attachments_worker: skipping filename by filter " . $attachment['filename']);
214
- break;
215
  }
216
  } else {
217
  DebugEcho('save_attachments_worker: un-named attachment');
206
 
207
  if ($this->is_banned_filename($attachment['filename'], $config['banned_files_list'])) {
208
  DebugEcho("save_attachments_worker: skipping banned filename " . $attachment['filename']);
209
+ continue;
210
  }
211
 
212
  if (false === apply_filters('postie_include_attachment', true, $attachment)) {
213
  DebugEcho("save_attachments_worker: skipping filename by filter " . $attachment['filename']);
214
+ continue;
215
  }
216
  } else {
217
  DebugEcho('save_attachments_worker: un-named attachment');
postie.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  Description: Create posts via email. Significantly upgrades the Post by Email features of WordPress.
7
- Version: 1.9.37
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
  License: GPL3
@@ -28,14 +28,14 @@
28
  */
29
 
30
  /*
31
- $Id: postie.php 2109869 2019-06-21 02:21:59Z WayneAllen $
32
  */
33
 
34
  if (!defined('WPINC')) {
35
  die; // Exit if accessed directly
36
  }
37
 
38
- define('POSTIE_VERSION', '1.9.37');
39
  define('POSTIE_ROOT', dirname(__FILE__));
40
  define('POSTIE_URL', WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
41
 
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  Description: Create posts via email. Significantly upgrades the Post by Email features of WordPress.
7
+ Version: 1.9.38
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
  License: GPL3
28
  */
29
 
30
  /*
31
+ $Id: postie.php 2129475 2019-07-27 15:09:15Z WayneAllen $
32
  */
33
 
34
  if (!defined('WPINC')) {
35
  die; // Exit if accessed directly
36
  }
37
 
38
+ define('POSTIE_VERSION', '1.9.38');
39
  define('POSTIE_ROOT', dirname(__FILE__));
40
  define('POSTIE_URL', WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
41
 
readme.txt CHANGED
@@ -7,7 +7,7 @@ Tags: e-mail, email, post-by-email
7
  Requires PHP: 5.3
8
  Requires at least: 4.0
9
  Tested up to: 5.2
10
- Stable tag: 1.9.37
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
@@ -107,6 +107,9 @@ All script, style and body tags are stripped from html emails.
107
  Attachments are now processed in the order they were attached.
108
 
109
  == CHANGELOG ==
 
 
 
110
  = 1.9.37 (2019-06-20) =
111
  * Update logging to output encoding info
112
  * Fix bug where non-image titles are blank
7
  Requires PHP: 5.3
8
  Requires at least: 4.0
9
  Tested up to: 5.2
10
+ Stable tag: 1.9.38
11
  License: GPLv2 or later
12
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
13
 
107
  Attachments are now processed in the order they were attached.
108
 
109
  == CHANGELOG ==
110
+ = 1.9.38 (2019-07-27) =
111
+ * Fix bug where filtering out an attachment prevented other attachments from being processed
112
+
113
  = 1.9.37 (2019-06-20) =
114
  * Update logging to output encoding info
115
  * Fix bug where non-image titles are blank