3 function email_connect($mailbox,$username,$password) {
4 if(! function_exists('imap_open'))
7 $mbox = imap_open($mailbox,$username,$password);
12 function email_poll($mbox,$email_addr) {
14 if(! ($mbox && $email_addr))
17 $search = imap_search($mbox,'FROM "' . $email_addr . '"', SE_UID);
18 return (($search) ? $search : array());
22 function construct_mailbox_name($mailacct) {
23 $ret = '{' . $mailacct['server'] . (($mailacct['port']) ? ':' . $mailacct['port'] : '');
24 $ret .= (($mailacct['ssltype']) ? '/' . $mailacct['ssltype'] . '/novalidate-cert' : '');
25 $ret .= '}' . $mailacct['mailbox'];
30 function email_msg_meta($mbox,$uid) {
31 $ret = (($mbox && $uid) ? imap_fetch_overview($mbox,$uid,FT_UID) : array(array()));
32 return ((count($ret)) ? $ret[0] : array());
36 function email_get_msg($mbox,$uid) {
39 $struc = (($mbox && $uid) ? imap_fetchstructure($mbox,$uid,FT_UID) : null);
45 $ret['body'] = email_get_part($mbox,$uid,$struc,0);
48 foreach($struc->parts as $ptop => $p) {
49 $x = email_get_part($mbox,$uid,$p,$ptop + 1);
57 // At the moment - only return plain/text.
58 // Later we'll repackage inline images as data url's and make the HTML safe
60 function email_get_part($mbox,$uid,$p,$partno) {
61 // $partno = '1', '2', '2.1', '2.1.3', etc for multipart, 0 if simple
62 global $htmlmsg,$plainmsg,$charset,$attachments;
68 ? imap_fetchbody($mbox,$uid,$partno, FT_UID|FT_PEEK)
69 : imap_body($mbox,$uid,FT_UID|FT_PEEK);
71 // Any part may be encoded, even plain text messages, so check everything.
73 $data = quoted_printable_decode($data);
74 elseif ($p->encoding==3)
75 $data = base64_decode($data);
78 // get all parameters, like charset, filenames of attachments, etc.
81 foreach ($p->parameters as $x)
82 $params[strtolower($x->attribute)] = $x->value;
84 foreach ($p->dparameters as $x)
85 $params[strtolower($x->attribute)] = $x->value;
88 // Any part with a filename is an attachment,
89 // so an attached text file (type 0) is not mistaken as the message.
91 if ($params['filename'] || $params['name']) {
92 // filename may be given as 'Filename' or 'Name' or both
93 $filename = ($params['filename'])? $params['filename'] : $params['name'];
94 // filename may be encoded, so see imap_mime_header_decode()
95 $attachments[$filename] = $data; // this is a problem if two files have same name
99 if ($p->type == 0 && $data) {
100 // Messages may be split in different parts because of inline attachments,
101 // so append parts together with blank row.
102 if (strtolower($p->subtype)=='plain')
103 return (trim($data) ."\n\n");
107 // $htmlmsg .= $data ."<br><br>";
108 $charset = $params['charset']; // assume all parts are same charset
112 // Many bounce notifications embed the original message as type 2,
113 // but AOL uses type 1 (multipart), which is not handled here.
114 // There are no PHP functions to parse embedded messages,
115 // so this just appends the raw source to the main message.
116 // elseif ($p->type==2 && $data) {
117 // $plainmsg .= $data."\n\n";
122 foreach ($p->parts as $partno0=>$p2) {
123 $x = email_get_part($mbox,$uid,$p2,$partno . '.' . ($partno0+1)); // 1.2, 1.2.1, etc.