Postie - Version 1.7.17

Version Description

(2015-10-12) = * New action, postie_log_error * New action, postie_log_debug * New feature to turn off all logging * Only errors logged by default

Download this release

Release Info

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

Code changes from version 1.7.16 to 1.7.17

Files changed (7) hide show
  1. config_form.php +7 -3
  2. docs/Changes.txt +6 -0
  3. docs/Postie.txt +1 -1
  4. postie-functions.php +192 -169
  5. postie.php +3 -3
  6. postieIMAP.php +3 -3
  7. readme.txt +7 -1
config_form.php CHANGED
@@ -241,14 +241,14 @@
241
  }
242
  ?>><?php _e('every 30 seconds', 'postie') ?>
243
  </option>
244
-
245
  <option value="fifteenseconds" <?php
246
  if ($interval == "fifteenseconds") {
247
  echo "selected='selected'";
248
  }
249
  ?>><?php _e('every 15 seconds', 'postie') ?>
250
  </option>
251
-
252
  <option value="manual" <?php
253
  if ($interval == "manual") {
254
  echo "selected='selected'";
@@ -277,6 +277,10 @@
277
  <?php echo BuildBooleanSelect(__("Delete email after posting", 'postie'), 'postie-settings[delete_mail_after_processing]', $delete_mail_after_processing, __("Only set to no for testing purposes", 'postie')); ?>
278
  <?php echo BuildBooleanSelect(__("Ignore mail state", 'postie'), 'postie-settings[ignore_mail_state]', $ignore_mail_state, __("Ignore whether the mails is 'read' or 'unread' If 'No' then only unread messages are processed.", 'postie')); ?>
279
  <?php echo BuildTextArea(__("Allowed SMTP servers", 'postie'), "postie-settings[smtp]", $smtp, __("Only allow messages which have been sent throught the following SMTP servers. Put each server on a separate line. Leave blank to allow any SMTP server.", 'postie')); ?>
 
 
 
 
280
  </table>
281
  </div>
282
 
@@ -450,7 +454,7 @@
450
 
451
  <?php echo BuildBooleanSelect(__("Treat Replies As", 'postie'), "postie-settings[reply_as_comment]", $reply_as_comment, "", array("comments", "new posts")); ?>
452
  <?php echo BuildBooleanSelect(__("Strip Original Content from Replies", 'postie'), "postie-settings[strip_reply]", $strip_reply, "Only applicable if replies are trated as comments"); ?>
453
-
454
  <?php echo BuildBooleanSelect(__("Forward Rejected Mail", 'postie'), "postie-settings[forward_rejected_mail]", $forward_rejected_mail); ?>
455
  <?php echo BuildBooleanSelect(__("Allow Subject In Mail", 'postie'), "postie-settings[allow_subject_in_mail]", $allow_subject_in_mail, "Enclose the subject between '#' on the very first line. E.g. #this is my subject#"); ?>
456
  <?php echo BuildBooleanSelect(__("Allow HTML In Mail Subject", 'postie'), "postie-settings[allow_html_in_subject]", $allow_html_in_subject); ?>
241
  }
242
  ?>><?php _e('every 30 seconds', 'postie') ?>
243
  </option>
244
+
245
  <option value="fifteenseconds" <?php
246
  if ($interval == "fifteenseconds") {
247
  echo "selected='selected'";
248
  }
249
  ?>><?php _e('every 15 seconds', 'postie') ?>
250
  </option>
251
+
252
  <option value="manual" <?php
253
  if ($interval == "manual") {
254
  echo "selected='selected'";
277
  <?php echo BuildBooleanSelect(__("Delete email after posting", 'postie'), 'postie-settings[delete_mail_after_processing]', $delete_mail_after_processing, __("Only set to no for testing purposes", 'postie')); ?>
278
  <?php echo BuildBooleanSelect(__("Ignore mail state", 'postie'), 'postie-settings[ignore_mail_state]', $ignore_mail_state, __("Ignore whether the mails is 'read' or 'unread' If 'No' then only unread messages are processed.", 'postie')); ?>
279
  <?php echo BuildTextArea(__("Allowed SMTP servers", 'postie'), "postie-settings[smtp]", $smtp, __("Only allow messages which have been sent throught the following SMTP servers. Put each server on a separate line. Leave blank to allow any SMTP server.", 'postie')); ?>
280
+
281
+ <?php echo BuildBooleanSelect(__("Enable Error Logging", 'postie'), 'postie-settings[postie_log_error]', $postie_log_error, __("Log error messages to the web server error log.", 'postie')); ?>
282
+ <?php echo BuildBooleanSelect(__("Enable Debug Logging", 'postie'), 'postie-settings[postie_log_debug]', $postie_log_debug, __("Log debug messages to the web server error log.", 'postie')); ?>
283
+
284
  </table>
285
  </div>
286
 
454
 
455
  <?php echo BuildBooleanSelect(__("Treat Replies As", 'postie'), "postie-settings[reply_as_comment]", $reply_as_comment, "", array("comments", "new posts")); ?>
456
  <?php echo BuildBooleanSelect(__("Strip Original Content from Replies", 'postie'), "postie-settings[strip_reply]", $strip_reply, "Only applicable if replies are trated as comments"); ?>
457
+
458
  <?php echo BuildBooleanSelect(__("Forward Rejected Mail", 'postie'), "postie-settings[forward_rejected_mail]", $forward_rejected_mail); ?>
459
  <?php echo BuildBooleanSelect(__("Allow Subject In Mail", 'postie'), "postie-settings[allow_subject_in_mail]", $allow_subject_in_mail, "Enclose the subject between '#' on the very first line. E.g. #this is my subject#"); ?>
460
  <?php echo BuildBooleanSelect(__("Allow HTML In Mail Subject", 'postie'), "postie-settings[allow_html_in_subject]", $allow_html_in_subject); ?>
docs/Changes.txt CHANGED
@@ -27,6 +27,12 @@ All script, style and body tags are stripped from html emails.
27
  Attachments are now processed in the order they were attached.
28
 
29
  == CHANGELOG ==
 
 
 
 
 
 
30
  = 1.7.16 (2015-10-08) =
31
  * Ensure comments are valid html after striping if preferred text type is html
32
  * Add setting to control comment content (strip_reply)
27
  Attachments are now processed in the order they were attached.
28
 
29
  == CHANGELOG ==
30
+ = 1.7.17 (2015-10-12) =
31
+ * New action, postie_log_error
32
+ * New action, postie_log_debug
33
+ * New feature to turn off all logging
34
+ * Only errors logged by default
35
+
36
  = 1.7.16 (2015-10-08) =
37
  * Ensure comments are valid html after striping if preferred text type is html
38
  * Add setting to control comment content (strip_reply)
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.3.1
9
- Stable tag: 1.7.16
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.3.1
9
+ Stable tag: 1.7.17
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 1260699 2015-10-06 22:30:27Z WayneAllen $
4
  */
5
 
6
  class PostiePostModifiers {
@@ -58,29 +58,29 @@ if (!function_exists('mb_str_replace')) {
58
  }
59
 
60
  function postie_environment() {
61
- DebugEcho("Postie Version: " . POSTIE_VERSION);
62
- DebugEcho("Wordpress Version: " . get_bloginfo('version'));
63
- DebugEcho("PHP Version: " . phpversion());
64
- DebugEcho("OS: " . php_uname());
65
- DebugEcho("Debug mode: " . (IsDebugMode() ? "On" : "Off"));
66
- DebugEcho("Time: " . date('Y-m-d H:i:s', time()) . " GMT");
67
  DebugEcho("Error log: " . ini_get('error_log'));
68
  DebugEcho("TMP dir: " . get_temp_dir());
69
  DebugEcho("Postie is in " . plugin_dir_path(__FILE__));
70
 
71
  if (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
72
- DebugEcho("Alternate cron is enabled");
73
  }
74
 
75
  if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) {
76
- DebugEcho("WordPress cron is disabled. Postie will not run unless you have an external cron set up.");
77
  }
78
 
79
- DebugEcho("Cron: " . (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON === true ? "Off" : "On"));
80
- DebugEcho("Alternate Cron: " . (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON === true ? "On" : "Off"));
81
 
82
  if (defined('WP_CRON_LOCK_TIMEOUT') && WP_CRON_LOCK_TIMEOUT === true) {
83
- DebugEcho("Cron lock timeout is:" . WP_CRON_LOCK_TIMEOUT);
84
  }
85
  }
86
 
@@ -110,44 +110,44 @@ if (!function_exists('fnmatch')) {
110
 
111
  }
112
 
113
- function LogInfo($v) {
114
- error_log("Postie: $v");
115
- }
116
-
117
- function EchoInfo($v) {
118
  if (php_sapi_name() == "cli") {
119
- print( "$v\n");
120
  } else {
121
  //flush the buffers
122
  while (ob_get_level() > 0) {
123
  ob_end_flush();
124
  }
125
- print( "<pre>" . htmlspecialchars($v) . "</pre>\n");
126
  }
127
- LogInfo($v);
 
 
 
 
 
 
 
 
 
 
 
 
 
128
  }
129
 
130
  function DebugDump($v) {
131
- if (IsDebugMode()) {
132
- $o = print_r($v, true);
133
- if (php_sapi_name() == "cli") {
134
- print( "$o\n");
135
- } else {
136
- //flush the buffers
137
- while (ob_get_level() > 0) {
138
- ob_end_flush();
139
- }
140
- print( "<pre>\n");
141
- EchoInfo($o);
142
- print( "</pre>\n");
143
- }
144
  }
 
145
  }
146
 
147
  function DebugEcho($v) {
148
- if (IsDebugMode()) {
149
- EchoInfo($v);
150
  }
 
151
  }
152
 
153
  function tag_Date(&$content, $message_date, $isHtml) {
@@ -620,8 +620,14 @@ function make_links($text) {
620
 
621
  function getPostAuthorDetails(&$subject, &$content, &$mimeDecodedEmail) {
622
 
623
- $theDate = $mimeDecodedEmail->headers['date'];
624
- $theEmail = RemoveExtraCharactersInEmailAddress($mimeDecodedEmail->headers["from"]);
 
 
 
 
 
 
625
 
626
  $regAuthor = get_user_by('email', $theEmail);
627
  if ($regAuthor) {
@@ -643,7 +649,7 @@ function getPostAuthorDetails(&$subject, &$content, &$mimeDecodedEmail) {
643
  $thFeAuthor = GetNameFromEmail($matches[1]);
644
  $mimeDecodedEmail->headers['from'] = $theAuthor;
645
  }
646
- //TODO dosen't always work with HTML
647
  if (preg_match("/\ndate:(.*?)\n/i", $content, $matches)) {
648
  $theDate = $matches[1];
649
  DebugEcho("date in Fwd: $theDate");
@@ -1090,7 +1096,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
1090
  $attachments["html"][$filename] = "<a href='$file'>" . $icon . $filename . '</a>' . "\n";
1091
  DebugEcho("GetContent: text attachment: adding '$filename'");
1092
  } else {
1093
- LogInfo($file_id->get_error_message());
1094
  }
1095
  } else {
1096
  DebugEcho("GetContent: text attachment: skipping '$filename'");
@@ -1129,7 +1135,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
1129
  $icon = chooseAttachmentIcon($file, $mimetype_primary, $mimetype_secondary, $config['icon_set'], $config['icon_size']);
1130
  $attachments["html"][$filename] = "<a href='$file'>" . $icon . $filename . '</a>' . "\n";
1131
  } else {
1132
- LogInfo($file_id->get_error_message());
1133
  }
1134
  }
1135
  }
@@ -1165,7 +1171,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
1165
  }
1166
  }
1167
  } else {
1168
- LogInfo("image error: " . $file_id->get_error_message());
1169
  }
1170
  break;
1171
 
@@ -1190,7 +1196,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
1190
  }
1191
  $attachments["html"][$filename] = parseTemplate($file_id, $mimetype_primary, $audioTemplate, $filename);
1192
  } else {
1193
- LogInfo("audio error: " . $file_id->get_error_message());
1194
  }
1195
  break;
1196
 
@@ -1219,7 +1225,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
1219
  $attachments["html"][$filename] = parseTemplate($file_id, $mimetype_primary, $videoTemplate, $filename);
1220
  //echo "videoTemplate = $videoTemplate\n";
1221
  } else {
1222
- LogInfo($file_id->get_error_message());
1223
  }
1224
  break;
1225
 
@@ -1247,7 +1253,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
1247
  DebugEcho("GetContent: No content-id");
1248
  }
1249
  } else {
1250
- LogInfo($file_id->get_error_message());
1251
  }
1252
  } else {
1253
  DebugEcho("GetContent: Not in supported filetype list");
@@ -1796,7 +1802,7 @@ function filter_AppleFile(&$mimeDecodedEmail) {
1796
  for ($i = 0; $i < count($mimeDecodedEmail->parts); $i++) {
1797
  if ($mimeDecodedEmail->parts[$i]->ctype_secondary == "applefile") {
1798
  $found = true;
1799
- LogInfo("Removing 'applefile'");
1800
  } else {
1801
  $newParts[] = $mimeDecodedEmail->parts[$i];
1802
  }
@@ -2990,7 +2996,9 @@ function config_GetDefaults() {
2990
  'force_user_login' => false,
2991
  'auto_gallery_link' => 'default',
2992
  'ignore_mail_state' => false,
2993
- 'strip_reply' => true
 
 
2994
  );
2995
  }
2996
 
@@ -3476,29 +3484,36 @@ function DebugFiltersFor($hook = '') {
3476
  }
3477
 
3478
  function postie_test_config() {
3479
- $config = config_Read();
3480
- extract($config);
3481
  get_currentuserinfo();
3482
 
3483
  if (!current_user_can('manage_options')) {
3484
- LogInfo("non-admin tried to set options");
3485
  echo "<h2> Sorry only admin can run this file</h2>";
3486
  exit();
3487
  }
 
 
 
 
 
 
 
 
3488
  ?>
3489
  <div class="wrap">
3490
  <h1>Postie Configuration Test</h1>
3491
- <?php
3492
- postie_environment();
3493
- ?>
3494
 
3495
  <h2>Clock Tests</h2>
3496
  <p>This shows what time it would be if you posted right now</p>
3497
- <?php
3498
- $content = "";
3499
- $data = tag_Delay($content, null, $config['time_offset']);
3500
- EchoInfo("Post time: $data[0]");
3501
- ?>
3502
  <h2>Encoding</h2>
3503
  <?php
3504
  EchoInfo("default_charset: " . ini_get('default_charset'));
@@ -3515,138 +3530,146 @@ function postie_test_config() {
3515
  ?>
3516
  <h2>Connect to Mail Host</h2>
3517
 
3518
- <?php
3519
- if (!$mail_server || !$mail_server_port || !$mail_userid) {
3520
- EchoInfo("FAIL - server settings not complete");
3521
- } else {
3522
- DebugEcho("checking");
3523
- }
3524
 
3525
- switch (strtolower($config["input_protocol"])) {
3526
- case 'imap':
3527
- case 'imap-ssl':
3528
- case 'pop3-ssl':
3529
- if (!HasIMAPSupport()) {
3530
- EchoInfo("Sorry - you do not have IMAP php module installed - it is required for this mail setting.");
3531
- } else {
3532
- require_once("postieIMAP.php");
3533
- $mail_server = &PostieIMAP::Factory($config["input_protocol"]);
3534
- if ($email_tls) {
3535
- $mail_server->TLSOn();
3536
- }
3537
- if (!$mail_server->connect($config["mail_server"], $config["mail_server_port"], $config["mail_userid"], $config["mail_password"])) {
3538
- EchoInfo("Unable to connect. The server said:");
3539
- EchoInfo($mail_server->error());
3540
- } else {
3541
- EchoInfo("Successful " . strtoupper($config['input_protocol']) . " connection on port {$config["mail_server_port"]}");
3542
- EchoInfo("# of waiting messages: " . $mail_server->getNumberOfMessages());
3543
- $mail_server->disconnect();
3544
- }
3545
- }
3546
- break;
3547
- case 'pop3':
3548
- default:
3549
- require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'class-pop3.php');
3550
- $pop3 = new POP3();
3551
- if (defined('POSTIE_DEBUG')) {
3552
- $pop3->DEBUG = POSTIE_DEBUG;
3553
  }
3554
- if (!$pop3->connect($config["mail_server"], $config["mail_server_port"])) {
3555
- EchoInfo("Unable to connect. The server said:" . $pop3->ERROR);
 
3556
  } else {
3557
- EchoInfo("Sucessful " . strtoupper($config['input_protocol']) . " connection on port {$config["mail_server_port"]}");
3558
- $msgs = $pop3->login($config["mail_userid"], $config["mail_password"]);
3559
- if ($msgs === false) {
3560
- //workaround for bug reported here Apr 12, 2013
3561
- //https://sourceforge.net/tracker/?func=detail&atid=100311&aid=3610701&group_id=311
3562
- //originally repoted here:
3563
- //https://core.trac.wordpress.org/ticket/10587
3564
- if (empty($pop3->ERROR)) {
3565
- EchoInfo("No waiting messages");
3566
- } else {
3567
- EchoInfo("Unable to login. The server said:" . $pop3->ERROR);
3568
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
3569
  } else {
3570
- EchoInfo("# of waiting messages: $msgs");
3571
  }
3572
- $pop3->quit();
 
3573
  }
3574
- break;
3575
- }
3576
- ?>
 
 
3577
  </div>
3578
- <?php
3579
- }
3580
-
3581
- function postie_get_mail() {
3582
- require_once (plugin_dir_path(__FILE__) . 'mimedecode.php');
3583
- if (!function_exists('file_get_html')) {
3584
- require_once (plugin_dir_path(__FILE__) . 'simple_html_dom.php');
3585
  }
3586
 
3587
- EchoInfo("Starting mail fetch");
3588
- postie_environment();
3589
- $wp_content_path = dirname(dirname(dirname(__FILE__)));
3590
- DebugEcho("wp_content_path: $wp_content_path");
3591
- if (file_exists($wp_content_path . DIRECTORY_SEPARATOR . "filterPostie.php")) {
3592
- DebugEcho("found filterPostie.php in $wp_content_path");
3593
- include_once ($wp_content_path . DIRECTORY_SEPARATOR . "filterPostie.php");
3594
- }
3595
 
3596
- if (has_filter('postie_post')) {
3597
- echo "Postie: filter 'postie_post' is depricated in favor of 'postie_post_before'";
3598
- }
 
 
 
 
3599
 
3600
- $test_email = null;
3601
- $config = config_Read();
3602
- //extract($config);
3603
- if (!array_key_exists('maxemails', $config)) {
3604
- $config['maxemails'] = 0;
3605
- }
 
 
3606
 
3607
- $emails = FetchMail($config['mail_server'], $config['mail_server_port'], $config['mail_userid'], $config['mail_password'], $config['input_protocol'], $config['time_offset'], $test_email, $config['delete_mail_after_processing'], $config['maxemails'], $config['email_tls']);
3608
- $message = 'Done.';
 
3609
 
3610
- EchoInfo(sprintf(__("There are %d messages to process", 'postie'), count($emails)));
 
 
 
3611
 
3612
- if (function_exists('memory_get_usage')) {
3613
- DebugEcho(__("memory at start of email processing:", 'postie') . memory_get_usage());
3614
- }
3615
 
3616
- DebugDump($config);
3617
 
3618
- //loop through messages
3619
- $message_number = 0;
3620
- foreach ($emails as $email) {
3621
- $message_number++;
3622
- DebugEcho("$message_number: ------------------------------------");
3623
- //sanity check to see if there is any info in the message
3624
- if ($email == NULL) {
3625
- $message = __('Dang, message is empty!', 'postie');
3626
- EchoInfo("$message_number: $message");
3627
- continue;
3628
- } else if (($config['ignore_mail_state'] == false) && ( $email == 'already read')) {
3629
- $message = __("Message is already marked 'read'.", 'postie');
3630
- EchoInfo("$message_number: $message");
3631
- continue;
3632
  }
3633
 
3634
- $mimeDecodedEmail = DecodeMIMEMail($email);
3635
 
3636
- DebugEmailOutput($email, $mimeDecodedEmail);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3637
 
3638
- //Check poster to see if a valid person
3639
- $poster = ValidatePoster($mimeDecodedEmail, $config);
3640
- if (!empty($poster)) {
3641
- PostEmail($poster, $mimeDecodedEmail, $config);
3642
- } else {
3643
- EchoInfo("Ignoring email - not authorized.");
 
 
 
 
 
 
 
3644
  }
3645
- flush();
3646
- }
3647
- EchoInfo("Mail fetch complete, $message_number emails");
3648
 
3649
- if (function_exists('memory_get_usage')) {
3650
- DebugEcho("memory at end of email processing:" . memory_get_usage());
 
3651
  }
3652
- }
1
  <?php
2
  /*
3
+ $Id: postie-functions.php 1264439 2015-10-12 21:21:59Z WayneAllen $
4
  */
5
 
6
  class PostiePostModifiers {
58
  }
59
 
60
  function postie_environment() {
61
+ EchoInfo("Postie Version: " . POSTIE_VERSION);
62
+ EchoInfo("Wordpress Version: " . get_bloginfo('version'));
63
+ EchoInfo("PHP Version: " . phpversion());
64
+ EchoInfo("OS: " . php_uname());
65
+ EchoInfo("POSTIE_DEBUG: " . (IsDebugMode() ? "On" : "Off"));
66
+ EchoInfo("Time: " . date('Y-m-d H:i:s', time()) . " GMT");
67
  DebugEcho("Error log: " . ini_get('error_log'));
68
  DebugEcho("TMP dir: " . get_temp_dir());
69
  DebugEcho("Postie is in " . plugin_dir_path(__FILE__));
70
 
71
  if (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON) {
72
+ EchoInfo("Alternate cron is enabled");
73
  }
74
 
75
  if (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON) {
76
+ EchoInfo("WordPress cron is disabled. Postie will not run unless you have an external cron set up.");
77
  }
78
 
79
+ EchoInfo("Cron: " . (defined('DISABLE_WP_CRON') && DISABLE_WP_CRON === true ? "Off" : "On"));
80
+ EchoInfo("Alternate Cron: " . (defined('ALTERNATE_WP_CRON') && ALTERNATE_WP_CRON === true ? "On" : "Off"));
81
 
82
  if (defined('WP_CRON_LOCK_TIMEOUT') && WP_CRON_LOCK_TIMEOUT === true) {
83
+ EchoInfo("Cron lock timeout is:" . WP_CRON_LOCK_TIMEOUT);
84
  }
85
  }
86
 
110
 
111
  }
112
 
113
+ function postie_log_onscreen($data) {
 
 
 
 
114
  if (php_sapi_name() == "cli") {
115
+ print( "$data\n");
116
  } else {
117
  //flush the buffers
118
  while (ob_get_level() > 0) {
119
  ob_end_flush();
120
  }
121
+ print( "<pre>" . htmlspecialchars($data) . "</pre>\n");
122
  }
123
+ }
124
+
125
+ function postie_log_error($v) {
126
+ postie_log_onscreen($v);
127
+ error_log("Postie [error]: $v");
128
+ }
129
+
130
+ function postie_log_debug($data) {
131
+ error_log("Postie [debug]: $data");
132
+ }
133
+
134
+ function EchoInfo($v) {
135
+ postie_log_onscreen($v);
136
+ do_action('postie_log_debug', $v);
137
  }
138
 
139
  function DebugDump($v) {
140
+ if (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG) {
141
+ postie_log_onscreen(print_r($v, true));
 
 
 
 
 
 
 
 
 
 
 
142
  }
143
+ do_action('postie_log_debug', print_r($v, true));
144
  }
145
 
146
  function DebugEcho($v) {
147
+ if (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG) {
148
+ postie_log_onscreen($v);
149
  }
150
+ do_action('postie_log_debug', $v);
151
  }
152
 
153
  function tag_Date(&$content, $message_date, $isHtml) {
620
 
621
  function getPostAuthorDetails(&$subject, &$content, &$mimeDecodedEmail) {
622
 
623
+ $theDate = null;
624
+ if (array_key_exists("date", $mimeDecodedEmail->headers) && !empty($mimeDecodedEmail->headers["date"])) {
625
+ $theDate = $mimeDecodedEmail->headers['date'];
626
+ }
627
+ $theEmail = '';
628
+ if (array_key_exists("from", $mimeDecodedEmail->headers) && !empty($mimeDecodedEmail->headers["from"])) {
629
+ $theEmail = RemoveExtraCharactersInEmailAddress($mimeDecodedEmail->headers["from"]);
630
+ }
631
 
632
  $regAuthor = get_user_by('email', $theEmail);
633
  if ($regAuthor) {
649
  $thFeAuthor = GetNameFromEmail($matches[1]);
650
  $mimeDecodedEmail->headers['from'] = $theAuthor;
651
  }
652
+ //TODO doesn't always work with HTML
653
  if (preg_match("/\ndate:(.*?)\n/i", $content, $matches)) {
654
  $theDate = $matches[1];
655
  DebugEcho("date in Fwd: $theDate");
1096
  $attachments["html"][$filename] = "<a href='$file'>" . $icon . $filename . '</a>' . "\n";
1097
  DebugEcho("GetContent: text attachment: adding '$filename'");
1098
  } else {
1099
+ do_action('postie_log_error', $file_id->get_error_message());
1100
  }
1101
  } else {
1102
  DebugEcho("GetContent: text attachment: skipping '$filename'");
1135
  $icon = chooseAttachmentIcon($file, $mimetype_primary, $mimetype_secondary, $config['icon_set'], $config['icon_size']);
1136
  $attachments["html"][$filename] = "<a href='$file'>" . $icon . $filename . '</a>' . "\n";
1137
  } else {
1138
+ do_action('postie_log_error', $file_id->get_error_message());
1139
  }
1140
  }
1141
  }
1171
  }
1172
  }
1173
  } else {
1174
+ do_action('postie_log_error', "image error: " . $file_id->get_error_message());
1175
  }
1176
  break;
1177
 
1196
  }
1197
  $attachments["html"][$filename] = parseTemplate($file_id, $mimetype_primary, $audioTemplate, $filename);
1198
  } else {
1199
+ do_action('postie_log_error', "audio error: " . $file_id->get_error_message());
1200
  }
1201
  break;
1202
 
1225
  $attachments["html"][$filename] = parseTemplate($file_id, $mimetype_primary, $videoTemplate, $filename);
1226
  //echo "videoTemplate = $videoTemplate\n";
1227
  } else {
1228
+ do_action('postie_log_error', $file_id->get_error_message());
1229
  }
1230
  break;
1231
 
1253
  DebugEcho("GetContent: No content-id");
1254
  }
1255
  } else {
1256
+ do_action('postie_log_error', $file_id->get_error_message());
1257
  }
1258
  } else {
1259
  DebugEcho("GetContent: Not in supported filetype list");
1802
  for ($i = 0; $i < count($mimeDecodedEmail->parts); $i++) {
1803
  if ($mimeDecodedEmail->parts[$i]->ctype_secondary == "applefile") {
1804
  $found = true;
1805
+ DebugEcho("Removing 'applefile'");
1806
  } else {
1807
  $newParts[] = $mimeDecodedEmail->parts[$i];
1808
  }
2996
  'force_user_login' => false,
2997
  'auto_gallery_link' => 'default',
2998
  'ignore_mail_state' => false,
2999
+ 'strip_reply' => true,
3000
+ 'postie_log_error' => true,
3001
+ 'postie_log_debug' => false
3002
  );
3003
  }
3004
 
3484
  }
3485
 
3486
  function postie_test_config() {
3487
+
 
3488
  get_currentuserinfo();
3489
 
3490
  if (!current_user_can('manage_options')) {
3491
+ DebugEcho("non-admin tried to set options");
3492
  echo "<h2> Sorry only admin can run this file</h2>";
3493
  exit();
3494
  }
3495
+
3496
+ $config = config_Read();
3497
+ if (true == $config['postie_log_error'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
3498
+ add_action('postie_log_error', 'postie_log_error');
3499
+ }
3500
+ if (true == $config['postie_log_debug'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
3501
+ add_action('postie_log_debug', 'postie_log_debug');
3502
+ }
3503
  ?>
3504
  <div class="wrap">
3505
  <h1>Postie Configuration Test</h1>
3506
+ <?php
3507
+ postie_environment();
3508
+ ?>
3509
 
3510
  <h2>Clock Tests</h2>
3511
  <p>This shows what time it would be if you posted right now</p>
3512
+ <?php
3513
+ $content = "";
3514
+ $data = tag_Delay($content, null, $config['time_offset']);
3515
+ EchoInfo("Post time: $data[0]");
3516
+ ?>
3517
  <h2>Encoding</h2>
3518
  <?php
3519
  EchoInfo("default_charset: " . ini_get('default_charset'));
3530
  ?>
3531
  <h2>Connect to Mail Host</h2>
3532
 
3533
+ <?php
3534
+ if (!$config['mail_server'] || !$config['mail_server_port'] || !$config['mail_userid']) {
3535
+ EchoInfo("FAIL - server settings not complete");
3536
+ } else {
3537
+ DebugEcho("checking");
3538
+ }
3539
 
3540
+ switch (strtolower($config["input_protocol"])) {
3541
+ case 'imap':
3542
+ case 'imap-ssl':
3543
+ case 'pop3-ssl':
3544
+ if (!HasIMAPSupport()) {
3545
+ EchoInfo("Sorry - you do not have IMAP php module installed - it is required for this mail setting.");
3546
+ } else {
3547
+ require_once("postieIMAP.php");
3548
+ $mail_server = &PostieIMAP::Factory($config["input_protocol"]);
3549
+ if ($config['email_tls']) {
3550
+ $mail_server->TLSOn();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3551
  }
3552
+ if (!$mail_server->connect($config["mail_server"], $config["mail_server_port"], $config["mail_userid"], $config["mail_password"])) {
3553
+ EchoInfo("Unable to connect. The server said:");
3554
+ EchoInfo($mail_server->error());
3555
  } else {
3556
+ EchoInfo("Successful " . strtoupper($config['input_protocol']) . " connection on port {$config["mail_server_port"]}");
3557
+ EchoInfo("# of waiting messages: " . $mail_server->getNumberOfMessages());
3558
+ $mail_server->disconnect();
3559
+ }
3560
+ }
3561
+ break;
3562
+ case 'pop3':
3563
+ default:
3564
+ require_once(ABSPATH . WPINC . DIRECTORY_SEPARATOR . 'class-pop3.php');
3565
+ $pop3 = new POP3();
3566
+ if (defined('POSTIE_DEBUG')) {
3567
+ $pop3->DEBUG = POSTIE_DEBUG;
3568
+ }
3569
+ if (!$pop3->connect($config["mail_server"], $config["mail_server_port"])) {
3570
+ EchoInfo("Unable to connect. The server said:" . $pop3->ERROR);
3571
+ } else {
3572
+ EchoInfo("Sucessful " . strtoupper($config['input_protocol']) . " connection on port {$config["mail_server_port"]}");
3573
+ $msgs = $pop3->login($config["mail_userid"], $config["mail_password"]);
3574
+ if ($msgs === false) {
3575
+ //workaround for bug reported here Apr 12, 2013
3576
+ //https://sourceforge.net/tracker/?func=detail&atid=100311&aid=3610701&group_id=311
3577
+ //originally repoted here:
3578
+ //https://core.trac.wordpress.org/ticket/10587
3579
+ if (empty($pop3->ERROR)) {
3580
+ EchoInfo("No waiting messages");
3581
  } else {
3582
+ EchoInfo("Unable to login. The server said:" . $pop3->ERROR);
3583
  }
3584
+ } else {
3585
+ EchoInfo("# of waiting messages: $msgs");
3586
  }
3587
+ $pop3->quit();
3588
+ }
3589
+ break;
3590
+ }
3591
+ ?>
3592
  </div>
3593
+ <?php
 
 
 
 
 
 
3594
  }
3595
 
3596
+ function postie_get_mail() {
3597
+ require_once (plugin_dir_path(__FILE__) . 'mimedecode.php');
3598
+ if (!function_exists('file_get_html')) {
3599
+ require_once (plugin_dir_path(__FILE__) . 'simple_html_dom.php');
3600
+ }
 
 
 
3601
 
3602
+ $config = config_Read();
3603
+ if (true == $config['postie_log_error'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
3604
+ add_action('postie_log_error', 'postie_log_error');
3605
+ }
3606
+ if (true == $config['postie_log_debug'] || (defined('POSTIE_DEBUG') && true == POSTIE_DEBUG)) {
3607
+ add_action('postie_log_debug', 'postie_log_debug');
3608
+ }
3609
 
3610
+ EchoInfo("Starting mail fetch");
3611
+ postie_environment();
3612
+ $wp_content_path = dirname(dirname(dirname(__FILE__)));
3613
+ DebugEcho("wp_content_path: $wp_content_path");
3614
+ if (file_exists($wp_content_path . DIRECTORY_SEPARATOR . "filterPostie.php")) {
3615
+ DebugEcho("found filterPostie.php in $wp_content_path");
3616
+ include_once ($wp_content_path . DIRECTORY_SEPARATOR . "filterPostie.php");
3617
+ }
3618
 
3619
+ if (has_filter('postie_post')) {
3620
+ echo "Postie: filter 'postie_post' is depricated in favor of 'postie_post_before'";
3621
+ }
3622
 
3623
+ $test_email = null;
3624
+ if (!array_key_exists('maxemails', $config)) {
3625
+ $config['maxemails'] = 0;
3626
+ }
3627
 
3628
+ $emails = FetchMail($config['mail_server'], $config['mail_server_port'], $config['mail_userid'], $config['mail_password'], $config['input_protocol'], $config['time_offset'], $test_email, $config['delete_mail_after_processing'], $config['maxemails'], $config['email_tls']);
3629
+ $message = 'Done.';
 
3630
 
3631
+ EchoInfo(sprintf(__("There are %d messages to process", 'postie'), count($emails)));
3632
 
3633
+ if (function_exists('memory_get_usage')) {
3634
+ DebugEcho(__("memory at start of email processing:", 'postie') . memory_get_usage());
 
 
 
 
 
 
 
 
 
 
 
 
3635
  }
3636
 
3637
+ DebugDump($config);
3638
 
3639
+ //loop through messages
3640
+ $message_number = 0;
3641
+ foreach ($emails as $email) {
3642
+ $message_number++;
3643
+ DebugEcho("$message_number: ------------------------------------");
3644
+ //sanity check to see if there is any info in the message
3645
+ if ($email == NULL) {
3646
+ $message = __('Dang, message is empty!', 'postie');
3647
+ EchoInfo("$message_number: $message");
3648
+ continue;
3649
+ } else if (($config['ignore_mail_state'] == false) && ( $email == 'already read')) {
3650
+ $message = __("Message is already marked 'read'.", 'postie');
3651
+ EchoInfo("$message_number: $message");
3652
+ continue;
3653
+ }
3654
 
3655
+ $mimeDecodedEmail = DecodeMIMEMail($email);
3656
+
3657
+ DebugEmailOutput($email, $mimeDecodedEmail);
3658
+
3659
+ //Check poster to see if a valid person
3660
+ $poster = ValidatePoster($mimeDecodedEmail, $config);
3661
+ if (!empty($poster)) {
3662
+ PostEmail($poster, $mimeDecodedEmail, $config);
3663
+ EchoInfo("$message_number: processed");
3664
+ } else {
3665
+ EchoInfo("Ignoring email - not authorized.");
3666
+ }
3667
+ flush();
3668
  }
3669
+ EchoInfo("Mail fetch complete, $message_number emails");
 
 
3670
 
3671
+ if (function_exists('memory_get_usage')) {
3672
+ DebugEcho("memory at end of email processing:" . memory_get_usage());
3673
+ }
3674
  }
3675
+
postie.php CHANGED
@@ -4,7 +4,7 @@
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  Description: Create posts via email. Signifigantly upgrades the Post by Email features of Word Press.
7
- Version: 1.7.16
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
  License: GPL2
@@ -28,12 +28,12 @@
28
  */
29
 
30
  /*
31
- $Id: postie.php 1261949 2015-10-08 20:05:58Z WayneAllen $
32
  */
33
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib_autolink.php");
34
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "postie-functions.php");
35
 
36
- define('POSTIE_VERSION', '1.7.16');
37
  define("POSTIE_ROOT", dirname(__FILE__));
38
  define("POSTIE_URL", WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
39
 
4
  Plugin Name: Postie
5
  Plugin URI: http://PostiePlugin.com/
6
  Description: Create posts via email. Signifigantly upgrades the Post by Email features of Word Press.
7
+ Version: 1.7.17
8
  Author: Wayne Allen
9
  Author URI: http://PostiePlugin.com/
10
  License: GPL2
28
  */
29
 
30
  /*
31
+ $Id: postie.php 1264467 2015-10-12 21:56:58Z WayneAllen $
32
  */
33
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "lib_autolink.php");
34
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . "postie-functions.php");
35
 
36
+ define('POSTIE_VERSION', '1.7.17');
37
  define("POSTIE_ROOT", dirname(__FILE__));
38
  define("POSTIE_URL", WP_PLUGIN_URL . '/' . basename(dirname(__FILE__)));
39
 
postieIMAP.php CHANGED
@@ -93,7 +93,7 @@ class PostieIMAP {
93
  $this->_connected = true;
94
  DebugEcho($this->_protocol . ": connected");
95
  } else {
96
- LogInfo("imap_open failed: " . imap_last_error());
97
  }
98
  return $this->_connected;
99
  }
@@ -103,12 +103,12 @@ class PostieIMAP {
103
  * @return integer
104
  */
105
  function getNumberOfMessages() {
106
- $status = imap_status($this->_connection, $this->_mailbox, SA_ALL);
107
  DebugDump($status);
108
  if ($status) {
109
  return max($status->messages, imap_num_msg($this->_connection));
110
  } else {
111
- LogInfo("Error imap_status did not return a value");
112
  //DebugDump($this);
113
  return 0;
114
  }
93
  $this->_connected = true;
94
  DebugEcho($this->_protocol . ": connected");
95
  } else {
96
+ do_action('postie_log_error', "imap_open failed: " . imap_last_error());
97
  }
98
  return $this->_connected;
99
  }
103
  * @return integer
104
  */
105
  function getNumberOfMessages() {
106
+ $status = imap_status($this->_connection, $this->_mailbox, SA_ALL);
107
  DebugDump($status);
108
  if ($status) {
109
  return max($status->messages, imap_num_msg($this->_connection));
110
  } else {
111
+ do_action('postie_log_error', "Error imap_status did not return a value");
112
  //DebugDump($this);
113
  return 0;
114
  }
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.3.1
9
- Stable tag: 1.7.16
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -235,6 +235,12 @@ All script, style and body tags are stripped from html emails.
235
  Attachments are now processed in the order they were attached.
236
 
237
  == CHANGELOG ==
 
 
 
 
 
 
238
  = 1.7.16 (2015-10-08) =
239
  * Ensure comments are valid html after striping if preferred text type is html
240
  * Add setting to control comment content (strip_reply)
6
  Tags: e-mail, email, post-by-email
7
  Requires at least: 3.3.0
8
  Tested up to: 4.3.1
9
+ Stable tag: 1.7.17
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
235
  Attachments are now processed in the order they were attached.
236
 
237
  == CHANGELOG ==
238
+ = 1.7.17 (2015-10-12) =
239
+ * New action, postie_log_error
240
+ * New action, postie_log_debug
241
+ * New feature to turn off all logging
242
+ * Only errors logged by default
243
+
244
  = 1.7.16 (2015-10-08) =
245
  * Ensure comments are valid html after striping if preferred text type is html
246
  * Add setting to control comment content (strip_reply)