Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 197 lines (159 sloc) 6.075 kb
b43564c *** empty log message ***
saxmatt authored
1 <?php
5b81135 Allow wp-config.php to exist one level up from WordPress root directory....
ryan authored
2 require(dirname(__FILE__) . '/wp-load.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
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
8 $time_difference = get_option('gmt_offset') * 3600;
5b0fcdb Timezone fix from Kimmo Suominen.
saxmatt authored
9
c913685 Massive options cleanup and another step of cleaning up the upgrade/inst...
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
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
14 if (!$pop3->connect(get_option('mailserver_url'), get_option('mailserver_port')))
b7f907b Escape pop3 error messages. Props xknown. fixes #5484
ryan authored
15 wp_die(wp_specialchars($pop3->ERROR));
b43564c *** empty log message ***
saxmatt authored
16
80f85b5 Ensure wp-mail doesn't issue a 500 error if no messages are available to...
westi authored
17 if (!$pop3->user(get_option('mailserver_login')))
b7f907b Escape pop3 error messages. Props xknown. fixes #5484
ryan authored
18 wp_die(wp_specialchars($pop3->ERROR));
b43564c *** empty log message ***
saxmatt authored
19
80f85b5 Ensure wp-mail doesn't issue a 500 error if no messages are available to...
westi authored
20 $count = $pop3->pass(get_option('mailserver_pass'));
21 if (false === $count)
b7f907b Escape pop3 error messages. Props xknown. fixes #5484
ryan authored
22 wp_die(wp_specialchars($pop3->ERROR));
80f85b5 Ensure wp-mail doesn't issue a 500 error if no messages are available to...
westi authored
23 if (0 == $count)
24 echo "<p>There doesn't seem to be any new mail.</p>\n"; // will fall-through to end of for loop
b43564c *** empty log message ***
saxmatt authored
25
a0ad8e4 New mail functionality.
saxmatt authored
26 for ($i=1; $i <= $count; $i++) :
b43564c *** empty log message ***
saxmatt authored
27
a0ad8e4 New mail functionality.
saxmatt authored
28 $message = $pop3->get($i);
b43564c *** empty log message ***
saxmatt authored
29
30 $content = '';
31 $content_type = '';
7068240 Add support to wp-mail.php for quoted-printable Content-Transfer-Encodin...
rob1n authored
32 $content_transfer_encoding = '';
b43564c *** empty log message ***
saxmatt authored
33 $boundary = '';
34 $bodysignal = 0;
a7c0525 When posting by email, publish only if user has publish caps, otherwise ...
ryan authored
35 $post_author = 1;
36 $author_found = false;
7068240 Add support to wp-mail.php for quoted-printable Content-Transfer-Encodin...
rob1n authored
37 $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
a0ad8e4 New mail functionality.
saxmatt authored
38 foreach ($message as $line) :
39 if (strlen($line) < 3) $bodysignal = 1;
40
b43564c *** empty log message ***
saxmatt authored
41 if ($bodysignal) {
42 $content .= $line;
43 } else {
5b0fcdb Timezone fix from Kimmo Suominen.
saxmatt authored
44 if (preg_match('/Content-Type: /i', $line)) {
b43564c *** empty log message ***
saxmatt authored
45 $content_type = trim($line);
46 $content_type = substr($content_type, 14, strlen($content_type)-14);
47 $content_type = explode(';', $content_type);
48 $content_type = $content_type[0];
49 }
7068240 Add support to wp-mail.php for quoted-printable Content-Transfer-Encodin...
rob1n authored
50 if (preg_match('/Content-Transfer-Encoding: /i', $line)) {
51 $content_transfer_encoding = trim($line);
52 $content_transfer_encoding = substr($content_transfer_encoding, 27, strlen($content_transfer_encoding)-14);
53 $content_transfer_encoding = explode(';', $content_transfer_encoding);
54 $content_transfer_encoding = $content_transfer_encoding[0];
55 }
b43564c *** empty log message ***
saxmatt authored
56 if (($content_type == 'multipart/alternative') && (preg_match('/boundary="/', $line)) && ($boundary == '')) {
57 $boundary = trim($line);
58 $boundary = explode('"', $boundary);
59 $boundary = $boundary[1];
60 }
5b0fcdb Timezone fix from Kimmo Suominen.
saxmatt authored
61 if (preg_match('/Subject: /i', $line)) {
b43564c *** empty log message ***
saxmatt authored
62 $subject = trim($line);
63 $subject = substr($subject, 9, strlen($subject)-9);
1bf946e Fixes #1515
matt authored
64 $subject = wp_iso_descrambler($subject);
3e1304d More wp-mail timezone and delimiter fixes from Kitten.
rboren authored
65 // Captures any text in the subject before $phone_delim as the subject
66 $subject = explode($phone_delim, $subject);
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
67 $subject = $subject[0];
b43564c *** empty log message ***
saxmatt authored
68 }
cb96ccc Have WP mailed post come from author if email matches author in DB. Hat ...
saxmatt authored
69
a92c487 Fix email address parsing in wp-mail.php. Props Bobcat. fixes #5169
ryan authored
70 // Set the author using the email address (From or Reply-To, the last used)
cb96ccc Have WP mailed post come from author if email matches author in DB. Hat ...
saxmatt authored
71 // otherwise use the site admin
88735ac Strip From/Reply-To from e-mail before sanitizing in wp-mail.php. Props...
markjaquith authored
72 if ( preg_match('/(From|Reply-To): /', $line) ) {
a92c487 Fix email address parsing in wp-mail.php. Props Bobcat. fixes #5169
ryan authored
73 if ( preg_match('|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i', $line, $matches) )
74 $author = $matches[0];
75 else
76 $author = trim($line);
77 $author = sanitize_email($author);
1b7798d Properly sanitize e-mail addresses in wp-mail.php. Props giannis1. fix...
markjaquith authored
78 if ( is_email($author) ) {
645bbfa Formatting cleanups from johnjosephbachir. fixes #4775
ryan authored
79 echo "Author = {$author} <p>";
a7c0525 When posting by email, publish only if user has publish caps, otherwise ...
ryan authored
80 $userdata = get_user_by_email($author);
81 if (!$userdata) {
645bbfa Formatting cleanups from johnjosephbachir. fixes #4775
ryan authored
82 $post_author = 1;
a7c0525 When posting by email, publish only if user has publish caps, otherwise ...
ryan authored
83 $author_found = false;
84 } else {
85 $post_author = $userdata->ID;
86 $author_found = true;
87 }
88 } else {
cb96ccc Have WP mailed post come from author if email matches author in DB. Hat ...
saxmatt authored
89 $post_author = 1;
a7c0525 When posting by email, publish only if user has publish caps, otherwise ...
ryan authored
90 $author_found = false;
91 }
cb96ccc Have WP mailed post come from author if email matches author in DB. Hat ...
saxmatt authored
92 }
93
5b0fcdb Timezone fix from Kimmo Suominen.
saxmatt authored
94 if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37'
b43564c *** empty log message ***
saxmatt authored
95 $ddate = trim($line);
96 $ddate = str_replace('Date: ', '', $ddate);
97 if (strpos($ddate, ',')) {
98 $ddate = trim(substr($ddate, strpos($ddate, ',')+1, strlen($ddate)));
99 }
100 $date_arr = explode(' ', $ddate);
101 $date_time = explode(':', $date_arr[3]);
dd202ce Death to trailing tabs. Props Mark J. fixes #2405
ryan authored
102
b43564c *** empty log message ***
saxmatt authored
103 $ddate_H = $date_time[0];
104 $ddate_i = $date_time[1];
105 $ddate_s = $date_time[2];
dd202ce Death to trailing tabs. Props Mark J. fixes #2405
ryan authored
106
b43564c *** empty log message ***
saxmatt authored
107 $ddate_m = $date_arr[1];
108 $ddate_d = $date_arr[0];
109 $ddate_Y = $date_arr[2];
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
110 for ($j=0; $j<12; $j++) {
111 if ($ddate_m == $dmonths[$j]) {
112 $ddate_m = $j+1;
b43564c *** empty log message ***
saxmatt authored
113 }
114 }
84435bf big leap to GMT dates
michelvaldrighi authored
115
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
116 $time_zn = intval($date_arr[4]) * 36;
3e1304d More wp-mail timezone and delimiter fixes from Kitten.
rboren authored
117 $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
118 $ddate_U = $ddate_U - $time_zn;
119 $post_date = gmdate('Y-m-d H:i:s', $ddate_U + $time_difference);
b8df8fb now storing emailed posts as localtime+gmt
michelvaldrighi authored
120 $post_date_gmt = gmdate('Y-m-d H:i:s', $ddate_U);
b43564c *** empty log message ***
saxmatt authored
121 }
122 }
a0ad8e4 New mail functionality.
saxmatt authored
123 endforeach;
b43564c *** empty log message ***
saxmatt authored
124
a7c0525 When posting by email, publish only if user has publish caps, otherwise ...
ryan authored
125 // Set $post_status based on $author_found and on author's publish_posts capability
126 if ($author_found) {
127 $user = new WP_User($post_author);
128 if ($user->has_cap('publish_posts'))
129 $post_status = 'publish';
130 else
131 $post_status = 'pending';
132 } else {
133 // Author not found in DB, set status to pending. Author already set to admin.
134 $post_status = 'pending';
135 }
136
6ecaec3 Skip deprecated option replacement in wp-mail.php. props Nazgul. fixes...
markjaquith authored
137 $subject = trim($subject);
b43564c *** empty log message ***
saxmatt authored
138
a0ad8e4 New mail functionality.
saxmatt authored
139 if ($content_type == 'multipart/alternative') {
140 $content = explode('--'.$boundary, $content);
141 $content = $content[2];
142 $content = explode('Content-Transfer-Encoding: quoted-printable', $content);
143 $content = strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div>');
b43564c *** empty log message ***
saxmatt authored
144 }
a0ad8e4 New mail functionality.
saxmatt authored
145 $content = trim($content);
2f09416 Trim empty lines. Nothing but newline.
ryan authored
146
7068240 Add support to wp-mail.php for quoted-printable Content-Transfer-Encodin...
rob1n authored
147 if (stripos($content_transfer_encoding, "quoted-printable") !== false) {
148 $content = quoted_printable_decode($content);
149 }
150
3e1304d More wp-mail timezone and delimiter fixes from Kitten.
rboren authored
151 // Captures any text in the body after $phone_delim as the body
152 $content = explode($phone_delim, $content);
153 $content[1] ? $content = $content[1] : $content = $content[0];
b43564c *** empty log message ***
saxmatt authored
154
a0ad8e4 New mail functionality.
saxmatt authored
155 $content = trim($content);
b43564c *** empty log message ***
saxmatt authored
156
ed34ca0 Set GUID when posting.
saxmatt authored
157 $post_content = apply_filters('phone_content', $content);
b43564c *** empty log message ***
saxmatt authored
158
a0ad8e4 New mail functionality.
saxmatt authored
159 $post_title = xmlrpc_getposttitle($content);
b43564c *** empty log message ***
saxmatt authored
160
a0ad8e4 New mail functionality.
saxmatt authored
161 if ($post_title == '') $post_title = $subject;
b43564c *** empty log message ***
saxmatt authored
162
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
163 if (empty($post_categories)) $post_categories[] = get_option('default_email_category');
b43564c *** empty log message ***
saxmatt authored
164
ed34ca0 Set GUID when posting.
saxmatt authored
165 $post_category = $post_categories;
b43564c *** empty log message ***
saxmatt authored
166
e75e000 set emailed posts to be published. won't do no good moblogging if in the...
michelvaldrighi authored
167 $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
168 $post_data = add_magic_quotes($post_data);
b43564c *** empty log message ***
saxmatt authored
169
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
170 $post_ID = wp_insert_post($post_data);
b7f907b Escape pop3 error messages. Props xknown. fixes #5484
ryan authored
171 if ( is_wp_error( $post_ID ) )
9bfccd6 Add checks for WP_Error. Props filosofo. see #4809
ryan authored
172 echo "\n" . $post_ID->get_error_message();
b43564c *** empty log message ***
saxmatt authored
173
65950b5 moving the pop3->delete call to the end of the loop so that emails are d...
michelvaldrighi authored
174 if (!$post_ID) {
175 // we couldn't post, for whatever reason. better move forward to the next email
176 continue;
177 }
178
2f4218a Added filter and action hooks.
saxmatt authored
179 do_action('publish_phone', $post_ID);
5624ca0 Fix ups.
saxmatt authored
180
6d6280b Add some sanitization
ryan authored
181 echo "\n<p><b>Author:</b> " . wp_specialchars($post_author) . "</p>";
baf6e7b Don't echo posted content. Specialchars all other displayed info.
ryan authored
182 echo "\n<p><b>Posted title:</b> " . wp_specialchars($post_title) . "<br />";
5624ca0 Fix ups.
saxmatt authored
183
65950b5 moving the pop3->delete call to the end of the loop so that emails are d...
michelvaldrighi authored
184 if(!$pop3->delete($i)) {
6d6280b Add some sanitization
ryan authored
185 echo '<p>Oops '.wp_specialchars($pop3->ERROR).'</p></div>';
65950b5 moving the pop3->delete call to the end of the loop so that emails are d...
michelvaldrighi authored
186 $pop3->reset();
187 exit;
188 } else {
189 echo "<p>Mission complete, message <strong>$i</strong> deleted.</p>";
b43564c *** empty log message ***
saxmatt authored
190 }
191
a0ad8e4 New mail functionality.
saxmatt authored
192 endfor;
b43564c *** empty log message ***
saxmatt authored
193
a0ad8e4 New mail functionality.
saxmatt authored
194 $pop3->quit();
b43564c *** empty log message ***
saxmatt authored
195
7068240 Add support to wp-mail.php for quoted-printable Content-Transfer-Encodin...
rob1n authored
196 ?>
Something went wrong with that request. Please try again.