Skip to content
This repository

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
b43564cb » saxmatt
2003-04-01 *** empty log message ***
1 <?php
a6a1522a » 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
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. */
5b811357 » ryan
2008-05-21 Allow wp-config.php to exist one level up from WordPress root directo…
10 require(dirname(__FILE__) . '/wp-load.php');
b43564cb » saxmatt
2003-04-01 *** empty log message ***
11
a6a1522a » ryan
2008-05-25 File file level phpdoc from jacobsantos. see #7037
12 /** Get the POP3 class for which to access the mailbox. */
99a7358b » saxmatt
2003-12-18 Renaming Reloaded.
13 require_once(ABSPATH.WPINC.'/class-pop3.php');
b43564cb » saxmatt
2003-04-01 *** empty log message ***
14
a6a1522a » ryan
2008-05-25 File file level phpdoc from jacobsantos. see #7037
15 // WTF is this? Use constants instead.
b43564cb » saxmatt
2003-04-01 *** empty log message ***
16 error_reporting(2037);
17
849a0d29 » ryan
2006-08-30 Use get_option instead of get_settings. Just 'cause.
18 $time_difference = get_option('gmt_offset') * 3600;
5b0fcdb5 » saxmatt
2004-05-19 Timezone fix from Kimmo Suominen.
19
c9136856 » saxmatt
2004-09-05 Massive options cleanup and another step of cleaning up the upgrade/i…
20 $phone_delim = '::';
3e1304d6 » rboren
2004-07-27 More wp-mail timezone and delimiter fixes from Kitten.
21
b43564cb » saxmatt
2003-04-01 *** empty log message ***
22 $pop3 = new POP3();
23
849a0d29 » ryan
2006-08-30 Use get_option instead of get_settings. Just 'cause.
24 if (!$pop3->connect(get_option('mailserver_url'), get_option('mailserver_port')))
b7f907b8 » ryan
2007-12-18 Escape pop3 error messages. Props xknown. fixes #5484
25 wp_die(wp_specialchars($pop3->ERROR));
b43564cb » saxmatt
2003-04-01 *** empty log message ***
26
80f85b53 » westi
2007-12-05 Ensure wp-mail doesn't issue a 500 error if no messages are available…
27 if (!$pop3->user(get_option('mailserver_login')))
b7f907b8 » ryan
2007-12-18 Escape pop3 error messages. Props xknown. fixes #5484
28 wp_die(wp_specialchars($pop3->ERROR));
b43564cb » saxmatt
2003-04-01 *** empty log message ***
29
80f85b53 » westi
2007-12-05 Ensure wp-mail doesn't issue a 500 error if no messages are available…
30 $count = $pop3->pass(get_option('mailserver_pass'));
31 if (false === $count)
b7f907b8 » ryan
2007-12-18 Escape pop3 error messages. Props xknown. fixes #5484
32 wp_die(wp_specialchars($pop3->ERROR));
80f85b53 » westi
2007-12-05 Ensure wp-mail doesn't issue a 500 error if no messages are available…
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
b43564cb » saxmatt
2003-04-01 *** empty log message ***
35
a0ad8e4d » saxmatt
2004-04-24 New mail functionality.
36 for ($i=1; $i <= $count; $i++) :
b43564cb » saxmatt
2003-04-01 *** empty log message ***
37
a0ad8e4d » saxmatt
2004-04-24 New mail functionality.
38 $message = $pop3->get($i);
b43564cb » saxmatt
2003-04-01 *** empty log message ***
39
40 $content = '';
41 $content_type = '';
70682403 » rob1n
2007-04-06 Add support to wp-mail.php for quoted-printable Content-Transfer-Enco…
42 $content_transfer_encoding = '';
b43564cb » saxmatt
2003-04-01 *** empty log message ***
43 $boundary = '';
44 $bodysignal = 0;
a7c05258 » ryan
2007-11-29 When posting by email, publish only if user has publish caps, otherwi…
45 $post_author = 1;
46 $author_found = false;
70682403 » rob1n
2007-04-06 Add support to wp-mail.php for quoted-printable Content-Transfer-Enco…
47 $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
a0ad8e4d » saxmatt
2004-04-24 New mail functionality.
48 foreach ($message as $line) :
49 if (strlen($line) < 3) $bodysignal = 1;
50
b43564cb » saxmatt
2003-04-01 *** empty log message ***
51 if ($bodysignal) {
52 $content .= $line;
53 } else {
5b0fcdb5 » saxmatt
2004-05-19 Timezone fix from Kimmo Suominen.
54 if (preg_match('/Content-Type: /i', $line)) {
b43564cb » saxmatt
2003-04-01 *** empty log message ***
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 }
70682403 » rob1n
2007-04-06 Add support to wp-mail.php for quoted-printable Content-Transfer-Enco…
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 }
b43564cb » saxmatt
2003-04-01 *** empty log message ***
66 if (($content_type == 'multipart/alternative') && (preg_match('/boundary="/', $line)) && ($boundary == '')) {
67 $boundary = trim($line);
68 $boundary = explode('"', $boundary);
69 $boundary = $boundary[1];
70 }
5b0fcdb5 » saxmatt
2004-05-19 Timezone fix from Kimmo Suominen.
71 if (preg_match('/Subject: /i', $line)) {
b43564cb » saxmatt
2003-04-01 *** empty log message ***
72 $subject = trim($line);
73 $subject = substr($subject, 9, strlen($subject)-9);
1bf946e6 » matt
2005-11-14 Fixes #1515
74 $subject = wp_iso_descrambler($subject);
3e1304d6 » rboren
2004-07-27 More wp-mail timezone and delimiter fixes from Kitten.
75 // Captures any text in the subject before $phone_delim as the subject
76 $subject = explode($phone_delim, $subject);
87812da9 » rboren
2004-07-26 Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
77 $subject = $subject[0];
b43564cb » saxmatt
2003-04-01 *** empty log message ***
78 }
cb96cccd » saxmatt
2004-09-08 Have WP mailed post come from author if email matches author in DB. H…
79
a92c487c » ryan
2007-10-21 Fix email address parsing in wp-mail.php. Props Bobcat. fixes #5169
80 // Set the author using the email address (From or Reply-To, the last used)
cb96cccd » saxmatt
2004-09-08 Have WP mailed post come from author if email matches author in DB. H…
81 // otherwise use the site admin
88735ac4 » markjaquith
2007-10-10 Strip From/Reply-To from e-mail before sanitizing in wp-mail.php. Pro…
82 if ( preg_match('/(From|Reply-To): /', $line) ) {
a92c487c » ryan
2007-10-21 Fix email address parsing in wp-mail.php. Props Bobcat. fixes #5169
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);
1b7798d2 » markjaquith
2007-10-09 Properly sanitize e-mail addresses in wp-mail.php. Props giannis1. fi…
88 if ( is_email($author) ) {
645bbfa3 » ryan
2007-08-19 Formatting cleanups from johnjosephbachir. fixes #4775
89 echo "Author = {$author} <p>";
a7c05258 » ryan
2007-11-29 When posting by email, publish only if user has publish caps, otherwi…
90 $userdata = get_user_by_email($author);
91 if (!$userdata) {
645bbfa3 » ryan
2007-08-19 Formatting cleanups from johnjosephbachir. fixes #4775
92 $post_author = 1;
a7c05258 » ryan
2007-11-29 When posting by email, publish only if user has publish caps, otherwi…
93 $author_found = false;
94 } else {
95 $post_author = $userdata->ID;
96 $author_found = true;
97 }
98 } else {
cb96cccd » saxmatt
2004-09-08 Have WP mailed post come from author if email matches author in DB. H…
99 $post_author = 1;
a7c05258 » ryan
2007-11-29 When posting by email, publish only if user has publish caps, otherwi…
100 $author_found = false;
101 }
cb96cccd » saxmatt
2004-09-08 Have WP mailed post come from author if email matches author in DB. H…
102 }
103
5b0fcdb5 » saxmatt
2004-05-19 Timezone fix from Kimmo Suominen.
104 if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37'
b43564cb » saxmatt
2003-04-01 *** empty log message ***
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]);
dd202ce1 » ryan
2006-02-12 Death to trailing tabs. Props Mark J. fixes #2405
112
b43564cb » saxmatt
2003-04-01 *** empty log message ***
113 $ddate_H = $date_time[0];
114 $ddate_i = $date_time[1];
115 $ddate_s = $date_time[2];
dd202ce1 » ryan
2006-02-12 Death to trailing tabs. Props Mark J. fixes #2405
116
b43564cb » saxmatt
2003-04-01 *** empty log message ***
117 $ddate_m = $date_arr[1];
118 $ddate_d = $date_arr[0];
119 $ddate_Y = $date_arr[2];
87812da9 » rboren
2004-07-26 Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
120 for ($j=0; $j<12; $j++) {
121 if ($ddate_m == $dmonths[$j]) {
122 $ddate_m = $j+1;
b43564cb » saxmatt
2003-04-01 *** empty log message ***
123 }
124 }
84435bfa » michelvaldrighi
2004-02-23 big leap to GMT dates
125
87812da9 » rboren
2004-07-26 Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
126 $time_zn = intval($date_arr[4]) * 36;
3e1304d6 » rboren
2004-07-27 More wp-mail timezone and delimiter fixes from Kitten.
127 $ddate_U = gmmktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y);
87812da9 » rboren
2004-07-26 Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
128 $ddate_U = $ddate_U - $time_zn;
129 $post_date = gmdate('Y-m-d H:i:s', $ddate_U + $time_difference);
b8df8fb9 » michelvaldrighi
2004-03-25 now storing emailed posts as localtime+gmt
130 $post_date_gmt = gmdate('Y-m-d H:i:s', $ddate_U);
b43564cb » saxmatt
2003-04-01 *** empty log message ***
131 }
132 }
a0ad8e4d » saxmatt
2004-04-24 New mail functionality.
133 endforeach;
b43564cb » saxmatt
2003-04-01 *** empty log message ***
134
a7c05258 » ryan
2007-11-29 When posting by email, publish only if user has publish caps, otherwi…
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
6ecaec3d » markjaquith
2007-09-07 Skip deprecated option replacement in wp-mail.php. props Nazgul. fixe…
147 $subject = trim($subject);
b43564cb » saxmatt
2003-04-01 *** empty log message ***
148
a0ad8e4d » saxmatt
2004-04-24 New mail functionality.
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>');
b43564cb » saxmatt
2003-04-01 *** empty log message ***
154 }
a0ad8e4d » saxmatt
2004-04-24 New mail functionality.
155 $content = trim($content);
2f094162 » ryan
2007-06-14 Trim empty lines. Nothing but newline.
156
70682403 » rob1n
2007-04-06 Add support to wp-mail.php for quoted-printable Content-Transfer-Enco…
157 if (stripos($content_transfer_encoding, "quoted-printable") !== false) {
158 $content = quoted_printable_decode($content);
159 }
160
3e1304d6 » rboren
2004-07-27 More wp-mail timezone and delimiter fixes from Kitten.
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];
b43564cb » saxmatt
2003-04-01 *** empty log message ***
164
a0ad8e4d » saxmatt
2004-04-24 New mail functionality.
165 $content = trim($content);
b43564cb » saxmatt
2003-04-01 *** empty log message ***
166
ed34ca04 » saxmatt
2004-09-05 Set GUID when posting.
167 $post_content = apply_filters('phone_content', $content);
b43564cb » saxmatt
2003-04-01 *** empty log message ***
168
a0ad8e4d » saxmatt
2004-04-24 New mail functionality.
169 $post_title = xmlrpc_getposttitle($content);
b43564cb » saxmatt
2003-04-01 *** empty log message ***
170
a0ad8e4d » saxmatt
2004-04-24 New mail functionality.
171 if ($post_title == '') $post_title = $subject;
b43564cb » saxmatt
2003-04-01 *** empty log message ***
172
849a0d29 » ryan
2006-08-30 Use get_option instead of get_settings. Just 'cause.
173 if (empty($post_categories)) $post_categories[] = get_option('default_email_category');
b43564cb » saxmatt
2003-04-01 *** empty log message ***
174
ed34ca04 » saxmatt
2004-09-05 Set GUID when posting.
175 $post_category = $post_categories;
b43564cb » saxmatt
2003-04-01 *** empty log message ***
176
e75e0003 » michelvaldrighi
2005-02-01 set emailed posts to be published. won't do no good moblogging if in …
177 $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status');
df89b361 » ryan
2005-10-20 Give wp-mail a little love.
178 $post_data = add_magic_quotes($post_data);
b43564cb » saxmatt
2003-04-01 *** empty log message ***
179
3d219259 » matt
2007-03-23 Ryan slays the dragon. (Some of these return WP_Error objects.)
180 $post_ID = wp_insert_post($post_data);
b7f907b8 » ryan
2007-12-18 Escape pop3 error messages. Props xknown. fixes #5484
181 if ( is_wp_error( $post_ID ) )
9bfccd62 » ryan
2007-09-18 Add checks for WP_Error. Props filosofo. see #4809
182 echo "\n" . $post_ID->get_error_message();
b43564cb » saxmatt
2003-04-01 *** empty log message ***
183
65950b5a » michelvaldrighi
2005-01-31 moving the pop3->delete call to the end of the loop so that emails ar…
184 if (!$post_ID) {
185 // we couldn't post, for whatever reason. better move forward to the next email
186 continue;
187 }
188
2f4218a0 » saxmatt
2004-04-25 Added filter and action hooks.
189 do_action('publish_phone', $post_ID);
5624ca0f » saxmatt
2004-01-13 Fix ups.
190
6d6280b7 » ryan
2007-12-27 Add some sanitization
191 echo "\n<p><b>Author:</b> " . wp_specialchars($post_author) . "</p>";
baf6e7b6 » ryan
2007-12-29 Don't echo posted content. Specialchars all other displayed info.
192 echo "\n<p><b>Posted title:</b> " . wp_specialchars($post_title) . "<br />";
5624ca0f » saxmatt
2004-01-13 Fix ups.
193
65950b5a » michelvaldrighi
2005-01-31 moving the pop3->delete call to the end of the loop so that emails ar…
194 if(!$pop3->delete($i)) {
6d6280b7 » ryan
2007-12-27 Add some sanitization
195 echo '<p>Oops '.wp_specialchars($pop3->ERROR).'</p></div>';
65950b5a » michelvaldrighi
2005-01-31 moving the pop3->delete call to the end of the loop so that emails ar…
196 $pop3->reset();
197 exit;
198 } else {
199 echo "<p>Mission complete, message <strong>$i</strong> deleted.</p>";
b43564cb » saxmatt
2003-04-01 *** empty log message ***
200 }
201
a0ad8e4d » saxmatt
2004-04-24 New mail functionality.
202 endfor;
b43564cb » saxmatt
2003-04-01 *** empty log message ***
203
a0ad8e4d » saxmatt
2004-04-24 New mail functionality.
204 $pop3->quit();
b43564cb » saxmatt
2003-04-01 *** empty log message ***
205
a6a1522a » ryan
2008-05-25 File file level phpdoc from jacobsantos. see #7037
206 ?>
Something went wrong with that request. Please try again.