Postie - Version 1.8.15

Version Description

(2016-11-02) = * Fix bug where inline images were not being replaced correctly if WordPress changed the name of the attachment via sanitize_file_name()

Download this release

Release Info

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

Code changes from version 1.8.14 to 1.8.15

Files changed (5) hide show
  1. docs/Changes.txt +3 -0
  2. docs/Postie.txt +1 -1
  3. postie-functions.php +22 -21
  4. postie.php +3 -3
  5. readme.txt +4 -1
docs/Changes.txt CHANGED
@@ -32,6 +32,9 @@ All script, style and body tags are stripped from html emails.
32
  Attachments are now processed in the order they were attached.
33
 
34
  == CHANGELOG ==
 
 
 
35
  = 1.8.14 (2016-11-01) =
36
  * Fix bug where OS detection failure was preventing email processing
37
 
32
  Attachments are now processed in the order they were attached.
33
 
34
  == CHANGELOG ==
35
+ = 1.8.15 (2016-11-02) =
36
+ * Fix bug where inline images were not being replaced correctly if WordPress changed the name of the attachment via sanitize_file_name()
37
+
38
  = 1.8.14 (2016-11-01) =
39
  * Fix bug where OS detection failure was preventing email processing
40
 
docs/Postie.txt CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.6.1
9
- Stable tag: 1.8.14
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.6.1
9
+ Stable tag: 1.8.15
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
postie-functions.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
  /*
3
- $Id: postie-functions.php 1525589 2016-10-31 21:10:30Z WayneAllen $
4
  */
5
 
6
  class PostiePostModifiers {
@@ -194,8 +194,8 @@ function tag_CustomImageField($post_ID, $email, $config) {
194
  DebugEcho("Saving custom image post_meta");
195
 
196
  foreach (array_merge($email['attachment'], $email['inline'], $email['related']) as $attachment) {
197
- add_post_meta($post_ID, 'image', $attachment['filename']);
198
- DebugEcho("Saving custom attachment '{$attachment['filename']}'");
199
  }
200
  }
201
  }
@@ -215,11 +215,11 @@ function filter_AttachmentTemplates($content, $mimeDecodedEmail, $post_id, $conf
215
  DebugEcho("filter_AttachmentTemplates: featured image: $fiid");
216
 
217
  foreach ($mimeDecodedEmail['attachment'] as $attachment) {
218
- DebugEcho("filter_AttachmentTemplates: image: " . $attachment['filename']);
219
  $skip = ($fiid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
220
  if (!$skip) {
221
  if (!$addimages && $attachment['primary'] == 'image') {
222
- DebugEcho("filter_AttachmentTemplates: skip image " . $attachment['filename']);
223
  } else {
224
  $template = $attachment['template'];
225
  if ($config['images_append']) {
@@ -231,17 +231,17 @@ function filter_AttachmentTemplates($content, $mimeDecodedEmail, $post_id, $conf
231
  $html .= $template;
232
  }
233
  } else {
234
- DebugEcho("filter_AttachmentTemplates: skip attachment " . $attachment['filename']);
235
  }
236
  }
237
 
238
  if ($config['prefer_text_type'] == 'plain') {
239
  foreach (array_merge($mimeDecodedEmail['inline'], $mimeDecodedEmail['related']) as $attachment) {
240
- DebugEcho("filter_AttachmentTemplates: image: " . $attachment['filename']);
241
  $skip = ($fiid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
242
  if (!$skip) {
243
  if (!$addimages && $attachment['primary'] == 'image') {
244
- DebugEcho("filter_AttachmentTemplates: skip image (alt) " . $attachment['filename']);
245
  } else {
246
  $template = $attachment['template'];
247
  if ($config['images_append']) {
@@ -253,7 +253,7 @@ function filter_AttachmentTemplates($content, $mimeDecodedEmail, $post_id, $conf
253
  $html .= $template;
254
  }
255
  } else {
256
- DebugEcho("filter_AttachmentTemplates: skip attachment (alt) " . $attachment['filename']);
257
  }
258
  }
259
  }
@@ -917,7 +917,7 @@ function postie_save_attachments_worker(&$attachments, $post_id, $poster, $confi
917
 
918
  postie_save_attachment($attachment, $post_id, $poster, $config);
919
 
920
- $filename = $attachment['filename'];
921
  $fileext = $attachment['ext'];
922
  $mparts = explode('/', $attachment['mimetype']);
923
  $mimetype_primary = $mparts[0];
@@ -986,12 +986,13 @@ function postie_save_attachment(&$attachment, $post_id, $poster, $config) {
986
  $filename = $attachment['filename'];
987
  } else {
988
  $filename = uniqid();
 
989
  }
990
 
991
  DebugEcho("postie_save_attachment: pre sanitize file name '$filename'");
992
  //DebugDump($part);
993
  $filename = sanitize_file_name($filename);
994
- $attachment['filename'] = $filename;
995
 
996
  $fileext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
997
  $attachment['ext'] = $fileext;
@@ -1498,14 +1499,14 @@ function tag_Subject($content, $defaultTitle) {
1498
  }
1499
  }
1500
 
1501
- function postie_media_handle_upload($part, $post_id, $poster, $generate_thubnails = true, $mimetype_primary = null, $mimetype_secondary = null) {
1502
  $post_data = array();
1503
 
1504
  $tmpFile = tempnam(get_temp_dir(), 'postie');
1505
  if ($tmpFile !== false) {
1506
  $fp = fopen($tmpFile, 'w');
1507
  if ($fp) {
1508
- fwrite($fp, $part['data']);
1509
  fclose($fp);
1510
  } else {
1511
  EchoError("postie_media_handle_upload: Could not write to temp file: '$tmpFile' ");
@@ -1518,12 +1519,12 @@ function postie_media_handle_upload($part, $post_id, $poster, $generate_thubnail
1518
 
1519
  $name = 'postie-media.' . $namecs;
1520
 
1521
- if (isset($part['filename']) && !empty($part['filename'])) {
1522
- $name = $part['filename'];
1523
  }
1524
- DebugEcho("pre-sanitize name: $name, size: " . filesize($tmpFile));
1525
- $name = sanitize_file_name($name);
1526
- DebugEcho("post sanitize name: $name");
1527
  //DebugDump($part);
1528
 
1529
  $the_file = array('name' => $name,
@@ -1536,7 +1537,7 @@ function postie_media_handle_upload($part, $post_id, $poster, $generate_thubnail
1536
  DebugEcho("exploding zip file");
1537
  $parts = explode('.', $name);
1538
  $ext = $parts[count($parts) - 1];
1539
- $type = $part->primary . '/' . $part->secondary;
1540
  $the_file['ext'] = $ext;
1541
  $the_file['type'] = $type;
1542
  }
@@ -2062,7 +2063,7 @@ function filter_ReplaceInlineImage($content, &$email, $config) {
2062
  } else {
2063
  $template = $inlineImage['template'];
2064
  }
2065
- $inlinemarker = '<:inline ' . $inlineImage['filename'] . ' inline:>';
2066
  if (false !== stripos($content, $inlinemarker)) {
2067
  DebugEcho('filter_ReplaceInlineImage: ' . $inlineImage['filename']);
2068
  $content = str_ireplace($inlinemarker, $template, $content);
@@ -2112,7 +2113,7 @@ function filter_ReplaceImagePlaceHolders($content, &$email, $config, $post_id, $
2112
  }
2113
 
2114
  function filter_ReplaceImagePlaceHolders_worker($content, &$attachment, $imagePattern, $startIndex, $currentIndex) {
2115
- DebugEcho("filter_ReplaceImagePlaceHolders_worker: " . $attachment['filename']);
2116
 
2117
  if (empty($attachment['template'])) {
2118
  DebugEcho("filter_ReplaceImagePlaceHolders_worker: no template");
1
  <?php
2
  /*
3
+ $Id: postie-functions.php 1526975 2016-11-02 20:48:16Z WayneAllen $
4
  */
5
 
6
  class PostiePostModifiers {
194
  DebugEcho("Saving custom image post_meta");
195
 
196
  foreach (array_merge($email['attachment'], $email['inline'], $email['related']) as $attachment) {
197
+ add_post_meta($post_ID, 'image', $attachment['wp_filename']);
198
+ DebugEcho("Saving custom attachment '{$attachment['wp_filename']}'");
199
  }
200
  }
201
  }
215
  DebugEcho("filter_AttachmentTemplates: featured image: $fiid");
216
 
217
  foreach ($mimeDecodedEmail['attachment'] as $attachment) {
218
+ DebugEcho("filter_AttachmentTemplates: image: " . $attachment['wp_filename']);
219
  $skip = ($fiid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
220
  if (!$skip) {
221
  if (!$addimages && $attachment['primary'] == 'image') {
222
+ DebugEcho("filter_AttachmentTemplates: skip image " . $attachment['wp_filename']);
223
  } else {
224
  $template = $attachment['template'];
225
  if ($config['images_append']) {
231
  $html .= $template;
232
  }
233
  } else {
234
+ DebugEcho("filter_AttachmentTemplates: skip attachment " . $attachment['wp_filename']);
235
  }
236
  }
237
 
238
  if ($config['prefer_text_type'] == 'plain') {
239
  foreach (array_merge($mimeDecodedEmail['inline'], $mimeDecodedEmail['related']) as $attachment) {
240
+ DebugEcho("filter_AttachmentTemplates: image: " . $attachment['wp_filename']);
241
  $skip = ($fiid == $attachment['wp_id'] && !$config['include_featured_image']) || $attachment['exclude'];
242
  if (!$skip) {
243
  if (!$addimages && $attachment['primary'] == 'image') {
244
+ DebugEcho("filter_AttachmentTemplates: skip image (alt) " . $attachment['wp_filename']);
245
  } else {
246
  $template = $attachment['template'];
247
  if ($config['images_append']) {
253
  $html .= $template;
254
  }
255
  } else {
256
+ DebugEcho("filter_AttachmentTemplates: skip attachment (alt) " . $attachment['wp_filename']);
257
  }
258
  }
259
  }
917
 
918
  postie_save_attachment($attachment, $post_id, $poster, $config);
919
 
920
+ $filename = $attachment['wp_filename'];
921
  $fileext = $attachment['ext'];
922
  $mparts = explode('/', $attachment['mimetype']);
923
  $mimetype_primary = $mparts[0];
986
  $filename = $attachment['filename'];
987
  } else {
988
  $filename = uniqid();
989
+ $attachment['filename'] = $filename;
990
  }
991
 
992
  DebugEcho("postie_save_attachment: pre sanitize file name '$filename'");
993
  //DebugDump($part);
994
  $filename = sanitize_file_name($filename);
995
+ $attachment['wp_filename'] = $filename;
996
 
997
  $fileext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
998
  $attachment['ext'] = $fileext;
1499
  }
1500
  }
1501
 
1502
+ function postie_media_handle_upload($attachment, $post_id, $poster, $generate_thubnails = true, $mimetype_primary = null, $mimetype_secondary = null) {
1503
  $post_data = array();
1504
 
1505
  $tmpFile = tempnam(get_temp_dir(), 'postie');
1506
  if ($tmpFile !== false) {
1507
  $fp = fopen($tmpFile, 'w');
1508
  if ($fp) {
1509
+ fwrite($fp, $attachment['data']);
1510
  fclose($fp);
1511
  } else {
1512
  EchoError("postie_media_handle_upload: Could not write to temp file: '$tmpFile' ");
1519
 
1520
  $name = 'postie-media.' . $namecs;
1521
 
1522
+ if (isset($attachment['wp_filename']) && !empty($attachment['wp_filename'])) {
1523
+ $name = $attachment['wp_filename'];
1524
  }
1525
+ //DebugEcho("pre-sanitize name: $name, size: " . filesize($tmpFile));
1526
+ //$name = sanitize_file_name($name);
1527
+ //DebugEcho("post sanitize name: $name");
1528
  //DebugDump($part);
1529
 
1530
  $the_file = array('name' => $name,
1537
  DebugEcho("exploding zip file");
1538
  $parts = explode('.', $name);
1539
  $ext = $parts[count($parts) - 1];
1540
+ $type = $attachment->primary . '/' . $attachment->secondary;
1541
  $the_file['ext'] = $ext;
1542
  $the_file['type'] = $type;
1543
  }
2063
  } else {
2064
  $template = $inlineImage['template'];
2065
  }
2066
+ $inlinemarker = '<:inline ' . $inlineImage['filename'] . ' inline:>';//use the original non-sanitized name
2067
  if (false !== stripos($content, $inlinemarker)) {
2068
  DebugEcho('filter_ReplaceInlineImage: ' . $inlineImage['filename']);
2069
  $content = str_ireplace($inlinemarker, $template, $content);
2113
  }
2114
 
2115
  function filter_ReplaceImagePlaceHolders_worker($content, &$attachment, $imagePattern, $startIndex, $currentIndex) {
2116
+ DebugEcho("filter_ReplaceImagePlaceHolders_worker: " . $attachment['wp_filename']);
2117
 
2118
  if (empty($attachment['template'])) {
2119
  DebugEcho("filter_ReplaceImagePlaceHolders_worker: no template");
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.8.14
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
  License: GPL2
@@ -28,7 +28,7 @@
28
  */
29
 
30
  /*
31
- $Id: postie.php 1526284 2016-11-01 21:17:11Z WayneAllen $
32
  */
33
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fException.php");
34
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fUnexpectedException.php");
@@ -49,7 +49,7 @@ require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/pPop3MailServer.php"
49
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib_autolink.php");
50
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "postie-functions.php");
51
 
52
- define('POSTIE_VERSION', '1.8.14');
53
  define("POSTIE_ROOT", dirname(__FILE__));
54
  define("POSTIE_URL", WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
55
 
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.8.15
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
  License: GPL2
28
  */
29
 
30
  /*
31
+ $Id: postie.php 1526978 2016-11-02 20:50:22Z WayneAllen $
32
  */
33
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fException.php");
34
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib/fUnexpectedException.php");
49
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib_autolink.php");
50
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "postie-functions.php");
51
 
52
+ define('POSTIE_VERSION', '1.8.15');
53
  define("POSTIE_ROOT", dirname(__FILE__));
54
  define("POSTIE_URL", WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
55
 
readme.txt CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.6.1
9
- Stable tag: 1.8.14
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -240,6 +240,9 @@ All script, style and body tags are stripped from html emails.
240
  Attachments are now processed in the order they were attached.
241
 
242
  == CHANGELOG ==
 
 
 
243
  = 1.8.14 (2016-11-01) =
244
  * Fix bug where OS detection failure was preventing email processing
245
 
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.6.1
9
+ Stable tag: 1.8.15
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
240
  Attachments are now processed in the order they were attached.
241
 
242
  == CHANGELOG ==
243
+ = 1.8.15 (2016-11-02) =
244
+ * Fix bug where inline images were not being replaced correctly if WordPress changed the name of the attachment via sanitize_file_name()
245
+
246
  = 1.8.14 (2016-11-01) =
247
  * Fix bug where OS detection failure was preventing email processing
248