Skip to content
Newer
Older
100644 166 lines (130 sloc) 5.01 KB
b43564c *** empty log message ***
saxmatt authored
1 <?php
43e4a8a The great renaming.
saxmatt authored
2 require(dirname(__FILE__) . '/wp-config.php');
b43564c *** empty log message ***
saxmatt authored
3
99a7358 Renaming Reloaded.
saxmatt authored
4 require_once(ABSPATH.WPINC.'/class-pop3.php');
b43564c *** empty log message ***
saxmatt authored
5
6 error_reporting(2037);
7
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
8 $time_difference = get_settings('gmt_offset') * 3600;
5b0fcdb Timezone fix from Kimmo Suominen.
saxmatt authored
9
c913685 Massive options cleanup and another step of cleaning up the upgrade/i…
saxmatt authored
10 $phone_delim = '::';
3e1304d More wp-mail timezone and delimiter fixes from Kitten.
rboren authored
11
b43564c *** empty log message ***
saxmatt authored
12 $pop3 = new POP3();
13
a0ad8e4 New mail functionality.
saxmatt authored
14 if (!$pop3->connect(get_settings('mailserver_url'), get_settings('mailserver_port'))) :
b43564c *** empty log message ***
saxmatt authored
15 echo "Ooops $pop3->ERROR <br />\n";
16 exit;
a0ad8e4 New mail functionality.
saxmatt authored
17 endif;
b43564c *** empty log message ***
saxmatt authored
18
a0ad8e4 New mail functionality.
saxmatt authored
19 $count = $pop3->login(get_settings('mailserver_login'), get_settings('mailserver_pass'));
20 if (0 == $count) die(__('There doesn&#8217;t seem to be any new mail.'));
b43564c *** empty log message ***
saxmatt authored
21
22
a0ad8e4 New mail functionality.
saxmatt authored
23 for ($i=1; $i <= $count; $i++) :
b43564c *** empty log message ***
saxmatt authored
24
a0ad8e4 New mail functionality.
saxmatt authored
25 $message = $pop3->get($i);
b43564c *** empty log message ***
saxmatt authored
26
27 $content = '';
28 $content_type = '';
29 $boundary = '';
30 $bodysignal = 0;
31 $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
32 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
a0ad8e4 New mail functionality.
saxmatt authored
33 foreach ($message as $line) :
34 if (strlen($line) < 3) $bodysignal = 1;
35
b43564c *** empty log message ***
saxmatt authored
36 if ($bodysignal) {
37 $content .= $line;
38 } else {
5b0fcdb Timezone fix from Kimmo Suominen.
saxmatt authored
39 if (preg_match('/Content-Type: /i', $line)) {
b43564c *** empty log message ***
saxmatt authored
40 $content_type = trim($line);
41 $content_type = substr($content_type, 14, strlen($content_type)-14);
42 $content_type = explode(';', $content_type);
43 $content_type = $content_type[0];
44 }
45 if (($content_type == 'multipart/alternative') && (preg_match('/boundary="/', $line)) && ($boundary == '')) {
46 $boundary = trim($line);
47 $boundary = explode('"', $boundary);
48 $boundary = $boundary[1];
49 }
5b0fcdb Timezone fix from Kimmo Suominen.
saxmatt authored
50 if (preg_match('/Subject: /i', $line)) {
b43564c *** empty log message ***
saxmatt authored
51 $subject = trim($line);
52 $subject = substr($subject, 9, strlen($subject)-9);
1bf946e Fixes #1515
matt authored
53 $subject = wp_iso_descrambler($subject);
3e1304d More wp-mail timezone and delimiter fixes from Kitten.
rboren authored
54 // Captures any text in the subject before $phone_delim as the subject
55 $subject = explode($phone_delim, $subject);
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
56 $subject = $subject[0];
b43564c *** empty log message ***
saxmatt authored
57 }
cb96ccc Have WP mailed post come from author if email matches author in DB. H…
saxmatt authored
58
59 // Set the author using the email address (To or Reply-To, the last used)
60 // otherwise use the site admin
61 if (preg_match('/From: /', $line) | preg_match('Reply-To: /', $line)) {
62 $author=trim($line);
63 if ( ereg("([a-zA-Z0-9\_\-\.]+@[\a-zA-z0-9\_\-\.]+)", $author , $regs) ) {
7310346 wp-mail quote escaping fix from majelbstoat. fixes #2209
ryan authored
64 $author = $regs[1];
65 echo "Author = {$author} <p>";
66 $author = $wpdb->escape($author);
67 $result = $wpdb->get_row("SELECT ID FROM $wpdb->users WHERE user_email='$author' LIMIT 1");
cb96ccc Have WP mailed post come from author if email matches author in DB. H…
saxmatt authored
68 if (!$result)
69 $post_author = 1;
70 else
71 $post_author = $result->ID;
72 } else
73 $post_author = 1;
74 }
75
5b0fcdb Timezone fix from Kimmo Suominen.
saxmatt authored
76 if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37'
b43564c *** empty log message ***
saxmatt authored
77 $ddate = trim($line);
78 $ddate = str_replace('Date: ', '', $ddate);
79 if (strpos($ddate, ',')) {
80 $ddate = trim(substr($ddate, strpos($ddate, ',')+1, strlen($ddate)));
81 }
82 $date_arr = explode(' ', $ddate);
83 $date_time = explode(':', $date_arr[3]);
dd202ce Death to trailing tabs. Props Mark J. fixes #2405
ryan authored
84
b43564c *** empty log message ***
saxmatt authored
85 $ddate_H = $date_time[0];
86 $ddate_i = $date_time[1];
87 $ddate_s = $date_time[2];
dd202ce Death to trailing tabs. Props Mark J. fixes #2405
ryan authored
88
b43564c *** empty log message ***
saxmatt authored
89 $ddate_m = $date_arr[1];
90 $ddate_d = $date_arr[0];
91 $ddate_Y = $date_arr[2];
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
92 for ($j=0; $j<12; $j++) {
93 if ($ddate_m == $dmonths[$j]) {
94 $ddate_m = $j+1;
b43564c *** empty log message ***
saxmatt authored
95 }
96 }
84435bf big leap to GMT dates
michelvaldrighi authored
97
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
98 $time_zn = intval($date_arr[4]) * 36;
3e1304d More wp-mail timezone and delimiter fixes from Kitten.
rboren authored
99 $ddate_U = gmmktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y);
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
100 $ddate_U = $ddate_U - $time_zn;
101 $post_date = gmdate('Y-m-d H:i:s', $ddate_U + $time_difference);
b8df8fb now storing emailed posts as localtime+gmt
michelvaldrighi authored
102 $post_date_gmt = gmdate('Y-m-d H:i:s', $ddate_U);
b43564c *** empty log message ***
saxmatt authored
103 }
104 }
a0ad8e4 New mail functionality.
saxmatt authored
105 endforeach;
b43564c *** empty log message ***
saxmatt authored
106
a0ad8e4 New mail functionality.
saxmatt authored
107 $subject = trim(str_replace(get_settings('subjectprefix'), '', $subject));
b43564c *** empty log message ***
saxmatt authored
108
a0ad8e4 New mail functionality.
saxmatt authored
109 if ($content_type == 'multipart/alternative') {
110 $content = explode('--'.$boundary, $content);
111 $content = $content[2];
112 $content = explode('Content-Transfer-Encoding: quoted-printable', $content);
113 $content = strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div>');
b43564c *** empty log message ***
saxmatt authored
114 }
a0ad8e4 New mail functionality.
saxmatt authored
115 $content = trim($content);
3e1304d More wp-mail timezone and delimiter fixes from Kitten.
rboren authored
116 // Captures any text in the body after $phone_delim as the body
117 $content = explode($phone_delim, $content);
118 $content[1] ? $content = $content[1] : $content = $content[0];
b43564c *** empty log message ***
saxmatt authored
119
a0ad8e4 New mail functionality.
saxmatt authored
120 echo "<p><b>Content-type:</b> $content_type, <b>boundary:</b> $boundary</p>\n";
121 echo "<p><b>Raw content:</b><br /><pre>".$content.'</pre></p>';
b43564c *** empty log message ***
saxmatt authored
122
a0ad8e4 New mail functionality.
saxmatt authored
123 $content = trim($content);
b43564c *** empty log message ***
saxmatt authored
124
ed34ca0 Set GUID when posting.
saxmatt authored
125 $post_content = apply_filters('phone_content', $content);
b43564c *** empty log message ***
saxmatt authored
126
a0ad8e4 New mail functionality.
saxmatt authored
127 $post_title = xmlrpc_getposttitle($content);
b43564c *** empty log message ***
saxmatt authored
128
a0ad8e4 New mail functionality.
saxmatt authored
129 if ($post_title == '') $post_title = $subject;
b43564c *** empty log message ***
saxmatt authored
130
bc0c6ed Use default_email_category. Credit: Kitten.
rboren authored
131 if (empty($post_categories)) $post_categories[] = get_settings('default_email_category');
b43564c *** empty log message ***
saxmatt authored
132
ed34ca0 Set GUID when posting.
saxmatt authored
133 $post_category = $post_categories;
b43564c *** empty log message ***
saxmatt authored
134
e75e000 set emailed posts to be published. won't do no good moblogging if in …
michelvaldrighi authored
135 // or maybe we should leave the choice to email drafts? propose a way
136 $post_status = 'publish';
137
138 $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status');
df89b36 Give wp-mail a little love.
ryan authored
139 $post_data = add_magic_quotes($post_data);
b43564c *** empty log message ***
saxmatt authored
140
b9ea830 no wonder posting by e-mail was broken
michelvaldrighi authored
141 $post_ID = wp_insert_post($post_data);
b43564c *** empty log message ***
saxmatt authored
142
65950b5 moving the pop3->delete call to the end of the loop so that emails ar…
michelvaldrighi authored
143 if (!$post_ID) {
144 // we couldn't post, for whatever reason. better move forward to the next email
145 continue;
146 }
147
2f4218a Added filter and action hooks.
saxmatt authored
148 do_action('publish_phone', $post_ID);
5624ca0 Fix ups.
saxmatt authored
149
cb96ccc Have WP mailed post come from author if email matches author in DB. H…
saxmatt authored
150 echo "\n<p><b>Author:</b> $post_author</p>";
a0ad8e4 New mail functionality.
saxmatt authored
151 echo "\n<p><b>Posted title:</b> $post_title<br />";
152 echo "\n<b>Posted content:</b><br /><pre>".$content.'</pre></p>';
5624ca0 Fix ups.
saxmatt authored
153
65950b5 moving the pop3->delete call to the end of the loop so that emails ar…
michelvaldrighi authored
154 if(!$pop3->delete($i)) {
155 echo '<p>Oops '.$pop3->ERROR.'</p></div>';
156 $pop3->reset();
157 exit;
158 } else {
159 echo "<p>Mission complete, message <strong>$i</strong> deleted.</p>";
b43564c *** empty log message ***
saxmatt authored
160 }
161
a0ad8e4 New mail functionality.
saxmatt authored
162 endfor;
b43564c *** empty log message ***
saxmatt authored
163
a0ad8e4 New mail functionality.
saxmatt authored
164 $pop3->quit();
b43564c *** empty log message ***
saxmatt authored
165
527b31e Added ezSQL and small HTML fixes.
saxmatt authored
166 ?>
Something went wrong with that request. Please try again.