/* retrieve the response and the message */
$response = $response[$tag];
$message = $message[$tag];
-
+
if (!empty($read[$tag])) {
return $read[$tag][0];
} else {
function sqimap_run_pipelined_command ($imap_stream, $aQueryList, $handle_errors,
&$aServerResponse, &$aServerMessage, $unique_id = false,
- $filter=false,$outputstream=false,$no_return=false) {
-
+ $filter=false,$outputstream=false,$no_return=false) {
$aResponse = false;
+
/*
Do not fire all calls at once to the imap-server but split the calls up
in portions of $iChunkSize. If we do not do that I think we misbehave as
$aQueryChunks = array();
$iLoops = floor($iQueryCount / $iChunkSize);
- if ($iLoops * $iChunkSize !== $iQueryCount) ++$iLoops;
+ if ($iLoops * $iChunkSize != $iQueryCount) ++$iLoops;
if (!function_exists('array_chunk')) { // arraychunk replacement
- reset($aQueryList);
+ reset($aQueryList);
for($i=0;$i<$iLoops;++$i) {
- for($j=0;$j<$iChunkSize;++$j) {
- $key = key($aQueryList);
- $aTmp[$key] = $aQueryList[$key];
- if (next($aQueryList) === false) break;
- }
- $aQueryChunks[] = $aTmp;
- }
+ for($j=0;$j<$iChunkSize;++$j) {
+ $key = key($aQueryList);
+ $aTmp[$key] = $aQueryList[$key];
+ if (next($aQueryList) === false) break;
+ }
+ $aQueryChunks[] = $aTmp;
+ }
} else {
$aQueryChunks = array_chunk($aQueryList,$iChunkSize,true);
}
fputs($imap_stream,$query);
$aResults[$tag] = false;
}
-
+// $aQuery = array_reverse($aQuery,true);
foreach($aQuery as $tag => $query) {
- if (!$aResults[$tag]) {
+ if ($aResults[$tag] == false) {
$aReturnedResponse = sqimap_retrieve_imap_response ($imap_stream, $tag,
$handle_errors, $response, $message, $query,
$filter,$outputstream,$no_return);
foreach ($aReturnedResponse as $returned_tag => $aResponse) {
- if (!empty($aResponse)) {
+ if (!empty($aResponse)) {
$aResults[$returned_tag] = $aResponse[0];
- } else {
- $aResults[$returned_tag] = $aResponse;
- }
+ } else {
+ $aResults[$returned_tag] = $aResponse;
+ }
$aServerResponse[$returned_tag] = $response[$returned_tag];
$aServerMessage[$returned_tag] = $message[$returned_tag];
}
_("Reason:") . ' '.
'There is a plugin installed which make use of the <br>' .
'SquirrelMail internal function sqimap_read_data_list.<br>'.
- 'Please adapt the installed plugin and let it use<br>'.
- 'sqimap_run_command or sqimap_run_command_list instead<br><br>'.
- 'The following query was issued:<br>'.
+ 'Please adapt the installed plugin and let it use<br>'.
+ 'sqimap_run_command or sqimap_run_command_list instead<br><br>'.
+ 'The following query was issued:<br>'.
htmlspecialchars($query) . '<br>' . "</font><br>\n";
error_box($string,$color);
echo '</body></html>';
$resultlist = array();
$data = array();
$read = sqimap_fgets($imap_stream);
- $i = 0;
+ $i = $k = 0;
while ($read) {
$char = $read{0};
switch ($char)
$arg = substr($s,0,$j);
}
$found_tag = substr($read,0,$i-1);
- if ($arg && $found_tag==$tag) {
+ if ($found_tag) {
switch ($arg)
{
case 'OK':
if (!empty($data)) {
$resultlist[] = $data;
}
- $aResponse[$tag] = $resultlist;
- break 3; /* switch switch while */
+ $aResponse[$found_tag] = $resultlist;
+ $data = $resultlist = array();
+ if ($found_tag == $tag) {
+ break 3; /* switch switch while */
+ }
+ break;
default:
/* this shouldn't happen */
$response[$found_tag] = $arg;
$resultlist[] = $data;
}
$aResponse[$found_tag] = $resultlist;
- break 3; /* switch switch while */
- }
- } elseif($found_tag !== $tag) {
- /* not the tag we are looking for, continue */
- if (!empty($data)) {
- $resultlist[] = $data;
- }
- $aResponse[$found_tag] = $resultlist;
- $resultlist = $data = array();
- $read = sqimap_fgets($imap_stream);
- if ($read === false) { /* error */
- break 3; /* switch switch while */
+ $data = $resultlist = array();
+ if ($found_tag == $tag) {
+ break 3; /* switch switch while */
+ }
}
- break;
}
+ $read = sqimap_fgets($imap_stream);
+ if ($read === false) { /* error */
+ break 3; /* switch switch while */
+ }
+ break;
} // end case $tag{0}
case '*':
$s = substr($read,-3);
} while ($s === "}\r\n");
break 1;
- }
+ }
break;
} // end case '*'
} // end switch
$boxesall[$g]['flags'] = array();
if (isset($line[$g])) {
ereg("\(([^)]*)\)",$line[$g],$regs);
- // FIXME Flags do contain the \ character. \NoSelect \NoInferiors
- // and $MDNSent <= last one doesn't have the \
- // It's better to follow RFC3501 instead of using our own naming.
+ // FIXME Flags do contain the \ character. \NoSelect \NoInferiors
+ // and $MDNSent <= last one doesn't have the \
+ // It's better to follow RFC3501 instead of using our own naming.
$flags = trim(strtolower(str_replace('\\', '',$regs[1])));
if ($flags) {
$boxesall[$g]['flags'] = explode(' ', $flags);
continue;
}
$lowerbox = strtolower($box);
- // mailboxes are casesensitive => inbox.sent != inbox.Sent
- // nevermind, to many dependencies this should be fixed!
-
+ // mailboxes are casesensitive => inbox.sent != inbox.Sent
+ // nevermind, to many dependencies this should be fixed!
+
if (strtolower($box) == 'inbox') { // inbox is special and not casesensitive
$box2 = _("INBOX");
} else {
- switch ($shorten_box_names)
- {
- case 2: /* delimited, style = 2 */
+ switch ($shorten_box_names)
+ {
+ case 2: /* delimited, style = 2 */
$box2 = str_replace(' ', '. ', $boxes_part['formatted']);
- break;
+ break;
case 1: /* indent, style = 1 */
$box2 = $boxes_part['formatted'];
- break;
+ break;
default: /* default, long names, style = 0 */
$box2 = str_replace(' ', ' ', imap_utf7_decode_local($boxes_part['unformatted-disp']));
- break;
- }
+ break;
+ }
}
if ($show_selected != 0 && in_array($lowerbox, $show_selected) ) {
$mbox_options .= '<OPTION VALUE="'.$box.'" SELECTED>'.$box2.'</OPTION>' . "\n";
/*
* Workaround for mailboxes returned as literal
* Doesn't work if the mailbox name is multiple lines
- * (larger then fgets buffer)
+ * (larger then fgets buffer)
*/
if (isset($lsub_ary[$i + 1]) && substr($lsub_ary[$i],-3) == "}\r\n") {
- if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
+ if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
$lsub_ary[$i], $regs)) {
- $i++;
- $lsub_ary[$i] = $regs[1] . '"' . addslashes(trim($lsub_ary[$i])) . '"' . $regs[2];
- }
+ $i++;
+ $lsub_ary[$i] = $regs[1] . '"' . addslashes(trim($lsub_ary[$i])) . '"' . $regs[2];
+ }
}
$temp_mailbox_name = find_mailbox_name($lsub_ary[$i]);
$sorted_lsub_ary[] = $temp_mailbox_name;
$inbox_subscribed = true;
}
}
- /* remove duplicates */
- $sorted_lsub_ary = array_unique($sorted_lsub_ary);
+ /* remove duplicates */
+ $sorted_lsub_ary = array_unique($sorted_lsub_ary);
- /* natural sort mailboxes */
+ /* natural sort mailboxes */
if (isset($sorted_lsub_ary)) {
usort($sorted_lsub_ary, 'user_strcasecmp');
}
- /*
- * The LSUB response doesn't provide us information about \Noselect
- * mail boxes. The LIST response does, that's why we need to do a LIST
- * call to retrieve the flags for the mailbox
+ /*
+ * The LSUB response doesn't provide us information about \Noselect
+ * mail boxes. The LIST response does, that's why we need to do a LIST
+ * call to retrieve the flags for the mailbox
* Note: according RFC2060 an imap server may provide \NoSelect flags in the LSUB response.
* in other words, we cannot rely on it.
- */
+ */
$sorted_list_ary = array();
for ($i=0; $i < count($sorted_lsub_ary); $i++) {
if (substr($sorted_lsub_ary[$i], -1) == $delimiter) {
/* Another workaround for literals */
if (isset($read[1]) && substr($read[1],-3) == "}\r\n") {
- if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
+ if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
$read[0], $regs)) {
- $read[0] = $regs[1] . '"' . addslashes(trim($read[1])) . '"' . $regs[2];
- }
+ $read[0] = $regs[1] . '"' . addslashes(trim($read[1])) . '"' . $regs[2];
+ }
}
if (isset($read[0])) {
true, $response, $message);
/* Another workaround for literals */
if (isset($inbox_ary[1]) && substr($inbox_ary[0],-3) == "}\r\n") {
- if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
+ if (ereg("^(\\* [A-Z]+.*)\\{[0-9]+\\}([ \n\r\t]*)$",
$inbox_ary[0], $regs)) {
- $inbox_ary[0] = $regs[1] . '"' . addslashes(trim($inbox_ary[1])) .
+ $inbox_ary[0] = $regs[1] . '"' . addslashes(trim($inbox_ary[1])) .
'"' . $regs[2];
- }
+ }
}
$sorted_list_ary[] = $inbox_ary[0];
$sorted_lsub_ary[] = find_mailbox_name($inbox_ary[0]);
/* Find INBOX */
$cnt = count($boxesall);
- $used = array_pad($used,$cnt,false);
+ $used = array_pad($used,$cnt,false);
for($k = 0; $k < $cnt; ++$k) {
if (strtolower($boxesall[$k]['unformatted']) == 'inbox') {
$boxesnew[] = $boxesall[$k];
$used[$k] = true;
- break;
+ break;
}
}
/* List special folders and their subfolders, if requested. */
$boxesnew[] = $boxesall[$k];
$used[$k] = true;
}
- }
- }
+ }
+ }
/* Rest of the folders */
for($k = 0; $k < $cnt; $k++) {
}
$sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect);
}
- // FIX ME this requires a config setting inside conf.pl instead of checking on server type
+ // FIX ME this requires a config setting inside conf.pl instead of checking on server type
if ($imap_server_type == "uw") {
- $aQuery = array();
- $aTag = array();
- // prepare an array with queries
- foreach ($sorted_lsub_ary as $aMbx) {
- $mbx = $aMbx['mbx'];
- $query = "LIST \"\" \"$mbx\"";
+ $aQuery = array();
+ $aTag = array();
+ // prepare an array with queries
+ foreach ($sorted_lsub_ary as $aMbx) {
+ $mbx = $aMbx['mbx'];
+ $query = "LIST \"\" \"$mbx\"";
sqimap_prepare_pipelined_query($query,$tag,$aQuery,false);
- $aTag[$tag] = $mbx;
- }
- $sorted_lsub_ary = array();
- // execute all the queries at once
- $aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
- foreach($aTag as $tag => $mbx) {
- if ($aServerResponse[$tag] == 'OK') {
- $sResponse = implode('', $aResponse[$tag]);
- $noselect = check_is_noselect($sResponse);
- $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect);
- }
- }
- $cnt = count($sorted_lsub_ary);
+ $aTag[$tag] = $mbx;
+ }
+ $sorted_lsub_ary = array();
+ // execute all the queries at once
+ $aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
+ foreach($aTag as $tag => $mbx) {
+ if ($aServerResponse[$tag] == 'OK') {
+ $sResponse = implode('', $aResponse[$tag]);
+ $noselect = check_is_noselect($sResponse);
+ $sorted_lsub_ary[] = array ('mbx' => $mbx, 'noselect' => $noselect);
+ }
+ }
+ $cnt = count($sorted_lsub_ary);
}
$sorted_lsub_ary = array_values($sorted_lsub_ary);
function sqimap_tree_to_ref_array(&$mbx_tree,&$aMbxs) {
+ if ($mbx_tree)
$aMbxs[] =& $mbx_tree;
if ($mbx_tree->mbxs) {
$iCnt = count($mbx_tree->mbxs);
for ($i=0;$i<$iCnt;++$i) {
- $aMbxs[] =& sqimap_tree_to_ref_array($mbx_tree->mbxs[$i],$aMbxs);
+ sqimap_tree_to_ref_array($mbx_tree->mbxs[$i],$aMbxs);
}
}
}
if($unseen_notify == 3) {
$cnt = count($aMbxs);
for($i=0;$i<$cnt;++$i) {
- $oMbx =& $aMbxs[$i];
- if (!$oMbx->is_noselect) {
+ $oMbx =& $aMbxs[$i];
+ if (!$oMbx->is_noselect) {
$mbx = $oMbx->mailboxname_full;
- if ($unseen_type == 2 ||
- ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
- $query = "STATUS \"$mbx\" (MESSAGES UNSEEN)";
- } else {
- $query = "STATUS \"$mbx\" (UNSEEN)";
- }
+ if ($unseen_type == 2 ||
+ ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
+ $query = "STATUS \"$mbx\" (MESSAGES UNSEEN)";
+ } else {
+ $query = "STATUS \"$mbx\" (UNSEEN)";
+ }
sqimap_prepare_pipelined_query($query,$tag,$aQuery,false);
- } else {
- $oMbx->unseen = $oMbx->total = false;
- $tag = false;
- }
- $oMbx->tag = $tag;
- $aMbxs[$i] =& $oMbx;
+ } else {
+ $oMbx->unseen = $oMbx->total = false;
+ $tag = false;
+ }
+ $oMbx->tag = $tag;
+ $aMbxs[$i] =& $oMbx;
}
// execute all the queries at once
$aResponse = sqimap_run_pipelined_command ($imap_stream, $aQuery, false, $aServerResponse, $aServerMessage);
$cnt = count($aMbxs);
for($i=0;$i<$cnt;++$i) {
- $oMbx =& $aMbxs[$i];
- $tag = $oMbx->tag;
- if ($tag && $aServerResponse[$tag] == 'OK') {
- $sResponse = implode('', $aResponse[$tag]);
+ $oMbx =& $aMbxs[$i];
+ $tag = $oMbx->tag;
+ if ($tag && $aServerResponse[$tag] == 'OK') {
+ $sResponse = implode('', $aResponse[$tag]);
if (preg_match('/UNSEEN\s+([0-9]+)/i', $sResponse, $regs)) {
$oMbx->unseen = $regs[1];
}
if (preg_match('/MESSAGES\s+([0-9]+)/i', $sResponse, $regs)) {
$oMbx->total = $regs[1];
- }
- }
- unset($oMbx->tag);
- }
+ }
+ }
+ unset($oMbx->tag);
+ }
} else if ($unseen_notify == 2) { // INBOX only
$cnt = count($aMbxs);
for($i=0;$i<$cnt;++$i) {
- $oMbx =& $aMbxs[$i];
- if (strtoupper($oMbx->mailboxname_full) == 'INBOX' ||
- ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
- if ($unseen_type == 2 ||
- ($oMbx->mailboxname_full == $trash_folder && $move_to_trash)) {
- $aStatus = sqimap_status_messages($imap_stream,$oMbx->mailboxname_full);
- $oMbx->unseen = $aStatus['UNSEEN'];
- $oMbx->total = $aStatus['MESSAGES'];
- } else {
- $oMbx->unseen = sqimap_unseen_messages($imap_stream,$oMbx->mailboxname_full);
- }
- $aMbxs[$i] =& $oMbx;
- if (!$move_to_trash && $trash_folder) {
- break;
- } else {
- // trash comes after INBOX
- if ($oMbx->mailboxname_full == $trash_folder) {
- break;
- }
- }
- }
- }
- }
+ $oMbx =& $aMbxs[$i];
+ if (strtoupper($oMbx->mailboxname_full) == 'INBOX' ||
+ ($move_to_trash && $oMbx->mailboxname_full == $trash_folder)) {
+ if ($unseen_type == 2 ||
+ ($oMbx->mailboxname_full == $trash_folder && $move_to_trash)) {
+ $aStatus = sqimap_status_messages($imap_stream,$oMbx->mailboxname_full);
+ $oMbx->unseen = $aStatus['UNSEEN'];
+ $oMbx->total = $aStatus['MESSAGES'];
+ } else {
+ $oMbx->unseen = sqimap_unseen_messages($imap_stream,$oMbx->mailboxname_full);
+ }
+ $aMbxs[$i] =& $oMbx;
+ if (!$move_to_trash && $trash_folder) {
+ break;
+ } else {
+ // trash comes after INBOX
+ if ($oMbx->mailboxname_full == $trash_folder) {
+ break;
+ }
+ }
+ }
+ }
+ }
}
?>