Skip to content

HTTPS clone URL

Subversion checkout URL

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