/** * Returns a message array with all the information about a message. * See the documentation folder for more information about this array. * * @param resource $imap_stream imap connection * @param integer $id uid of the message * @param string $mailbox used for error handling, can be removed because we should return an error code and generate the message elsewhere * @param int $hide Indicates whether or not to hide any errors: 0 = don't hide, 1 = hide (just exit), 2 = hide (return FALSE), 3 = hide (return error string) (OPTIONAL; default don't hide) * @return mixed Message object or FALSE/error string if error occurred and $hide is set to 2/3 */ function sqimap_get_message($imap_stream, $id, $mailbox, $hide = 0) { // typecast to int to prohibit 1:* msgs sets // Update: $id should always be sanitized into a BIGINT so this // is being removed; leaving this code here in case something goes // wrong, however //$id = (int) $id; $flags = array(); $read = sqimap_run_command($imap_stream, "FETCH {$id} (FLAGS BODYSTRUCTURE)", true, $response, $message, TRUE); if ($read) { if (preg_match('/.+FLAGS\\s\\((.*)\\)\\s/AUi', $read[0], $regs)) { if (trim($regs[1])) { $flags = preg_split('/ /', $regs[1], -1, PREG_SPLIT_NO_EMPTY); } } } else { if ($hide == 1) { exit; } if ($hide == 2) { return FALSE; } /* the message was not found, maybe the mailbox was modified? */ global $sort, $startMessage; $errmessage = _("The server couldn't find the message you requested."); if ($hide == 3) { return $errmessage; } $errmessage .= '<p>' . _("Most probably your message list was out of date and the message has been moved away or deleted (perhaps by another program accessing the same mailbox)."); /* this will include a link back to the message list */ error_message($errmessage, $mailbox, $sort, (int) $startMessage); exit; } $bodystructure = implode('', $read); $msg = mime_structure($bodystructure, $flags); $read = sqimap_run_command($imap_stream, "FETCH {$id} BODY[HEADER]", true, $response, $message, TRUE); $rfc822_header = new Rfc822Header(); $rfc822_header->parseHeader($read); $msg->rfc822_header = $rfc822_header; parse_message_entities($msg, $id, $imap_stream); return $msg; }
function sqimap_get_message($imap_stream, $id, $mailbox) { global $uid_support; $flags = array(); $read = sqimap_run_command($imap_stream, "FETCH {$id} (FLAGS BODYSTRUCTURE)", true, $response, $message, $uid_support); if ($read) { if (preg_match('/.+FLAGS\\s\\((.*)\\)\\s/AUi', $read[0], $regs)) { if (trim($regs[1])) { $flags = preg_split('/ /', $regs[1], -1, 'PREG_SPLIT_NI_EMPTY'); } } } else { echo "ERROR Yeah I know, not a very usefull errormessage (id = {$id}, mailbox = {$mailbox} sqimap_get_message)"; exit; } $bodystructure = implode('', $read); $msg = mime_structure($bodystructure, $flags); $read = sqimap_run_command($imap_stream, "FETCH {$id} BODY[HEADER]", true, $response, $message, $uid_support); $rfc822_header = new Rfc822Header(); $rfc822_header->parseHeader($read); $msg->rfc822_header = $rfc822_header; return $msg; }
/** * Returns a message array with all the information about a message. * See the documentation folder for more information about this array. */ function sqimap_get_message($imap_stream, $id, $mailbox) { global $uid_support; // typecast to int to prohibit 1:* msgs sets $id = (int) $id; $flags = array(); $read = sqimap_run_command($imap_stream, "FETCH {$id} (FLAGS BODYSTRUCTURE)", true, $response, $message, $uid_support); if ($read) { if (preg_match('/.+FLAGS\\s\\((.*)\\)\\s/AUi', $read[0], $regs)) { if (trim($regs[1])) { $flags = preg_split('/ /', $regs[1], -1, PREG_SPLIT_NO_EMPTY); } } } else { /* the message was not found, maybe the mailbox was modified? */ global $sort, $startMessage, $color; $errmessage = _("The server couldn't find the message you requested.") . '<p>' . _("Most probably your message list was out of date and the message has been moved away or deleted (perhaps by another program accessing the same mailbox)."); /* this will include a link back to the message list */ error_message($errmessage, $mailbox, $sort, (int) $startMessage, $color); exit; } $bodystructure = implode('', $read); $msg = mime_structure($bodystructure, $flags); $read = sqimap_run_command($imap_stream, "FETCH {$id} BODY[HEADER]", true, $response, $message, $uid_support); $rfc822_header = new Rfc822Header(); $rfc822_header->parseHeader($read); $msg->rfc822_header = $rfc822_header; parse_message_entities($msg, $id, $imap_stream); return $msg; }