Skip to content

HTTPS clone URL

Subversion checkout URL

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