Postie - Version 1.4.37

Version Description

(2013.03.11) = * Fixed bug in tag handling * Fixed bug in category detection * Worked around a bug in WordPress that was mangling filenames that are not in ASCII, i.e. Arabic, Hebrew, Cyrillic, etc.

Download this release

Release Info

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

Code changes from version 1.4.36 to 1.4.37

Revision CHANGED
@@ -1,2 +1,2 @@
1
- Revision: 677681
2
- Last Changed Date: 2013-03-06 21:55:00 -0800 (Wed, 06 Mar 2013)
1
+ Revision: 679961
2
+ Last Changed Date: 2013-03-08 16:05:57 -0800 (Fri, 08 Mar 2013)
docs/Changes.txt CHANGED
@@ -10,6 +10,11 @@ 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.36 (2013.03.07) =
14
  * Removed some debugging code from filters and hooks
15
  * Fixed bug where the date command was being ignored
10
  Attachments are now processed in the order they were attached.
11
 
12
  == CHANGELOG ==
13
+ = 1.4.37 (2013.03.11) =
14
+ * Fixed bug in tag handling
15
+ * Fixed bug in category detection
16
+ * Worked around a bug in WordPress that was mangling filenames that are not in ASCII, i.e. Arabic, Hebrew, Cyrillic, etc.
17
+
18
  = 1.4.36 (2013.03.07) =
19
  * Removed some debugging code from filters and hooks
20
  * Fixed bug where the date command was being ignored
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.1
9
- Stable tag: 1.4.36
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.1
9
+ Stable tag: 1.4.37
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
docs/TODO.txt CHANGED
@@ -10,6 +10,7 @@ setting for default post type
10
  automatically create category if it doesn't exist. new option to allow this feature?
11
  WP MU support
12
  new command to set post status: published, draft, pending review, private
 
13
 
14
  standardize tags
15
  fix postie settings http://alisothegeek.com/2011/01/wordpress-settings-api-tutorial-1/
10
  automatically create category if it doesn't exist. new option to allow this feature?
11
  WP MU support
12
  new command to set post status: published, draft, pending review, private
13
+ support setting "post format"
14
 
15
  standardize tags
16
  fix postie settings http://alisothegeek.com/2011/01/wordpress-settings-api-tutorial-1/
postie-functions.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  /*
4
- $Id: postie-functions.php 677715 2013-03-07 22:06:16Z WayneAllen $
5
  */
6
 
7
  //to turn on debug output add the following line to wp-config.php
@@ -367,19 +367,21 @@ function tag_PostType(&$subject) {
367
 
368
  $custom_post_type_delim = "//";
369
  if (strpos($subject, $custom_post_type_delim) !== FALSE) {
370
-
371
  // Captures the custom post type in the subject before $custom_post_type_delim
372
  $separated_subject = explode($custom_post_type_delim, $subject);
373
  $custom_post_type = $separated_subject[0];
374
  $subject = trim($separated_subject[1]);
 
375
 
376
  $custom_post_type = trim(strtolower($custom_post_type));
377
 
378
  // Check if custom post type exists, if not, set default post type of 'post'
379
  $known_post_types = get_post_types();
 
380
 
381
  if (in_array($custom_post_type, array_map('strtolower', $known_post_types))) {
382
  $post_type = $custom_post_type;
 
383
  } else {
384
  $post_type = 'post';
385
  }
@@ -469,24 +471,24 @@ function linkifyVideo($text, $shortcode = false) {
469
 
470
  function make_links($text) {
471
  return preg_replace(
472
- array(
473
- '/(?(?=<a[^>]*>.+<\/a>)
474
  (?:<a[^>]*>.+<\/a>)
475
  |
476
  ([^="\']?)((?:https?|ftp|bf2|):\/\/[^<> \n\r]+)
477
  )/iex',
478
- '/<a([^>]*)target="?[^"\']+"?/i',
479
- '/<a([^>]+)>/i',
480
- '/(^|\s)(www.[^<> \n\r]+)/iex',
481
- '/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)
482
  (\\.[A-Za-z0-9-]+)*)/iex'
483
- ), array(
484
- "stripslashes((strlen('\\2')>0?'\\1<a href=\"\\2\">\\2</a>\\3':'\\0'))",
485
- '<a\\1',
486
- '<a\\1 >',
487
- "stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\">\\2</a>\\3':'\\0'))",
488
- "stripslashes((strlen('\\2')>0?'<a href=\"mailto:\\0\">\\0</a>':'\\0'))"
489
- ), $text
490
  );
491
  }
492
 
@@ -1646,9 +1648,6 @@ function postie_handle_upload(&$file, $overrides = false, $time = null) {
1646
  // You may define your own function and pass the name in $overrides['upload_error_handler']
1647
  $upload_error_handler = 'wp_handle_upload_error';
1648
 
1649
- // You may define your own function and pass the name in $overrides['unique_filename_callback']
1650
- $unique_filename_callback = null;
1651
-
1652
  // $_POST['action'] must be set and its value must equal $overrides['action'] or this:
1653
  $action = 'wp_handle_upload';
1654
 
@@ -1709,9 +1708,9 @@ function postie_handle_upload(&$file, $overrides = false, $time = null) {
1709
  if (!( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] ))
1710
  return $upload_error_handler($file, $uploads['error']);
1711
 
1712
- // fix filename (remove non-standard characters)
1713
- $file['name'] = preg_replace("/[^\x9\xA\xD\x20-\x7F]/", "", $file['name']);
1714
- $filename = wp_unique_filename($uploads['path'], $file['name'], $unique_filename_callback);
1715
  DebugEcho("wp_unique_filename: $filename");
1716
 
1717
  // Move the file to the uploads dir
@@ -1737,6 +1736,10 @@ function postie_handle_upload(&$file, $overrides = false, $time = null) {
1737
  return $return;
1738
  }
1739
 
 
 
 
 
1740
  /**
1741
  * This method sorts thru the mime parts of the message. It is looking for a certain type of text attachment. If
1742
  * that type is present it filters out all other text types. If it is not - then nothing is done
@@ -2239,7 +2242,7 @@ function tag_Tags(&$content, $defaultTags) {
2239
  if (!empty($matches[1])) {
2240
  DebugEcho("Found tags: $matches[1]");
2241
  $content = str_replace($matches[0], "", $content);
2242
- $post_tags = preg_split("/,\s*/", $matches[1]);
2243
  //DebugDump($post_tags);
2244
  }
2245
  }
@@ -2327,9 +2330,11 @@ function lookup_category($trial_category, $category_match) {
2327
  return $term->term_id;
2328
  }
2329
  $term = get_term_by('id', $trial_category, 'category');
2330
- if ($term !== false) {
 
 
2331
  //then cateogry was an ID and found
2332
- return $term->term_id;
2333
  }
2334
  if (empty($found_category) && $category_match) {
2335
  DebugEcho("category wildcard lookup: $trial_category");
@@ -2801,13 +2806,13 @@ function config_ValidateSettings($in) {
2801
  //DebugDump($in);
2802
  $out = array();
2803
 
2804
- // use the default as a template:
2805
- // if a field is present in the defaults, we want to store it; otherwise we discard it
2806
  $allowed_keys = config_GetDefaults();
2807
  foreach ($allowed_keys as $key => $default)
2808
  $out[$key] = array_key_exists($key, $in) ? $in[$key] : $default;
2809
 
2810
- // some fields are always forced to lower case:
2811
  $lowercase = array('authorized_addresses', 'smtp', 'supported_file_types', 'video1types', 'video2types', 'audiotypes');
2812
  foreach ($lowercase as $field) {
2813
  $out[$field] = ( is_array($out[$field]) ) ? array_map("strtolower", $out[$field]) : strtolower($out[$field]);
1
  <?php
2
 
3
  /*
4
+ $Id: postie-functions.php 680123 2013-03-11 23:18:14Z WayneAllen $
5
  */
6
 
7
  //to turn on debug output add the following line to wp-config.php
367
 
368
  $custom_post_type_delim = "//";
369
  if (strpos($subject, $custom_post_type_delim) !== FALSE) {
 
370
  // Captures the custom post type in the subject before $custom_post_type_delim
371
  $separated_subject = explode($custom_post_type_delim, $subject);
372
  $custom_post_type = $separated_subject[0];
373
  $subject = trim($separated_subject[1]);
374
+ DebugEcho("post type: found possible type '$custom_post_type'");
375
 
376
  $custom_post_type = trim(strtolower($custom_post_type));
377
 
378
  // Check if custom post type exists, if not, set default post type of 'post'
379
  $known_post_types = get_post_types();
380
+ DebugDump($known_post_types);
381
 
382
  if (in_array($custom_post_type, array_map('strtolower', $known_post_types))) {
383
  $post_type = $custom_post_type;
384
+ DebugEcho("post type: found type '$post_type'");
385
  } else {
386
  $post_type = 'post';
387
  }
471
 
472
  function make_links($text) {
473
  return preg_replace(
474
+ array(
475
+ '/(?(?=<a[^>]*>.+<\/a>)
476
  (?:<a[^>]*>.+<\/a>)
477
  |
478
  ([^="\']?)((?:https?|ftp|bf2|):\/\/[^<> \n\r]+)
479
  )/iex',
480
+ '/<a([^>]*)target="?[^"\']+"?/i',
481
+ '/<a([^>]+)>/i',
482
+ '/(^|\s)(www.[^<> \n\r]+)/iex',
483
+ '/(([_A-Za-z0-9-]+)(\\.[_A-Za-z0-9-]+)*@([A-Za-z0-9-]+)
484
  (\\.[A-Za-z0-9-]+)*)/iex'
485
+ ), array(
486
+ "stripslashes((strlen('\\2')>0?'\\1<a href=\"\\2\">\\2</a>\\3':'\\0'))",
487
+ '<a\\1',
488
+ '<a\\1 >',
489
+ "stripslashes((strlen('\\2')>0?'\\1<a href=\"http://\\2\">\\2</a>\\3':'\\0'))",
490
+ "stripslashes((strlen('\\2')>0?'<a href=\"mailto:\\0\">\\0</a>':'\\0'))"
491
+ ), $text
492
  );
493
  }
494
 
1648
  // You may define your own function and pass the name in $overrides['upload_error_handler']
1649
  $upload_error_handler = 'wp_handle_upload_error';
1650
 
 
 
 
1651
  // $_POST['action'] must be set and its value must equal $overrides['action'] or this:
1652
  $action = 'wp_handle_upload';
1653
 
1708
  if (!( ( $uploads = wp_upload_dir($time) ) && false === $uploads['error'] ))
1709
  return $upload_error_handler($file, $uploads['error']);
1710
 
1711
+ // fix filename (encode non-standard characters)
1712
+ $file['name'] = filename_fix($file['name']);
1713
+ $filename = wp_unique_filename($uploads['path'], $file['name']);
1714
  DebugEcho("wp_unique_filename: $filename");
1715
 
1716
  // Move the file to the uploads dir
1736
  return $return;
1737
  }
1738
 
1739
+ function filename_fix($filename) {
1740
+ return str_replace ('%','',urlencode($filename));
1741
+ }
1742
+
1743
  /**
1744
  * This method sorts thru the mime parts of the message. It is looking for a certain type of text attachment. If
1745
  * that type is present it filters out all other text types. If it is not - then nothing is done
2242
  if (!empty($matches[1])) {
2243
  DebugEcho("Found tags: $matches[1]");
2244
  $content = str_replace($matches[0], "", $content);
2245
+ $post_tags = preg_split("/,\s*/", trim($matches[1]));
2246
  //DebugDump($post_tags);
2247
  }
2248
  }
2330
  return $term->term_id;
2331
  }
2332
  $term = get_term_by('id', $trial_category, 'category');
2333
+ if (is_array($term)) {
2334
+ DebugEcho("category: found by id $trial_category");
2335
+ DebugDump($term);
2336
  //then cateogry was an ID and found
2337
+ return $term['term_id'];
2338
  }
2339
  if (empty($found_category) && $category_match) {
2340
  DebugEcho("category wildcard lookup: $trial_category");
2806
  //DebugDump($in);
2807
  $out = array();
2808
 
2809
+ // use the default as a template:
2810
+ // if a field is present in the defaults, we want to store it; otherwise we discard it
2811
  $allowed_keys = config_GetDefaults();
2812
  foreach ($allowed_keys as $key => $default)
2813
  $out[$key] = array_key_exists($key, $in) ? $in[$key] : $default;
2814
 
2815
+ // some fields are always forced to lower case:
2816
  $lowercase = array('authorized_addresses', 'smtp', 'supported_file_types', 'video1types', 'video2types', 'audiotypes');
2817
  foreach ($lowercase as $field) {
2818
  $out[$field] = ( is_array($out[$field]) ) ? array_map("strtolower", $out[$field]) : strtolower($out[$field]);
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.36
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 677715 2013-03-07 22:06:16Z WayneAllen $
31
  */
32
 
33
  define("POSTIE_ROOT", dirname(__FILE__));
@@ -199,23 +199,29 @@ function check_postie() {
199
  }
200
 
201
  function postie_cron($interval = false) {
 
202
  if (!$interval) {
203
  $config = config_Read();
204
  $interval = $config['interval'];
 
205
  }
206
- if (!$interval || $interval == '')
207
  $interval = 'hourly';
 
 
208
  if ($interval == 'manual') {
209
- wp_clear_scheduled_hook('check_postie_hook');
 
210
  } else {
211
  if (false === wp_schedule_event(time(), $interval, 'check_postie_hook')) {
212
  //Do not echo output in filters, it seems to break some installs
213
- error_log("Postie: Failed to set up cron task.");
214
  }
215
  }
216
  }
217
 
218
  function postie_decron() {
 
219
  wp_clear_scheduled_hook('check_postie_hook');
220
  }
221
 
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.37
8
  Author: Wayne Allen
9
  Author URI: http://allens-home.com/
10
  License: GPL2
27
  */
28
 
29
  /*
30
+ $Id: postie.php 680123 2013-03-11 23:18:14Z WayneAllen $
31
  */
32
 
33
  define("POSTIE_ROOT", dirname(__FILE__));
199
  }
200
 
201
  function postie_cron($interval = false) {
202
+ error_log("Postie: setting up cron task: $interval");
203
  if (!$interval) {
204
  $config = config_Read();
205
  $interval = $config['interval'];
206
+ error_log("Postie: setting up cron task from config: $interval");
207
  }
208
+ if (!$interval || $interval == ''){
209
  $interval = 'hourly';
210
+ error_log("Postie: setting up cron task: defaulting to hourly");
211
+ }
212
  if ($interval == 'manual') {
213
+ postie_decron();
214
+ error_log("Postie: clearing cron (manual)");
215
  } else {
216
  if (false === wp_schedule_event(time(), $interval, 'check_postie_hook')) {
217
  //Do not echo output in filters, it seems to break some installs
218
+ error_log("Postie: Failed to set up cron task: $interval");
219
  }
220
  }
221
  }
222
 
223
  function postie_decron() {
224
+ error_log("Postie: clearing cron");
225
  wp_clear_scheduled_hook('check_postie_hook');
226
  }
227
 
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.1
9
- Stable tag: 1.4.36
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -426,6 +426,11 @@ All script, style and body tags are stripped from html emails.
426
  Attachments are now processed in the order they were attached.
427
 
428
  == CHANGELOG ==
 
 
 
 
 
429
  = 1.4.36 (2013.03.07) =
430
  * Removed some debugging code from filters and hooks
431
  * Fixed bug where the date command was being ignored
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
  Tested up to: 3.5.1
9
+ Stable tag: 1.4.37
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
426
  Attachments are now processed in the order they were attached.
427
 
428
  == CHANGELOG ==
429
+ = 1.4.37 (2013.03.11) =
430
+ * Fixed bug in tag handling
431
+ * Fixed bug in category detection
432
+ * Worked around a bug in WordPress that was mangling filenames that are not in ASCII, i.e. Arabic, Hebrew, Cyrillic, etc.
433
+
434
  = 1.4.36 (2013.03.07) =
435
  * Removed some debugging code from filters and hooks
436
  * Fixed bug where the date command was being ignored
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,6 +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", $post['post_content']);
61
  }
62
 
@@ -75,7 +76,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() {
@@ -97,11 +98,11 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
97
  $config['prefer_text_type'] = 'html';
98
 
99
  $post = $this->process_file("data/signature.var", $config);
100
- $this->assertEquals('test content<div><br></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> ', $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
+ echo $post['post_content'];
61
  $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", $post['post_content']);
62
  }
63
 
76
  $config['prefer_text_type'] = 'html';
77
 
78
  $post = $this->process_file("data/ics-attachment.var", $config);
79
+ $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']);
80
  }
81
 
82
  function testTagsImg() {
98
  $config['prefer_text_type'] = 'html';
99
 
100
  $post = $this->process_file("data/signature.var", $config);
101
+ $this->assertEquals('test content<div><br></div> ', $post['post_content']);
102
 
103
  $config['prefer_text_type'] = 'html';
104
  $post = $this->process_file("data/signature.var", $config);
105
+ $this->assertEquals('test content<div><br></div> ', $post['post_content']);
106
  }
107
 
108
  function testQuotedPrintable() {
test/postie-functionsTest.php CHANGED
@@ -581,6 +581,19 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
581
  $this->assertEquals("stuff ", $e);
582
  }
583
 
 
 
 
 
 
 
 
 
 
 
 
 
 
584
  }
585
 
586
  ?>
581
  $this->assertEquals("stuff ", $e);
582
  }
583
 
584
+ function test_filename_fix() {
585
+ $f = "simple.png";
586
+ $this->assertEquals($f, filename_fix($f));
587
+
588
+ $f = "moiré-pättern.png";
589
+ $this->assertEquals("moireCC81-paCC88ttern.png", filename_fix($f));
590
+
591
+ $f = "וְאָהַבְתָּ.png";
592
+ $this->assertEquals("D795D6B0D790D6B8D794D6B7D791D6B0D7AAD6BCD6B8.png", filename_fix($f));
593
+
594
+ $this->assertEquals("D09AD0BED0B3D0B0D182D0BE.png",filename_fix("Когато.png"));
595
+ }
596
+
597
  }
598
 
599
  ?>