function cacheMessage($id, $data)
 {
     $data['subject'] = htmlspecialchars($data['subject'], ENT_QUOTES, 'UTF-8');
     $data['account_id'] = $this->_data['account_id'];
     $data['full_from'] = htmlspecialchars($data['from'], ENT_QUOTES, 'UTF-8');
     $RFC822 = new RFC822();
     $address = $RFC822->parse_address_list($data['from']);
     $data['sender'] = isset($address[0]['email']) ? htmlspecialchars($address[0]['email'], ENT_QUOTES, 'UTF-8') : '';
     $data['from'] = isset($address[0]['personal']) ? htmlspecialchars($address[0]['personal'], ENT_QUOTES, 'UTF-8') : '';
     //to
     if (!empty($data['to'])) {
         $to = array();
         foreach ($data['to'] as $address) {
             $address = $RFC822->parse_address_list($address);
             $to[] = array('email' => htmlspecialchars($address[0]['email'], ENT_QUOTES, 'UTF-8'), 'name' => htmlspecialchars($address[0]['personal'], ENT_QUOTES, 'UTF-8'));
         }
         $data['to'] = $to;
     }
     //cc
     if (!empty($data['cc'])) {
         $cc = array();
         foreach ($data['cc'] as $address) {
             $address = $RFC822->parse_address_list($address);
             $cc[] = array('email' => htmlspecialchars($address[0]['email'], ENT_QUOTES, 'UTF-8'), 'name' => htmlspecialchars($address[0]['personal'], ENT_QUOTES, 'UTF-8'));
         }
         $data['cc'] = $cc;
     }
     //bcc
     if (!empty($data['bcc'])) {
         $bcc = array();
         foreach ($data['bcc'] as $address) {
             $address = $RFC822->parse_address_list($address);
             $bcc[] = array('email' => htmlspecialchars($address[0]['email'], ENT_QUOTES, 'UTF-8'), 'name' => htmlspecialchars($address[0]['personal'], ENT_QUOTES, 'UTF-8'));
         }
         $data['bcc'] = $bcc;
     }
     $data['date'] = osC_DateTime::getShort(osC_DateTime::fromUnixTimestamp($data['udate']), true);
     $parts = array_reverse($this->_inbox->f("parts"));
     $html_alternative = false;
     for ($i = 0; $i < count($parts); $i++) {
         if (eregi('html', $parts[$i]['mime']) && (strtolower($parts[$i]['type']) == 'alternative' || strtolower($parts[$i]['type']) == 'related')) {
             $html_alternative = true;
         }
     }
     $data['body'] = '';
     //attachments
     $attachments = array();
     if (eregi('html', $data['content_type'])) {
         $default_mime = 'text/html';
     } else {
         $default_mime = 'text/plain';
     }
     $part_count = count($parts);
     if ($part_count == 1) {
         //if there's only one part use the message parameters.
         if (eregi('plain', $parts[0]['mime'])) {
             $parts[0]['mime'] = $default_mime;
         }
         if (!empty($data['content_transfer_encoding'])) {
             $parts[0]['transfer'] = $data['content_transfer_encoding'];
         }
     }
     while ($part = array_shift($parts)) {
         $mime = isset($part["mime"]) ? strtolower($part["mime"]) : $default_mime;
         //some clients just send html
         if ($mime == 'html') {
             $mime = 'text/html';
         }
         if (empty($data['body']) && !eregi('attachment', $part["disposition"]) && (eregi('html', $mime) || eregi('plain', $mime) && (!$html_alternative || strtolower($part['type']) != 'alternative') || $mime == "text/enriched" || $mime == "unknown/unknown")) {
             $part_body = $this->_inbox->view_part($data['uid'], $part["number"], $part["transfer"], $part["charset"]);
             switch ($mime) {
                 case 'unknown/unknown':
                 case 'text/plain':
                     $uuencoded_attachments = $this->_inbox->extract_uuencoded_attachments($part_body);
                     $part_body = Imap::text_to_html($part_body);
                     for ($i = 0; $i < count($uuencoded_attachments); $i++) {
                         $attachment = $uuencoded_attachments[$i];
                         $attachment['number'] = $part['number'];
                         unset($attachment['data']);
                         $attachment['uuencoded_partnumber'] = $i + 1;
                         $attachments[] = $attachment;
                     }
                     break;
                 case 'text/html':
                     $part_body = Imap::convert_html($part_body);
                     break;
                 case 'text/enriched':
                     $part_body = Imap::enriched_to_html($part_body);
                     break;
             }
             $data['body'] .= $part_body;
         } else {
             $attachments[] = $part;
         }
     }
     //$data['event']=false;
     $data['attachments'] = array();
     $index = 0;
     for ($i = 0; $i < count($attachments); $i++) {
         if ($this->_inbox->part_is_attachment($attachments[$i])) {
             $attachment = $attachments[$i];
             $attachment['index'] = $index;
             $attachment['extension'] = Imap::get_extension($attachments[$i]["name"]);
             $data['attachments'][] = $attachment;
             $index++;
         }
         if (!empty($attachments[$i]["id"])) {
             //when an image has an id it belongs somewhere in the text we gathered above so replace the
             //source id with the correct link to display the image.
             if ($attachments[$i]["id"] != '') {
                 $tmp_id = $attachments[$i]["id"];
                 if (strpos($tmp_id, '>')) {
                     $tmp_id = substr($attachments[$i]["id"], 1, strlen($attachments[$i]["id"]) - 2);
                 }
                 $image_id = "cid:" . $tmp_id;
                 //            $url = $GO_MODULES->modules['email']['url']."attachment.php?account_id=".$account['id']."&mailbox=".urlencode($mailbox)."&amp;uid=".$uid."&amp;part=".$attachments[$i]["number"]."&amp;transfer=".$attachments[$i]["transfer"]."&amp;mime=".$attachments[$i]["mime"]."&amp;filename=".urlencode($attachments[$i]["name"]);
                 //            $data['body'] = str_replace($id, $url, $data['body']);
             }
         }
     }
     //save message cache
     $file = DIR_FS_CACHE_ADMIN . 'emails/' . md5($this->_data['accounts_id'] . $this->_data['accounts_email']) . '/messages/' . md5($id . $data['fetch_timestamp']) . '.php';
     if ($h = fopen($file, 'w')) {
         $cached_message = var_export($data, true);
         $date = date("r");
         $cached_message_string = '<?php //created: {' . $date . 'accounts_id: ' . $this->_data['accounts_id'] . ';;;id:' . $id . ';;;time_stamp:' . $data['fetch_timestamp'] . '}' . "\n\n" . '$cacheFile = ' . $cached_message . "\n\n" . '?>';
         fputs($h, $cached_message_string);
         fclose($h);
     }
     //save attachments cache
     $conn = $this->_inbox->conn;
     $msg_no = imap_msgno($conn, $data['uid']);
     $structure = imap_fetchstructure($conn, $msg_no);
     $file_attachment = DIR_FS_CACHE_ADMIN . 'emails/' . md5($this->_data['accounts_id'] . $this->_data['accounts_email']) . '/attachments/' . md5($id . $data['fetch_timestamp']);
     if ($structure->type == 1 && !empty($structure->parts)) {
         $this->cacheAttachments($msg_no, $structure->parts, 0, $file_attachment);
     }
     return true;
 }
Exemplo n.º 2
0
 public static function parse($address = null, $default_domain = null, $nest_groups = null, $validate = null, $limit = null)
 {
     $dummy = new RFC822($address, $default_domain, $nest_groups, $validate, $limit);
     return $dummy->parseAddressList();
 }