Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 213 lines (178 sloc) 7.135 kb
416ef54d » m
2003-04-01 *** empty log message ***
1 <?php
81421442 » ryan
2008-05-25 File file level phpdoc from jacobsantos. see #7037
2 /**
3 * Gets the email message from the user's mailbox to add as
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
4 * a WordPress post. Mailbox connection information must be
5 * configured under Settings > Writing
81421442 » ryan
2008-05-25 File file level phpdoc from jacobsantos. see #7037
6 *
7 * @package WordPress
8 */
9
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
10 /** Make sure that the WordPress bootstrap has run before continuing. */
7a8250ab » ryan
2008-05-21 Allow wp-config.php to exist one level up from WordPress root directo…
11 require(dirname(__FILE__) . '/wp-load.php');
416ef54d » m
2003-04-01 *** empty log message ***
12
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
13 /** Get the POP3 class with which to access the mailbox. */
14 require_once( ABSPATH . WPINC . '/class-pop3.php' );
416ef54d » m
2003-04-01 *** empty log message ***
15
10c50147 » ryan
2009-04-23 Don't absint gmt_offset. Props Hirvine. fixes #9162
16 $time_difference = get_option('gmt_offset') * 3600;
ba1450cb » m
2004-05-19 Timezone fix from Kimmo Suominen.
17
84db5807 » m
2004-09-05 Massive options cleanup and another step of cleaning up the upgrade/i…
18 $phone_delim = '::';
e841a2dd » ryan
2004-07-27 More wp-mail timezone and delimiter fixes from Kitten.
19
416ef54d » m
2003-04-01 *** empty log message ***
20 $pop3 = new POP3();
21
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
22 if ( ! $pop3->connect(get_option('mailserver_url'), get_option('mailserver_port') ) ||
23 ! $pop3->user(get_option('mailserver_login')) ||
24 ( ! $count = $pop3->pass(get_option('mailserver_pass')) ) ) {
25 $pop3->quit();
26 wp_die( ( 0 === $count ) ? __("There doesn't seem to be any new mail.") : wp_specialchars($pop3->ERROR) );
27 }
416ef54d » m
2003-04-01 *** empty log message ***
28
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
29 for ( $i = 1; $i <= $count; $i++ ) {
416ef54d » m
2003-04-01 *** empty log message ***
30
00cb612e » m
2004-04-24 New mail functionality.
31 $message = $pop3->get($i);
416ef54d » m
2003-04-01 *** empty log message ***
32
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
33 $bodysignal = false;
34 $boundary = '';
35 $charset = '';
416ef54d » m
2003-04-01 *** empty log message ***
36 $content = '';
37 $content_type = '';
814f6618 » rob1n
2007-04-06 Add support to wp-mail.php for quoted-printable Content-Transfer-Enco…
38 $content_transfer_encoding = '';
f3480316 » ryan
2007-11-29 When posting by email, publish only if user has publish caps, otherwi…
39 $post_author = 1;
40 $author_found = false;
814f6618 » rob1n
2007-04-06 Add support to wp-mail.php for quoted-printable Content-Transfer-Enco…
41 $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
42 foreach ($message as $line) {
43 // body signal
44 if ( strlen($line) < 3 )
45 $bodysignal = true;
46 if ( $bodysignal ) {
416ef54d » m
2003-04-01 *** empty log message ***
47 $content .= $line;
48 } else {
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
49 if ( preg_match('/Content-Type: /i', $line) ) {
416ef54d » m
2003-04-01 *** empty log message ***
50 $content_type = trim($line);
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
51 $content_type = substr($content_type, 14, strlen($content_type) - 14);
416ef54d » m
2003-04-01 *** empty log message ***
52 $content_type = explode(';', $content_type);
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
53 if ( ! empty( $content_type[1] ) ) {
54 $charset = explode('=', $content_type[1]);
55 $charset = ( ! empty( $charset[1] ) ) ? trim($charset[1]) : '';
56 }
416ef54d » m
2003-04-01 *** empty log message ***
57 $content_type = $content_type[0];
58 }
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
59 if ( preg_match('/Content-Transfer-Encoding: /i', $line) ) {
814f6618 » rob1n
2007-04-06 Add support to wp-mail.php for quoted-printable Content-Transfer-Enco…
60 $content_transfer_encoding = trim($line);
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
61 $content_transfer_encoding = substr($content_transfer_encoding, 27, strlen($content_transfer_encoding) - 27);
814f6618 » rob1n
2007-04-06 Add support to wp-mail.php for quoted-printable Content-Transfer-Enco…
62 $content_transfer_encoding = explode(';', $content_transfer_encoding);
63 $content_transfer_encoding = $content_transfer_encoding[0];
64 }
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
65 if ( ( $content_type == 'multipart/alternative' ) && ( false !== strpos($line, 'boundary="') ) && ( '' == $boundary ) ) {
416ef54d » m
2003-04-01 *** empty log message ***
66 $boundary = trim($line);
67 $boundary = explode('"', $boundary);
68 $boundary = $boundary[1];
69 }
ba1450cb » m
2004-05-19 Timezone fix from Kimmo Suominen.
70 if (preg_match('/Subject: /i', $line)) {
416ef54d » m
2003-04-01 *** empty log message ***
71 $subject = trim($line);
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
72 $subject = substr($subject, 9, strlen($subject) - 9);
e841a2dd » ryan
2004-07-27 More wp-mail timezone and delimiter fixes from Kitten.
73 // Captures any text in the subject before $phone_delim as the subject
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
74 if ( function_exists('iconv_mime_decode') ) {
75 $subject = iconv_mime_decode($subject, 2, get_option('blog_charset'));
76 } else {
77 $subject = wp_iso_descrambler($subject);
78 }
e841a2dd » ryan
2004-07-27 More wp-mail timezone and delimiter fixes from Kitten.
79 $subject = explode($phone_delim, $subject);
3f7cd011 » ryan
2004-07-26 Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
80 $subject = $subject[0];
416ef54d » m
2003-04-01 *** empty log message ***
81 }
230cd124 » m
2004-09-08 Have WP mailed post come from author if email matches author in DB. H…
82
4678d483 » ryan
2007-10-21 Fix email address parsing in wp-mail.php. Props Bobcat. fixes #5169
83 // Set the author using the email address (From or Reply-To, the last used)
230cd124 » m
2004-09-08 Have WP mailed post come from author if email matches author in DB. H…
84 // otherwise use the site admin
4b5cac84 » markjaquith
2007-10-10 Strip From/Reply-To from e-mail before sanitizing in wp-mail.php. Pro…
85 if ( preg_match('/(From|Reply-To): /', $line) ) {
4678d483 » ryan
2007-10-21 Fix email address parsing in wp-mail.php. Props Bobcat. fixes #5169
86 if ( preg_match('|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i', $line, $matches) )
87 $author = $matches[0];
88 else
89 $author = trim($line);
90 $author = sanitize_email($author);
994d0d80 » markjaquith
2007-10-09 Properly sanitize e-mail addresses in wp-mail.php. Props giannis1. fi…
91 if ( is_email($author) ) {
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
92 echo '<p>' . sprintf(__('Author is %s'), $author) . '</p>';
f3480316 » ryan
2007-11-29 When posting by email, publish only if user has publish caps, otherwi…
93 $userdata = get_user_by_email($author);
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
94 if ( empty($userdata) ) {
f3480316 » ryan
2007-11-29 When posting by email, publish only if user has publish caps, otherwi…
95 $author_found = false;
96 } else {
97 $post_author = $userdata->ID;
98 $author_found = true;
99 }
100 } else {
101 $author_found = false;
102 }
230cd124 » m
2004-09-08 Have WP mailed post come from author if email matches author in DB. H…
103 }
104
ba1450cb » m
2004-05-19 Timezone fix from Kimmo Suominen.
105 if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37'
416ef54d » m
2003-04-01 *** empty log message ***
106 $ddate = trim($line);
107 $ddate = str_replace('Date: ', '', $ddate);
108 if (strpos($ddate, ',')) {
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
109 $ddate = trim(substr($ddate, strpos($ddate, ',') + 1, strlen($ddate)));
416ef54d » m
2003-04-01 *** empty log message ***
110 }
111 $date_arr = explode(' ', $ddate);
112 $date_time = explode(':', $date_arr[3]);
7b2e2c34 » ryan
2006-02-12 Death to trailing tabs. Props Mark J. fixes #2405
113
416ef54d » m
2003-04-01 *** empty log message ***
114 $ddate_H = $date_time[0];
115 $ddate_i = $date_time[1];
116 $ddate_s = $date_time[2];
7b2e2c34 » ryan
2006-02-12 Death to trailing tabs. Props Mark J. fixes #2405
117
416ef54d » m
2003-04-01 *** empty log message ***
118 $ddate_m = $date_arr[1];
119 $ddate_d = $date_arr[0];
120 $ddate_Y = $date_arr[2];
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
121 for ( $j = 0; $j < 12; $j++ ) {
122 if ( $ddate_m == $dmonths[$j] ) {
3f7cd011 » ryan
2004-07-26 Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
123 $ddate_m = $j+1;
416ef54d » m
2003-04-01 *** empty log message ***
124 }
125 }
fd285bc1 » michelvaldrighi
2004-02-23 big leap to GMT dates
126
3f7cd011 » ryan
2004-07-26 Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
127 $time_zn = intval($date_arr[4]) * 36;
e841a2dd » ryan
2004-07-27 More wp-mail timezone and delimiter fixes from Kitten.
128 $ddate_U = gmmktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y);
3f7cd011 » ryan
2004-07-26 Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
129 $ddate_U = $ddate_U - $time_zn;
130 $post_date = gmdate('Y-m-d H:i:s', $ddate_U + $time_difference);
0b3ee13e » michelvaldrighi
2004-03-25 now storing emailed posts as localtime+gmt
131 $post_date_gmt = gmdate('Y-m-d H:i:s', $ddate_U);
416ef54d » m
2003-04-01 *** empty log message ***
132 }
133 }
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
134 }
416ef54d » m
2003-04-01 *** empty log message ***
135
f3480316 » ryan
2007-11-29 When posting by email, publish only if user has publish caps, otherwi…
136 // Set $post_status based on $author_found and on author's publish_posts capability
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
137 if ( $author_found ) {
f3480316 » ryan
2007-11-29 When posting by email, publish only if user has publish caps, otherwi…
138 $user = new WP_User($post_author);
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
139 $post_status = ( $user->has_cap('publish_posts') ) ? 'publish' : 'pending';
f3480316 » ryan
2007-11-29 When posting by email, publish only if user has publish caps, otherwi…
140 } else {
141 // Author not found in DB, set status to pending. Author already set to admin.
142 $post_status = 'pending';
143 }
144
36b8f74f » ryan
2009-03-18 Trim trailing whitespace
145 $subject = trim($subject);
146
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
147 if ( $content_type == 'multipart/alternative' ) {
00cb612e » m
2004-04-24 New mail functionality.
148 $content = explode('--'.$boundary, $content);
149 $content = $content[2];
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
150 // match case-insensitive content-transfer-encoding
151 if ( preg_match( '/Content-Transfer-Encoding: quoted-printable/i', $content, $delim) ) {
152 $content = explode($delim[0], $content);
153 $content = $content[1];
154 }
155 $content = strip_tags($content, '<img><p><br><i><b><u><em><strong><strike><font><span><div>');
416ef54d » m
2003-04-01 *** empty log message ***
156 }
00cb612e » m
2004-04-24 New mail functionality.
157 $content = trim($content);
5ffa7fcc » ryan
2007-06-14 Trim empty lines. Nothing but newline.
158
5bf2774b » westi
2009-01-22 Add a filter to allow post-by-email plugins better control over the c…
159 //Give Post-By-Email extending plugins full access to the content
160 //Either the raw content or the content of the last quoted-printable section
161 $content = apply_filters('wp_mail_original_content', $content);
36b8f74f » ryan
2009-03-18 Trim trailing whitespace
162
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
163 if ( false !== stripos($content_transfer_encoding, "quoted-printable") ) {
814f6618 » rob1n
2007-04-06 Add support to wp-mail.php for quoted-printable Content-Transfer-Enco…
164 $content = quoted_printable_decode($content);
165 }
166
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
167 if ( function_exists('iconv') && ! empty( $charset ) ) {
168 $content = iconv($charset, get_option('blog_charset'), $content);
169 }
e775da62 » ryan
2008-12-09 Strip trailing whitespace
170
e841a2dd » ryan
2004-07-27 More wp-mail timezone and delimiter fixes from Kitten.
171 // Captures any text in the body after $phone_delim as the body
172 $content = explode($phone_delim, $content);
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
173 $content = empty( $content[1] ) ? $content[0] : $content[1];
416ef54d » m
2003-04-01 *** empty log message ***
174
00cb612e » m
2004-04-24 New mail functionality.
175 $content = trim($content);
416ef54d » m
2003-04-01 *** empty log message ***
176
22a580ad » m
2004-09-05 Set GUID when posting.
177 $post_content = apply_filters('phone_content', $content);
416ef54d » m
2003-04-01 *** empty log message ***
178
00cb612e » m
2004-04-24 New mail functionality.
179 $post_title = xmlrpc_getposttitle($content);
416ef54d » m
2003-04-01 *** empty log message ***
180
00cb612e » m
2004-04-24 New mail functionality.
181 if ($post_title == '') $post_title = $subject;
416ef54d » m
2003-04-01 *** empty log message ***
182
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
183 $post_category = array(get_option('default_email_category'));
416ef54d » m
2003-04-01 *** empty log message ***
184
88486b54 » michelvaldrighi
2005-02-01 set emailed posts to be published. won't do no good moblogging if in …
185 $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status');
cef26e6c » ryan
2005-10-20 Give wp-mail a little love.
186 $post_data = add_magic_quotes($post_data);
416ef54d » m
2003-04-01 *** empty log message ***
187
a738b423 » m
2007-03-23 Ryan slays the dragon. (Some of these return WP_Error objects.)
188 $post_ID = wp_insert_post($post_data);
ce60a1a7 » ryan
2007-12-18 Escape pop3 error messages. Props xknown. fixes #5484
189 if ( is_wp_error( $post_ID ) )
9fd8e27d » ryan
2007-09-18 Add checks for WP_Error. Props filosofo. see #4809
190 echo "\n" . $post_ID->get_error_message();
416ef54d » m
2003-04-01 *** empty log message ***
191
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
192 // We couldn't post, for whatever reason. Better move forward to the next email.
193 if ( empty( $post_ID ) )
18c87010 » michelvaldrighi
2005-01-31 moving the pop3->delete call to the end of the loop so that emails ar…
194 continue;
195
1355366b » m
2004-04-25 Added filter and action hooks.
196 do_action('publish_phone', $post_ID);
26b05224 » m
2004-01-13 Fix ups.
197
5f0ea77e » ryan
2008-11-03 Localization for wp-mail. Props filosofo. fixes #8051
198 echo "\n<p>" . sprintf(__('<strong>Author:</strong> %s'), wp_specialchars($post_author)) . '</p>';
199 echo "\n<p>" . sprintf(__('<strong>Posted title:</strong> %s'), wp_specialchars($post_title)) . '</p>';
26b05224 » m
2004-01-13 Fix ups.
200
18c87010 » michelvaldrighi
2005-01-31 moving the pop3->delete call to the end of the loop so that emails ar…
201 if(!$pop3->delete($i)) {
5f0ea77e » ryan
2008-11-03 Localization for wp-mail. Props filosofo. fixes #8051
202 echo '<p>' . sprintf(__('Oops: %s'), wp_specialchars($pop3->ERROR)) . '</p>';
18c87010 » michelvaldrighi
2005-01-31 moving the pop3->delete call to the end of the loop so that emails ar…
203 $pop3->reset();
204 exit;
205 } else {
5f0ea77e » ryan
2008-11-03 Localization for wp-mail. Props filosofo. fixes #8051
206 echo '<p>' . sprintf(__('Mission complete. Message <strong>%s</strong> deleted.'), $i) . '</p>';
416ef54d » m
2003-04-01 *** empty log message ***
207 }
208
1818670e » westi
2008-12-02 Improve wp-mail utf8 support. Fixes #6788 props filosofo.
209 }
416ef54d » m
2003-04-01 *** empty log message ***
210
00cb612e » m
2004-04-24 New mail functionality.
211 $pop3->quit();
416ef54d » m
2003-04-01 *** empty log message ***
212
5f0ea77e » ryan
2008-11-03 Localization for wp-mail. Props filosofo. fixes #8051
213 ?>
Something went wrong with that request. Please try again.