Skip to content
Newer
Older
100644 154 lines (117 sloc) 4.48 KB
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
1 <?php
43e4a8a The great renaming.
saxmatt authored Dec 11, 2003
2 require(dirname(__FILE__) . '/wp-config.php');
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
3
99a7358 Renaming Reloaded.
saxmatt authored Dec 18, 2003
4 require_once(ABSPATH.WPINC.'/class-pop3.php');
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
5
6 error_reporting(2037);
7
8 $pop3 = new POP3();
9
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
10 if (!$pop3->connect(get_settings('mailserver_url'), get_settings('mailserver_port'))) :
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
11 echo "Ooops $pop3->ERROR <br />\n";
12 exit;
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
13 endif;
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
14
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
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 Apr 1, 2003
17
18
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
19 for ($i=1; $i <= $count; $i++) :
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
20
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
21 $message = $pop3->get($i);
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
22
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
23 if(!$pop3->delete($i)) {
24 echo '<p>Oops '.$pop3->ERROR.'</p></div>';
25 $pop3->reset();
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
26 exit;
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
27 } else {
28 echo "<p>Mission complete, message <strong>$i</strong> deleted.</p>";
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
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 Apr 24, 2004
37 foreach ($message as $line) :
38 if (strlen($line) < 3) $bodysignal = 1;
39
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
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 Feb 22, 2004
57 if (!preg_match('#\=\?(.+)\?Q\?(.+)\?\=#i', $subject)) {
58 $subject = wp_iso_descrambler($subject);
59 }
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
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 Feb 23, 2004
83
b8df8fb now storing emailed posts as localtime+gmt
michelvaldrighi authored Mar 25, 2004
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 Apr 1, 2003
86 }
87 }
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
88 endforeach;
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
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 Apr 24, 2004
94 $subject = trim(str_replace(get_settings('subjectprefix'), '', $subject));
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
95
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
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 Apr 1, 2003
101 }
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
102 $content = trim($content);
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
103
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
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 Apr 1, 2003
106
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
107 $content = trim($content);
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
108
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
109 $content = trim($content);
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
110
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
111 $post_title = xmlrpc_getposttitle($content);
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
112
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
113 if ($post_title == '') $post_title = $subject;
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
114
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
115 if (empty($post_categories)) $post_categories[] = get_settings('default_category');
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
116
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
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 Apr 1, 2003
120
121
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
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 Apr 1, 2003
123
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
124 $result = $wpdb->query($sql);
125 $post_ID = $wpdb->insert_id;
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
126
127
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
128 pingback($content, $post_ID);
5624ca0 Fix ups.
saxmatt authored Jan 13, 2004
129
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
130 echo "\n<p><b>Posted title:</b> $post_title<br />";
131 echo "\n<b>Posted content:</b><br /><pre>".$content.'</pre></p>';
5624ca0 Fix ups.
saxmatt authored Jan 13, 2004
132
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
133 if (!$post_categories) $post_categories[] = 1;
134 foreach ($post_categories as $post_category) :
135 $post_category = intval($post_category);
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
136
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
137 // Double check it's not there already
138 $exists = $wpdb->get_row("SELECT * FROM $tablepost2cat WHERE post_id = $post_ID AND category_id = $post_category");
139
140 if (!$exists && $result) {
141 $wpdb->query("
142 INSERT INTO $tablepost2cat
143 (post_id, category_id)
144 VALUES
145 ($post_ID, $post_category)
146 ");
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
147 }
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
148 endforeach;
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
149
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
150 endfor;
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
151
a0ad8e4 New mail functionality.
saxmatt authored Apr 24, 2004
152 $pop3->quit();
b43564c *** empty log message ***
saxmatt authored Apr 1, 2003
153
527b31e Added ezSQL and small HTML fixes.
saxmatt authored Jun 14, 2003
154 ?>
Something went wrong with that request. Please try again.