Subversion Repositories website

[/] [trunk/] [wp-mail.php] - Blame information for rev 84

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 84 drecordon
<?php
2 drecordon
require(dirname(__FILE__) . '/wp-config.php');
3 drecordon
4 drecordon
require_once(ABSPATH.WPINC.'/class-pop3.php');
5 drecordon
6 drecordon
error_reporting(2037);
7 drecordon
8 drecordon
$time_difference get_option('gmt_offset') * 3600;
9 drecordon
10 drecordon
$phone_delim '::';
11 drecordon
12 drecordon
$pop3 = new POP3();
13 drecordon
14 drecordon
if (!$pop3->connect(get_option('mailserver_url'), get_option('mailserver_port')))
15 drecordon
    wp_die($pop3->ERROR);
16 drecordon
17 drecordon
$count $pop3->login(get_option('mailserver_login'), get_option('mailserver_pass'));
18 drecordon
if (== $countwp_die(__('There doesn&#8217;t seem to be any new mail.'));
19 drecordon
20 drecordon
21 drecordon
for ($i=1$i <= $count$i++) :
22 drecordon
23 drecordon
    $message $pop3->get($i);
24 drecordon
25 drecordon
    $content '';
26 drecordon
    $content_type '';
27 drecordon
    $content_transfer_encoding '';
28 drecordon
    $boundary '';
29 drecordon
    $bodysignal 0;
30 drecordon
    $dmonths = array('Jan''Feb''Mar''Apr''May''Jun''Jul''Aug''Sep''Oct''Nov''Dec');
31 drecordon
    foreach ($message as $line) :
32 drecordon
        if (strlen($line) < 3$bodysignal 1;
33 drecordon
34 drecordon
        if ($bodysignal) {
35 drecordon
            $content .= $line;
36 drecordon
        } else {
37 drecordon
            if (preg_match('/Content-Type: /i'$line)) {
38 drecordon
                $content_type trim($line);
39 drecordon
                $content_type substr($content_type14strlen($content_type)-14);
40 drecordon
                $content_type explode(';'$content_type);
41 drecordon
                $content_type $content_type[0];
42 drecordon
            }
43 drecordon
            if (preg_match('/Content-Transfer-Encoding: /i'$line)) {
44 drecordon
                $content_transfer_encoding trim($line);
45 drecordon
                $content_transfer_encoding substr($content_transfer_encoding27strlen($content_transfer_encoding)-14);
46 drecordon
                $content_transfer_encoding explode(';'$content_transfer_encoding);
47 drecordon
                $content_transfer_encoding $content_transfer_encoding[0];
48 drecordon
            }
49 drecordon
            if (($content_type == 'multipart/alternative') && (preg_match('/boundary="/'$line)) && ($boundary == '')) {
50 drecordon
                $boundary trim($line);
51 drecordon
                $boundary explode('"'$boundary);
52 drecordon
                $boundary $boundary[1];
53 drecordon
            }
54 drecordon
            if (preg_match('/Subject: /i'$line)) {
55 drecordon
                $subject trim($line);
56 drecordon
                $subject substr($subject9strlen($subject)-9);
57 drecordon
                $subject wp_iso_descrambler($subject);
58 drecordon
                // Captures any text in the subject before $phone_delim as the subject
59 drecordon
                $subject explode($phone_delim$subject);
60 drecordon
                $subject $subject[0];
61 drecordon
            }
62 drecordon
63 drecordon
            // Set the author using the email address (From or Reply-To, the last used)
64 drecordon
            // otherwise use the site admin
65 drecordon
            if ( preg_match('/(From|Reply-To): /'$line) )  {
66 drecordon
                if ( preg_match('|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i'$line$matches) )
67 drecordon
                    $author $matches[0];
68 drecordon
                else
69 drecordon
                    $author trim($line);
70 drecordon
                $author sanitize_email($author);
71 drecordon
                if ( is_email($author) ) {
72 drecordon
                    echo "Author = {$author} <p>";
73 drecordon
                    $author $wpdb->escape($author);
74 drecordon
                    $result $wpdb->get_row("SELECT ID FROM $wpdb->users WHERE user_email='$author' LIMIT 1");
75 drecordon
                    if (!$result)
76 drecordon
                        $post_author 1;
77 drecordon
                    else
78 drecordon
                        $post_author $result->ID;
79 drecordon
                } else
80 drecordon
                    $post_author 1;
81 drecordon
            }
82 drecordon
83 drecordon
            if (preg_match('/Date: /i'$line)) { // of the form '20 Mar 2002 20:32:37'
84 drecordon
                $ddate trim($line);
85 drecordon
                $ddate str_replace('Date: '''$ddate);
86 drecordon
                if (strpos($ddate',')) {
87 drecordon
                    $ddate trim(substr($ddatestrpos($ddate',')+1strlen($ddate)));
88 drecordon
                }
89 drecordon
                $date_arr explode(' '$ddate);
90 drecordon
                $date_time explode(':'$date_arr[3]);
91 drecordon
92 drecordon
                $ddate_H $date_time[0];
93 drecordon
                $ddate_i $date_time[1];
94 drecordon
                $ddate_s $date_time[2];
95 drecordon
96 drecordon
                $ddate_m $date_arr[1];
97 drecordon
                $ddate_d $date_arr[0];
98 drecordon
                $ddate_Y $date_arr[2];
99 drecordon
                for ($j=0$j<12$j++) {
100 drecordon
                    if ($ddate_m == $dmonths[$j]) {
101 drecordon
                        $ddate_m $j+1;
102 drecordon
                    }
103 drecordon
                }
104 drecordon
105 drecordon
                $time_zn intval($date_arr[4]) * 36;
106 drecordon
                $ddate_U gmmktime($ddate_H$ddate_i$ddate_s$ddate_m$ddate_d$ddate_Y);
107 drecordon
                $ddate_U $ddate_U $time_zn;
108 drecordon
                $post_date gmdate('Y-m-d H:i:s'$ddate_U $time_difference);
109 drecordon
                $post_date_gmt gmdate('Y-m-d H:i:s'$ddate_U);
110 drecordon
            }
111 drecordon
        }
112 drecordon
    endforeach;
113 drecordon
114 drecordon
    $subject trim($subject);
115 drecordon
116 drecordon
    if ($content_type == 'multipart/alternative') {
117 drecordon
        $content explode('--'.$boundary$content);
118 drecordon
        $content $content[2];
119 drecordon
        $content explode('Content-Transfer-Encoding: quoted-printable'$content);
120 drecordon
        $content strip_tags($content[1], '<img><p><br><i><b><u><em><strong><strike><font><span><div>');
121 drecordon
    }
122 drecordon
    $content trim($content);
123 drecordon
124 drecordon
    if (stripos($content_transfer_encoding"quoted-printable") !== false) {
125 drecordon
        $content quoted_printable_decode($content);
126 drecordon
    }
127 drecordon
128 drecordon
    // Captures any text in the body after $phone_delim as the body
129 drecordon
    $content explode($phone_delim$content);
130 drecordon
    $content[1] ? $content $content[1] : $content $content[0];
131 drecordon
132 drecordon
    echo "<p><b>Content-type:</b> $content_type, <b>Content-Transfer-Encoding:</b> $content_transfer_encoding, <b>boundary:</b> $boundary</p>\n";
133 drecordon
    echo "<p><b>Raw content:</b><br /><pre>".$content.'</pre></p>';
134 drecordon
135 drecordon
    $content trim($content);
136 drecordon
137 drecordon
    $post_content apply_filters('phone_content'$content);
138 drecordon
139 drecordon
    $post_title xmlrpc_getposttitle($content);
140 drecordon
141 drecordon
    if ($post_title == ''$post_title $subject;
142 drecordon
143 drecordon
    if (empty($post_categories)) $post_categories[] = get_option('default_email_category');
144 drecordon
145 drecordon
    $post_category $post_categories;
146 drecordon
147 drecordon
    // or maybe we should leave the choice to email drafts? propose a way
148 drecordon
    $post_status 'publish';
149 drecordon
150 drecordon
    $post_data compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category''post_status');
151 drecordon
    $post_data add_magic_quotes($post_data);
152 drecordon
153 drecordon
    $post_ID wp_insert_post($post_data);
154 drecordon
    if ( is_wp_error$post_ID ) ) 
155 drecordon
        echo "\n" $post_ID->get_error_message();
156 drecordon
157 drecordon
    if (!$post_ID) {
158 drecordon
        // we couldn't post, for whatever reason. better move forward to the next email
159 drecordon
        continue;
160 drecordon
    }
161 drecordon
162 drecordon
    do_action('publish_phone'$post_ID);
163 drecordon
164 drecordon
    echo "\n<p><b>Author:</b> $post_author</p>";
165 drecordon
    echo "\n<p><b>Posted title:</b> $post_title<br />";
166 drecordon
    echo "\n<b>Posted content:</b><br /><pre>".$content.'</pre></p>';
167 drecordon
168 drecordon
    if(!$pop3->delete($i)) {
169 drecordon
        echo '<p>Oops '.$pop3->ERROR.'</p></div>';
170 drecordon
        $pop3->reset();
171 drecordon
        exit;
172 drecordon
    } else {
173 drecordon
        echo "<p>Mission complete, message <strong>$i</strong> deleted.</p>";
174 drecordon
    }
175 drecordon
176 drecordon
endfor;
177 drecordon
178 drecordon
$pop3->quit();
179 drecordon
180 drecordon
?>