* @param int $imap_stream The resource ID for the IMAP socket
* @param string $id The list of messages to copy
* @param string $mailbox The destination to copy to
- * @return bool
+ * @param bool $handle_errors Show error messages in case of a NO, BAD or BYE response
+ * @return bool If the copy completed without errors
*/
-function sqimap_msgs_list_copy($imap_stream, $id, $mailbox) {
+function sqimap_msgs_list_copy($imap_stream, $id, $mailbox, $handle_errors = true) {
$msgs_id = sqimap_message_list_squisher($id);
- $read = sqimap_run_command ($imap_stream, "COPY $msgs_id " . sqimap_encode_mailbox_name($mailbox), true, $response, $message, TRUE);
+ $read = sqimap_run_command ($imap_stream, "COPY $msgs_id " . sqimap_encode_mailbox_name($mailbox), $handle_errors, $response, $message, TRUE);
if ($response == 'OK') {
return true;
} else {
* @param int $imap_stream The resource ID for the IMAP socket
* @param string $id The list of messages to move
* @param string $mailbox The destination to move to
- * @return void
+ * @param bool $handle_errors Show error messages in case of a NO, BAD or BYE response
+ * @return bool If the move completed without errors
*/
-function sqimap_msgs_list_move($imap_stream, $id, $mailbox) {
+function sqimap_msgs_list_move($imap_stream, $id, $mailbox, $handle_errors = true) {
$msgs_id = sqimap_message_list_squisher($id);
- if (sqimap_msgs_list_copy ($imap_stream, $id, $mailbox)) {
+ if (sqimap_msgs_list_copy ($imap_stream, $id, $mailbox, $handle_errors)) {
return sqimap_toggle_flag($imap_stream, $id, '\\Deleted', true, true);
} else {
return false;
* @param resource imap connection
* @param string $mailbox mailbox, used for checking if it concerns the trash_folder
* @param array $id list with uid's
- * @param bool $bypass_trash skip copy to trash
+ * @param bool $bypass_trash (since 1.5.0) skip copy to trash
* @return array $aMessageList array with messages containing the new flags and UID @see parseFetch
+ * @since 1.4.0
*/
function sqimap_msgs_list_delete($imap_stream, $mailbox, $id, $bypass_trash=false) {
// FIX ME, remove globals by introducing an associative array with properties
$sPersonal = (isset($addr[SQM_ADDR_PERSONAL]) && $addr[SQM_ADDR_PERSONAL]) ?
$addr[SQM_ADDR_PERSONAL] : "";
$sEmail = ($addr[SQM_ADDR_HOST]) ?
- $addr[SQM_ADDR_HOST] . "@".$addr[SQM_ADDR_HOST] :
+ $addr[SQM_ADDR_MAILBOX] . "@".$addr[SQM_ADDR_HOST] :
$addr[SQM_ADDR_HOST];
$v[$f] = ($sPersonal) ? decodeHeader($sPersonal):$sEmail;'),$sSortField);
$walk = true;
}
+/**
+ * Normalise the different Priority headers into a uniform value,
+ * namely that of the X-Priority header (1, 3, 5). Supports:
+ * Prioirty, X-Priority, Importance.
+ * X-MS-Mail-Priority is not parsed because it always coincides
+ * with one of the other headers.
+ *
+ * DUPLICATE CODE ALERT:
+ * NOTE: this is actually a duplicate from the function in
+ * class/mime/Rfc822Header.php.
+ */
function parsePriority($value) {
$value = strtolower(array_shift(split('/\w/',trim($value))));
if ( is_numeric($value) ) {
/**
* Retrieves a list with headers, flags, size or internaldate from the imap server
- * @param resource $imap_stream imap connection
- * @param array $msg_list array with id's to create a msgs set from
- * @param array $aHeaderFields requested header fields
- * @param array $aFetchItems requested other fetch items like FLAGS, RFC822.SIZE
- * @return array $aMessages associative array with messages. Key is the UID, value is an associative array
+ *
+ * WARNING: function is not portable between SquirrelMail 1.2.x, 1.4.x and 1.5.x.
+ * Output format, third argument and $msg_list array format requirements differ.
+ * @param stream $imap_stream imap connection
+ * @param array $msg_list array with id's to create a msgs set from
+ * @param array $aHeaderFields (since 1.5.0) requested header fields
+ * @param array $aFetchItems (since 1.5.0) requested other fetch items like FLAGS, RFC822.SIZE
+ * @return array $aMessages associative array with messages. Key is the UID, value is an associative array
+ * @since 1.1.3
*/
function sqimap_get_small_header_list($imap_stream, $msg_list,
- $aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Importance', 'Priority', 'Content-Type'),
+ $aHeaderFields = array('Date', 'To', 'Cc', 'From', 'Subject', 'X-Priority', 'Content-Type'),
$aFetchItems = array('FLAGS', 'RFC822.SIZE', 'INTERNALDATE')) {
$aMessageList = array();
+ /**
+ * Catch other priority headers as well
+ */
+ if (in_array('X-Priority',$aHeaderFields,true)) {
+ $aHeaderFields[] = 'Importance';
+ $aHeaderFields[] = 'Priority';
+ }
+
$bUidFetch = ! in_array('UID', $aFetchItems, true);
/* Get the small headers for each message in $msg_list */
* @author Marc Groot Koerkamp
*/
function parseFetch($aResponse,$aMessageList = array()) {
- foreach ($aResponse as $r) {
- $msg = array();
- // use unset because we do isset below
- $read = implode('',$r);
+ for ($j=0,$iCnt=count($aResponse);$j<$iCnt;++$j) {
+ $aMsg = array();
+ $read = implode('',$aResponse[$j]);
+ // free up memmory
+ unset($aResponse[$j]); /* unset does not reindex the array. the for loop is safe */
/*
- * #id<space>FETCH<space>(
- */
+ * #id<space>FETCH<space>(
+ */
/* extract the message id */
- $i_space = strpos($read,' ',2);
- $id = substr($read,2,$i_space-2);
- $msg['ID'] = $id;
+ $i_space = strpos($read,' ',2);/* position 2ed <space> */
+ $id = substr($read,2/* skip "*<space>" */,$i_space -2);
+ $aMsg['ID'] = $id;
$fetch = substr($read,$i_space+1,5);
if (!is_numeric($id) && $fetch !== 'FETCH') {
- $msg['ERROR'] = $read; // htmlspecialchars should be done just before display. this is backend code
+ $aMsg['ERROR'] = $read; // htmlspecialchars should be done just before display. this is backend code
break;
}
$i = strpos($read,'(',$i_space+5);
$i = strpos($read,' ');
$arg = substr($read,0,$i);
++$i;
+ /*
+ * use allcaps for imap items and lowcaps for headers as key for the $aMsg array
+ */
switch ($arg)
{
case 'UID':
$flag = strtolower($flag);
$aFlags[$flag] = true;
}
- $msg['FLAGS'] = $aFlags;
+ $aMsg['FLAGS'] = $aFlags;
break;
case 'RFC822.SIZE':
$i_pos = strpos($read,' ',$i);
$i_pos = strpos($read,')',$i);
}
if ($i_pos) {
- $msg['SIZE'] = substr($read,$i,$i_pos-$i);
+ $aMsg['SIZE'] = substr($read,$i,$i_pos-$i);
$i = $i_pos+1;
} else {
break 3;
}
-
break;
case 'ENVELOPE':
- break; // to be implemented, moving imap code out of the nessages class
- sqimap_parse_address($read,$i,$msg);
- break; // to be implemented, moving imap code out of the nessages class
+ // sqimap_parse_address($read,$i,$aMsg);
+ break; // to be implemented, moving imap code out of the Message class
case 'BODYSTRUCTURE':
- break;
+ break; // to be implemented, moving imap code out of the Message class
case 'INTERNALDATE':
- $msg['INTERNALDATE'] = trim(str_replace(' ', ' ',parseString($read,$i)));
+ $aMsg['INTERNALDATE'] = trim(str_replace(' ', ' ',parseString($read,$i)));
break;
case 'BODY.PEEK[HEADER.FIELDS':
case 'BODY[HEADER.FIELDS':
- $i = strpos($read,'{',$i);
+ $i = strpos($read,'{',$i); // header is always returned as literal because it contain \n characters
$header = parseString($read,$i);
if ($header === false) break 2;
/* First we replace all \r\n by \n, and unfold the header */
$hdr = trim(str_replace(array("\r\n", "\n\t", "\n "),array("\n", ' ', ' '), $header));
- /* Now we can make a new header array with */
- /* each element representing a headerline */
- $hdr = explode("\n" , $hdr);
+ /* Now we can make a new header array with
+ each element representing a headerline */
+ $aHdr = explode("\n" , $hdr);
$aReceived = array();
- foreach ($hdr as $line) {
+ foreach ($aHdr as $line) {
$pos = strpos($line, ':');
if ($pos > 0) {
$field = strtolower(substr($line, 0, $pos));
if (!strstr($field,' ')) { /* valid field */
$value = trim(substr($line, $pos+1));
- switch($field)
- {
- case 'to': $msg['TO'] = $value; break;
- case 'cc': $msg['CC'] = $value; break;
- case 'from': $msg['FROM'] = $value; break;
- case 'date':
- $msg['DATE'] = str_replace(' ', ' ', $value);
- break;
- case 'x-priority':
- case 'importance':
- case 'priority':
- $msg['PRIORITY'] = parsePriority($value); break;
- case 'subject': $msg['SUBJECT'] = $value; break;
- case 'content-type':
- $type = $value;
- if ($pos = strpos($type, ";")) {
- $type = substr($type, 0, $pos);
- }
- $type = explode("/", $type);
- if(!is_array($type) || count($type) < 2) {
- $msg['TYPE0'] = 'text';
- $msg['TYPE1'] = 'plain';
- } else {
- $msg['TYPE0'] = strtolower($type[0]);
- $msg['TYPE1'] = strtolower($type[1]);
- }
- break;
- case 'received':
- $aReceived[] = $value;
- break;
- default: break;
+ switch($field) {
+ case 'date':
+ $aMsg['date'] = trim(str_replace(' ', ' ', $value));
+ break;
+ case 'x-priority': $aMsg['x-priority'] = ($value) ? (int) $value{0} : 3; break;
+ case 'priority':
+ case 'importance':
+ if (!isset($aMsg['x-priority'])) {
+ $value = strtolower(array_shift(split('/\w/',trim($value))));
+ if (is_numeric($value)) {
+ $value = (int) $value;
+ } elseif ( $value == 'non-urgent' || $value == 'low' ) {
+ $value = 3;
+ } elseif ( $value == 'urgent' || $value == 'high' ) {
+ $value = 1;
+ } else {
+ // default is normal priority
+ $value = 3;
+ }
+ $aMsg['x-priority'] = $value;
+ }
+ break;
+ case 'content-type':
+ $type = $value;
+ if ($pos = strpos($type, ";")) {
+ $type = substr($type, 0, $pos);
+ }
+ $type = explode("/", $type);
+ if(!is_array($type) || count($type) < 2) {
+ $aMsg['content-type'] = array('text','plain');
+ } else {
+ $aMsg['content-type'] = array(strtolower($type[0]),strtolower($type[1]));
+ }
+ break;
+ case 'received':
+ $aMsg['received'][] = $value;
+ break;
+ default:
+ $aMsg[$field] = $value;
+ break;
}
}
}
}
- if (count($aReceived)) {
- $msg['RECEIVED'] = $aReceived;
- }
break;
default:
++$i;
}
$msgi ="$unique_id";
$msg['UID'] = $unique_id;
-
- $aMessageList[$msgi] = $msg;
- ++$msgi;
+ $aMessageList[$msgi] = $aMsg;
}
return $aMessageList;
}
-
/**
* Work in process
* @private
return $msg;
}
-
-/**
- * Deprecated !!!!!!! DO NOT USE THIS, use sqimap_msgs_list_copy instead
- */
-function sqimap_messages_copy($imap_stream, $start, $end, $mailbox) {
- $read = sqimap_run_command ($imap_stream, "COPY $start:$end " . sqimap_encode_mailbox_name($mailbox), true, $response, $message, TRUE);
-}
-
-
-/**
- * Deprecated !!!!!!! DO NOT USE THIS, use sqimap_msgs_list_delete instead
- */
-function sqimap_messages_delete($imap_stream, $start, $end, $mailbox, $bypass_trash=false) {
- global $move_to_trash, $trash_folder;
-
- if (($move_to_trash == true) && ($bypass_trash != true) &&
- (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder))) {
- sqimap_messages_copy ($imap_stream, $start, $end, $trash_folder);
- }
- sqimap_messages_flag ($imap_stream, $start, $end, "Deleted", true);
-}
-
-
-/**
- * Deprecated !!!!!!! DO NOT USE THIS, use sqimap_toggle_flag instead
- * Set a flag on the provided uid list
- * @param resource imap connection
- */
-function sqimap_messages_flag($imap_stream, $start, $end, $flag, $handle_errors) {
- $read = sqimap_run_command ($imap_stream, "STORE $start:$end +FLAGS (\\$flag)", $handle_errors, $response, $message, TRUE);
-}
-
-
-/**
- * @deprecated
- */
-function sqimap_get_small_header($imap_stream, $id, $sent) {
- $res = sqimap_get_small_header_list($imap_stream, $id, $sent);
- return $res[0];
-}
-
-?>
\ No newline at end of file
+?>