/**
* Returns the number of unseen messages in this folder.
+ * obsoleted by sqimap_status_messages !
*/
function sqimap_unseen_messages ($imap_stream, $mailbox) {
- $read_ary = sqimap_run_command ($imap_stream, 'STATUS ' . sqimap_encode_mailbox_name($mailbox) . ' (UNSEEN)', false, $result, $message);
- $i = 0;
- $regs = array(false, false);
- while (isset($read_ary[$i])) {
- if (ereg("UNSEEN ([0-9]+)", $read_ary[$i], $regs)) {
- break;
- }
- $i++;
- }
- return $regs[1];
+ $aStatus = sqimap_status_messages($imap_stream,$mailbox,array('UNSEEN'));
+ return $aStatus['UNSEEN'];
}
/**
- * Returns the number of total/unseen/recent messages in this folder
+ * Returns the status items of a mailbox.
+ * Default it returns MESSAGES,UNSEEN and RECENT
+ * Supported status items are MESSAGES, UNSEEN, RECENT, UIDNEXT and UIDVALIDITY
*/
-function sqimap_status_messages ($imap_stream, $mailbox) {
- $read_ary = sqimap_run_command ($imap_stream, 'STATUS ' . sqimap_encode_mailbox_name($mailbox) . ' (MESSAGES UNSEEN RECENT)', false, $result, $message);
+function sqimap_status_messages ($imap_stream, $mailbox,
+ $aStatusItems = array('MESSAGES','UNSEEN','RECENT')) {
+
+ $aStatusItems = implode(' ',$aStutusItems);
+ $read_ary = sqimap_run_command ($imap_stream, 'STATUS ' . sqimap_encode_mailbox_name($mailbox) .
+ " ($aStatusItems)", false, $result, $message);
$i = 0;
- $messages = $unseen = $recent = false;
+ $messages = $unseen = $recent = $uidnext = $uidvalidity = false;
$regs = array(false,false);
while (isset($read_ary[$i])) {
if (preg_match('/UNSEEN\s+([0-9]+)/i', $read_ary[$i], $regs)) {
if (preg_match('/RECENT\s+([0-9]+)/i', $read_ary[$i], $regs)) {
$recent = $regs[1];
}
+ if (preg_match('/UIDNEXT\s+([0-9]+)/i', $read_ary[$i], $regs)) {
+ $uidnext = $regs[1];
+ }
+ if (preg_match('/UIDVALIDITY\s+([0-9]+)/i', $read_ary[$i], $regs)) {
+ $uidvalidity = $regs[1];
+ }
$i++;
}
- return array('MESSAGES' => $messages, 'UNSEEN'=>$unseen, 'RECENT' => $recent);
+ return array('MESSAGES' => $messages,
+ 'UNSEEN'=>$unseen,
+ 'RECENT' => $recent,
+ 'UIDNEXT' => $uidnext,
+ 'UIDVALIDITY' => $uidvalidity);
}
* won't be changed - the array element for the message
* will just be removed.
*/
-function sqimap_mailbox_expunge_dmn($message_id)
+function sqimap_mailbox_expunge_dmn($message_id, $aMbxResponse, &$server_sort_array)
{
global $msgs, $msort, $sort, $imapConnection,
- $mailbox, $mbx_response, $auto_expunge,
+ $mailbox, $auto_expunge,
$sort, $allow_server_sort, $thread_sort_messages, $allow_thread_sort,
$username, $data_dir;
$cnt = 0;
+ if (!isset($sort) || $sort === false) {
+ sqgetGlobalVar('sort',$sort,SQ_GET);
+ }
// Got to grab this out of prefs, since it isn't saved from mailbox_view.php
if ($allow_thread_sort) {
$thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox",0);
if ($auto_expunge) {
$cnt = sqimap_mailbox_expunge($imapConnection, $mailbox, true);
+ } else {
+ return $cnt;
}
// And after all that mucking around, update the sort list!
// Remind me why the hell we need those two arrays again?!
- sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
-
-
if ( $allow_thread_sort && $thread_sort_messages ) {
$server_sort_array = get_thread_sort($imapConnection);
} elseif ( $allow_server_sort ) {
- $key = array_search($message_id,$server_sort_array,true);
- if ($key !== false) {
- unset($server_sort_array[$key]);
- $server_sort_array = array_values($server_sort_array);
+ if (is_array($server_sort_array)) {
+ $key = array_search($message_id,$server_sort_array,true);
+ if ($key !== false) {
+ unset($server_sort_array[$key]);
+ $server_sort_array = array_values($server_sort_array);
+ } else {
+ $server_sort_array = sqimap_get_sort_order($imapConnection,$sort,$aMbxResponse);
+ }
+ } else {
+ $server_sort_array = sqimap_get_sort_order($imapConnection,$sort,$aMbxResponse);
}
- } else {
- $server_sort_array = sqimap_get_php_sort_order($imapConnection, $mbx_response);
+ } else {
+ $server_sort_array = sqimap_get_php_sort_order($imapConnection,
+ $sort,$aMbxResponse);
}
- sqsession_register('server_sort_array',$server_sort_array);
+ sqsession_register($server_sort_array,'server_sort_array');
return $cnt;
}
*/
function getServerSortMessages($imapConnection, $start_msg, $show_num,
$num_msgs, $server_sort_order, $mbxresponse) {
- if (isset($mbxresponse['SORT_ARRAY']) && $mbxresponse['SORT_ARRAY']) {
+ if (isset($mbxresponse['SORT_ARRAY']) && is_array($mbxresponse['SORT_ARRAY'])) {
$id = $mbxresponse['SORT_ARRAY'];
} else {
$id = sqimap_get_sort_order($imapConnection, $server_sort_order,$mbxresponse);
*/
if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
-
- sqimap_mailbox_expunge_dmn($delete_id);
+ sqimap_mailbox_expunge_dmn($delete_id,$mbx_response,$server_sort_array);
}
/**
if (!isset($messages[$uidvalidity])) {
$messages[$uidvalidity] = array();
}
-if (!isset($messages[$uidvalidity][$passed_id])) {
+if (!isset($messages[$uidvalidity][$passed_id]) || $delete_id) {
$message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
$FirstTimeSee = !$message->is_seen;
$message->is_seen = true;
sqgetGlobalVar('aLastSelectedMailbox',$aLastSelectedMailbox,SQ_SESSION);
+// deal with imap servers that do not return the required UIDNEXT or
+// UIDVALIDITY response
+// from a SELECT call (since rfc 3501 it's required)
+if (!isset($aMbxResponse['UIDNEXT']) || !isset($aMbxResponse['UIDVALIDITY'])) {
+ $aStatus = sqimap_status_messages($imapConnection,$mailbox,
+ array('UIDNEXT','UIDVALIDITY'));
+ $aMbxResponse['UIDNEXT'] = $aStatus['UIDNEXT'];
+ $aMbxResponse['UIDVALIDTY'] = $aStatus['UIDVALIDITY'];
+}
+
if ($aLastSelectedMailbox && !isset($newsort)) {
- // check if we deal with the same mailbox
- if ($aLastSelectedMailbox['NAME'] == $mailbox) {
- if ($aLastSelectedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
- $aLastSelectedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
- $aLastSelectedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT']) {
- // sort is still valid
- sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
- $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
- }
- }
+ // check if we deal with the same mailbox
+ if ($aLastSelectedMailbox['NAME'] == $mailbox) {
+ if ($aLastSelectedMailbox['EXISTS'] == $aMbxResponse['EXISTS'] &&
+ $aLastSelectedMailbox['UIDVALIDITY'] == $aMbxResponse['UIDVALIDITY'] &&
+ $aLastSelectedMailbox['UIDNEXT'] == $aMbxResponse['UIDNEXT']) {
+ // sort is still valid
+ sqgetGlobalVar('server_sort_array',$server_sort_array,SQ_SESSION);
+ if ($server_sort_array && is_array($server_sort_array)) {
+ $aMbxResponse['SORT_ARRAY'] = $server_sort_array;
+ }
+ }
+ }
}
$aLastSelectedMailbox['NAME'] = $mailbox;