/** * Parse message headers * * @param integer $message_id * @param MailboxManagerEmail $email * @return MailboxManagerEmail */ function parseMessageHeaders($message_id, &$email) { if (!instance_of($email, 'MailboxManagerEmail')) { $email = new MailboxManagerEmail(); } // if $headers = $this->getMessageHeaders($message_id); if (!is_object($headers)) { return new Error(lang('Could not retrieve headers for that messsage. Does message with id #:message_id exists?', array('message_id' => $message_id))); } // if $email->setId($message_id); $email->setSubject(imap_utf8_alt($headers->Subject)); $email->setDate($headers->Date); $email->setSize($headers->Size); $email->setHeaders(imap_fetchheader($this->getConnection(), $message_id)); if (is_foreachable($headers->from)) { foreach ($headers->from as $from) { $email->addAddress($from->mailbox . '@' . $from->host, imap_utf8_alt($from->personal), 'from'); } // foreach } // if if (is_foreachable($headers->to)) { foreach ($headers->to as $to) { $email->addAddress($to->mailbox . '@' . $to->host, imap_utf8_alt($to->personal), 'to'); } // foreach } // if if (is_foreachable($headers->reply_to)) { foreach ($headers->reply_to as $reply_to) { $email->addAddress($reply_to->mailbox . '@' . $reply_to->host, imap_utf8_alt($reply_to->personal), 'reply_to'); } // foreach } // if if (is_foreachable($headers->cc)) { foreach ($headers->cc as $cc) { $email->addAddress($cc->mailbox . '@' . $cc->host, imap_utf8_alt($cc->personal), 'cc'); } // foreach } // if if (is_foreachable($headers->bcc)) { foreach ($headers->bcc as $bcc) { $email->addAddress($bcc->mailbox . '@' . $bcc->host, imap_utf8_alt($bcc->personal), 'bcc'); } // foreach } // if return $email; }