* This implements functions that manipulate messages
* NOTE: Quite a few functions in this file are obsolete
*
- * @copyright 1999-2010 The SquirrelMail Project Team
+ * @copyright 1999-2022 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id$
* @package squirrelmail
/**
* Set a flag on the provided uid list
* @param resource imap connection
- * @param array $id list with uid's
+ * @param mixed $id Normally an array which is a list with message UIDs to be flagged
+ * or a string range such as "1:*"
* @param string $flag Flags to set/unset flags can be i.e.'\Seen', '\Answered', '\Seen \Answered'
* @param bool $set add (true) or remove (false) the provided flag
* @param bool $handle_errors Show error messages in case of a NO, BAD or BYE response
$msgs_id = sqimap_message_list_squisher($id);
$set_string = ($set ? '+' : '-');
- for ($i=0; $i<sizeof($id); $i++) {
- $aMessageList["$id[$i]"] = array();
+ $aMessageList = array();
+ // TODO: There doesn't seem to be a reason to set up $aMessageList anyway because an empty array for each message doesn't add anything to the parseFetch() return value, so this code block could be simply deleted:
+ if (!is_string($id)) {
+ for ($i=0; $i<sizeof($id); $i++) {
+ $aMessageList["$id[$i]"] = array();
+ }
}
$aResponse = sqimap_run_command_list($imap_stream, "STORE $msgs_id ".$set_string."FLAGS ($flag)", $handle_errors, $response, $message, TRUE);
// some broken IMAP servers do not return UID elements on UID STORE
// if this is the case, then we need to do a UID FETCH
- $testkey=$id[0];
- if (!isset($parseFetchResults[$testkey]['UID'])) {
+ if (!empty($parseFetchResults)
+ && !isset(reset($parseFetchResults)['UID'])) {
$aResponse = sqimap_run_command_list($imap_stream, "FETCH $msgs_id (FLAGS)", $handle_errors, $response, $message, TRUE);
$parseFetchResults = parseFetch($aResponse,$aMessageList);
}
case 'TO':
case 'CC':
if(!$walk) {
- array_walk($msgs, create_function('&$v,&$k,$f',
- '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
- $addr = reset(parseRFC822Address($v[$f],1));
- $sPersonal = (isset($addr[SQM_ADDR_PERSONAL]) && $addr[SQM_ADDR_PERSONAL]) ?
- $addr[SQM_ADDR_PERSONAL] : "";
- $sEmail = ($addr[SQM_ADDR_HOST]) ?
- $addr[SQM_ADDR_MAILBOX] . "@".$addr[SQM_ADDR_HOST] :
- $addr[SQM_ADDR_HOST];
- $v[$f] = ($sPersonal) ? decodeHeader($sPersonal, true, false):$sEmail;'),$sSortField);
+ if (check_php_version(5, 3, 0))
+ $walk_function = function(&$v,&$k,$f) {
+ $v[$f] = (isset($v[$f])) ? $v[$f] : "";
+ $addr = reset(parseRFC822Address($v[$f],1));
+ $sPersonal = (isset($addr[SQM_ADDR_PERSONAL]) && $addr[SQM_ADDR_PERSONAL]) ?
+ $addr[SQM_ADDR_PERSONAL] : "";
+ $sEmail = ($addr[SQM_ADDR_HOST]) ?
+ $addr[SQM_ADDR_MAILBOX] . "@".$addr[SQM_ADDR_HOST] :
+ $addr[SQM_ADDR_HOST];
+ $v[$f] = ($sPersonal) ? decodeHeader($sPersonal, true, false):$sEmail;
+ };
+ else
+ $walk_function = create_function('&$v,&$k,$f',
+ '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
+ $addr = reset(parseRFC822Address($v[$f],1));
+ $sPersonal = (isset($addr[SQM_ADDR_PERSONAL]) && $addr[SQM_ADDR_PERSONAL]) ?
+ $addr[SQM_ADDR_PERSONAL] : "";
+ $sEmail = ($addr[SQM_ADDR_HOST]) ?
+ $addr[SQM_ADDR_MAILBOX] . "@".$addr[SQM_ADDR_HOST] :
+ $addr[SQM_ADDR_HOST];
+ $v[$f] = ($sPersonal) ? decodeHeader($sPersonal, true, false):$sEmail;');
+ array_walk($msgs, $walk_function, $sSortField);
$walk = true;
}
// nobreak
case 'SUBJECT':
if(!$walk) {
- array_walk($msgs, create_function('&$v,&$k,$f',
- '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
- $v[$f] = strtolower(decodeHeader(trim($v[$f]), true, false));
- $v[$f] = (preg_match("/^(?:(?:vedr|sv|re|aw|fw|fwd|\[\w\]):\s*)*\s*(.*)$/si", $v[$f], $matches)) ?
- $matches[1] : $v[$f];'),$sSortField);
+ if (check_php_version(5, 3, 0))
+ $walk_function = function(&$v,&$k,$f) {
+ $v[$f] = (isset($v[$f])) ? $v[$f] : "";
+ $v[$f] = strtolower(decodeHeader(trim($v[$f]), true, false));
+ $v[$f] = (preg_match("/^(?:(?:vedr|sv|re|aw|fw|fwd|\[\w\]):\s*)*\s*(.*)$/si", $v[$f], $matches)) ?
+ $matches[1] : $v[$f];
+ };
+ else
+ $walk_function = create_function('&$v,&$k,$f',
+ '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
+ $v[$f] = strtolower(decodeHeader(trim($v[$f]), true, false));
+ $v[$f] = (preg_match("/^(?:(?:vedr|sv|re|aw|fw|fwd|\[\w\]):\s*)*\s*(.*)$/si", $v[$f], $matches)) ?
+ $matches[1] : $v[$f];');
+ array_walk($msgs, $walk_function, $sSortField);
$walk = true;
}
foreach ($msgs as $item) {
case 'DATE':
case 'INTERNALDATE':
if(!$walk) {
- array_walk($msgs, create_function('&$v,$k,$f',
- '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
- $v[$f] = getTimeStamp(explode(" ",$v[$f]));'),$sSortField);
+ if (check_php_version(5, 3, 0))
+ $walk_function = function(&$v,$k,$f) {
+ $v[$f] = (isset($v[$f])) ? $v[$f] : "";
+ $v[$f] = getTimeStamp(explode(" ",$v[$f]));
+ };
+ else
+ $walk_function = create_function('&$v,$k,$f',
+ '$v[$f] = (isset($v[$f])) ? $v[$f] : "";
+ $v[$f] = getTimeStamp(explode(" ",$v[$f]));');
+ array_walk($msgs, $walk_function, $sSortField);
$walk = true;
}
// nobreak;
if ($sThreadResponse) {
for ($i=0,$iCnt = strlen($sThreadResponse);$i<$iCnt;++$i) {
- $cChar = $sThreadResponse{$i};
+ $cChar = $sThreadResponse[$i];
switch ($cChar) {
case '(': // new sub thread
// correction for a subthread of a thread with no parents in thread
* @return string $s parsed string without the double quotes or literal count
*/
function parseString($read,&$i) {
- $char = $read{$i};
+ $char = $read[$i];
$s = '';
if ($char == '"') {
$iPos = ++$i;
while (true) {
$iPos = strpos($read,'"',$iPos);
if (!$iPos) break;
- if ($iPos && $read{$iPos -1} != '\\') {
+ if ($iPos && $read[$iPos -1] != '\\') {
$s = substr($read,$i,($iPos-$i));
$i = $iPos;
break;
$aMsg['ID'] = $id;
$fetch = substr($read,$i_space+1,5);
if (!is_numeric($id) && $fetch !== 'FETCH') {
- $aMsg['ERROR'] = $read; // htmlspecialchars should be done just before display. this is backend code
+ $aMsg['ERROR'] = $read; // sm_encode_html_special_chars should be done just before display. this is backend code
break;
}
$i = strpos($read,'(',$i_space+5);
case 'BODYSTRUCTURE':
break; // to be implemented, moving imap code out of the Message class
case 'INTERNALDATE':
- $aMsg['INTERNALDATE'] = trim(str_replace(' ', ' ',parseString($read,$i)));
+ $aMsg['INTERNALDATE'] = trim(preg_replace('/\s+/', ' ',parseString($read,$i)));
break;
case 'BODY.PEEK[HEADER.FIELDS':
case 'BODY[HEADER.FIELDS':
$value = trim(substr($line, $pos+1));
switch($field) {
case 'date':
- $aMsg['date'] = trim(str_replace(' ', ' ', $value));
+ $aMsg['date'] = trim(preg_replace('/\s+/', ' ', $value));
break;
- case 'x-priority': $aMsg['x-priority'] = ($value) ? (int) $value{0} : 3; break;
+ case 'x-priority': $aMsg['x-priority'] = ($value) ? (int) $value[0] : 3; break;
case 'priority':
case 'importance':
// duplicate code with Rfc822Header.cls:parsePriority()
$arg_no = 0;
$arg_a = array();
++$i;
- for ($cnt = strlen($read); ($i < $cnt) && ($read{$i} != ')'); ++$i) {
- $char = strtoupper($read{$i});
+ for ($cnt = strlen($read); ($i < $cnt) && ($read[$i] != ')'); ++$i) {
+ $char = strtoupper($read[$i]);
switch ($char) {
case '{':
case '"':
$addr_a = array();
$group = '';
$a=0;
- for (; $i < $cnt && $read{$i} != ')'; ++$i) {
- if ($read{$i} == '(') {
+ for (; $i < $cnt && $read[$i] != ')'; ++$i) {
+ if ($read[$i] == '(') {
$addr = sqimap_parse_address($read, $i);
if (($addr[3] == '') && ($addr[2] != '')) {
/* start of group */
*/
function sqimap_parse_address($read, &$i) {
$arg_a = array();
- for (; $read{$i} != ')'; ++$i) {
- $char = strtoupper($read{$i});
+ for (; $read[$i] != ')'; ++$i) {
+ $char = strtoupper($read[$i]);
switch ($char) {
case '{':
case '"': $arg_a[] = parseString($read,$i); break;