Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 157 lines (122 sloc) 4.731 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
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
8 $time_difference = get_settings('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
a0ad8e4 New mail functionality.
saxmatt authored
14 if (!$pop3->connect(get_settings('mailserver_url'), get_settings('mailserver_port'))) :
b43564c *** empty log message ***
saxmatt authored
15 echo "Ooops $pop3->ERROR <br />\n";
16 exit;
a0ad8e4 New mail functionality.
saxmatt authored
17 endif;
b43564c *** empty log message ***
saxmatt authored
18
a0ad8e4 New mail functionality.
saxmatt authored
19 $count = $pop3->login(get_settings('mailserver_login'), get_settings('mailserver_pass'));
20 if (0 == $count) die(__('There doesn&#8217;t seem to be any new mail.'));
b43564c *** empty log message ***
saxmatt authored
21
22
a0ad8e4 New mail functionality.
saxmatt authored
23 for ($i=1; $i <= $count; $i++) :
b43564c *** empty log message ***
saxmatt authored
24
a0ad8e4 New mail functionality.
saxmatt authored
25 $message = $pop3->get($i);
b43564c *** empty log message ***
saxmatt authored
26
a0ad8e4 New mail functionality.
saxmatt authored
27 if(!$pop3->delete($i)) {
28 echo '<p>Oops '.$pop3->ERROR.'</p></div>';
29 $pop3->reset();
b43564c *** empty log message ***
saxmatt authored
30 exit;
a0ad8e4 New mail functionality.
saxmatt authored
31 } else {
32 echo "<p>Mission complete, message <strong>$i</strong> deleted.</p>";
b43564c *** empty log message ***
saxmatt authored
33 }
34
35 $content = '';
36 $content_type = '';
37 $boundary = '';
38 $bodysignal = 0;
39 $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
40 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
a0ad8e4 New mail functionality.
saxmatt authored
41 foreach ($message as $line) :
42 if (strlen($line) < 3) $bodysignal = 1;
43
b43564c *** empty log message ***
saxmatt authored
44 if ($bodysignal) {
45 $content .= $line;
46 } else {
5b0fcdb Timezone fix from Kimmo Suominen.
saxmatt authored
47 if (preg_match('/Content-Type: /i', $line)) {
b43564c *** empty log message ***
saxmatt authored
48 $content_type = trim($line);
49 $content_type = substr($content_type, 14, strlen($content_type)-14);
50 $content_type = explode(';', $content_type);
51 $content_type = $content_type[0];
52 }
53 if (($content_type == 'multipart/alternative') && (preg_match('/boundary="/', $line)) && ($boundary == '')) {
54 $boundary = trim($line);
55 $boundary = explode('"', $boundary);
56 $boundary = $boundary[1];
57 }
5b0fcdb Timezone fix from Kimmo Suominen.
saxmatt authored
58 if (preg_match('/Subject: /i', $line)) {
b43564c *** empty log message ***
saxmatt authored
59 $subject = trim($line);
60 $subject = substr($subject, 9, strlen($subject)-9);
a616593 fixes to handle ISO-scrambled email subjects in wp-mail
michelvaldrighi authored
61 if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $subject)) {
62 $subject = wp_iso_descrambler($subject);
63 }
3e1304d More wp-mail timezone and delimiter fixes from Kitten.
rboren authored
64 // Captures any text in the subject before $phone_delim as the subject
65 $subject = explode($phone_delim, $subject);
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
66 $subject = $subject[0];
b43564c *** empty log message ***
saxmatt authored
67 }
5b0fcdb Timezone fix from Kimmo Suominen.
saxmatt authored
68 if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37'
b43564c *** empty log message ***
saxmatt authored
69 $ddate = trim($line);
70 $ddate = str_replace('Date: ', '', $ddate);
71 if (strpos($ddate, ',')) {
72 $ddate = trim(substr($ddate, strpos($ddate, ',')+1, strlen($ddate)));
73 }
74 $date_arr = explode(' ', $ddate);
75 $date_time = explode(':', $date_arr[3]);
76
77 $ddate_H = $date_time[0];
78 $ddate_i = $date_time[1];
79 $ddate_s = $date_time[2];
80
81 $ddate_m = $date_arr[1];
82 $ddate_d = $date_arr[0];
83 $ddate_Y = $date_arr[2];
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
84 for ($j=0; $j<12; $j++) {
85 if ($ddate_m == $dmonths[$j]) {
86 $ddate_m = $j+1;
b43564c *** empty log message ***
saxmatt authored
87 }
88 }
84435bf big leap to GMT dates
michelvaldrighi authored
89
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
90 $time_zn = intval($date_arr[4]) * 36;
3e1304d More wp-mail timezone and delimiter fixes from Kitten.
rboren authored
91 $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
92 $ddate_U = $ddate_U - $time_zn;
93 $post_date = gmdate('Y-m-d H:i:s', $ddate_U + $time_difference);
b8df8fb now storing emailed posts as localtime+gmt
michelvaldrighi authored
94 $post_date_gmt = gmdate('Y-m-d H:i:s', $ddate_U);
b43564c *** empty log message ***
saxmatt authored
95 }
96 }
a0ad8e4 New mail functionality.
saxmatt authored
97 endforeach;
b43564c *** empty log message ***
saxmatt authored
98
a0ad8e4 New mail functionality.
saxmatt authored
99 $subject = trim(str_replace(get_settings('subjectprefix'), '', $subject));
b43564c *** empty log message ***
saxmatt authored
100
a0ad8e4 New mail functionality.
saxmatt authored
101 if ($content_type == 'multipart/alternative') {
102 $content = explode('--'.$boundary, $content);
103 $content = $content[2];
104 $content = explode('Content-Transfer-Encoding: quoted-printable', $content);
105 $content = strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div>');
b43564c *** empty log message ***
saxmatt authored
106 }
a0ad8e4 New mail functionality.
saxmatt authored
107 $content = trim($content);
3e1304d More wp-mail timezone and delimiter fixes from Kitten.
rboren authored
108 // Captures any text in the body after $phone_delim as the body
109 $content = explode($phone_delim, $content);
110 $content[1] ? $content = $content[1] : $content = $content[0];
b43564c *** empty log message ***
saxmatt authored
111
a0ad8e4 New mail functionality.
saxmatt authored
112 echo "<p><b>Content-type:</b> $content_type, <b>boundary:</b> $boundary</p>\n";
113 echo "<p><b>Raw content:</b><br /><pre>".$content.'</pre></p>';
b43564c *** empty log message ***
saxmatt authored
114
a0ad8e4 New mail functionality.
saxmatt authored
115 $content = trim($content);
b43564c *** empty log message ***
saxmatt authored
116
ed34ca0 Set GUID when posting.
saxmatt authored
117 $post_content = apply_filters('phone_content', $content);
b43564c *** empty log message ***
saxmatt authored
118
a0ad8e4 New mail functionality.
saxmatt authored
119 $post_title = xmlrpc_getposttitle($content);
b43564c *** empty log message ***
saxmatt authored
120
a0ad8e4 New mail functionality.
saxmatt authored
121 if ($post_title == '') $post_title = $subject;
b43564c *** empty log message ***
saxmatt authored
122
bc0c6ed Use default_email_category. Credit: Kitten.
rboren authored
123 if (empty($post_categories)) $post_categories[] = get_settings('default_email_category');
b43564c *** empty log message ***
saxmatt authored
124
ed34ca0 Set GUID when posting.
saxmatt authored
125 $post_category = $post_categories;
b43564c *** empty log message ***
saxmatt authored
126
ed34ca0 Set GUID when posting.
saxmatt authored
127 $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category');
b43564c *** empty log message ***
saxmatt authored
128
ed34ca0 Set GUID when posting.
saxmatt authored
129 wp_insert_post($post_data);
b43564c *** empty log message ***
saxmatt authored
130
2f4218a Added filter and action hooks.
saxmatt authored
131 do_action('publish_phone', $post_ID);
5624ca0 Fix ups.
saxmatt authored
132
a0ad8e4 New mail functionality.
saxmatt authored
133 echo "\n<p><b>Posted title:</b> $post_title<br />";
134 echo "\n<b>Posted content:</b><br /><pre>".$content.'</pre></p>';
5624ca0 Fix ups.
saxmatt authored
135
87812da Queue, SMS, timezone, and permalink fixes for wp-mail from MooKitty.
rboren authored
136 if (!$post_categories) $post_categories[] = 1;
137 foreach ($post_categories as $post_category) :
a0ad8e4 New mail functionality.
saxmatt authored
138 $post_category = intval($post_category);
b43564c *** empty log message ***
saxmatt authored
139
a0ad8e4 New mail functionality.
saxmatt authored
140 // Double check it's not there already
25ae03e Giant commit, sorry mailing list people. Move all table names to new $wp...
saxmatt authored
141 $exists = $wpdb->get_row("SELECT * FROM $wpdb->post2cat WHERE post_id = $post_ID AND category_id = $post_category");
a0ad8e4 New mail functionality.
saxmatt authored
142
143 if (!$exists && $result) {
144 $wpdb->query("
25ae03e Giant commit, sorry mailing list people. Move all table names to new $wp...
saxmatt authored
145 INSERT INTO $wpdb->post2cat
a0ad8e4 New mail functionality.
saxmatt authored
146 (post_id, category_id)
147 VALUES
148 ($post_ID, $post_category)
149 ");
b43564c *** empty log message ***
saxmatt authored
150 }
a0ad8e4 New mail functionality.
saxmatt authored
151 endforeach;
b43564c *** empty log message ***
saxmatt authored
152
a0ad8e4 New mail functionality.
saxmatt authored
153 endfor;
b43564c *** empty log message ***
saxmatt authored
154
a0ad8e4 New mail functionality.
saxmatt authored
155 $pop3->quit();
b43564c *** empty log message ***
saxmatt authored
156
527b31e Added ezSQL and small HTML fixes.
saxmatt authored
157 ?>
Something went wrong with that request. Please try again.