Postie - Version 1.4.11

Version Description

  • Attachments are now processed in the order they were attached.
  • All script, style and body tags are stripped from html emails.
Download this release

Release Info

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

Code changes from version 1.4.10 to 1.4.11

Revision CHANGED
@@ -1,2 +0,0 @@
1
- Revision: 637111
2
- Last Changed Date: 2012-12-10 21:29:00 -0800 (Mon, 10 Dec 2012)
 
 
config_form.php CHANGED
@@ -1,9 +1,22 @@
1
  <div class="wrap">
 
 
 
 
 
 
 
 
 
 
 
2
  <h2>
3
  <a style='text-decoration:none' href='options-general.php?page=postie/postie.php'>
4
  <img src="../wp-content/plugins/postie/images/mail.png" alt="postie" /><?php _e('Postie Options', 'postie'); ?>
5
  </a>
6
  </h2>
 
 
7
  <?php
8
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'postie-functions.php');
9
  if (isset($_POST["action"])) {
@@ -38,8 +51,6 @@
38
  if (empty($config))
39
  $config = ResetPostieConfig();
40
 
41
-
42
-
43
  $arrays = get_arrayed_settings();
44
  // some fields are stored as arrays, because that makes back-end processing much easier
45
  // and we need to convert those fields to strings here, for the options form
@@ -60,6 +71,9 @@
60
  <?php if (isset($_GET['message'])) : ?>
61
  <div class="updated"><p><?php _e($messages[$_GET['message']], 'postie'); ?></p></div>
62
  <?php endif; ?>
 
 
 
63
  <form name="postie-options" method="post">
64
  <input type="hidden" name="action" value="reset" />
65
  <input name="Submit" value="<?php _e("Reset Settings To Defaults", 'postie') ?> &raquo;" type="submit" class='button'>
@@ -74,6 +88,7 @@
74
  <input name="Submit" value="<?php _e("Test Config", 'postie'); ?>&raquo;" type="submit" class='button'>
75
  <?php _e("this will run a special script to test your configuration options", 'postie'); ?>
76
  </form>
 
77
  <form name="postie-options" method="post" action='options.php'>
78
  <?php
79
  settings_fields('postie-settings');
1
  <div class="wrap">
2
+ <div style="float:right; width: 220px; border: 1px solid darkgrey; padding:2px;border-radius:10px;" >
3
+ <p class="" style="text-align:center;font-weight: bolder; margin-top: 0px; margin-bottom: 2px;">Please Donate</p>
4
+ <p style="margin-top: 0;margin-bottom: 2px;">Your generous donation allows me to continue developing Postie for the WordPress community.</p>
5
+ <form style="" action="https://www.paypal.com/cgi-bin/webscr" method="post">
6
+ <input type="hidden" name="cmd" value="_s-xclick">
7
+ <input type="hidden" name="hosted_button_id" value="HPK99BJ88V4C2">
8
+ <div style="text-align:center;">
9
+ <input style="border: none; margin: 0;" type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif" name="submit" alt="PayPal - The safer, easier way to pay online!">
10
+ </div>
11
+ </form>
12
+ </div>
13
  <h2>
14
  <a style='text-decoration:none' href='options-general.php?page=postie/postie.php'>
15
  <img src="../wp-content/plugins/postie/images/mail.png" alt="postie" /><?php _e('Postie Options', 'postie'); ?>
16
  </a>
17
  </h2>
18
+
19
+
20
  <?php
21
  require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'postie-functions.php');
22
  if (isset($_POST["action"])) {
51
  if (empty($config))
52
  $config = ResetPostieConfig();
53
 
 
 
54
  $arrays = get_arrayed_settings();
55
  // some fields are stored as arrays, because that makes back-end processing much easier
56
  // and we need to convert those fields to strings here, for the options form
71
  <?php if (isset($_GET['message'])) : ?>
72
  <div class="updated"><p><?php _e($messages[$_GET['message']], 'postie'); ?></p></div>
73
  <?php endif; ?>
74
+
75
+
76
+
77
  <form name="postie-options" method="post">
78
  <input type="hidden" name="action" value="reset" />
79
  <input name="Submit" value="<?php _e("Reset Settings To Defaults", 'postie') ?> &raquo;" type="submit" class='button'>
88
  <input name="Submit" value="<?php _e("Test Config", 'postie'); ?>&raquo;" type="submit" class='button'>
89
  <?php _e("this will run a special script to test your configuration options", 'postie'); ?>
90
  </form>
91
+
92
  <form name="postie-options" method="post" action='options.php'>
93
  <?php
94
  settings_fields('postie-settings');
docs/Changes.txt CHANGED
@@ -3,6 +3,17 @@
3
  * All script, style and body tags are stripped from html emails.
4
 
5
  == CHANGELOG ==
 
 
 
 
 
 
 
 
 
 
 
6
  = 1.4.10 (2012.12.11) =
7
  * Fixed warning when there is no subject
8
  * Removed all script and style tags from HTML content in place of XSS warning
3
  * All script, style and body tags are stripped from html emails.
4
 
5
  == CHANGELOG ==
6
+ = 1.4.11.(2012.12.14) =
7
+ * Fixed bug where having a colon in the subject caused the subject to get truncated
8
+ * Added donation link to admin screen
9
+ * Fixed bug where #img# captions with double-byte characters were not working
10
+ * Fixed bug where default settings were corrupt
11
+ * Fixed several bugs in tag detection logic
12
+ * Fixed bug where non-base64 and non-quoted-printable sections were not converted to utf-8
13
+ * Fixed bug where the end filter wasn't removed from the post
14
+ * Add additional logging to attachment upload process
15
+ * Changes to support WP 3.5
16
+
17
  = 1.4.10 (2012.12.11) =
18
  * Fixed warning when there is no subject
19
  * Removed all script and style tags from HTML content in place of XSS warning
docs/Postie.txt CHANGED
@@ -5,8 +5,8 @@ Author URI: http://allens-home.com/
5
  Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
- Tested up to: 3.4.2
9
- Stable tag: 1.4.10
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
5
  Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
+ Tested up to: 3.5
9
+ Stable tag: 1.4.11
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
get_mail.php CHANGED
@@ -36,6 +36,7 @@ if (function_exists('memory_get_usage'))
36
 
37
  //loop through messages
38
  foreach ($emails as $email) {
 
39
  //sanity check to see if there is any info in the message
40
  if ($email == NULL) {
41
  $message = __('Dang, message is empty!', 'postie');
36
 
37
  //loop through messages
38
  foreach ($emails as $email) {
39
+ DebugEcho("------------------------------------");
40
  //sanity check to see if there is any info in the message
41
  if ($email == NULL) {
42
  $message = __('Dang, message is empty!', 'postie');
postie-functions.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  /*
4
- $Id: postie-functions.php 637396 2012-12-12 00:48:27Z WayneAllen $
5
  */
6
 
7
  /* TODO
@@ -18,6 +18,32 @@
18
  //to turn on debug output add the following line to wp-config.php
19
  //define('POSTIE_DEBUG', true);
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  function postie_disable_revisions($restore = false) {
22
  global $_wp_post_type_features, $_postie_revisions;
23
 
@@ -123,7 +149,7 @@ function PostEmail($poster, $mimeDecodedEmail, $config) {
123
  EchoInfo("new post id is $post_id");
124
 
125
  $content = GetContent($mimeDecodedEmail, $attachments, $post_id, $poster, $config);
126
- DebugEcho("the content is $content");
127
 
128
  $subject = GetSubject($mimeDecodedEmail, $content, $config);
129
 
@@ -244,6 +270,7 @@ function PostEmail($poster, $mimeDecodedEmail, $config) {
244
  }
245
  postie_disable_revisions(true);
246
  postie_increase_memory(true);
 
247
  }
248
 
249
  /** FUNCTIONS * */
@@ -423,9 +450,8 @@ function checkReply(&$subject) {
423
  preg_match("/-(.[^-]*)$/", $tmpSubject, $tmpSubject_matches);
424
  $tmpSubject = trim($tmpSubject_matches[1]);
425
  }
426
- $checkExistingPostQuery = "SELECT ID FROM $wpdb->posts WHERE
427
- '$tmpSubject' = post_title";
428
- if ($id = $wpdb->get_var($wpdb->prepare($checkExistingPostQuery))) {
429
  if (is_array($id)) {
430
  $id = $id[count($id) - 1];
431
  }
@@ -576,7 +602,11 @@ function POP3MessageFetch($server = NULL, $port = NULL, $email = NULL, $password
576
  function PostToDB($details, $isReply, $postToDb = true, $customImageField = false) {
577
  if ($postToDb) {
578
  if (!$isReply) {
579
- $post_ID = wp_insert_post($details);
 
 
 
 
580
  } else {
581
  $comment = array(
582
  'comment_author' => $details['comment_author'],
@@ -596,7 +626,7 @@ function PostToDB($details, $isReply, $postToDb = true, $customImageField = fals
596
 
597
  $post_ID = wp_insert_comment($comment);
598
  }
599
- if ($customImageField) {
600
  DebugEcho("Saving custom image fields");
601
  //DebugDump($details['customImages']);
602
 
@@ -606,8 +636,6 @@ function PostToDB($details, $isReply, $postToDb = true, $customImageField = fals
606
  add_post_meta($post_ID, 'image' . $imageField, $image);
607
  $imageField++;
608
  }
609
- } else {
610
- add_post_meta($post_ID, 'image', $details['customImages'][0]);
611
  }
612
  }
613
  }
@@ -634,7 +662,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
634
  extract($config);
635
  global $charset, $encoding;
636
 
637
- $meta_return = NULL;
638
  DebugEcho("primary= " . $part->ctype_primary . ", secondary = " . $part->ctype_secondary);
639
 
640
  DecodeBase64Part($part);
@@ -671,17 +699,15 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
671
  $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
672
  }
673
  } else {
674
- // fix filename (remove non-standard characters)
675
- DebugEcho("extracting file name for attachement");
676
- //DebugDump($part);
677
-
678
  $filename = "";
679
  if (is_array($part->ctype_parameters) && array_key_exists('name', $part->ctype_parameters)) {
 
680
  $filename = preg_replace("/[^\x9\xA\xD\x20-\x7F]/", "", $part->ctype_parameters['name']);
681
  DebugEcho("Filename: $filename");
682
  }
683
  switch (strtolower($part->ctype_primary)) {
684
  case 'multipart':
 
685
  FilterTextParts($part, $prefer_text_type);
686
  foreach ($part->parts as $section) {
687
  $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
@@ -689,6 +715,7 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
689
  break;
690
 
691
  case 'text':
 
692
  if (array_key_exists('charset', $part->ctype_parameters) && !empty($part->ctype_parameters['charset'])) {
693
  $charset = $part->ctype_parameters['charset'];
694
  DebugEcho("charset: $charset");
@@ -701,25 +728,29 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
701
 
702
  if (array_key_exists('content-transfer-encoding', $part->headers)) {
703
  //DebugDump($part);
704
- $part->body = HandleMessageEncoding($part->headers["content-transfer-encoding"], $part->ctype_parameters["charset"], $part->body, $message_encoding, $message_dequote);
705
  //DebugDump($part);
706
  }
707
 
708
  //go through each sub-section
709
  if ($part->ctype_secondary == 'enriched') {
710
  //convert enriched text to HTML
 
711
  $meta_return .= etf2HTML($part->body) . "\n";
712
  } elseif ($part->ctype_secondary == 'html') {
713
  //strip excess HTML
 
714
  $meta_return .= HTML2HTML($part->body) . "\n";
715
  } else {
716
  //regular text, so just strip the pgp signature
 
717
  if ($allow_html_in_body) {
718
- $meta_return .= $part->body . "\n";
719
  } else {
720
- $meta_return .= htmlentities($part->body) . "\n";
721
  }
722
  $meta_return = StripPGP($meta_return);
 
723
  }
724
  break;
725
 
@@ -778,12 +809,14 @@ function GetContent($part, &$attachments, $post_id, $poster, $config) {
778
  break;
779
  $file_id = postie_media_handle_upload($part, $post_id, $poster);
780
  $file = wp_get_attachment_url($file_id);
781
- $cid = trim($part->headers["content-id"], "<>");
782
- ; //cids are in <cid>
783
- $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $icon_set, $icon_size);
784
- $attachments["html"][$filename] = "<a href='$file'>" . $icon . $filename . '</a>' . "\n";
785
- if ($cid) {
786
- $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1);
 
 
787
  }
788
  }
789
  break;
@@ -868,14 +901,14 @@ function etf2HTML($content) {
868
  function HTML2HTML($content) {
869
  $html = str_get_html($content);
870
  if ($html) {
871
- foreach ($html->find('script, style') as $node) {
872
- $node->outertext = '';
873
- }
874
- $html->load($html->save());
875
 
876
  $b = $html->find('body');
877
  if ($b) {
878
- $content = $b[0]->innertext;
879
  }
880
  }
881
  return $content;
@@ -957,13 +990,13 @@ function checkSMTP($mimeDecodedEmail, $smtpservers) {
957
  * @param string
958
  * @param string
959
  */
960
- function StartFilter(&$content, $start) {
961
- DebugEcho("start filter $start");
962
  $pos = strpos($content, $start);
963
  if ($pos === false) {
964
- return($content);
965
  }
966
- $content = substr($content, $pos + strlen($start), strlen($content));
 
967
  }
968
 
969
  /**
@@ -995,10 +1028,10 @@ function remove_signature($content, $filterList) {
995
  * @param filter
996
  */
997
  function EndFilter($content, $end) {
998
- DebugEcho("end filter $end");
999
  $pos = strpos($content, $end);
1000
  if ($pos === false)
1001
  return $content;
 
1002
  return $content = substr($content, 0, $pos);
1003
  }
1004
 
@@ -1049,7 +1082,7 @@ function ConvertUTF8ToISO_8859_1($contenttransferencoding, $currentcharset, $bod
1049
  $body = utf8_decode($body);
1050
  }
1051
  if ($contenttransferencoding == 'quoted-printable') {
1052
- $body = iconv($currentcharset, 'UTF-8', quoted_printable_decode($body));
1053
  }
1054
  }
1055
  return $body;
@@ -1062,92 +1095,25 @@ function HandleMessageEncoding($contenttransferencoding, $charset, $body, $blogE
1062
  DebugEcho("before HandleMessageEncoding");
1063
  DebugEcho("charset: $charset");
1064
  DebugEcho("encoding: $contenttransferencoding");
 
1065
 
1066
  if ($contenttransferencoding == 'base64') {
1067
  DebugEcho("HandleMessageEncoding: base64 detected");
1068
  $body = base64_decode($body);
1069
- $body = iconv($charset, $blogEncoding, $body);
1070
  }
1071
  if ($dequote && $contenttransferencoding == 'quoted-printable') {
1072
  DebugEcho("quoted-printable detected");
1073
- $body = iconv($charset, $blogEncoding, quoted_printable_decode($body));
1074
  }
1075
 
1076
  DebugEcho("after HandleMessageEncoding");
 
 
1077
  return $body;
1078
  }
1079
 
1080
  function ConvertToUTF_8($charset, $body) {
1081
- $charset = strtolower($charset);
1082
-
1083
- switch ($charset) {
1084
- case "iso-8859-1":
1085
- $body = utf8_encode($body);
1086
- break;
1087
- case "iso-2022-jp":
1088
- $body = iconv("ISO-2022-JP", "UTF-8//TRANSLIT", $body);
1089
- break;
1090
- case ($charset == "windows-1252" || $charset == "cp-1252" || $charset == "cp 1252"):
1091
- $body = cp1252_to_utf8($body);
1092
- break;
1093
- case ($charset == "windows-1256" || $charset == "cp-1256" || $charset == "cp 1256"):
1094
- $body = iconv("Windows-1256", "UTF-8//TRANSLIT", $body);
1095
- break;
1096
- case 'koi8-r':
1097
- $body = iconv("koi8-r", "UTF-8//TRANSLIT", $body);
1098
- break;
1099
- case 'iso-8859-2':
1100
- $body = iconv("iso-8859-2", "UTF-8//TRANSLIT", $body);
1101
- break;
1102
- case "big5":
1103
- $body = iconv("BIG5", "UTF-8//TRANSLIT", $body);
1104
- break;
1105
- case "gb2312":
1106
- $body = iconv("GB2312", "UTF-8//TRANSLIT", $body);
1107
- break;
1108
- case "iso-8859-15":
1109
- $body = iconv("iso-8859-15", "UTF-8//TRANSLIT", $body);
1110
- break;
1111
- default :
1112
- $body = iconv($charset, "UTF-8//TRANSLIT", $body);
1113
- break;
1114
- }
1115
- return $body;
1116
- }
1117
-
1118
- /* this function will convert windows-1252 (also known as cp-1252 to utf-8 */
1119
-
1120
- function cp1252_to_utf8($str) {
1121
- $cp1252_map = array(
1122
- "\xc2\x80" => "\xe2\x82\xac",
1123
- "\xc2\x82" => "\xe2\x80\x9a",
1124
- "\xc2\x83" => "\xc6\x92",
1125
- "\xc2\x84" => "\xe2\x80\x9e",
1126
- "\xc2\x85" => "\xe2\x80\xa6",
1127
- "\xc2\x86" => "\xe2\x80\xa0",
1128
- "\xc2\x87" => "\xe2\x80\xa1",
1129
- "\xc2\x88" => "\xcb\x86",
1130
- "\xc2\x89" => "\xe2\x80\xb0",
1131
- "\xc2\x8a" => "\xc5\xa0",
1132
- "\xc2\x8b" => "\xe2\x80\xb9",
1133
- "\xc2\x8c" => "\xc5\x92",
1134
- "\xc2\x8e" => "\xc5\xbd",
1135
- "\xc2\x91" => "\xe2\x80\x98",
1136
- "\xc2\x92" => "\xe2\x80\x99",
1137
- "\xc2\x93" => "\xe2\x80\x9c",
1138
- "\xc2\x94" => "\xe2\x80\x9d",
1139
- "\xc2\x95" => "\xe2\x80\xa2",
1140
- "\xc2\x96" => "\xe2\x80\x93",
1141
- "\xc2\x97" => "\xe2\x80\x94",
1142
- "\xc2\x98" => "\xcb\x9c",
1143
- "\xc2\x99" => "\xe2\x84\xa2",
1144
- "\xc2\x9a" => "\xc5\xa1",
1145
- "\xc2\x9b" => "\xe2\x80\xba",
1146
- "\xc2\x9c" => "\xc5\x93",
1147
- "\xc2\x9e" => "\xc5\xbe",
1148
- "\xc2\x9f" => "\xc5\xb8"
1149
- );
1150
- return strtr(utf8_encode($str), $cp1252_map);
1151
  }
1152
 
1153
  /**
@@ -1159,7 +1125,8 @@ function DecodeBase64Part(&$part) {
1159
  DebugEcho("DecodeBase64Part: base64 detected");
1160
  //DebugDump($part);
1161
  if (is_array($part->ctype_parameters) && array_key_exists('charset', $part->ctype_parameters)) {
1162
- $part->body = iconv($part->ctype_parameters['charset'], 'UTF-8', base64_decode($part->body));
 
1163
  } else {
1164
  $part->body = base64_decode($part->body);
1165
  }
@@ -1272,10 +1239,13 @@ function FilterAppleFile(&$mimeDecodedEmail) {
1272
  function postie_media_handle_upload($part, $post_id, $poster, $post_data = array()) {
1273
  $overrides = array('test_form' => false);
1274
  $tmpFile = tempnam(getenv('TEMP'), 'postie');
 
1275
  if (!is_writable($tmpFile)) {
1276
  $uploadDir = wp_upload_dir();
1277
  $tmpFile = tempnam($uploadDir['path'], 'postie');
 
1278
  }
 
1279
  $fp = fopen($tmpFile, 'w');
1280
  if ($fp) {
1281
  fwrite($fp, $part->body);
@@ -1292,13 +1262,16 @@ function postie_media_handle_upload($part, $post_id, $poster, $post_data = array
1292
  } else {
1293
  $name = $part->ctype_parameters['name'];
1294
  }
 
1295
 
1296
  $the_file = array('name' => $name,
1297
  'tmp_name' => $tmpFile,
1298
  'size' => filesize($tmpFile),
1299
  'error' => ''
1300
  );
 
1301
  if (stristr('.zip', $name)) {
 
1302
  $parts = explode('.', $name);
1303
  $ext = $parts[count($parts) - 1];
1304
  $type = $part->primary . '/' . $part->secondary;
@@ -1309,13 +1282,16 @@ function postie_media_handle_upload($part, $post_id, $poster, $post_data = array
1309
 
1310
  $time = current_time('mysql');
1311
  $post = get_post($post_id);
1312
- if (substr($post->post_date, 0, 4) > 0)
 
1313
  $time = $post->post_date;
 
1314
 
1315
  $file = postie_handle_upload($the_file, $overrides, $time);
1316
  //unlink($tmpFile);
1317
 
1318
  if (isset($file['error'])) {
 
1319
  throw new Exception($file['error']);
1320
  return new WP_Error('upload_error', $file['error']);
1321
  }
@@ -1329,10 +1305,14 @@ function postie_media_handle_upload($part, $post_id, $poster, $post_data = array
1329
  // use image exif/iptc data for title and caption defaults if possible
1330
  include_once(ABSPATH . '/wp-admin/includes/image.php');
1331
  if ($image_meta = @wp_read_image_metadata($file)) {
1332
- if (trim($image_meta['title']))
1333
  $title = $image_meta['title'];
1334
- if (trim($image_meta['caption']))
 
 
1335
  $content = $image_meta['caption'];
 
 
1336
  }
1337
 
1338
  // Construct the attachment array
@@ -1350,6 +1330,8 @@ function postie_media_handle_upload($part, $post_id, $poster, $post_data = array
1350
  $id = wp_insert_attachment($attachment, $file, $post_id);
1351
  if (!is_wp_error($id)) {
1352
  wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));
 
 
1353
  }
1354
 
1355
  return $id;
@@ -1438,7 +1420,7 @@ function postie_handle_upload(&$file, $overrides = false, $time = null) {
1438
  // Move the file to the uploads dir
1439
  $new_file = $uploads['path'] . "/$filename";
1440
  if (false === @ rename($file['tmp_name'], $new_file)) {
1441
- print_r($file);
1442
  return $upload_error_handler($file, sprintf(__('The uploaded file could not be moved to %s.'), $uploads['path']));
1443
  }
1444
 
@@ -1818,7 +1800,6 @@ function ReplaceImageCIDs(&$content, &$attachments) {
1818
  // DebugDump($attachments);
1819
  // DebugEcho('$used');
1820
  // DebugDump($used);
1821
-
1822
  // for ($i = 0; $i < count($attachments["html"]); $i++) {
1823
  // if (!in_array($i, $used)) {
1824
  // $html[] = $att[$i];
@@ -1859,12 +1840,15 @@ function ReplaceImagePlaceHolders(&$content, $attachments, $config) {
1859
  foreach ($attachments as $attachementName => $imageTemplate) {
1860
  // looks for ' #img1# ' etc... and replaces with image
1861
  $img_placeholder_temp = str_replace("%", intval($startIndex + $i), $image_placeholder);
1862
- $eimg_placeholder_temp = str_replace("%", intval($startIndex + $i), "#eimg%#");
1863
  $img_placeholder_temp = rtrim($img_placeholder_temp, '#');
 
 
1864
  $eimg_placeholder_temp = rtrim($eimg_placeholder_temp, '#');
1865
 
 
1866
  if (stristr($content, $img_placeholder_temp) || stristr($content, $eimg_placeholder_temp)) {
1867
  // look for caption
 
1868
  $caption = '';
1869
  $content = preg_replace("/&#0?39;/", "'", $content);
1870
  $content = preg_replace("/&(#0?34|quot);/", "\"", $content);
@@ -1876,12 +1860,18 @@ function ReplaceImagePlaceHolders(&$content, $attachments, $config) {
1876
  } else {
1877
  DebugEcho("No caption found");
1878
  }
1879
- $imageTemplate = str_replace('{CAPTION}', $caption, $imageTemplate);
 
 
 
1880
  $img_placeholder_temp.='#';
1881
  $eimg_placeholder_temp.='#';
 
 
1882
  $content = str_ireplace($img_placeholder_temp, $imageTemplate, $content);
1883
  $content = str_ireplace($eimg_placeholder_temp, $imageTemplate, $content);
1884
  } else {
 
1885
  $imageTemplate = str_replace('{CAPTION}', '', $imageTemplate);
1886
  /* if using the gallery shortcode, don't add pictures at all */
1887
  if (!preg_match("/\[gallery[^\[]*\]/", $content, $matches)) {
@@ -1916,6 +1906,7 @@ function GetSubject(&$mimeDecodedEmail, &$content, $config) {
1916
  $mimeDecodedEmail->headers['subject'] = $subject;
1917
  } else {
1918
  $subject = $mimeDecodedEmail->headers['subject'];
 
1919
  if (array_key_exists('content-transfer-encoding', $mimeDecodedEmail->headers)) {
1920
  $encoding = $mimeDecodedEmail->headers["content-transfer-encoding"];
1921
  } else if (array_key_exists("content-transfer-encoding", $mimeDecodedEmail->ctype_parameters)) {
@@ -1935,8 +1926,8 @@ function GetSubject(&$mimeDecodedEmail, &$content, $config) {
1935
 
1936
  for ($i = 0; $i < count($elements); $i++) {
1937
  $thischarset = $elements[$i]->charset;
1938
- if ($thischarset == 'default')
1939
- $thischarset = $charset;
1940
 
1941
  $subject.=HandleMessageEncoding($encoding, $thischarset, $elements[$i]->text, $message_encoding, $message_dequote);
1942
  }
@@ -1952,7 +1943,7 @@ function GetSubject(&$mimeDecodedEmail, &$content, $config) {
1952
  if (strpos($subject, "\x1b\x24\x42") !== false) {
1953
  // found iso-2022-jp escape sequence in subject... convert!
1954
  DebugEcho("extra parsing for ISO-2022-JP");
1955
- $subject = iconv("ISO-2022-JP//TRANSLIT", "UTF-8", $subject);
1956
  }
1957
  return $subject;
1958
  }
@@ -1963,15 +1954,19 @@ function GetSubject(&$mimeDecodedEmail, &$content, $config) {
1963
  */
1964
  function postie_get_tags(&$content, $defaultTags) {
1965
  $post_tags = array();
1966
- //try and determine tags
1967
- if (preg_match('/tags: ?(.*)\n/i', $content, $matches)) {
1968
- $content = str_replace($matches[0], "", $content);
1969
- $post_tags = preg_split("/,\s*/", $matches[1]);
 
 
 
 
1970
  }
1971
- if (!count($post_tags) && !empty($defaultTags)) {
1972
  $post_tags = $defaultTags;
1973
  }
1974
- return($post_tags);
1975
  }
1976
 
1977
  /**
@@ -1995,16 +1990,17 @@ function GetPostExcerpt(&$content, $filterNewLines, $convertNewLines) {
1995
  */
1996
  function GetPostCategories(&$subject, $defaultCategory) {
1997
  global $wpdb;
 
1998
  $post_categories = array();
1999
  $matches = array();
2000
  //try and determine category
2001
- if (preg_match('/(.+): (.*)/', $subject, $matches)) {
2002
  $subject = trim($matches[2]);
2003
  $matches[1] = array($matches[1]);
2004
- } else if (preg_match_all('/\[(.[^\[]*)\]/', $subject, $matches)) {
2005
  preg_match("/]([^\[]*)$/", $subject, $subject_matches);
2006
  $subject = trim($subject_matches[1]);
2007
- } else if (preg_match_all('/-(.[^-]*)-/', $subject, $matches)) {
2008
  preg_match("/-(.[^-]*)$/", $subject, $subject_matches);
2009
  $subject = trim($subject_matches[1]);
2010
  }
@@ -2031,13 +2027,14 @@ function GetPostCategories(&$subject, $defaultCategory) {
2031
  } elseif ($category = $wpdb->get_var($sql_sub_name)) {
2032
  //then cateogry is a start of a name and found
2033
  }
2034
- if ($category) {
2035
  $post_categories[] = $category;
2036
  }
2037
  }
2038
  }
2039
  if (!count($post_categories)) {
2040
  $post_categories[] = $defaultCategory;
 
2041
  }
2042
  return $post_categories;
2043
  }
@@ -2059,8 +2056,8 @@ function DisplayEmailPost($details) {
2059
  EchoInfo('Postname: ' . $details["post_name"]);
2060
  EchoInfo('Post Id: ' . $details["ID"]);
2061
  EchoInfo('Post Type: ' . $details["post_type"]); /* Added by Raam Dev <raam@raamdev.com> */
2062
- EchoInfo('Posted content:');
2063
- EchoInfo($details["post_content"]);
2064
  }
2065
 
2066
  /**
@@ -2261,14 +2258,11 @@ function GetDBConfig() {
2261
  if (!isset($config["PREFER_TEXT_TYPE"]))
2262
  $config["PREFER_TEXT_TYPE"] = "plain";
2263
  if (!isset($config["DEFAULT_TITLE"]))
2264
- $config["DEFAULT_TITLE"] = "Live Fro
2265
- m The Field";
2266
  if (!isset($config["INPUT_PROTOCOL"]))
2267
- $config["INPUT_PROTOCOL"]
2268
- = "pop3";
2269
  if (!isset($config["IMAGE_PLACEHOLDER"]))
2270
- $config["IMAGE_PLACEHOLDER"] = "#img%
2271
- #";
2272
  if (!isset($config["IMAGES_APPEND"]))
2273
  $config["IMAGES_APPEND"] = true;
2274
 
@@ -2311,8 +2305,7 @@ function GetDBConfig() {
2311
  if (!isset($config["BANNED_FILES_LIST"]))
2312
  $config["BANNED_FILES_LIST"] = array();
2313
  if (!isset($config["SUPPORTED_FILE_TYPES"]))
2314
- $config["SUPPORTED_FILE_TYPES"] = array("video", "applicatio
2315
- n");
2316
  if (!isset($config["AUTHORIZED_ADDRESSES"]))
2317
  $config["AUTHORIZED_ADDRESSES"] = array();
2318
  if (!isset($config["MAIL_SERVER"]))
@@ -2336,15 +2329,13 @@ function GetDBConfig() {
2336
  $config["TIME_OFFSET"] = get_option('gmt_offset');
2337
  if (!isset($config["WRAP_PRE"]))
2338
  $config["WRAP_PRE"] = 'no';
2339
- if (!isset($config["CONVERTUR
2340
- LS"]))
2341
  $config["CONVERTURLS"] = true;
2342
  if (!isset($config["SHORTCODE"]))
2343
  $config["SHORTCODE"] = false;
2344
  if (!isset($config["ADD_META"]))
2345
  $config["ADD_META"] = 'no';
2346
- $config['ICON_SETS'] = array('silver', 'black', 'w
2347
- hite', 'custom', 'none');
2348
  if (!isset($config["ICON_SET"]))
2349
  $config["ICON_SET"] = 'silver';
2350
  $config['ICON_SIZES'] = array(32, 48, 64);
@@ -2363,19 +2354,15 @@ function GetDBConfig() {
2363
  $config["AUDIOTEMPLATE"] = $simple_link;
2364
 
2365
  //video1
2366
-
2367
  if (!isset($config["VIDEO1TYPES"]))
2368
- $config['VIDEO1TYPES'] = array('mp4', 'mpeg4', '3gp',
2369
- '3gpp', '3gpp2',
2370
- '3gp2', 'mov', 'mpeg');
2371
  if (!isset($config["AUDIOTYPES"]))
2372
  $config['AUDIOTYPES'] = array('m4a', 'mp3', 'ogg', 'wav', 'mpeg');
2373
  if (!isset($config["SELECTED_VIDEO2TEMPLATE"]))
2374
  $config['SELECTED_VIDEO2TEMPLATE'] = 'simple_link';
2375
  include('templates/video1_templates.php');
2376
  $config['VIDEO1TEMPLATES'] = $video1Templates;
2377
- if
2378
- (!isset($config["VIDEO1TEMPLATE"]))
2379
  $config["VIDEO1TEMPLATE"] = $simple_link;
2380
 
2381
  //video2
@@ -2383,16 +2370,13 @@ function GetDBConfig() {
2383
  $config['VIDEO2TYPES'] = array('x-flv');
2384
  if (!isset($config["POST_STATUS"]))
2385
  $config["POST_STATUS"] = 'publish';
2386
- if (!isset($config["IMAGE_NE
2387
- W_WINDOW"]))
2388
  $config["IMAGE_NEW_WINDOW"] = false;
2389
- if (!isset($config["FILTERN
2390
- EWLINES"]))
2391
  $config["FILTERNEWLINES"] = true;
2392
  include('templates/video2_templates.php');
2393
  $config['VIDEO2TEMPLATES'] = $video2Templates;
2394
- if (!isset($config["V
2395
- IDEO2TEMPLATE"]))
2396
  $config["VIDEO2TEMPLATE"] = $simple_link;
2397
 
2398
  //image
@@ -2461,8 +2445,7 @@ function get_postie_config() {
2461
  function get_arrayed_settings() {
2462
  return array(
2463
  ', ' => array('audiotypes', 'video1types', 'video2types', 'default_post_tags'),
2464
- "\n" => array('smtp', 'authorized_addresses', 'supported_file_types',
2465
- 'banned_files_list', 'sig_pattern_list'));
2466
  }
2467
 
2468
  /**
@@ -2517,7 +2500,7 @@ function TestPostieDirectory() {
2517
  */
2518
  function TestForMarkdown() {
2519
  if (in_array("markdown.php", get_option("active_plugins"))) {
2520
- return(true);
2521
  }
2522
  return false;
2523
  }
@@ -2609,18 +2592,23 @@ function DebugEmailOutput(&$email, &$mimeDecodedEmail) {
2609
  //DebugDump($email);
2610
  //DebugDump($mimeDecodedEmail);
2611
 
2612
- $fname = POSTIE_ROOT . DIRECTORY_SEPARATOR . "test_emails" . DIRECTORY_SEPARATOR . SafeFileName($mimeDecodedEmail->headers["message-id"]);
2613
- $file = fopen($fname . ".txt ", "w");
2614
- fwrite($file, $email);
2615
- fclose($file);
 
 
2616
 
2617
- $file = fopen($fname . "-mime.txt ", "w");
2618
- fwrite($file, print_r($mimeDecodedEmail, true));
2619
- fclose($file);
2620
 
2621
- $file = fopen($fname . ".php ", "w");
2622
- fwrite($file, serialize($email));
2623
- fclose($file);
 
 
 
2624
  }
2625
  }
2626
 
@@ -2636,10 +2624,10 @@ function SpecialMessageParsing(&$content, &$attachments, $config) {
2636
  return;
2637
  }
2638
  if ($message_start) {
2639
- StartFilter($content, $message_start);
2640
  }
2641
  if ($message_end) {
2642
- EndFilter($content, $message_end);
2643
  }
2644
  if ($drop_signature) {
2645
  $content = remove_signature($content, $sig_pattern_list);
1
  <?php
2
 
3
  /*
4
+ $Id: postie-functions.php 639439 2012-12-14 22:03:09Z WayneAllen $
5
  */
6
 
7
  /* TODO
18
  //to turn on debug output add the following line to wp-config.php
19
  //define('POSTIE_DEBUG', true);
20
 
21
+ if (!function_exists('mb_str_replace')) {
22
+
23
+ function mb_str_replace($search, $replace, $subject, &$count = 0) {
24
+ if (!is_array($subject)) {
25
+ // Normalize $search and $replace so they are both arrays of the same length
26
+ $searches = is_array($search) ? array_values($search) : array($search);
27
+ $replacements = is_array($replace) ? array_values($replace) : array($replace);
28
+ $replacements = array_pad($replacements, count($searches), '');
29
+
30
+ foreach ($searches as $key => $search) {
31
+ $parts = mb_split(preg_quote($search), $subject);
32
+ $count += count($parts) - 1;
33
+ $subject = implode($replacements[$key], $parts);
34
+ }
35
+ } else {
36
+ // Call mb_str_replace for each subject in array, recursively
37
+ foreach ($subject as $key => $value) {
38
+ $subject[$key] = mb_str_replace($search, $replace, $value, $count);
39
+ }
40
+ }
41
+
42
+ return $subject;
43
+ }
44
+
45
+ }
46
+
47
  function postie_disable_revisions($restore = false) {
48
  global $_wp_post_type_features, $_postie_revisions;
49
 
149
  EchoInfo("new post id is $post_id");
150
 
151
  $content = GetContent($mimeDecodedEmail, $attachments, $post_id, $poster, $config);
152
+ //DebugEcho("the content is $content");
153
 
154
  $subject = GetSubject($mimeDecodedEmail, $content, $config);
155
 
270
  }
271
  postie_disable_revisions(true);
272
  postie_increase_memory(true);
273
+ DebugEcho("Done");
274
  }
275
 
276
  /** FUNCTIONS * */
450
  preg_match("/-(.[^-]*)$/", $tmpSubject, $tmpSubject_matches);
451
  $tmpSubject = trim($tmpSubject_matches[1]);
452
  }
453
+ $checkExistingPostQuery = "SELECT ID FROM $wpdb->posts WHERE '$tmpSubject' = post_title";
454
+ if ($id = $wpdb->get_var($wpdb->prepare($checkExistingPostQuery, array()))) {
 
455
  if (is_array($id)) {
456
  $id = $id[count($id) - 1];
457
  }
602
  function PostToDB($details, $isReply, $postToDb = true, $customImageField = false) {
603
  if ($postToDb) {
604
  if (!$isReply) {
605
+ $post_ID = wp_insert_post($details, true);
606
+ if (is_wp_error($post_ID)) {
607
+ EchoInfo("Error: " . $post_ID->get_error_message());
608
+ wp_delete_post($details['ID']);
609
+ }
610
  } else {
611
  $comment = array(
612
  'comment_author' => $details['comment_author'],
626
 
627
  $post_ID = wp_insert_comment($comment);
628
  }
629
+ if ($customImageField && $post_ID) {
630
  DebugEcho("Saving custom image fields");
631
  //DebugDump($details['customImages']);
632
 
636
  add_post_meta($post_ID, 'image' . $imageField, $image);
637
  $imageField++;
638
  }
 
 
639
  }
640
  }
641
  }
662
  extract($config);
663
  global $charset, $encoding;
664
 
665
+ $meta_return = '';
666
  DebugEcho("primary= " . $part->ctype_primary . ", secondary = " . $part->ctype_secondary);
667
 
668
  DecodeBase64Part($part);
699
  $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
700
  }
701
  } else {
 
 
 
 
702
  $filename = "";
703
  if (is_array($part->ctype_parameters) && array_key_exists('name', $part->ctype_parameters)) {
704
+ // fix filename (remove non-standard characters)
705
  $filename = preg_replace("/[^\x9\xA\xD\x20-\x7F]/", "", $part->ctype_parameters['name']);
706
  DebugEcho("Filename: $filename");
707
  }
708
  switch (strtolower($part->ctype_primary)) {
709
  case 'multipart':
710
+ //DebugDump($part);
711
  FilterTextParts($part, $prefer_text_type);
712
  foreach ($part->parts as $section) {
713
  $meta_return .= GetContent($section, $attachments, $post_id, $poster, $config);
715
  break;
716
 
717
  case 'text':
718
+ DebugDump($part);
719
  if (array_key_exists('charset', $part->ctype_parameters) && !empty($part->ctype_parameters['charset'])) {
720
  $charset = $part->ctype_parameters['charset'];
721
  DebugEcho("charset: $charset");
728
 
729
  if (array_key_exists('content-transfer-encoding', $part->headers)) {
730
  //DebugDump($part);
731
+ $part->body = HandleMessageEncoding($encoding, $charset, $part->body, $message_encoding, $message_dequote);
732
  //DebugDump($part);
733
  }
734
 
735
  //go through each sub-section
736
  if ($part->ctype_secondary == 'enriched') {
737
  //convert enriched text to HTML
738
+ DebugEcho("enriched");
739
  $meta_return .= etf2HTML($part->body) . "\n";
740
  } elseif ($part->ctype_secondary == 'html') {
741
  //strip excess HTML
742
+ DebugEcho("html");
743
  $meta_return .= HTML2HTML($part->body) . "\n";
744
  } else {
745
  //regular text, so just strip the pgp signature
746
+ DebugEcho("plain text");
747
  if ($allow_html_in_body) {
748
+ $meta_return .= $part->body;
749
  } else {
750
+ $meta_return .= htmlentities($part->body);
751
  }
752
  $meta_return = StripPGP($meta_return);
753
+ $meta_return = "<div>$meta_return</div>\n";
754
  }
755
  break;
756
 
809
  break;
810
  $file_id = postie_media_handle_upload($part, $post_id, $poster);
811
  $file = wp_get_attachment_url($file_id);
812
+ if (array_key_exists('content-id', $part->headers)) {
813
+ $cid = trim($part->headers["content-id"], "<>");
814
+ //cids are in <cid>
815
+ $icon = chooseAttachmentIcon($file, $part->ctype_primary, $part->ctype_secondary, $icon_set, $icon_size);
816
+ $attachments["html"][$filename] = "<a href='$file'>" . $icon . $filename . '</a>' . "\n";
817
+ if ($cid) {
818
+ $attachments["cids"][$cid] = array($file, count($attachments["html"]) - 1);
819
+ }
820
  }
821
  }
822
  break;
901
  function HTML2HTML($content) {
902
  $html = str_get_html($content);
903
  if ($html) {
904
+ // foreach ($html->find('script, style') as $node) {
905
+ // $node->outertext = '';
906
+ // }
907
+ // $html->load($html->save());
908
 
909
  $b = $html->find('body');
910
  if ($b) {
911
+ $content = "<div>" . $b[0]->innertext . "</div>\n";
912
  }
913
  }
914
  return $content;
990
  * @param string
991
  * @param string
992
  */
993
+ function StartFilter($content, $start) {
 
994
  $pos = strpos($content, $start);
995
  if ($pos === false) {
996
+ return $content;
997
  }
998
+ DebugEcho("start filter $start");
999
+ return substr($content, $pos + strlen($start), strlen($content));
1000
  }
1001
 
1002
  /**
1028
  * @param filter
1029
  */
1030
  function EndFilter($content, $end) {
 
1031
  $pos = strpos($content, $end);
1032
  if ($pos === false)
1033
  return $content;
1034
+ DebugEcho("end filter $end");
1035
  return $content = substr($content, 0, $pos);
1036
  }
1037
 
1082
  $body = utf8_decode($body);
1083
  }
1084
  if ($contenttransferencoding == 'quoted-printable') {
1085
+ $body = iconv($currentcharset, "UTF-8//TRANSLIT", quoted_printable_decode($body));
1086
  }
1087
  }
1088
  return $body;
1095
  DebugEcho("before HandleMessageEncoding");
1096
  DebugEcho("charset: $charset");
1097
  DebugEcho("encoding: $contenttransferencoding");
1098
+ //DebugDump($body);
1099
 
1100
  if ($contenttransferencoding == 'base64') {
1101
  DebugEcho("HandleMessageEncoding: base64 detected");
1102
  $body = base64_decode($body);
 
1103
  }
1104
  if ($dequote && $contenttransferencoding == 'quoted-printable') {
1105
  DebugEcho("quoted-printable detected");
1106
+ $body = quoted_printable_decode($body);
1107
  }
1108
 
1109
  DebugEcho("after HandleMessageEncoding");
1110
+ if (strtolower($charset) != 'default')
1111
+ $body = iconv($charset, $blogEncoding . '//TRANSLIT', $body);
1112
  return $body;
1113
  }
1114
 
1115
  function ConvertToUTF_8($charset, $body) {
1116
+ return iconv($charset, "UTF-8//TRANSLIT", $body);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1117
  }
1118
 
1119
  /**
1125
  DebugEcho("DecodeBase64Part: base64 detected");
1126
  //DebugDump($part);
1127
  if (is_array($part->ctype_parameters) && array_key_exists('charset', $part->ctype_parameters)) {
1128
+ $part->body = iconv($part->ctype_parameters['charset'], 'UTF-8//TRANSLIT', base64_decode($part->body));
1129
+ $part->ctype_parameters['charset'] = 'default'; //so we don't double decode
1130
  } else {
1131
  $part->body = base64_decode($part->body);
1132
  }
1239
  function postie_media_handle_upload($part, $post_id, $poster, $post_data = array()) {
1240
  $overrides = array('test_form' => false);
1241
  $tmpFile = tempnam(getenv('TEMP'), 'postie');
1242
+ DebugEcho("tmpfile: $tmpFile");
1243
  if (!is_writable($tmpFile)) {
1244
  $uploadDir = wp_upload_dir();
1245
  $tmpFile = tempnam($uploadDir['path'], 'postie');
1246
+ DebugEcho("tmpfile not writeable, using: $tmpFile");
1247
  }
1248
+
1249
  $fp = fopen($tmpFile, 'w');
1250
  if ($fp) {
1251
  fwrite($fp, $part->body);
1262
  } else {
1263
  $name = $part->ctype_parameters['name'];
1264
  }
1265
+ DebugEcho("name: $name, size: " . filesize($tmpFile));
1266
 
1267
  $the_file = array('name' => $name,
1268
  'tmp_name' => $tmpFile,
1269
  'size' => filesize($tmpFile),
1270
  'error' => ''
1271
  );
1272
+
1273
  if (stristr('.zip', $name)) {
1274
+ DebugEcho("exploding zip file");
1275
  $parts = explode('.', $name);
1276
  $ext = $parts[count($parts) - 1];
1277
  $type = $part->primary . '/' . $part->secondary;
1282
 
1283
  $time = current_time('mysql');
1284
  $post = get_post($post_id);
1285
+ if (substr($post->post_date, 0, 4) > 0) {
1286
+ DebugEcho("using post date");
1287
  $time = $post->post_date;
1288
+ }
1289
 
1290
  $file = postie_handle_upload($the_file, $overrides, $time);
1291
  //unlink($tmpFile);
1292
 
1293
  if (isset($file['error'])) {
1294
+ DebugDump($file['error']);
1295
  throw new Exception($file['error']);
1296
  return new WP_Error('upload_error', $file['error']);
1297
  }
1305
  // use image exif/iptc data for title and caption defaults if possible
1306
  include_once(ABSPATH . '/wp-admin/includes/image.php');
1307
  if ($image_meta = @wp_read_image_metadata($file)) {
1308
+ if (trim($image_meta['title'])) {
1309
  $title = $image_meta['title'];
1310
+ DebugEcho("Using metadata title: $title");
1311
+ }
1312
+ if (trim($image_meta['caption'])) {
1313
  $content = $image_meta['caption'];
1314
+ DebugEcho("Using metadata caption: $caption");
1315
+ }
1316
  }
1317
 
1318
  // Construct the attachment array
1330
  $id = wp_insert_attachment($attachment, $file, $post_id);
1331
  if (!is_wp_error($id)) {
1332
  wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file));
1333
+ } else {
1334
+ EchoInfo("There was an error adding the attachement: " . $id->get_error_message());
1335
  }
1336
 
1337
  return $id;
1420
  // Move the file to the uploads dir
1421
  $new_file = $uploads['path'] . "/$filename";
1422
  if (false === @ rename($file['tmp_name'], $new_file)) {
1423
+ DebugDump($file);
1424
  return $upload_error_handler($file, sprintf(__('The uploaded file could not be moved to %s.'), $uploads['path']));
1425
  }
1426
 
1800
  // DebugDump($attachments);
1801
  // DebugEcho('$used');
1802
  // DebugDump($used);
 
1803
  // for ($i = 0; $i < count($attachments["html"]); $i++) {
1804
  // if (!in_array($i, $used)) {
1805
  // $html[] = $att[$i];
1840
  foreach ($attachments as $attachementName => $imageTemplate) {
1841
  // looks for ' #img1# ' etc... and replaces with image
1842
  $img_placeholder_temp = str_replace("%", intval($startIndex + $i), $image_placeholder);
 
1843
  $img_placeholder_temp = rtrim($img_placeholder_temp, '#');
1844
+
1845
+ $eimg_placeholder_temp = str_replace("%", intval($startIndex + $i), "#eimg%#");
1846
  $eimg_placeholder_temp = rtrim($eimg_placeholder_temp, '#');
1847
 
1848
+ DebugEcho("img_placeholder_temp: $img_placeholder_temp");
1849
  if (stristr($content, $img_placeholder_temp) || stristr($content, $eimg_placeholder_temp)) {
1850
  // look for caption
1851
+ DebugEcho("Found $img_placeholder_temp or $eimg_placeholder_temp");
1852
  $caption = '';
1853
  $content = preg_replace("/&#0?39;/", "'", $content);
1854
  $content = preg_replace("/&(#0?34|quot);/", "\"", $content);
1860
  } else {
1861
  DebugEcho("No caption found");
1862
  }
1863
+ //DebugEcho("parameterize templete: " . htmlentities($imageTemplate));
1864
+ $imageTemplate = mb_str_replace('{CAPTION}', $caption, $imageTemplate);
1865
+ //DebugEcho("populated templete: " . htmlentities($imageTemplate));
1866
+
1867
  $img_placeholder_temp.='#';
1868
  $eimg_placeholder_temp.='#';
1869
+
1870
+ //DebugEcho("replacing " . htmlentities($img_placeholder_temp) . " with template");
1871
  $content = str_ireplace($img_placeholder_temp, $imageTemplate, $content);
1872
  $content = str_ireplace($eimg_placeholder_temp, $imageTemplate, $content);
1873
  } else {
1874
+ DebugEcho("No $img_placeholder_temp or $eimg_placeholder_temp found");
1875
  $imageTemplate = str_replace('{CAPTION}', '', $imageTemplate);
1876
  /* if using the gallery shortcode, don't add pictures at all */
1877
  if (!preg_match("/\[gallery[^\[]*\]/", $content, $matches)) {
1906
  $mimeDecodedEmail->headers['subject'] = $subject;
1907
  } else {
1908
  $subject = $mimeDecodedEmail->headers['subject'];
1909
+ DebugEcho(("Predecoded subject: $subject"));
1910
  if (array_key_exists('content-transfer-encoding', $mimeDecodedEmail->headers)) {
1911
  $encoding = $mimeDecodedEmail->headers["content-transfer-encoding"];
1912
  } else if (array_key_exists("content-transfer-encoding", $mimeDecodedEmail->ctype_parameters)) {
1926
 
1927
  for ($i = 0; $i < count($elements); $i++) {
1928
  $thischarset = $elements[$i]->charset;
1929
+ // if ($thischarset == 'default')
1930
+ // $thischarset = $charset;
1931
 
1932
  $subject.=HandleMessageEncoding($encoding, $thischarset, $elements[$i]->text, $message_encoding, $message_dequote);
1933
  }
1943
  if (strpos($subject, "\x1b\x24\x42") !== false) {
1944
  // found iso-2022-jp escape sequence in subject... convert!
1945
  DebugEcho("extra parsing for ISO-2022-JP");
1946
+ $subject = iconv("ISO-2022-JP", "UTF-8//TRANSLIT", $subject);
1947
  }
1948
  return $subject;
1949
  }
1954
  */
1955
  function postie_get_tags(&$content, $defaultTags) {
1956
  $post_tags = array();
1957
+ //try and determine tags
1958
+ if (preg_match('/tags: ?(.*)$/im', $content, $matches)) {
1959
+ if (!empty($matches[1])) {
1960
+ DebugEcho("Found tags: $matches[1]");
1961
+ $content = str_replace($matches[0], "", $content);
1962
+ $post_tags = preg_split("/,\s*/", $matches[1]);
1963
+ //DebugDump($post_tags);
1964
+ }
1965
  }
1966
+ if (count($post_tags) == 0 && is_array($defaultTags)) {
1967
  $post_tags = $defaultTags;
1968
  }
1969
+ return $post_tags;
1970
  }
1971
 
1972
  /**
1990
  */
1991
  function GetPostCategories(&$subject, $defaultCategory) {
1992
  global $wpdb;
1993
+ $original_subject = $subject;
1994
  $post_categories = array();
1995
  $matches = array();
1996
  //try and determine category
1997
+ if (preg_match('/(.+): (.*)/', $subject, $matches)) { // <category>:<Subject>
1998
  $subject = trim($matches[2]);
1999
  $matches[1] = array($matches[1]);
2000
+ } else if (preg_match_all('/\[(.[^\[]*)\]/', $subject, $matches)) { // [<category1>] [<category2>] <Subject>
2001
  preg_match("/]([^\[]*)$/", $subject, $subject_matches);
2002
  $subject = trim($subject_matches[1]);
2003
+ } else if (preg_match_all('/-(.[^-]*)-/', $subject, $matches)) { // -<category>- -<category2>- <Subject>
2004
  preg_match("/-(.[^-]*)$/", $subject, $subject_matches);
2005
  $subject = trim($subject_matches[1]);
2006
  }
2027
  } elseif ($category = $wpdb->get_var($sql_sub_name)) {
2028
  //then cateogry is a start of a name and found
2029
  }
2030
+ if (!empty($category)) {
2031
  $post_categories[] = $category;
2032
  }
2033
  }
2034
  }
2035
  if (!count($post_categories)) {
2036
  $post_categories[] = $defaultCategory;
2037
+ $subject = $original_subject;
2038
  }
2039
  return $post_categories;
2040
  }
2056
  EchoInfo('Postname: ' . $details["post_name"]);
2057
  EchoInfo('Post Id: ' . $details["ID"]);
2058
  EchoInfo('Post Type: ' . $details["post_type"]); /* Added by Raam Dev <raam@raamdev.com> */
2059
+ // EchoInfo('Posted content:');
2060
+ // EchoInfo($details["post_content"]);
2061
  }
2062
 
2063
  /**
2258
  if (!isset($config["PREFER_TEXT_TYPE"]))
2259
  $config["PREFER_TEXT_TYPE"] = "plain";
2260
  if (!isset($config["DEFAULT_TITLE"]))
2261
+ $config["DEFAULT_TITLE"] = "Live From The Field";
 
2262
  if (!isset($config["INPUT_PROTOCOL"]))
2263
+ $config["INPUT_PROTOCOL"] = "pop3";
 
2264
  if (!isset($config["IMAGE_PLACEHOLDER"]))
2265
+ $config["IMAGE_PLACEHOLDER"] = "#img%#";
 
2266
  if (!isset($config["IMAGES_APPEND"]))
2267
  $config["IMAGES_APPEND"] = true;
2268
 
2305
  if (!isset($config["BANNED_FILES_LIST"]))
2306
  $config["BANNED_FILES_LIST"] = array();
2307
  if (!isset($config["SUPPORTED_FILE_TYPES"]))
2308
+ $config["SUPPORTED_FILE_TYPES"] = array("video", "application");
 
2309
  if (!isset($config["AUTHORIZED_ADDRESSES"]))
2310
  $config["AUTHORIZED_ADDRESSES"] = array();
2311
  if (!isset($config["MAIL_SERVER"]))
2329
  $config["TIME_OFFSET"] = get_option('gmt_offset');
2330
  if (!isset($config["WRAP_PRE"]))
2331
  $config["WRAP_PRE"] = 'no';
2332
+ if (!isset($config["CONVERTURLS"]))
 
2333
  $config["CONVERTURLS"] = true;
2334
  if (!isset($config["SHORTCODE"]))
2335
  $config["SHORTCODE"] = false;
2336
  if (!isset($config["ADD_META"]))
2337
  $config["ADD_META"] = 'no';
2338
+ $config['ICON_SETS'] = array('silver', 'black', 'white', 'custom', 'none');
 
2339
  if (!isset($config["ICON_SET"]))
2340
  $config["ICON_SET"] = 'silver';
2341
  $config['ICON_SIZES'] = array(32, 48, 64);
2354
  $config["AUDIOTEMPLATE"] = $simple_link;
2355
 
2356
  //video1
 
2357
  if (!isset($config["VIDEO1TYPES"]))
2358
+ $config['VIDEO1TYPES'] = array('mp4', 'mpeg4', '3gp', '3gpp', '3gpp2', '3gp2', 'mov', 'mpeg');
 
 
2359
  if (!isset($config["AUDIOTYPES"]))
2360
  $config['AUDIOTYPES'] = array('m4a', 'mp3', 'ogg', 'wav', 'mpeg');
2361
  if (!isset($config["SELECTED_VIDEO2TEMPLATE"]))
2362
  $config['SELECTED_VIDEO2TEMPLATE'] = 'simple_link';
2363
  include('templates/video1_templates.php');
2364
  $config['VIDEO1TEMPLATES'] = $video1Templates;
2365
+ if (!isset($config["VIDEO1TEMPLATE"]))
 
2366
  $config["VIDEO1TEMPLATE"] = $simple_link;
2367
 
2368
  //video2
2370
  $config['VIDEO2TYPES'] = array('x-flv');
2371
  if (!isset($config["POST_STATUS"]))
2372
  $config["POST_STATUS"] = 'publish';
2373
+ if (!isset($config["IMAGE_NEW_WINDOW"]))
 
2374
  $config["IMAGE_NEW_WINDOW"] = false;
2375
+ if (!isset($config["FILTERNEWLINES"]))
 
2376
  $config["FILTERNEWLINES"] = true;
2377
  include('templates/video2_templates.php');
2378
  $config['VIDEO2TEMPLATES'] = $video2Templates;
2379
+ if (!isset($config["VIDEO2TEMPLATE"]))
 
2380
  $config["VIDEO2TEMPLATE"] = $simple_link;
2381
 
2382
  //image
2445
  function get_arrayed_settings() {
2446
  return array(
2447
  ', ' => array('audiotypes', 'video1types', 'video2types', 'default_post_tags'),
2448
+ "\n" => array('smtp', 'authorized_addresses', 'supported_file_types', 'banned_files_list', 'sig_pattern_list'));
 
2449
  }
2450
 
2451
  /**
2500
  */
2501
  function TestForMarkdown() {
2502
  if (in_array("markdown.php", get_option("active_plugins"))) {
2503
+ return true;
2504
  }
2505
  return false;
2506
  }
2592
  //DebugDump($email);
2593
  //DebugDump($mimeDecodedEmail);
2594
 
2595
+ $dname = POSTIE_ROOT . DIRECTORY_SEPARATOR . "test_emails" . DIRECTORY_SEPARATOR;
2596
+ if (is_dir($dname)) {
2597
+ $fname = $dname . SafeFileName($mimeDecodedEmail->headers["message-id"]);
2598
+ $file = fopen($fname . ".txt ", "w");
2599
+ fwrite($file, $email);
2600
+ fclose($file);
2601
 
2602
+ $file = fopen($fname . "-mime.txt ", "w");
2603
+ fwrite($file, print_r($mimeDecodedEmail, true));
2604
+ fclose($file);
2605
 
2606
+ $file = fopen($fname . ".php ", "w");
2607
+ fwrite($file, serialize($email));
2608
+ fclose($file);
2609
+ } else {
2610
+ DebugEcho("The directory $dname does not exist, creating this optional directory will allow saving copies of emails for debugging purposes.");
2611
+ }
2612
  }
2613
  }
2614
 
2624
  return;
2625
  }
2626
  if ($message_start) {
2627
+ $content = StartFilter($content, $message_start);
2628
  }
2629
  if ($message_end) {
2630
+ $content = EndFilter($content, $message_end);
2631
  }
2632
  if ($drop_signature) {
2633
  $content = remove_signature($content, $sig_pattern_list);
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.10
8
  Author: Wayne Allen
9
  Author URI: http://allens-home.com/
10
  License: GPL2
@@ -27,10 +27,8 @@
27
  */
28
 
29
  /*
30
- $Id: postie.php 637396 2012-12-12 00:48:27Z WayneAllen $
31
  * -= Requests Pending =-
32
- * German Umlats don't work
33
- * Problems under PHP5
34
  * Problem with some mail server
35
  * Multiple emails should tie to a single account
36
  * Each user should be able to have a default category
@@ -52,10 +50,10 @@
52
  * www.cdavies.org/permalink/watchingbrowserembeddedgpvideosinlinux.php
53
  * Support private posts
54
  * Make it possible to post without a script at all
55
- * * TODO - fix corruption of rtf attachments
56
  * TODO - add port checking in tests
57
- * TODO - non-image uploads get ignored in content when using autogallery - see
58
- replaceimageplaceholders
59
  */
60
 
61
  define("POSTIE_ROOT", dirname(__FILE__));
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.11
8
  Author: Wayne Allen
9
  Author URI: http://allens-home.com/
10
  License: GPL2
27
  */
28
 
29
  /*
30
+ $Id: postie.php 639546 2012-12-15 05:05:41Z WayneAllen $
31
  * -= Requests Pending =-
 
 
32
  * Problem with some mail server
33
  * Multiple emails should tie to a single account
34
  * Each user should be able to have a default category
50
  * www.cdavies.org/permalink/watchingbrowserembeddedgpvideosinlinux.php
51
  * Support private posts
52
  * Make it possible to post without a script at all
53
+ * TODO - fix corruption of rtf attachments
54
  * TODO - add port checking in tests
55
+ * TODO - non-image uploads get ignored in content when using autogallery - see replaceimageplaceholders
56
+ * TODO - code to set featured image
57
  */
58
 
59
  define("POSTIE_ROOT", dirname(__FILE__));
readme.txt CHANGED
@@ -5,8 +5,8 @@ Author URI: http://allens-home.com/
5
  Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
- Tested up to: 3.4.2
9
- Stable tag: 1.4.10
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
@@ -358,6 +358,17 @@ It is also possible to turn the WordPress cron off. Please make sure something l
358
  * All script, style and body tags are stripped from html emails.
359
 
360
  == CHANGELOG ==
 
 
 
 
 
 
 
 
 
 
 
361
  = 1.4.10 (2012.12.11) =
362
  * Fixed warning when there is no subject
363
  * Removed all script and style tags from HTML content in place of XSS warning
5
  Plugin URI: http://PostiePlugin.com/
6
  Tags: e-mail, email
7
  Requires at least: 3.0
8
+ Tested up to: 3.5
9
+ Stable tag: 1.4.11
10
  License: GPLv2 or later
11
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
12
 
358
  * All script, style and body tags are stripped from html emails.
359
 
360
  == CHANGELOG ==
361
+ = 1.4.11.(2012.12.14) =
362
+ * Fixed bug where having a colon in the subject caused the subject to get truncated
363
+ * Added donation link to admin screen
364
+ * Fixed bug where #img# captions with double-byte characters were not working
365
+ * Fixed bug where default settings were corrupt
366
+ * Fixed several bugs in tag detection logic
367
+ * Fixed bug where non-base64 and non-quoted-printable sections were not converted to utf-8
368
+ * Fixed bug where the end filter wasn't removed from the post
369
+ * Add additional logging to attachment upload process
370
+ * Changes to support WP 3.5
371
+
372
  = 1.4.10 (2012.12.11) =
373
  * Fixed warning when there is no subject
374
  * Removed all script and style tags from HTML content in place of XSS warning
test/inlineimageTest.php CHANGED
@@ -106,7 +106,7 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
106
 
107
  $customImages = SpecialMessageParsing($content, $attachments, $config);
108
  $this->assertEquals(null, $customImages);
109
- $this->assertEquals("test content\n\n", $content);
110
 
111
  $post_excerpt = GetPostExcerpt($content, $filternewlines, $convertnewline);
112
 
@@ -179,6 +179,11 @@ class postiefunctions2Test extends PHPUnit_Framework_TestCase {
179
  ReplaceImagePlaceHolders($c, $attachements, $config);
180
  $this->assertEquals("test template with I'd like some cheese. test", $c);
181
 
 
 
 
 
 
182
  $c = "test #img1 caption='[image-caption]'# test";
183
  ReplaceImagePlaceHolders($c, $attachements, $config);
184
  $this->assertEquals("test template with [image-caption] test", $c);
106
 
107
  $customImages = SpecialMessageParsing($content, $attachments, $config);
108
  $this->assertEquals(null, $customImages);
109
+ $this->assertEquals("<div>test content\n\n", $content);
110
 
111
  $post_excerpt = GetPostExcerpt($content, $filternewlines, $convertnewline);
112
 
179
  ReplaceImagePlaceHolders($c, $attachements, $config);
180
  $this->assertEquals("test template with I'd like some cheese. test", $c);
181
 
182
+ $c = "test #img1 caption=\"Eiskernbrecher mögens laut\"# test";
183
+ ReplaceImagePlaceHolders($c, $attachements, $config);
184
+ $this->assertEquals("test template with Eiskernbrecher mögens laut test", $c);
185
+
186
+
187
  $c = "test #img1 caption='[image-caption]'# test";
188
  ReplaceImagePlaceHolders($c, $attachements, $config);
189
  $this->assertEquals("test template with [image-caption] test", $c);
test/postie-functionsTest.php CHANGED
@@ -5,6 +5,10 @@ require'../postie-functions.php';
5
  require'../simple_html_dom.php';
6
  require '../postie.php';
7
 
 
 
 
 
8
  class postiefunctionsTest extends PHPUnit_Framework_TestCase {
9
 
10
  public function testAllowCommentsOnPost() {
@@ -147,6 +151,13 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
147
 
148
  $c = "test xxx test";
149
  $this->assertEquals("test ", EndFilter($c, "xxx"));
 
 
 
 
 
 
 
150
  }
151
 
152
  public function testFilterNewLines() {
@@ -201,15 +212,15 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
201
  $subject = "//";
202
  $this->assertEquals("post", GetPostType($subject));
203
  $this->assertEquals("", $subject);
204
-
205
  $subject = "Image//test";
206
  $this->assertEquals("image", GetPostType($subject));
207
  $this->assertEquals("test", $subject);
208
-
209
  $subject = "Image // test";
210
  $this->assertEquals("image", GetPostType($subject));
211
  $this->assertEquals("test", $subject);
212
-
213
  $subject = "video//test";
214
  $this->assertEquals("video", GetPostType($subject));
215
  $this->assertEquals("test", $subject);
@@ -237,12 +248,33 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
237
  $this->assertEquals("default", $c[0]);
238
  $this->assertEquals("test", $s);
239
 
 
 
 
 
 
240
  $wpdb->t_get_var = "1";
241
  $s = "1: test";
242
  $c = GetPostCategories($s, "default");
243
  $this->assertEquals("1", $c[0]);
244
  $this->assertEquals("test", $s);
245
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
246
  $wpdb->t_get_var = "general";
247
  $s = "general: test";
248
  $c = GetPostCategories($s, "default");
@@ -254,6 +286,7 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
254
  $this->assertEquals("general", $c[0]);
255
  $this->assertEquals("test", $s);
256
 
 
257
  $s = "-general- test";
258
  $c = GetPostCategories($s, "default");
259
  $this->assertEquals("general", $c[0]);
@@ -263,7 +296,7 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
263
  $s = "specific: test";
264
  $c = GetPostCategories($s, "default");
265
  $this->assertEquals("default", $c[0]);
266
- $this->assertEquals("test", $s);
267
 
268
  $wpdb->t_get_var = "1";
269
  $s = "[1] [1] test";
@@ -277,9 +310,9 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
277
  public function testHTML2HTML() {
278
  $this->assertEquals("", HTML2HTML(""));
279
  $this->assertEquals("test", HTML2HTML("test"));
280
- $this->assertEquals("test", HTML2HTML("<html lang='en'><body>test</body></html>"));
281
- $this->assertEquals("test", HTML2HTML("<html lang='en'><head><title>title</title></head><body>test</body></html>"));
282
- $this->assertEquals("test", HTML2HTML("<body>test</body>"));
283
  $this->assertEquals("<strong>test</strong>", HTML2HTML("<strong>test</strong>"));
284
  }
285
 
@@ -305,6 +338,83 @@ class postiefunctionsTest extends PHPUnit_Framework_TestCase {
305
  $this->assertEquals(3, count($newsched));
306
  }
307
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  }
309
 
310
  ?>
5
  require'../simple_html_dom.php';
6
  require '../postie.php';
7
 
8
+ define('WP_DEBUG', true);
9
+ define('WP_DEBUG_LOG', true);
10
+ define('POSTIE_DEBUG', true);
11
+
12
  class postiefunctionsTest extends PHPUnit_Framework_TestCase {
13
 
14
  public function testAllowCommentsOnPost() {
151
 
152
  $c = "test xxx test";
153
  $this->assertEquals("test ", EndFilter($c, "xxx"));
154
+
155
+ $c = "tags: Station, Kohnen, Flugzeug\n:end\n21.10.2012";
156
+ $this->assertEquals("tags: Station, Kohnen, Flugzeug\n", EndFilter($c, ":end"));
157
+
158
+ $c = "This is a test :end";
159
+ $this->assertEquals("This is a test ", EndFilter($c, ":end"));
160
+
161
  }
162
 
163
  public function testFilterNewLines() {
212
  $subject = "//";
213
  $this->assertEquals("post", GetPostType($subject));
214
  $this->assertEquals("", $subject);
215
+
216
  $subject = "Image//test";
217
  $this->assertEquals("image", GetPostType($subject));
218
  $this->assertEquals("test", $subject);
219
+
220
  $subject = "Image // test";
221
  $this->assertEquals("image", GetPostType($subject));
222
  $this->assertEquals("test", $subject);
223
+
224
  $subject = "video//test";
225
  $this->assertEquals("video", GetPostType($subject));
226
  $this->assertEquals("test", $subject);
248
  $this->assertEquals("default", $c[0]);
249
  $this->assertEquals("test", $s);
250
 
251
+ $s = ":test";
252
+ $c = GetPostCategories($s, "default");
253
+ $this->assertEquals("default", $c[0]);
254
+ $this->assertEquals(":test", $s);
255
+
256
  $wpdb->t_get_var = "1";
257
  $s = "1: test";
258
  $c = GetPostCategories($s, "default");
259
  $this->assertEquals("1", $c[0]);
260
  $this->assertEquals("test", $s);
261
 
262
+ $wpdb->t_get_var = null;
263
+ $s = "not a category: test";
264
+ $c = GetPostCategories($s, "default");
265
+ $this->assertEquals("default", $c[0]);
266
+ $this->assertEquals("not a category: test", $s);
267
+
268
+ $s = "[not a category] test";
269
+ $c = GetPostCategories($s, "default");
270
+ $this->assertEquals("default", $c[0]);
271
+ $this->assertEquals("[not a category] test", $s);
272
+
273
+ $s = "-not a category- test";
274
+ $c = GetPostCategories($s, "default");
275
+ $this->assertEquals("default", $c[0]);
276
+ $this->assertEquals("-not a category- test", $s);
277
+
278
  $wpdb->t_get_var = "general";
279
  $s = "general: test";
280
  $c = GetPostCategories($s, "default");
286
  $this->assertEquals("general", $c[0]);
287
  $this->assertEquals("test", $s);
288
 
289
+
290
  $s = "-general- test";
291
  $c = GetPostCategories($s, "default");
292
  $this->assertEquals("general", $c[0]);
296
  $s = "specific: test";
297
  $c = GetPostCategories($s, "default");
298
  $this->assertEquals("default", $c[0]);
299
+ $this->assertEquals("specific: test", $s);
300
 
301
  $wpdb->t_get_var = "1";
302
  $s = "[1] [1] test";
310
  public function testHTML2HTML() {
311
  $this->assertEquals("", HTML2HTML(""));
312
  $this->assertEquals("test", HTML2HTML("test"));
313
+ $this->assertEquals("<div>test</div>\n", HTML2HTML("<html lang='en'><body>test</body></html>"));
314
+ $this->assertEquals("<div>test</div>\n", HTML2HTML("<html lang='en'><head><title>title</title></head><body>test</body></html>"));
315
+ $this->assertEquals("<div>test</div>\n", HTML2HTML("<body>test</body>"));
316
  $this->assertEquals("<strong>test</strong>", HTML2HTML("<strong>test</strong>"));
317
  }
318
 
338
  $this->assertEquals(3, count($newsched));
339
  }
340
 
341
+ public function testpostie_get_tags() {
342
+ $c = "";
343
+ $t = postie_get_tags($c, "");
344
+ $this->assertEquals(0, count($t));
345
+ $this->assertEquals("", $c);
346
+
347
+ $c = "test";
348
+ $t = postie_get_tags($c, "");
349
+ $this->assertEquals(0, count($t));
350
+ $this->assertEquals("test", $c);
351
+
352
+ $c = "test";
353
+ $t = postie_get_tags($c, array("tag1"));
354
+ $this->assertEquals(1, count($t));
355
+ $this->assertEquals("tag1", $t[0]);
356
+ $this->assertEquals("test", $c);
357
+
358
+ $c = "test tags:";
359
+ $t = postie_get_tags($c, "");
360
+ $this->assertEquals(0, count($t));
361
+ $this->assertEquals("test tags:", $c);
362
+
363
+ $c = "test tags:\n";
364
+ $t = postie_get_tags($c, "");
365
+ $this->assertEquals(0, count($t));
366
+ $this->assertEquals("test tags:\n", $c);
367
+
368
+ $c = "test tags: tag1";
369
+ $t = postie_get_tags($c, "");
370
+ $this->assertEquals(1, count($t));
371
+ $this->assertEquals("test ", $c);
372
+
373
+ $c = "test\ntags: tag1";
374
+ $t = postie_get_tags($c, "");
375
+ $this->assertEquals(1, count($t));
376
+ $this->assertEquals("test\n", $c);
377
+
378
+ $c = "test tags: tag1\n";
379
+ $t = postie_get_tags($c, "");
380
+ $this->assertEquals(1, count($t));
381
+ $this->assertEquals("tag1", $t[0]);
382
+ $this->assertEquals("test \n", $c);
383
+
384
+ $c = "test tags:tag1";
385
+ $t = postie_get_tags($c, "");
386
+ $this->assertEquals(1, count($t));
387
+ $this->assertEquals("tag1", $t[0]);
388
+ $this->assertEquals("test ", $c);
389
+
390
+ $c = "test tags:tag1";
391
+ $t = postie_get_tags($c, array("tagx"));
392
+ $this->assertEquals(1, count($t));
393
+ $this->assertEquals("tag1", $t[0]);
394
+ $this->assertEquals("test ", $c);
395
+
396
+ $c = "test tags:tag1,tag2";
397
+ $t = postie_get_tags($c, "");
398
+ $this->assertEquals(2, count($t));
399
+ $this->assertEquals("tag1", $t[0]);
400
+ $this->assertEquals("tag2", $t[1]);
401
+ $this->assertEquals("test ", $c);
402
+
403
+ $c = "test tags: tag3,tag4\nmore stuff\n:end";
404
+ $t = postie_get_tags($c, "");
405
+ $this->assertEquals(2, count($t));
406
+ $this->assertEquals("tag3", $t[0]);
407
+ $this->assertEquals("tag4", $t[1]);
408
+ $this->assertEquals("test \nmore stuff\n:end", $c);
409
+
410
+ $c = "test tags:tag1,tag2\nmore stuff\n:end";
411
+ $t = postie_get_tags($c, "");
412
+ $this->assertEquals(2, count($t));
413
+ $this->assertEquals("tag1", $t[0]);
414
+ $this->assertEquals("tag2", $t[1]);
415
+ $this->assertEquals("test \nmore stuff\n:end", $c);
416
+ }
417
+
418
  }
419
 
420
  ?>
test/wpstub.php CHANGED
@@ -1,6 +1,6 @@
1
  <?php
2
 
3
- define('ABSPATH', dirname(__FILE__) . '/');
4
  define('WP_PLUGIN_URL', 'localhost');
5
 
6
  class wpdb {
@@ -32,8 +32,7 @@ function current_time() {
32
  return '2005-08-05 10:41:13';
33
  }
34
 
35
- function is_admin()
36
- {
37
  return false;
38
  }
39
 
@@ -56,17 +55,17 @@ function wp_check_filetype() {
56
 
57
  function wp_upload_dir() {
58
  return array(
59
- 'path' => '/tmp',
60
  'url' => 'http://example.com/upload/',
61
- 'subdir' => '/tmp/',
62
- 'basedir' => '/tmp;',
63
  'baseurl' => 'http://example.com/',
64
  'error' => false
65
  );
66
  }
67
 
68
  function wp_unique_filename() {
69
- return '/tmp/file.txt';
70
  }
71
 
72
  function wp_get_attachment_url() {
@@ -85,23 +84,24 @@ function get_attachment_link() {
85
  return 'http://example.net/wp-content/uploads/filename.jpg';
86
  }
87
 
88
- function get_user_by(){
89
  return false;
90
  }
91
 
92
- function register_activation_hook(){
93
 
94
  }
95
 
96
- function add_action(){
97
 
98
  }
99
 
100
- function add_filter(){
101
 
102
  }
103
 
104
- function register_deactivation_hook(){
105
 
106
  }
 
107
  ?>
1
  <?php
2
 
3
+ define('ABSPATH', dirname(dirname(__FILE__)) . '/');
4
  define('WP_PLUGIN_URL', 'localhost');
5
 
6
  class wpdb {
32
  return '2005-08-05 10:41:13';
33
  }
34
 
35
+ function is_admin() {
 
36
  return false;
37
  }
38
 
55
 
56
  function wp_upload_dir() {
57
  return array(
58
+ 'path' => sys_get_temp_dir(),
59
  'url' => 'http://example.com/upload/',
60
+ 'subdir' => sys_get_temp_dir(),
61
+ 'basedir' => sys_get_temp_dir(),
62
  'baseurl' => 'http://example.com/',
63
  'error' => false
64
  );
65
  }
66
 
67
  function wp_unique_filename() {
68
+ return tempnam(sys_get_temp_dir(), "postie");
69
  }
70
 
71
  function wp_get_attachment_url() {
84
  return 'http://example.net/wp-content/uploads/filename.jpg';
85
  }
86
 
87
+ function get_user_by() {
88
  return false;
89
  }
90
 
91
+ function register_activation_hook() {
92
 
93
  }
94
 
95
+ function add_action() {
96
 
97
  }
98
 
99
+ function add_filter() {
100
 
101
  }
102
 
103
+ function register_deactivation_hook() {
104
 
105
  }
106
+
107
  ?>