function getHeaderInfo($mid) { if (!($headerinfo = imap_headerinfo($this->mbox, $mid)) || !$headerinfo->from) { return null; } $raw_header = $this->getHeader($mid); $info = array('raw_header' => &$raw_header, 'headers' => $headerinfo, 'decoder' => $this, 'type' => $this->getMimeType($headerinfo)); Signal::send('mail.decoded', $this, $info); $sender = $headerinfo->from[0]; //Just what we need... $header = array('name' => $this->mime_decode(@$sender->personal), 'email' => trim(strtolower($sender->mailbox) . '@' . $sender->host), 'subject' => $this->mime_decode(@$headerinfo->subject), 'mid' => trim(@$headerinfo->message_id), 'header' => $raw_header, 'in-reply-to' => $headerinfo->in_reply_to, 'references' => $headerinfo->references); if ($replyto = $headerinfo->reply_to) { $header['reply-to'] = $replyto[0]->mailbox . '@' . $replyto[0]->host; $header['reply-to-name'] = $replyto[0]->personal; } // Put together a list of recipients $tolist = array(); if ($headerinfo->to) { $tolist['to'] = $headerinfo->to; } if ($headerinfo->cc) { $tolist['cc'] = $headerinfo->cc; } //Add delivered-to address to list. if (stripos($header['header'], 'delivered-to:') !== false && ($dt = Mail_Parse::findHeaderEntry($header['header'], 'delivered-to', true))) { if ($delivered_to = Mail_Parse::parseAddressList($dt)) { $tolist['delivered-to'] = $delivered_to; } } $header['recipients'] = array(); foreach ($tolist as $source => $list) { foreach ($list as $addr) { if (!($emailId = Email::getIdByEmail(strtolower($addr->mailbox) . '@' . $addr->host))) { //Skip virtual Delivered-To addresses if ($source == 'delivered-to') { continue; } $header['recipients'][] = array('source' => sprintf(_S("Email (%s)"), $source), 'name' => $this->mime_decode(@$addr->personal), 'email' => strtolower($addr->mailbox) . '@' . $addr->host); } elseif (!$header['emailId']) { $header['emailId'] = $emailId; } } } //See if any of the recipients is a delivered to address if ($tolist['delivered-to']) { foreach ($tolist['delivered-to'] as $addr) { foreach ($header['recipients'] as $i => $r) { if (strcasecmp($r['email'], $addr->mailbox . '@' . $addr->host) === 0) { $header['recipients'][$i]['source'] = 'delivered-to'; } } } } //BCCed? if (!$header['emailId']) { if ($headerinfo->bcc) { foreach ($headerinfo->bcc as $addr) { if ($header['emailId'] = Email::getIdByEmail(strtolower($addr->mailbox) . '@' . $addr->host)) { break; } } } } // Ensure we have a message-id. If unable to read it out of the // email, use the hash of the entire email headers if (!$header['mid'] && $header['header']) { $header['mid'] = Mail_Parse::findHeaderEntry($header['header'], 'message-id'); if (is_array($header['mid'])) { $header['mid'] = array_pop(array_filter($header['mid'])); } if (!$header['mid']) { $header['mid'] = '<' . md5($header['header']) . '@local>'; } } return $header; }
function getHeaderInfo($mid) { if (!($headerinfo = imap_headerinfo($this->mbox, $mid)) || !$headerinfo->from) { return null; } $sender = $headerinfo->from[0]; //Just what we need... $header = array('name' => @$sender->personal, 'email' => trim(strtolower($sender->mailbox) . '@' . $sender->host), 'subject' => @$headerinfo->subject, 'mid' => trim(@$headerinfo->message_id), 'header' => $this->getHeader($mid), 'in-reply-to' => $headerinfo->in_reply_to, 'references' => $headerinfo->references); if ($replyto = $headerinfo->reply_to) { $header['reply-to'] = $replyto[0]->mailbox . '@' . $replyto[0]->host; $header['reply-to-name'] = $replyto[0]->personal; } //Try to determine target email - useful when fetched inbox has // aliases that are independent emails within osTicket. $emailId = 0; $tolist = array(); if ($headerinfo->to) { $tolist = array_merge($tolist, $headerinfo->to); } if ($headerinfo->cc) { $tolist = array_merge($tolist, $headerinfo->cc); } if ($headerinfo->bcc) { $tolist = array_merge($tolist, $headerinfo->bcc); } foreach ($tolist as $addr) { if ($emailId = Email::getIdByEmail(strtolower($addr->mailbox) . '@' . $addr->host)) { break; } } $header['emailId'] = $emailId; // Ensure we have a message-id. If unable to read it out of the // email, use the hash of the entire email headers if (!$header['mid'] && $header['header']) { if (!($header['mid'] = Mail_Parse::findHeaderEntry($header['header'], 'message-id'))) { $header['mid'] = '<' . md5($header['header']) . '@local>'; } } return $header; }