Postie - Version 1.4.26

Version Description

(2013.01.15) = * Fixed a bug where signatures were not removed in html emails * Added support for text attachments such as text/calendar

Download this release

Release Info

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

Code changes from version 1.4.25 to 1.4.26

Revision CHANGED
@@ -1,2 +0,0 @@
1
- Revision: 653072
2
- Last Changed Date: 2013-01-13 21:19:07 -0800 (Sun, 13 Jan 2013)
 
 
docs/Changes.txt CHANGED
@@ -10,6 +10,10 @@ All script, style and body tags are stripped from html emails.
10
  Attachments are now processed in the order they were attached.
11
 
12
  == CHANGELOG ==
 
 
 
 
13
  = 1.4.25 (2013.01.15) =
14
  * Fixed a bug where newlines were being removed erroneously.
15
 
10
  Attachments are now processed in the order they were attached.
11
 
12
  == CHANGELOG ==
13
+ = 1.4.26 (2013.01.15) =
14
+ * Fixed a bug where signatures were not removed in html emails.
15
+ * Added support for text attachments such as text/calendar.
16
+
17
  = 1.4.25 (2013.01.15) =
18
  * Fixed a bug where newlines were being removed erroneously.
19
 
docs/Postie.txt CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
  Tested up to: 3.5
9
- Stable tag: 1.4.25
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
  Tested up to: 3.5
9
+ Stable tag: 1.4.26
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
get_mail.php CHANGED
@@ -37,6 +37,7 @@ EchoInfo(sprintf(__("There are %d messages to process", "postie"), count($emails
37
  if (function_exists('memory_get_usage'))
38
  EchoInfo(__("memory at start of e-mail processing:") . memory_get_usage());
39
 
 
40
  DebugDump($config);
41
 
42
  //loop through messages
37
  if (function_exists('memory_get_usage'))
38
  EchoInfo(__("memory at start of e-mail processing:") . memory_get_usage());
39
 
40
+ DebugEcho("Error log: " . ini_get('error_log'));
41
  DebugDump($config);
42
 
43
  //loop through messages
postie-functions.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  /*
4
- $Id: postie-functions.php 653157 2013-01-15 20:15:38Z WayneAllen $
5
  */
6
 
7
  /* TODO
@@ -152,7 +152,7 @@ function tag_Date(&$content, $message_date) {
152
 
153
  function CreatePost($poster, $mimeDecodedEmail, $post_id, &$is_reply, $config) {
154
 
155
- $fulldebug = true;
156
 
157
  extract($config);
158
 
@@ -188,8 +188,9 @@ function CreatePost($poster, $mimeDecodedEmail, $post_id, &$is_reply, $config) {
188
  DebugEcho("post sig: $content");
189
 
190
  $post_excerpt = tag_Excerpt($content, $filternewlines, $convertnewline);
191
- if ($fulldebug)
192
- DebugEcho("post excerpt: $content");
 
193
 
194
  $postAuthorDetails = getPostAuthorDetails($subject, $content, $mimeDecodedEmail);
195
  if ($fulldebug)
@@ -251,10 +252,11 @@ function CreatePost($poster, $mimeDecodedEmail, $post_id, &$is_reply, $config) {
251
  if ($fulldebug)
252
  DebugEcho("post body img: $content");
253
 
254
- filter_ReplaceImagePlaceHolders($post_excerpt, $attachments["html"], $config);
255
- if ($fulldebug)
256
- DebugEcho("post excerpt img: $content");
257
-
 
258
 
259
  $customImages = tag_CustomImageField($content, $attachments, $config);
260
  if ($fulldebug)
@@ -420,7 +422,7 @@ function filter_linkify($text) {
420
  # It turns urls into links, and video urls into embedded players
421
  //DebugEcho("begin: filter_linkify");
422
 
423
- $html = str_get_html($text, true, true, DEFAULT_TARGET_CHARSET, false);
424
  if ($html) {
425
  //DebugEcho("filter_linkify: " . $html->save());
426
  foreach ($html->find('text') as $element) {
@@ -436,11 +438,15 @@ function filter_linkify($text) {
436
  return $ret;
437
  }
438
 
 
 
 
 
439
  function filter_Videos($text, $shortcode = false) {
440
  # It turns urls into links, and video urls into embedded players
441
  //DebugEcho("begin: filter_Videos");
442
 
443
- $html = str_get_html($text, true, true, DEFAULT_TARGET_CHARSET, false);
444
  if ($html) {
445
  foreach ($html->find('text') as $element) {
446
  $element->innertext = linkifyVideo($element->innertext, $shortcode);
@@ -906,7 +912,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
906
  //strip excess HTML
907
  DebugEcho("html");
908
  $meta_return .= filter_CleanHtml($part->body) . "\n";
909
- } else {
910
  DebugEcho("plain text");
911
  if ($allow_html_in_body) {
912
  DebugEcho("html allowed");
@@ -918,6 +924,12 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
918
  }
919
  $meta_return = filter_StripPGP($meta_return);
920
  DebugEcho("meta return: $meta_return");
 
 
 
 
 
 
921
  }
922
 
923
  break;
@@ -1196,20 +1208,57 @@ function filter_RemoveSignature(&$content, $config) {
1196
  if ($config['drop_signature']) {
1197
  if (empty($config['sig_pattern_list']))
1198
  return;
 
1199
 
1200
- $arrcontent = explode("\n", $content);
1201
- $strcontent = '';
1202
- $pattern = '/^(' . implode('|', $config['sig_pattern_list']) . ')/';
1203
- for ($i = 0; $i < count($arrcontent); $i++) {
1204
- $line = trim($arrcontent[$i]);
1205
- if (preg_match($pattern, trim($line))) {
1206
- DebugEcho("signature found: removing");
1207
- break;
 
 
 
 
 
 
 
 
 
 
1208
  }
1209
- $strcontent .= $line . "\n";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1210
  }
1211
- $content = $strcontent;
1212
  }
 
1213
  }
1214
 
1215
  /**
@@ -1305,9 +1354,9 @@ function HandleMessageEncoding($contenttransferencoding, $charset, $body, $blogE
1305
  DebugEcho("after HandleMessageEncoding");
1306
  if (!empty($charset) && strtolower($charset) != 'default') {
1307
  DebugEcho("converting from $charset to $blogEncoding");
1308
- DebugEcho("before: $body");
1309
  $body = iconv($charset, $blogEncoding . '//TRANSLIT', $body);
1310
- DebugEcho("after: $body");
1311
  }
1312
  return $body;
1313
  }
@@ -1664,7 +1713,12 @@ function filter_PreferedText($mimeDecodedEmail, $preferTextType) {
1664
  DebugEcho("part: $i " . $mimeDecodedEmail->parts[$i]->ctype_primary);
1665
 
1666
  if ($mimeDecodedEmail->parts[$i]->ctype_primary == "text") {
1667
- if ($mimeDecodedEmail->parts[$i]->ctype_secondary == $preferTextType) {
 
 
 
 
 
1668
  $newParts[] = $mimeDecodedEmail->parts[$i];
1669
  }
1670
  } else {
1
  <?php
2
 
3
  /*
4
+ $Id: postie-functions.php 653384 2013-01-16 05:23:05Z WayneAllen $
5
  */
6
 
7
  /* TODO
152
 
153
  function CreatePost($poster, $mimeDecodedEmail, $post_id, &$is_reply, $config) {
154
 
155
+ $fulldebug = false;
156
 
157
  extract($config);
158
 
188
  DebugEcho("post sig: $content");
189
 
190
  $post_excerpt = tag_Excerpt($content, $filternewlines, $convertnewline);
191
+ //if ($fulldebug)
192
+ DebugEcho("post excerpt: $content");
193
+ DebugEcho("post excerpt excerpt: $post_excerpt");
194
 
195
  $postAuthorDetails = getPostAuthorDetails($subject, $content, $mimeDecodedEmail);
196
  if ($fulldebug)
252
  if ($fulldebug)
253
  DebugEcho("post body img: $content");
254
 
255
+ if ($post_excerpt) {
256
+ filter_ReplaceImagePlaceHolders($post_excerpt, $attachments["html"], $config);
257
+ if ($fulldebug)
258
+ DebugEcho("post excerpt img: $content");
259
+ }
260
 
261
  $customImages = tag_CustomImageField($content, $attachments, $config);
262
  if ($fulldebug)
422
  # It turns urls into links, and video urls into embedded players
423
  //DebugEcho("begin: filter_linkify");
424
 
425
+ $html = LoadDOM($text);
426
  if ($html) {
427
  //DebugEcho("filter_linkify: " . $html->save());
428
  foreach ($html->find('text') as $element) {
438
  return $ret;
439
  }
440
 
441
+ function LoadDOM($text) {
442
+ return str_get_html($text, true, true, DEFAULT_TARGET_CHARSET, false);
443
+ }
444
+
445
  function filter_Videos($text, $shortcode = false) {
446
  # It turns urls into links, and video urls into embedded players
447
  //DebugEcho("begin: filter_Videos");
448
 
449
+ $html = LoadDOM($text);
450
  if ($html) {
451
  foreach ($html->find('text') as $element) {
452
  $element->innertext = linkifyVideo($element->innertext, $shortcode);
912
  //strip excess HTML
913
  DebugEcho("html");
914
  $meta_return .= filter_CleanHtml($part->body) . "\n";
915
+ } elseif ($part->ctype_secondary == 'plain') {
916
  DebugEcho("plain text");
917
  if ($allow_html_in_body) {
918
  DebugEcho("html allowed");
924
  }
925
  $meta_return = filter_StripPGP($meta_return);
926
  DebugEcho("meta return: $meta_return");
927
+ } else {
928
+ DebugEcho("text Attachement: $filename");
929
+ $file_id = postie_media_handle_upload($part, $post_id, $poster);
930
+ $file = wp_get_attachment_url($file_id);
931
+ $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $icon_set, $icon_size);
932
+ $attachments["html"][$filename] = "<a href='$file'>" . $icon . $filename . '</a>' . "\n";
933
  }
934
 
935
  break;
1208
  if ($config['drop_signature']) {
1209
  if (empty($config['sig_pattern_list']))
1210
  return;
1211
+ DebugEcho("looking for signature in: $content");
1212
 
1213
+ $pattern = '/^(' . implode('|', $config['sig_pattern_list']) . ')/m';
1214
+
1215
+ $html = LoadDOM($content);
1216
+ if ($html !== false) {
1217
+ filter_RemoveSignatureWorker($html->root, $pattern);
1218
+ $content = $html->save();
1219
+ } else {
1220
+ DebugEcho("sig non-html");
1221
+ $arrcontent = explode("\n", $content);
1222
+ $strcontent = '';
1223
+
1224
+ for ($i = 0; $i < count($arrcontent); $i++) {
1225
+ $line = trim($arrcontent[$i]);
1226
+ if (preg_match($pattern, trim($line))) {
1227
+ DebugEcho("signature found: removing");
1228
+ break;
1229
+ }
1230
+ $strcontent .= $line;
1231
  }
1232
+ $content = $strcontent;
1233
+ }
1234
+ }
1235
+ }
1236
+
1237
+ function filter_RemoveSignatureWorker(&$html, $pattern) {
1238
+ $found = false;
1239
+ DebugEcho("sig count children: " . count($html->children()));
1240
+ if (preg_match($pattern, trim($html->plaintext), $matches)) {
1241
+ DebugEcho("signature found in base: removing");
1242
+ $found = true;
1243
+ $i = stripos($html->innertext, $matches[1]);
1244
+ $presig = substr($html->innertext, 0, $i);
1245
+ DebugEcho("sig new text: '$presig'");
1246
+ $html->innertext = $presig;
1247
+ }
1248
+
1249
+ foreach ($html->children() as $e) {
1250
+ DebugEcho("sig: " . $e->plaintext);
1251
+ if (!$found && preg_match($pattern, trim($e->plaintext))) {
1252
+ DebugEcho("signature found: removing");
1253
+ $found = true;
1254
+ }
1255
+ if ($found) {
1256
+ $e->outertext = '';
1257
+ } else {
1258
+ $found = filter_RemoveSignatureWorker($e, $pattern);
1259
  }
 
1260
  }
1261
+ return $found;
1262
  }
1263
 
1264
  /**
1354
  DebugEcho("after HandleMessageEncoding");
1355
  if (!empty($charset) && strtolower($charset) != 'default') {
1356
  DebugEcho("converting from $charset to $blogEncoding");
1357
+ //DebugEcho("before: $body");
1358
  $body = iconv($charset, $blogEncoding . '//TRANSLIT', $body);
1359
+ //DebugEcho("after: $body");
1360
  }
1361
  return $body;
1362
  }
1713
  DebugEcho("part: $i " . $mimeDecodedEmail->parts[$i]->ctype_primary);
1714
 
1715
  if ($mimeDecodedEmail->parts[$i]->ctype_primary == "text") {
1716
+ $ctype = $mimeDecodedEmail->parts[$i]->ctype_secondary;
1717
+ if ($ctype == 'html' || $ctype == 'plain') {
1718
+ if ($ctype == $preferTextType) {
1719
+ $newParts[] = $mimeDecodedEmail->parts[$i];
1720
+ }
1721
+ } else {
1722
  $newParts[] = $mimeDecodedEmail->parts[$i];
1723
  }
1724
  } else {
postie.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  Description: Signifigantly upgrades the posting by mail features of Word Press (See <a href='options-general.php?page=postie/postie.php'>Settings and options</a>) to configure your e-mail settings. See the <a href='http://wordpress.org/extend/plugins/postie/other_notes'>Readme</a> for usage. Visit the <a href='http://wordpress.org/support/plugin/postie'>postie forum</a> for support.
7
- Version: 1.4.25
8
  Author: Wayne Allen
9
  Author URI: http://allens-home.com/
10
  License: GPL2
@@ -27,7 +27,7 @@
27
  */
28
 
29
  /*
30
- $Id: postie.php 653157 2013-01-15 20:15:38Z WayneAllen $
31
  * -= Requests Pending =-
32
  * Problem with some mail server
33
  * Multiple emails should tie to a single account
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  Description: Signifigantly upgrades the posting by mail features of Word Press (See <a href='options-general.php?page=postie/postie.php'>Settings and options</a>) to configure your e-mail settings. See the <a href='http://wordpress.org/extend/plugins/postie/other_notes'>Readme</a> for usage. Visit the <a href='http://wordpress.org/support/plugin/postie'>postie forum</a> for support.
7
+ Version: 1.4.26
8
  Author: Wayne Allen
9
  Author URI: http://allens-home.com/
10
  License: GPL2
27
  */
28
 
29
  /*
30
+ $Id: postie.php 653384 2013-01-16 05:23:05Z WayneAllen $
31
  * -= Requests Pending =-
32
  * Problem with some mail server
33
  * Multiple emails should tie to a single account
postie_test.php CHANGED
@@ -15,7 +15,7 @@ if (!current_user_can('manage_options')) {
15
  echo "<h2> Sorry only admin can run this file</h2>";
16
  exit();
17
  }
18
-
19
  $images = array("Test.png", "Test.jpg", "Test.gif");
20
  ?>
21
  <div class="wrap">
15
  echo "<h2> Sorry only admin can run this file</h2>";
16
  exit();
17
  }
18
+ DebugEcho("Error log: " . ini_get('error_log'));
19
  $images = array("Test.png", "Test.jpg", "Test.gif");
20
  ?>
21
  <div class="wrap">
readme.txt CHANGED
@@ -6,7 +6,7 @@ Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
  Tested up to: 3.5
9
- Stable tag: 1.4.25
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -398,6 +398,10 @@ All script, style and body tags are stripped from html emails.
398
  Attachments are now processed in the order they were attached.
399
 
400
  == CHANGELOG ==
 
 
 
 
401
  = 1.4.25 (2013.01.15) =
402
  * Fixed a bug where newlines were being removed erroneously.
403
 
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
  Tested up to: 3.5
9
+ Stable tag: 1.4.26
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
398
  Attachments are now processed in the order they were attached.
399
 
400
  == CHANGELOG ==
401
+ = 1.4.26 (2013.01.15) =
402
+ * Fixed a bug where signatures were not removed in html emails
403
+ * Added support for text attachments such as text/calendar
404
+
405
  = 1.4.25 (2013.01.15) =
406
  * Fixed a bug where newlines were being removed erroneously.
407
 
test/inlineimageTest.php CHANGED
@@ -47,7 +47,7 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
47
  $config['imagetemplate'] = '<a href="{FILELINK}">{FILENAME}</a>';
48
 
49
  $post = $this->process_file("data/inline.var", $config);
50
- $this->assertEquals('test<div><br></div><div><img src="http://example.net/wp-content/uploads/filename" alt="Inline image 1"><br></div><div><br></div><div>test</div> ', $post['post_content']);
51
  $this->assertEquals('inline', $post['post_title']);
52
  }
53
 
@@ -57,7 +57,7 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
57
  $config['convertnewline'] = true;
58
 
59
  $post = $this->process_file("data/linebreaks.var", $config);
60
- $this->assertEquals("Test<br />\nEen stuck TekstEen stuck TekstEen stuck TekstEen stuck Tekst<br />\nEen stuck TekstEen stuck Tekst<br />\n<br />\nEen stuck TekstEen stuck Tekst<br />\n<br />\n", $post['post_content']);
61
  }
62
 
63
  function testjapaneseAttachment() {
@@ -75,7 +75,7 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
75
  $config['prefer_text_type'] = 'html';
76
 
77
  $post = $this->process_file("data/ics-attachment.var", $config);
78
- $this->assertEquals("<div dir='ltr'>sample text<div><br></div></div> <a href='http://example.net/wp-content/uploads/filename'><img src='localhost/postie/icons/silver/default-32.png' alt='default icon' />sample.ics</a> ", $post['post_content']);
79
  }
80
 
81
  function testTagsImg() {
@@ -94,14 +94,14 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
94
 
95
  function testSig() {
96
  $config = config_GetDefaults();
97
- $config['prefer_text_type'] = 'plain';
98
 
99
  $post = $this->process_file("data/signature.var", $config);
100
- $this->assertEquals('test content ', $post['post_content']);
101
 
102
  $config['prefer_text_type'] = 'html';
103
  $post = $this->process_file("data/signature.var", $config);
104
- $this->assertEquals('test content ', $post['post_content']);
105
  }
106
 
107
  function testQuotedPrintable() {
47
  $config['imagetemplate'] = '<a href="{FILELINK}">{FILENAME}</a>';
48
 
49
  $post = $this->process_file("data/inline.var", $config);
50
+ $this->assertEquals('test<div><br></div><div><img src="http://example.net/wp-content/uploads/filename" alt="Inline image 1"><br></div><div><br></div><div>test</div> ', $post['post_content']);
51
  $this->assertEquals('inline', $post['post_title']);
52
  }
53
 
57
  $config['convertnewline'] = true;
58
 
59
  $post = $this->process_file("data/linebreaks.var", $config);
60
+ $this->assertEquals("Test<br />\nEen stuck TekstEen stuck TekstEen stuck TekstEen stuck Tekst<br />\nEen stuck TekstEen stuck Tekst<br />\n<br />\nEen stuck TekstEen stuck Tekst<br />\n<br />", $post['post_content']);
61
  }
62
 
63
  function testjapaneseAttachment() {
75
  $config['prefer_text_type'] = 'html';
76
 
77
  $post = $this->process_file("data/ics-attachment.var", $config);
78
+ $this->assertEquals("<div dir='ltr'>sample text<div><br></div></div> <a href='http://example.net/wp-content/uploads/filename'><img src='localhost/postie/icons/silver/default-32.png' alt='default icon' />sample.ics</a> ", $post['post_content']);
79
  }
80
 
81
  function testTagsImg() {
94
 
95
  function testSig() {
96
  $config = config_GetDefaults();
97
+ $config['prefer_text_type'] = 'html';
98
 
99
  $post = $this->process_file("data/signature.var", $config);
100
+ $this->assertEquals('test content<div><br></div><div> ', $post['post_content']);
101
 
102
  $config['prefer_text_type'] = 'html';
103
  $post = $this->process_file("data/signature.var", $config);
104
+ $this->assertEquals('test content<div><br></div><div> ', $post['post_content']);
105
  }
106
 
107
  function testQuotedPrintable() {
test/postie-functionsTest.php CHANGED
@@ -369,19 +369,19 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
369
 
370
  $c = "";
371
  filter_RemoveSignature($c, $config);
372
- $this->assertEquals("\n", $c);
373
 
374
  $c = "test";
375
  filter_RemoveSignature($c, $config);
376
- $this->assertEquals("test\n", $c);
377
 
378
  $c = "";
379
  filter_RemoveSignature($c, $config);
380
- $this->assertEquals("\n", $c);
381
 
382
  $c = "test";
383
  filter_RemoveSignature($c, $config);
384
- $this->assertEquals("test\n", $c);
385
 
386
  $c = "line 1\nline 2\n--\nsig line 1\nsig line 2";
387
  filter_RemoveSignature($c, $config);
@@ -395,7 +395,7 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
395
  filter_RemoveSignature($c, $config);
396
  $this->assertEquals("line 1\nline 2\n", $c);
397
 
398
- $c = "line 1\nline 2\n --\nsig line 1\nsig line 2";
399
  filter_RemoveSignature($c, $config);
400
  $this->assertEquals("line 1\nline 2\n", $c);
401
 
369
 
370
  $c = "";
371
  filter_RemoveSignature($c, $config);
372
+ $this->assertEquals("", $c);
373
 
374
  $c = "test";
375
  filter_RemoveSignature($c, $config);
376
+ $this->assertEquals("test", $c);
377
 
378
  $c = "";
379
  filter_RemoveSignature($c, $config);
380
+ $this->assertEquals("", $c);
381
 
382
  $c = "test";
383
  filter_RemoveSignature($c, $config);
384
+ $this->assertEquals("test", $c);
385
 
386
  $c = "line 1\nline 2\n--\nsig line 1\nsig line 2";
387
  filter_RemoveSignature($c, $config);
395
  filter_RemoveSignature($c, $config);
396
  $this->assertEquals("line 1\nline 2\n", $c);
397
 
398
+ $c = "line 1\nline 2\n--\nsig line 1\nsig line 2";
399
  filter_RemoveSignature($c, $config);
400
  $this->assertEquals("line 1\nline 2\n", $c);
401