Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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