Version Description
(2020-03-29) = * Fix email notification bug
Download this release
Release Info
Developer | WayneAllen |
Plugin | Postie |
Version | 1.9.45 |
Comparing to | |
See all releases |
Code changes from version 1.9.44 to 1.9.45
- docs/Changes.txt +3 -0
- docs/Postie.txt +1 -1
- postie-api.php +1 -1
- postie-message.php +92 -95
- postie.class.php +2 -2
- postie.php +3 -3
- 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.44 (2020-03-23) =
|
39 |
* refactoring to separate email fetch from email processing
|
40 |
* add postie_register_shortcode_pre action for registering Postie shortcodes
|
35 |
Attachments are now processed in the order they were attached.
|
36 |
|
37 |
== CHANGELOG ==
|
38 |
+
= 1.9.45 (2020-03-29) =
|
39 |
+
* Fix email notification bug
|
40 |
+
|
41 |
= 1.9.44 (2020-03-23) =
|
42 |
* refactoring to separate email fetch from email processing
|
43 |
* add postie_register_shortcode_pre action for registering Postie shortcodes
|
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.4
|
10 |
-
Stable tag: 1.9.
|
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.4
|
10 |
+
Stable tag: 1.9.45
|
11 |
License: GPLv2 or later
|
12 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
13 |
|
postie-api.php
CHANGED
@@ -19,7 +19,7 @@ function lookup_category($trial_category, $category_match) {
|
|
19 |
function RemoveExtraCharactersInEmailAddress($address) {
|
20 |
$c = new PostieConfig();
|
21 |
$m = new PostieMessage(array(), $c->config_read());
|
22 |
-
return $m->
|
23 |
}
|
24 |
|
25 |
function EchoError($v) {
|
19 |
function RemoveExtraCharactersInEmailAddress($address) {
|
20 |
$c = new PostieConfig();
|
21 |
$m = new PostieMessage(array(), $c->config_read());
|
22 |
+
return $m->get_clean_emailaddress($address);
|
23 |
}
|
24 |
|
25 |
function EchoError($v) {
|
postie-message.php
CHANGED
@@ -2,8 +2,8 @@
|
|
2 |
|
3 |
class PostieMessage {
|
4 |
|
5 |
-
private $email;
|
6 |
-
private $config;
|
7 |
private $poster = 0;
|
8 |
private $post_id = 0;
|
9 |
private $is_reply = false;
|
@@ -47,11 +47,11 @@ class PostieMessage {
|
|
47 |
return (defined('POSTIE_DEBUG') && POSTIE_DEBUG == true);
|
48 |
}
|
49 |
|
50 |
-
function
|
51 |
return $this->email == null;
|
52 |
}
|
53 |
|
54 |
-
function
|
55 |
return $this->email == 'already read';
|
56 |
}
|
57 |
|
@@ -83,7 +83,7 @@ class PostieMessage {
|
|
83 |
|
84 |
function preprocess() {
|
85 |
DebugEcho("preprocess: Starting");
|
86 |
-
$this->
|
87 |
|
88 |
/* in order to do attachments correctly, we need to associate the
|
89 |
attachments with a post. So we add the post here, then update it */
|
@@ -95,7 +95,7 @@ class PostieMessage {
|
|
95 |
EchoError("preprocess: wp_insert_post failed: " . $this->post_id->get_error_message());
|
96 |
DebugDump($this->post_id->get_error_messages());
|
97 |
DebugDump($this->post_id->get_error_data());
|
98 |
-
$this->
|
99 |
}
|
100 |
DebugEcho("preprocess: Done");
|
101 |
}
|
@@ -109,8 +109,12 @@ class PostieMessage {
|
|
109 |
}
|
110 |
|
111 |
//Check poster to see if a valid person
|
112 |
-
$this->poster = $this->
|
113 |
if (empty($this->poster)) {
|
|
|
|
|
|
|
|
|
114 |
EchoError('process: Ignoring email - not authorized.');
|
115 |
return;
|
116 |
}
|
@@ -118,9 +122,9 @@ class PostieMessage {
|
|
118 |
DebugEcho("process: filter: pre postie_post_pre");
|
119 |
$this->email = apply_filters('postie_post_pre', $this->email);
|
120 |
|
121 |
-
$this->
|
122 |
|
123 |
-
$this->
|
124 |
|
125 |
$details = $this->create_post();
|
126 |
|
@@ -145,8 +149,6 @@ class PostieMessage {
|
|
145 |
return;
|
146 |
}
|
147 |
|
148 |
-
|
149 |
-
|
150 |
$postid = $this->save_post($details, $this->is_reply);
|
151 |
|
152 |
$recipients = array();
|
@@ -164,12 +166,12 @@ class PostieMessage {
|
|
164 |
$recipients[] = $user->user_email;
|
165 |
}
|
166 |
|
167 |
-
DebugEcho(
|
168 |
-
$this->email_notify($
|
169 |
|
170 |
if ($this->is_debugmode()) {
|
171 |
$post = get_post($this->post_id);
|
172 |
-
DebugEcho(
|
173 |
DebugDump($post);
|
174 |
}
|
175 |
|
@@ -180,7 +182,7 @@ class PostieMessage {
|
|
180 |
|
181 |
function postprocess() {
|
182 |
|
183 |
-
$this->
|
184 |
DebugEcho("postprocess: Done");
|
185 |
}
|
186 |
|
@@ -189,7 +191,7 @@ class PostieMessage {
|
|
189 |
* @param string
|
190 |
* @return string
|
191 |
*/
|
192 |
-
function
|
193 |
$matches = array();
|
194 |
if (preg_match('/^[^<>]+<([^<> ()]+)>$/', $address, $matches)) {
|
195 |
$address = $matches[1];
|
@@ -208,12 +210,12 @@ class PostieMessage {
|
|
208 |
* @param string - email address
|
209 |
* @return boolean
|
210 |
*/
|
211 |
-
function
|
212 |
$r = false;
|
213 |
-
if (is_array($
|
214 |
$a = strtolower(trim($address));
|
215 |
if (!empty($a)) {
|
216 |
-
$r = in_array($a, array_map('strtolower', $
|
217 |
}
|
218 |
}
|
219 |
return $r;
|
@@ -223,7 +225,7 @@ class PostieMessage {
|
|
223 |
* Determines if the sender is a valid user.
|
224 |
* @return integer|NULL
|
225 |
*/
|
226 |
-
function
|
227 |
$poster = null;
|
228 |
$from = '';
|
229 |
|
@@ -256,7 +258,7 @@ class PostieMessage {
|
|
256 |
|
257 |
$resentFrom = '';
|
258 |
if (array_key_exists('headers', $this->email) && array_key_exists('resent-from', $this->email['headers'])) {
|
259 |
-
$resentFrom = $this->
|
260 |
}
|
261 |
|
262 |
//See if the email address is one of the special authorized ones
|
@@ -269,6 +271,8 @@ class PostieMessage {
|
|
269 |
$user_ID = $user->ID;
|
270 |
} else {
|
271 |
DebugEcho("validate_poster: $from is not user of blog " . get_current_blog_id());
|
|
|
|
|
272 |
}
|
273 |
}
|
274 |
}
|
@@ -284,11 +288,11 @@ class PostieMessage {
|
|
284 |
DebugEcho("validate_poster: post postie_author $poster");
|
285 |
} else {
|
286 |
DebugEcho("validate_poster $user_ID does not have 'post_via_postie' permissions");
|
287 |
-
$user_ID =
|
288 |
}
|
289 |
}
|
290 |
|
291 |
-
if (empty($user_ID) && ($this->config['turn_authorization_off'] || $this->
|
292 |
DebugEcho("validate_poster: looking up default user " . $this->config['admin_username']);
|
293 |
$user = get_user_by('login', $this->config['admin_username']);
|
294 |
if ($user === false) {
|
@@ -303,36 +307,30 @@ class PostieMessage {
|
|
303 |
DebugEcho("validate_poster: found user '$poster'");
|
304 |
}
|
305 |
|
306 |
-
if (
|
307 |
-
|
308 |
-
if ($this->config['
|
309 |
-
$
|
310 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
311 |
}
|
312 |
-
return '';
|
313 |
}
|
314 |
|
315 |
-
//actually log in as the user
|
316 |
-
if ($this->config['force_user_login'] == true) {
|
317 |
-
$user = get_user_by('id', $poster);
|
318 |
-
if ($user) {
|
319 |
-
DebugEcho("validate_poster: logging in as {$user->user_login}");
|
320 |
-
wp_set_current_user($poster);
|
321 |
-
//wp_set_auth_cookie($poster);
|
322 |
-
do_action('wp_login', $user->user_login, $user);
|
323 |
-
} else {
|
324 |
-
DebugEcho("validate_poster: couldn't find $poster to force login");
|
325 |
-
}
|
326 |
-
}
|
327 |
return $poster;
|
328 |
}
|
329 |
|
330 |
-
function
|
331 |
-
return
|
332 |
}
|
333 |
|
334 |
function email_reject() {
|
335 |
-
DebugEcho(
|
336 |
|
337 |
$recipients = array(get_option('admin_email'));
|
338 |
$returnToSender = $this->config['return_to_sender'];
|
@@ -346,7 +344,7 @@ class PostieMessage {
|
|
346 |
array_push($recipients, $from);
|
347 |
}
|
348 |
|
349 |
-
$eblogname = $this->
|
350 |
$adminemail = get_option('admin_email');
|
351 |
|
352 |
$headers = array();
|
@@ -393,7 +391,7 @@ class PostieMessage {
|
|
393 |
unlink($attachHtml);
|
394 |
}
|
395 |
|
396 |
-
function
|
397 |
global $_wp_post_type_features, $_postie_revisions;
|
398 |
|
399 |
$_postie_revisions = false;
|
@@ -403,7 +401,7 @@ class PostieMessage {
|
|
403 |
}
|
404 |
}
|
405 |
|
406 |
-
function
|
407 |
global $_wp_post_type_features, $_postie_revisions;
|
408 |
|
409 |
if ($_postie_revisions) {
|
@@ -445,7 +443,7 @@ class PostieMessage {
|
|
445 |
DebugEcho("post tag_Excerpt: $this->content");
|
446 |
}
|
447 |
|
448 |
-
$postAuthorDetails = $this->
|
449 |
if ($fulldebug) {
|
450 |
DebugEcho("post getPostAuthorDetails: $this->content");
|
451 |
}
|
@@ -522,7 +520,7 @@ class PostieMessage {
|
|
522 |
}
|
523 |
|
524 |
if ($this->config['reply_as_comment'] == true) {
|
525 |
-
$id = $this->
|
526 |
if (empty($id)) {
|
527 |
DebugEcho("Not a reply");
|
528 |
$id = $this->post_id;
|
@@ -638,7 +636,7 @@ class PostieMessage {
|
|
638 |
DebugDump($post_ID->get_error_data());
|
639 |
wp_delete_post($details['ID']);
|
640 |
|
641 |
-
$this->
|
642 |
|
643 |
$post_ID = null;
|
644 |
} else {
|
@@ -679,7 +677,7 @@ class PostieMessage {
|
|
679 |
return $post_ID;
|
680 |
}
|
681 |
|
682 |
-
function
|
683 |
$recipients = array();
|
684 |
if ($this->config['postie_log_error_notify'] == '(Nobody)') {
|
685 |
return;
|
@@ -715,7 +713,7 @@ class PostieMessage {
|
|
715 |
$blogname = get_option("blogname");
|
716 |
$eblogname = "=?utf-8?b?" . base64_encode($blogname) . "?= ";
|
717 |
$posturl = get_permalink($postid);
|
718 |
-
$subject = $this->
|
719 |
|
720 |
$sendheaders = array("From: $eblogname <$myemailadd>");
|
721 |
|
@@ -775,7 +773,7 @@ class PostieMessage {
|
|
775 |
if (array_key_exists('filename', $attachment) && !empty($attachment['filename'])) {
|
776 |
DebugEcho('save_attachments_worker: ' . $attachment['filename']);
|
777 |
|
778 |
-
if ($this->
|
779 |
DebugEcho("save_attachments_worker: skipping banned filename " . $attachment['filename']);
|
780 |
continue;
|
781 |
}
|
@@ -806,7 +804,7 @@ class PostieMessage {
|
|
806 |
switch ($mimetype_primary) {
|
807 |
case 'text':
|
808 |
DebugEcho("save_attachments_worker: text attachment");
|
809 |
-
$icon = $this->
|
810 |
$attachment['template'] = "<a href='$file'>" . $icon . $filename . '</a>' . "\n";
|
811 |
break;
|
812 |
|
@@ -822,7 +820,7 @@ class PostieMessage {
|
|
822 |
$audioTemplate = $this->config['audiotemplate'];
|
823 |
} else {
|
824 |
DebugEcho("save_attachments_worker: using default audio template: $mimetype_secondary");
|
825 |
-
$icon = $this->
|
826 |
$audioTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
|
827 |
}
|
828 |
$attachment['template'] = $this->parse_template($file_id, $mimetype_primary, $audioTemplate, $filename);
|
@@ -838,7 +836,7 @@ class PostieMessage {
|
|
838 |
$videoTemplate = $this->config['video2template'];
|
839 |
} else {
|
840 |
DebugEcho("save_attachments_worker: using default template: $fileext");
|
841 |
-
$icon = $this->
|
842 |
$videoTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
|
843 |
}
|
844 |
$attachment['template'] = $this->parse_template($file_id, $mimetype_primary, $videoTemplate, $filename);
|
@@ -846,7 +844,7 @@ class PostieMessage {
|
|
846 |
|
847 |
default :
|
848 |
DebugEcho("save_attachments_worker: generic attachment ($mimetype_primary)");
|
849 |
-
$icon = $this->
|
850 |
$attachment['template'] = $this->parse_template($file_id, $mimetype_primary, $this->config['generaltemplate'], $filename, $icon) . "\n";
|
851 |
break;
|
852 |
}
|
@@ -926,7 +924,7 @@ class PostieMessage {
|
|
926 |
DebugEcho("save_attachment: text attachment: adding '$filename'");
|
927 |
} else {
|
928 |
EchoError($file_id->get_error_message());
|
929 |
-
$this->
|
930 |
}
|
931 |
|
932 |
break;
|
@@ -943,7 +941,7 @@ class PostieMessage {
|
|
943 |
}
|
944 |
} else {
|
945 |
EchoError("save_attachment image error: " . $file_id->get_error_message());
|
946 |
-
$this->
|
947 |
}
|
948 |
break;
|
949 |
|
@@ -954,7 +952,7 @@ class PostieMessage {
|
|
954 |
$attachment['wp_id'] = $file_id;
|
955 |
} else {
|
956 |
EchoError("save_attachment audio error: " . $file_id->get_error_message());
|
957 |
-
$this->
|
958 |
}
|
959 |
break;
|
960 |
|
@@ -965,7 +963,7 @@ class PostieMessage {
|
|
965 |
$attachment['wp_id'] = $file_id;
|
966 |
} else {
|
967 |
EchoError("save_attachment video error: " . $file_id->get_error_message());
|
968 |
-
$this->
|
969 |
}
|
970 |
break;
|
971 |
|
@@ -984,13 +982,13 @@ class PostieMessage {
|
|
984 |
DebugEcho("save_attachment: uploaded $file_id ($file)");
|
985 |
} else {
|
986 |
EchoError("save_attachment file error: " . $file_id->get_error_message());
|
987 |
-
$this->
|
988 |
}
|
989 |
} else {
|
990 |
EchoError("$filename has an unsupported MIME type $mimetype_primary and was not added.");
|
991 |
DebugEcho("save_attachment: Not in supported filetype list: '$mimetype_primary'");
|
992 |
DebugDump($this->config['supported_file_types']);
|
993 |
-
$this->
|
994 |
}
|
995 |
break;
|
996 |
}
|
@@ -1000,7 +998,7 @@ class PostieMessage {
|
|
1000 |
* Choose an appropriate file icon based on the extension and mime type of
|
1001 |
* the attachment
|
1002 |
*/
|
1003 |
-
function
|
1004 |
if ($iconSet == 'none') {
|
1005 |
return('');
|
1006 |
}
|
@@ -1142,7 +1140,7 @@ class PostieMessage {
|
|
1142 |
* @param string
|
1143 |
* @return boolean
|
1144 |
*/
|
1145 |
-
function
|
1146 |
if (preg_match('/ATT\d\d\d\d\d.txt/i', $filename)) {
|
1147 |
return true;
|
1148 |
}
|
@@ -1156,33 +1154,32 @@ class PostieMessage {
|
|
1156 |
foreach ($bannedFiles as $bannedFile) {
|
1157 |
if (fnmatch($bannedFile, $filename)) {
|
1158 |
EchoError("Ignoring attachment: $filename - it is on the banned files list.");
|
1159 |
-
$this->
|
1160 |
return true;
|
1161 |
}
|
1162 |
}
|
1163 |
return false;
|
1164 |
}
|
1165 |
|
1166 |
-
function
|
1167 |
-
$
|
1168 |
if ($this->config['prefer_text_type'] == 'html') {
|
1169 |
if (isset($this->email['html'])) {
|
1170 |
DebugEcho('get_content: html');
|
1171 |
-
$
|
1172 |
}
|
1173 |
} else {
|
1174 |
if (isset($this->email['text'])) {
|
1175 |
DebugEcho('get_content: plain');
|
1176 |
-
$
|
1177 |
}
|
1178 |
}
|
1179 |
-
return $meta_return;
|
1180 |
}
|
1181 |
|
1182 |
/**
|
1183 |
* This function looks for a subject at the beginning surrounded by # and then removes that from the content
|
1184 |
*/
|
1185 |
-
function
|
1186 |
DebugEcho("tag_Subject: Looking for subject in email body");
|
1187 |
|
1188 |
if (strlen($this->content) == 0 || substr($this->content, 0, 1) != "#") {
|
@@ -1205,14 +1202,14 @@ class PostieMessage {
|
|
1205 |
/**
|
1206 |
* This function handles finding and setting the correct subject
|
1207 |
*/
|
1208 |
-
function
|
1209 |
//assign the default title/subject
|
1210 |
$this->subject = $this->config[PostieConfigOptions::DefaultTitle];
|
1211 |
|
1212 |
if (empty($this->email['headers']['subject'])) {
|
1213 |
DebugEcho("get_subject: No subject in email");
|
1214 |
if ($this->config['allow_subject_in_mail']) {
|
1215 |
-
$this->
|
1216 |
}
|
1217 |
$this->email['headers']['subject'] = $this->subject;
|
1218 |
} else {
|
@@ -1220,7 +1217,7 @@ class PostieMessage {
|
|
1220 |
DebugEcho(("get_subject: Predecoded subject: $this->subject"));
|
1221 |
|
1222 |
if ($this->config['allow_subject_in_mail']) {
|
1223 |
-
$this->
|
1224 |
}
|
1225 |
}
|
1226 |
if (!$this->config['allow_html_in_subject']) {
|
@@ -1239,29 +1236,29 @@ class PostieMessage {
|
|
1239 |
DebugEcho("get_subject: '$this->subject'");
|
1240 |
}
|
1241 |
|
1242 |
-
function
|
1243 |
|
1244 |
-
$
|
1245 |
|
1246 |
-
$
|
1247 |
-
if ($
|
1248 |
-
$
|
1249 |
-
$
|
1250 |
-
$
|
1251 |
} else {
|
1252 |
-
$
|
1253 |
-
$
|
1254 |
-
$
|
1255 |
}
|
1256 |
|
1257 |
-
$
|
1258 |
-
'author' => $
|
1259 |
-
'comment_author_url' => $
|
1260 |
-
'user_ID' => $
|
1261 |
-
'email' => $
|
1262 |
);
|
1263 |
|
1264 |
-
return $
|
1265 |
}
|
1266 |
|
1267 |
/**
|
@@ -1297,11 +1294,11 @@ class PostieMessage {
|
|
1297 |
DebugEcho("media_handle_upload: wrote data to '$tmpFile'");
|
1298 |
} else {
|
1299 |
EchoError("media_handle_upload: Could not write to temp file: '$tmpFile' ");
|
1300 |
-
$this->
|
1301 |
}
|
1302 |
} else {
|
1303 |
EchoError("media_handle_upload: Could not create temp file in " . get_temp_dir());
|
1304 |
-
$this->
|
1305 |
}
|
1306 |
|
1307 |
$file_array = array(
|
@@ -1354,7 +1351,7 @@ class PostieMessage {
|
|
1354 |
EchoError("There was an error adding the attachment: " . $id->get_error_message());
|
1355 |
DebugDump($id->get_error_messages());
|
1356 |
DebugDump($id->get_error_data());
|
1357 |
-
$this->
|
1358 |
}
|
1359 |
|
1360 |
return $id;
|
@@ -1368,7 +1365,7 @@ class PostieMessage {
|
|
1368 |
* generated
|
1369 |
*/
|
1370 |
|
1371 |
-
function
|
1372 |
global $wpdb;
|
1373 |
|
1374 |
$id = NULL;
|
2 |
|
3 |
class PostieMessage {
|
4 |
|
5 |
+
private $email = array();
|
6 |
+
private $config = array();
|
7 |
private $poster = 0;
|
8 |
private $post_id = 0;
|
9 |
private $is_reply = false;
|
47 |
return (defined('POSTIE_DEBUG') && POSTIE_DEBUG == true);
|
48 |
}
|
49 |
|
50 |
+
function is_email_empty() {
|
51 |
return $this->email == null;
|
52 |
}
|
53 |
|
54 |
+
function is_email_read() {
|
55 |
return $this->email == 'already read';
|
56 |
}
|
57 |
|
83 |
|
84 |
function preprocess() {
|
85 |
DebugEcho("preprocess: Starting");
|
86 |
+
$this->revisions_disable();
|
87 |
|
88 |
/* in order to do attachments correctly, we need to associate the
|
89 |
attachments with a post. So we add the post here, then update it */
|
95 |
EchoError("preprocess: wp_insert_post failed: " . $this->post_id->get_error_message());
|
96 |
DebugDump($this->post_id->get_error_messages());
|
97 |
DebugDump($this->post_id->get_error_data());
|
98 |
+
$this->email_error("preprocess: wp_insert_post failed creating placeholder", $this->post_id->get_error_message());
|
99 |
}
|
100 |
DebugEcho("preprocess: Done");
|
101 |
}
|
109 |
}
|
110 |
|
111 |
//Check poster to see if a valid person
|
112 |
+
$this->poster = $this->get_author();
|
113 |
if (empty($this->poster)) {
|
114 |
+
if ($this->config['forward_rejected_mail']) {
|
115 |
+
$this->email_reject();
|
116 |
+
EchoError("A copy of the message has been forwarded to the administrator.");
|
117 |
+
}
|
118 |
EchoError('process: Ignoring email - not authorized.');
|
119 |
return;
|
120 |
}
|
122 |
DebugEcho("process: filter: pre postie_post_pre");
|
123 |
$this->email = apply_filters('postie_post_pre', $this->email);
|
124 |
|
125 |
+
$this->extract_content();
|
126 |
|
127 |
+
$this->extract_subject();
|
128 |
|
129 |
$details = $this->create_post();
|
130 |
|
149 |
return;
|
150 |
}
|
151 |
|
|
|
|
|
152 |
$postid = $this->save_post($details, $this->is_reply);
|
153 |
|
154 |
$recipients = array();
|
166 |
$recipients[] = $user->user_email;
|
167 |
}
|
168 |
|
169 |
+
DebugEcho('post_email: sending notifications');
|
170 |
+
$this->email_notify($recipients, $postid);
|
171 |
|
172 |
if ($this->is_debugmode()) {
|
173 |
$post = get_post($this->post_id);
|
174 |
+
DebugEcho('post_email: resulting post');
|
175 |
DebugDump($post);
|
176 |
}
|
177 |
|
182 |
|
183 |
function postprocess() {
|
184 |
|
185 |
+
$this->revisions_restore();
|
186 |
DebugEcho("postprocess: Done");
|
187 |
}
|
188 |
|
191 |
* @param string
|
192 |
* @return string
|
193 |
*/
|
194 |
+
function get_clean_emailaddress($address) {
|
195 |
$matches = array();
|
196 |
if (preg_match('/^[^<>]+<([^<> ()]+)>$/', $address, $matches)) {
|
197 |
$address = $matches[1];
|
210 |
* @param string - email address
|
211 |
* @return boolean
|
212 |
*/
|
213 |
+
function is_emailaddress_authorized($address, $authorized_addresses) {
|
214 |
$r = false;
|
215 |
+
if (is_array($authorized_addresses)) {
|
216 |
$a = strtolower(trim($address));
|
217 |
if (!empty($a)) {
|
218 |
+
$r = in_array($a, array_map('strtolower', $authorized_addresses));
|
219 |
}
|
220 |
}
|
221 |
return $r;
|
225 |
* Determines if the sender is a valid user.
|
226 |
* @return integer|NULL
|
227 |
*/
|
228 |
+
function get_author() {
|
229 |
$poster = null;
|
230 |
$from = '';
|
231 |
|
258 |
|
259 |
$resentFrom = '';
|
260 |
if (array_key_exists('headers', $this->email) && array_key_exists('resent-from', $this->email['headers'])) {
|
261 |
+
$resentFrom = $this->get_clean_emailaddress(trim($this->email['headers']['resent-from']));
|
262 |
}
|
263 |
|
264 |
//See if the email address is one of the special authorized ones
|
271 |
$user_ID = $user->ID;
|
272 |
} else {
|
273 |
DebugEcho("validate_poster: $from is not user of blog " . get_current_blog_id());
|
274 |
+
EchoError('Invalid sender: ' . htmlentities($from) . "! Not adding email!");
|
275 |
+
|
276 |
}
|
277 |
}
|
278 |
}
|
288 |
DebugEcho("validate_poster: post postie_author $poster");
|
289 |
} else {
|
290 |
DebugEcho("validate_poster $user_ID does not have 'post_via_postie' permissions");
|
291 |
+
$user_ID = '';
|
292 |
}
|
293 |
}
|
294 |
|
295 |
+
if (empty($user_ID) && ($this->config['turn_authorization_off'] || $this->is_emailaddress_authorized($from, $this->config['authorized_addresses']) || $this->is_emailaddress_authorized($resentFrom, $this->config['authorized_addresses']))) {
|
296 |
DebugEcho("validate_poster: looking up default user " . $this->config['admin_username']);
|
297 |
$user = get_user_by('login', $this->config['admin_username']);
|
298 |
if ($user === false) {
|
307 |
DebugEcho("validate_poster: found user '$poster'");
|
308 |
}
|
309 |
|
310 |
+
if ($poster) {
|
311 |
+
//actually log in as the user
|
312 |
+
if ($this->config['force_user_login'] == true) {
|
313 |
+
$user = get_user_by('id', $poster);
|
314 |
+
if ($user) {
|
315 |
+
DebugEcho("validate_poster: logging in as {$user->user_login}");
|
316 |
+
wp_set_current_user($poster);
|
317 |
+
//wp_set_auth_cookie($poster);
|
318 |
+
do_action('wp_login', $user->user_login, $user);
|
319 |
+
} else {
|
320 |
+
DebugEcho("validate_poster: couldn't find $poster to force login");
|
321 |
+
}
|
322 |
}
|
|
|
323 |
}
|
324 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
return $poster;
|
326 |
}
|
327 |
|
328 |
+
function email_header_encode($value) {
|
329 |
+
return '=?utf-8?b?' . base64_encode($value) . '?=';
|
330 |
}
|
331 |
|
332 |
function email_reject() {
|
333 |
+
DebugEcho('email_reject: start');
|
334 |
|
335 |
$recipients = array(get_option('admin_email'));
|
336 |
$returnToSender = $this->config['return_to_sender'];
|
344 |
array_push($recipients, $from);
|
345 |
}
|
346 |
|
347 |
+
$eblogname = $this->email_header_encode($blogname);
|
348 |
$adminemail = get_option('admin_email');
|
349 |
|
350 |
$headers = array();
|
391 |
unlink($attachHtml);
|
392 |
}
|
393 |
|
394 |
+
function revisions_disable() {
|
395 |
global $_wp_post_type_features, $_postie_revisions;
|
396 |
|
397 |
$_postie_revisions = false;
|
401 |
}
|
402 |
}
|
403 |
|
404 |
+
function revisions_restore() {
|
405 |
global $_wp_post_type_features, $_postie_revisions;
|
406 |
|
407 |
if ($_postie_revisions) {
|
443 |
DebugEcho("post tag_Excerpt: $this->content");
|
444 |
}
|
445 |
|
446 |
+
$postAuthorDetails = $this->get_author_details();
|
447 |
if ($fulldebug) {
|
448 |
DebugEcho("post getPostAuthorDetails: $this->content");
|
449 |
}
|
520 |
}
|
521 |
|
522 |
if ($this->config['reply_as_comment'] == true) {
|
523 |
+
$id = $this->get_parent_postid($this->subject);
|
524 |
if (empty($id)) {
|
525 |
DebugEcho("Not a reply");
|
526 |
$id = $this->post_id;
|
636 |
DebugDump($post_ID->get_error_data());
|
637 |
wp_delete_post($details['ID']);
|
638 |
|
639 |
+
$this->email_error("Failed to create {$details['post_type']}: {$details['post_title']}", "Error: " . $post_ID->get_error_message() . "\n\n" . $details['post_content']);
|
640 |
|
641 |
$post_ID = null;
|
642 |
} else {
|
677 |
return $post_ID;
|
678 |
}
|
679 |
|
680 |
+
function email_error($subject, $message) {
|
681 |
$recipients = array();
|
682 |
if ($this->config['postie_log_error_notify'] == '(Nobody)') {
|
683 |
return;
|
713 |
$blogname = get_option("blogname");
|
714 |
$eblogname = "=?utf-8?b?" . base64_encode($blogname) . "?= ";
|
715 |
$posturl = get_permalink($postid);
|
716 |
+
$subject = $this->subject;
|
717 |
|
718 |
$sendheaders = array("From: $eblogname <$myemailadd>");
|
719 |
|
773 |
if (array_key_exists('filename', $attachment) && !empty($attachment['filename'])) {
|
774 |
DebugEcho('save_attachments_worker: ' . $attachment['filename']);
|
775 |
|
776 |
+
if ($this->is_filename_banned($attachment['filename'])) {
|
777 |
DebugEcho("save_attachments_worker: skipping banned filename " . $attachment['filename']);
|
778 |
continue;
|
779 |
}
|
804 |
switch ($mimetype_primary) {
|
805 |
case 'text':
|
806 |
DebugEcho("save_attachments_worker: text attachment");
|
807 |
+
$icon = $this->get_attachment_icon($file, $mimetype_primary, $mimetype_secondary, $this->config['icon_set'], $this->config['icon_size']);
|
808 |
$attachment['template'] = "<a href='$file'>" . $icon . $filename . '</a>' . "\n";
|
809 |
break;
|
810 |
|
820 |
$audioTemplate = $this->config['audiotemplate'];
|
821 |
} else {
|
822 |
DebugEcho("save_attachments_worker: using default audio template: $mimetype_secondary");
|
823 |
+
$icon = $this->get_attachment_icon($file, $mimetype_primary, $mimetype_secondary, $this->config['icon_set'], $this->config['icon_size']);
|
824 |
$audioTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
|
825 |
}
|
826 |
$attachment['template'] = $this->parse_template($file_id, $mimetype_primary, $audioTemplate, $filename);
|
836 |
$videoTemplate = $this->config['video2template'];
|
837 |
} else {
|
838 |
DebugEcho("save_attachments_worker: using default template: $fileext");
|
839 |
+
$icon = $this->get_attachment_icon($file, $mimetype_primary, $mimetype_secondary, $this->config['icon_set'], $this->config['icon_size']);
|
840 |
$videoTemplate = '<a href="{FILELINK}">' . $icon . '{FILENAME}</a>';
|
841 |
}
|
842 |
$attachment['template'] = $this->parse_template($file_id, $mimetype_primary, $videoTemplate, $filename);
|
844 |
|
845 |
default :
|
846 |
DebugEcho("save_attachments_worker: generic attachment ($mimetype_primary)");
|
847 |
+
$icon = $this->get_attachment_icon($file, $mimetype_primary, $mimetype_secondary, $this->config['icon_set'], $this->config['icon_size']);
|
848 |
$attachment['template'] = $this->parse_template($file_id, $mimetype_primary, $this->config['generaltemplate'], $filename, $icon) . "\n";
|
849 |
break;
|
850 |
}
|
924 |
DebugEcho("save_attachment: text attachment: adding '$filename'");
|
925 |
} else {
|
926 |
EchoError($file_id->get_error_message());
|
927 |
+
$this->email_error("Failed to add text media file: $filename", $file_id->get_error_message());
|
928 |
}
|
929 |
|
930 |
break;
|
941 |
}
|
942 |
} else {
|
943 |
EchoError("save_attachment image error: " . $file_id->get_error_message());
|
944 |
+
$this->email_error("Failed to add image media file: $filename", $file_id->get_error_message());
|
945 |
}
|
946 |
break;
|
947 |
|
952 |
$attachment['wp_id'] = $file_id;
|
953 |
} else {
|
954 |
EchoError("save_attachment audio error: " . $file_id->get_error_message());
|
955 |
+
$this->email_error("Failed to add audio media file: $filename", $file_id->get_error_message());
|
956 |
}
|
957 |
break;
|
958 |
|
963 |
$attachment['wp_id'] = $file_id;
|
964 |
} else {
|
965 |
EchoError("save_attachment video error: " . $file_id->get_error_message());
|
966 |
+
$this->email_error("Failed to add video file: $filename", $file_id->get_error_message());
|
967 |
}
|
968 |
break;
|
969 |
|
982 |
DebugEcho("save_attachment: uploaded $file_id ($file)");
|
983 |
} else {
|
984 |
EchoError("save_attachment file error: " . $file_id->get_error_message());
|
985 |
+
$this->email_error("Failed to add media file: $filename", $file_id->get_error_message());
|
986 |
}
|
987 |
} else {
|
988 |
EchoError("$filename has an unsupported MIME type $mimetype_primary and was not added.");
|
989 |
DebugEcho("save_attachment: Not in supported filetype list: '$mimetype_primary'");
|
990 |
DebugDump($this->config['supported_file_types']);
|
991 |
+
$this->email_error("Unsupported MIME type: $mimetype_primary", "$filename has an unsupported MIME type $mimetype_primary and was not added.\nSupported types:\n" . print_r($config['supported_file_types'], true));
|
992 |
}
|
993 |
break;
|
994 |
}
|
998 |
* Choose an appropriate file icon based on the extension and mime type of
|
999 |
* the attachment
|
1000 |
*/
|
1001 |
+
function get_attachment_icon($file, $primary, $secondary, $iconSet = 'silver', $size = '32') {
|
1002 |
if ($iconSet == 'none') {
|
1003 |
return('');
|
1004 |
}
|
1140 |
* @param string
|
1141 |
* @return boolean
|
1142 |
*/
|
1143 |
+
function is_filename_banned($filename) {
|
1144 |
if (preg_match('/ATT\d\d\d\d\d.txt/i', $filename)) {
|
1145 |
return true;
|
1146 |
}
|
1154 |
foreach ($bannedFiles as $bannedFile) {
|
1155 |
if (fnmatch($bannedFile, $filename)) {
|
1156 |
EchoError("Ignoring attachment: $filename - it is on the banned files list.");
|
1157 |
+
$this->email_error("Ignoring attachment: $filename - it is on the banned files list.", "Ignoring attachment: $filename - it is on the banned files list.");
|
1158 |
return true;
|
1159 |
}
|
1160 |
}
|
1161 |
return false;
|
1162 |
}
|
1163 |
|
1164 |
+
function extract_content() {
|
1165 |
+
$this->content = '';
|
1166 |
if ($this->config['prefer_text_type'] == 'html') {
|
1167 |
if (isset($this->email['html'])) {
|
1168 |
DebugEcho('get_content: html');
|
1169 |
+
$this->content = $this->email['html'];
|
1170 |
}
|
1171 |
} else {
|
1172 |
if (isset($this->email['text'])) {
|
1173 |
DebugEcho('get_content: plain');
|
1174 |
+
$this->content = $this->email['text'];
|
1175 |
}
|
1176 |
}
|
|
|
1177 |
}
|
1178 |
|
1179 |
/**
|
1180 |
* This function looks for a subject at the beginning surrounded by # and then removes that from the content
|
1181 |
*/
|
1182 |
+
function extract_subject_body() {
|
1183 |
DebugEcho("tag_Subject: Looking for subject in email body");
|
1184 |
|
1185 |
if (strlen($this->content) == 0 || substr($this->content, 0, 1) != "#") {
|
1202 |
/**
|
1203 |
* This function handles finding and setting the correct subject
|
1204 |
*/
|
1205 |
+
function extract_subject() {
|
1206 |
//assign the default title/subject
|
1207 |
$this->subject = $this->config[PostieConfigOptions::DefaultTitle];
|
1208 |
|
1209 |
if (empty($this->email['headers']['subject'])) {
|
1210 |
DebugEcho("get_subject: No subject in email");
|
1211 |
if ($this->config['allow_subject_in_mail']) {
|
1212 |
+
$this->extract_subject_body();
|
1213 |
}
|
1214 |
$this->email['headers']['subject'] = $this->subject;
|
1215 |
} else {
|
1217 |
DebugEcho(("get_subject: Predecoded subject: $this->subject"));
|
1218 |
|
1219 |
if ($this->config['allow_subject_in_mail']) {
|
1220 |
+
$this->extract_subject_body();
|
1221 |
}
|
1222 |
}
|
1223 |
if (!$this->config['allow_html_in_subject']) {
|
1236 |
DebugEcho("get_subject: '$this->subject'");
|
1237 |
}
|
1238 |
|
1239 |
+
function get_author_details() {
|
1240 |
|
1241 |
+
$from = $this->email['headers']['from']['mailbox'] . '@' . $this->email['headers']['from']['host'];
|
1242 |
|
1243 |
+
$wpuser = get_user_by('email', $from);
|
1244 |
+
if ($wpuser !== false) {
|
1245 |
+
$name = $wpuser->user_login;
|
1246 |
+
$url = $wpuser->user_url;
|
1247 |
+
$id = $wpuser->ID;
|
1248 |
} else {
|
1249 |
+
$name = $this->get_name_from_email($from);
|
1250 |
+
$url = '';
|
1251 |
+
$id = '';
|
1252 |
}
|
1253 |
|
1254 |
+
$author_details = array(
|
1255 |
+
'author' => $name,
|
1256 |
+
'comment_author_url' => $url,
|
1257 |
+
'user_ID' => $id,
|
1258 |
+
'email' => $from
|
1259 |
);
|
1260 |
|
1261 |
+
return $author_details;
|
1262 |
}
|
1263 |
|
1264 |
/**
|
1294 |
DebugEcho("media_handle_upload: wrote data to '$tmpFile'");
|
1295 |
} else {
|
1296 |
EchoError("media_handle_upload: Could not write to temp file: '$tmpFile' ");
|
1297 |
+
$this->email_error("media_handle_upload: Could not write to temp file: '$tmpFile' ", "media_handle_upload: Could not write to temp file: '$tmpFile' ");
|
1298 |
}
|
1299 |
} else {
|
1300 |
EchoError("media_handle_upload: Could not create temp file in " . get_temp_dir());
|
1301 |
+
$this->email_error("media_handle_upload: Could not create temp file in " . get_temp_dir(), "media_handle_upload: Could not create temp file in " . get_temp_dir());
|
1302 |
}
|
1303 |
|
1304 |
$file_array = array(
|
1351 |
EchoError("There was an error adding the attachment: " . $id->get_error_message());
|
1352 |
DebugDump($id->get_error_messages());
|
1353 |
DebugDump($id->get_error_data());
|
1354 |
+
$this->email_error("There was an error adding the attachment: " . $attachment['wp_filename'], $id->get_error_message());
|
1355 |
}
|
1356 |
|
1357 |
return $id;
|
1365 |
* generated
|
1366 |
*/
|
1367 |
|
1368 |
+
function get_parent_postid(&$subject) {
|
1369 |
global $wpdb;
|
1370 |
|
1371 |
$id = NULL;
|
postie.class.php
CHANGED
@@ -196,12 +196,12 @@ class Postie {
|
|
196 |
|
197 |
$email = new PostieMessage($mailbox->fetchMessage($message['uid']), $config);
|
198 |
|
199 |
-
if ($email->
|
200 |
$message = __('Dang, message is empty!', 'postie');
|
201 |
EchoError("fetch_mail: $message_number: ");
|
202 |
DebugDump($message);
|
203 |
continue;
|
204 |
-
} else if ($email->
|
205 |
$message = __("Message is already marked 'read'.", 'postie');
|
206 |
DebugEcho("fetch_mail: $message_number");
|
207 |
DebugDump($message);
|
196 |
|
197 |
$email = new PostieMessage($mailbox->fetchMessage($message['uid']), $config);
|
198 |
|
199 |
+
if ($email->is_email_empty()) {
|
200 |
$message = __('Dang, message is empty!', 'postie');
|
201 |
EchoError("fetch_mail: $message_number: ");
|
202 |
DebugDump($message);
|
203 |
continue;
|
204 |
+
} else if ($email->is_email_read()) {
|
205 |
$message = __("Message is already marked 'read'.", 'postie');
|
206 |
DebugEcho("fetch_mail: $message_number");
|
207 |
DebugDump($message);
|
postie.php
CHANGED
@@ -4,14 +4,14 @@
|
|
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.
|
8 |
Author: Wayne Allen
|
9 |
Author URI: http://PostiePlugin.com/
|
10 |
License: GPL3
|
11 |
Text Domain: postie
|
12 |
*/
|
13 |
|
14 |
-
/* Copyright (c) 2015-
|
15 |
|
16 |
This program is free software: you can redistribute it and/or modify
|
17 |
it under the terms of the GNU General Public License as published by
|
@@ -28,7 +28,7 @@
|
|
28 |
*/
|
29 |
|
30 |
/*
|
31 |
-
$Id: postie.php
|
32 |
*/
|
33 |
|
34 |
if (!defined('WPINC')) {
|
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.45
|
8 |
Author: Wayne Allen
|
9 |
Author URI: http://PostiePlugin.com/
|
10 |
License: GPL3
|
11 |
Text Domain: postie
|
12 |
*/
|
13 |
|
14 |
+
/* Copyright (c) 2015-20 Wayne Allen (email : wayne@postieplugin.com)
|
15 |
|
16 |
This program is free software: you can redistribute it and/or modify
|
17 |
it under the terms of the GNU General Public License as published by
|
28 |
*/
|
29 |
|
30 |
/*
|
31 |
+
$Id: postie.php 2270347 2020-03-29 19:37:06Z WayneAllen $
|
32 |
*/
|
33 |
|
34 |
if (!defined('WPINC')) {
|
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.4
|
10 |
-
Stable tag: 1.9.
|
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.44 (2020-03-23) =
|
111 |
* refactoring to separate email fetch from email processing
|
112 |
* add postie_register_shortcode_pre action for registering Postie shortcodes
|
7 |
Requires PHP: 5.3
|
8 |
Requires at least: 4.0
|
9 |
Tested up to: 5.4
|
10 |
+
Stable tag: 1.9.45
|
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.45 (2020-03-29) =
|
111 |
+
* Fix email notification bug
|
112 |
+
|
113 |
= 1.9.44 (2020-03-23) =
|
114 |
* refactoring to separate email fetch from email processing
|
115 |
* add postie_register_shortcode_pre action for registering Postie shortcodes
|