MDL-48593 messageinbound: Correct header retrieval from IMAP server

Header retrieval should only be performed on the base message, and not each
part of the message as is currently performed.

This came to light because Google changed their IMAP server such that, if
you inform the data query that you wish to retrieve the headerText for a
part which does not contain a MIME header, then no message is retrieved in
the search causing a general failure of the IMAP fetch.

In normal circumstances, headers should only be a part of the base message
part.
This commit is contained in:
Andrew Nicols 2014-12-16 09:32:30 +08:00
parent 8f06fffbe1
commit 35df3d5373

View File

@ -367,7 +367,10 @@ class manager {
// Process and retrieve the message data for this message.
// This includes fetching the full content, as well as all headers, and attachments.
$this->process_message_data($envelope, $messagedata, $messageid);
if (!$this->process_message_data($envelope, $messagedata, $messageid)) {
mtrace("--- Message could not be found on the server. Is another process removing messages?");
return;
}
// When processing validation replies, we need to skip the sender verification phase as this has been
// manually completed.
@ -461,36 +464,25 @@ class manager {
$query = new \Horde_Imap_Client_Fetch_Query();
$query->imapDate();
// Fetch all of the message parts too.
$typemap = $structure->contentTypeMap();
foreach ($typemap as $part => $type) {
// The header.
$query->headerText(array(
'id' => $part,
));
}
// Fetch the message header.
$query->headerText();
// Retrieve the message with the above components.
$messagedata = $this->client->fetch($mailbox, $query, array('ids' => $messageid))->first();
// Store the data for this message.
$headers = '';
foreach ($typemap as $part => $type) {
// Grab all of the header data into a string.
$headers .= $messagedata->getHeaderText($part);
// We don't handle any of the other MIME content at this stage.
if (!$messagedata) {
// Message was not found! Somehow it has been removed or is no longer returned.
return null;
}
$data = new \stdClass();
// The message ID should always be in the first part.
$data = new \stdClass();
$data->messageid = $messagedata->getHeaderText(0, \Horde_Imap_Client_Data_Fetch::HEADER_PARSE)->getValue('Message-ID');
$data->subject = $envelope->subject;
$data->timestamp = $messagedata->getImapDate()->__toString();
$data->envelope = $envelope;
$data->data = $this->addressmanager->get_data();
$data->headers = $headers;
$data->headers = $messagedata->getHeaderText();
$this->currentmessagedata = $data;
@ -621,6 +613,9 @@ class manager {
private function process_message_part_attachment($messagedata, $partdata, $part, $filename) {
global $CFG;
// For Antivirus, the repository/lib.php must be included as it is not autoloaded.
require_once($CFG->dirroot . '/repository/lib.php');
// If a filename is present, assume that this part is an attachment.
$attachment = new \stdClass();
$attachment->filename = $filename;