sqimap_mailbox_select ($imap_stream, $mailbox);
fputs ($imap_stream, "a001 EXPUNGE\r\n");
$read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+ sqimap_mailbox_close ($imap_stream);
}
function sqimap_mailbox_exists ($imap_stream, $mailbox) {
fputs ($imap_stream, "a001 LIST \"\" \"$mailbox\"\r\n");
$mbx = sqimap_read_data($imap_stream, "a001", true, $response, $message);
- if (ereg ("$mailbox", $mbx[0])) {
- return true;
- } else {
- return false;
+ if ($mailbox) {
+ return !!(ereg ("$mailbox", $mbx[0])); // To force into true/false
}
}
+ /******************************************************************************
+ ** Closes an open mailbox
+ ******************************************************************************/
+ function sqimap_mailbox_close ($imap_stream) {
+ fputs ($imap_stream, "a001 CLOSE\r\n");
+ $tmp = sqimap_read_data($imap_stream, "a001", false, $response, $message);
+ }
-
/******************************************************************************
** Selects a mailbox
******************************************************************************/
- function sqimap_mailbox_select ($imap_stream, $mailbox, $hide) {
+ function sqimap_mailbox_select ($imap_stream, $mailbox, $hide=true, $recent=false) {
+ global $auto_expunge;
+
fputs ($imap_stream, "a001 SELECT \"$mailbox\"\r\n");
$read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
+ if ($recent) {
+ for ($i=0; $i<count($read); $i++) {
+ if (strpos(strtolower($read[$i]), "recent")) {
+ $r = explode(" ", $read[$i]);
+ }
+ }
+ return $r[1];
+ }
+ if ($auto_expunge) {
+ fputs ($imap_stream, "a001 EXPUNGE\r\n");
+ $tmp = sqimap_read_data($imap_stream, "a001", true, $a, $b);
+ }
}
for ($g=0; $g < count($line); $g++) {
$boxes[$g]["raw"] = $line[$g];
- $mailbox = $line_lsub[$g];
+ $mailbox = trim($line_lsub[$g]);
$dm_count = countCharInString($mailbox, $dm);
if (substr($mailbox, -1) == $dm)
$dm_count--;
for ($j = 0; $j < $dm_count - (countCharInString($folder_prefix, $dm)); $j++)
- $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
+ $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
$boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
$boxes[$g]["unformatted-dm"] = $mailbox;
$boxes[$g]["unformatted"] = $mailbox;
$boxes[$g]["id"] = $g;
- $flags = substr($line[$g], strpos($line[$g], "(")+1);
- $flags = substr($flags, 0, strpos($flags, ")"));
- $flags = str_replace("\\", "", $flags);
- $flags = trim(strtolower($flags));
+ ereg("\(([^)]*)\)",$line[$g],$regs);
+ $flags = trim(strtolower(str_replace("\\", "",$regs[1])));
if ($flags) {
$boxes[$g]["flags"] = explode(" ", $flags);
}
******************************************************************************/
function sqimap_mailbox_list ($imap_stream) {
global $load_prefs_php, $prefs_php, $config_php, $data_dir, $username, $list_special_folders_first;
- global $trash_folder, $sent_folder;
- global $move_to_trash, $move_to_sent;
+ global $trash_folder, $sent_folder;
+ global $move_to_trash, $move_to_sent;
$inbox_in_list = false;
$inbox_subscribed = false;
$inbox_subscribed = false;
fputs ($imap_stream, "a001 LSUB \"\" \"*\"\r\n");
$lsub_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+
for ($i=0;$i < count($lsub_ary); $i++) {
$sorted_lsub_ary[$i] = find_mailbox_name($lsub_ary[$i]);
if ($sorted_lsub_ary[$i] == "INBOX")
$inbox_subscribed = true;
}
+ $new_ary = array();
+ for ($i=0; $i < count($sorted_lsub_ary); $i++) {
+ if (!in_array($sorted_lsub_ary[$i], $new_ary)) {
+ $new_ary[] = $sorted_lsub_ary[$i];
+ }
+ }
+ $sorted_lsub_ary = $new_ary;
if (isset($sorted_lsub_ary)) {
sort($sorted_lsub_ary);
}
/** LIST array **/
- for ($i=0; $i < count($sorted_lsub_ary); $i++) {
- if (substr($sorted_lsub_ary[$i], -1) == $dm)
- $mbx = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i])-1);
- else
- $mbx = $sorted_lsub_ary[$i];
-
- fputs ($imap_stream, "a001 LIST \"\" \"$mbx\"\r\n");
- $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
- $sorted_list_ary[$i] = $read[0];
+ for ($i=0; $i < count($sorted_lsub_ary); $i++) {
+ if (substr($sorted_lsub_ary[$i], -1) == $dm)
+ $mbx = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i])-1);
+ else
+ $mbx = $sorted_lsub_ary[$i];
+
+ fputs ($imap_stream, "a001 LIST \"\" \"$mbx\"\r\n");
+ $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+ $sorted_list_ary[$i] = $read[0];
if (find_mailbox_name($sorted_list_ary[$i]) == "INBOX")
$inbox_in_list = true;
- }
+ }
/** Just in case they're not subscribed to their inbox, we'll get it for them anyway **/
if ($inbox_subscribed == false || $inbox_in_list == false) {
$sorted_lsub_ary[$pos] = find_mailbox_name($inbox_ary[0]);
}
- $boxes = sqimap_mailbox_parse ($sorted_list_ary, $sorted_lsub_ary, $dm);
-
- /** Now, lets sort for special folders **/
+ $boxes = sqimap_mailbox_parse ($sorted_list_ary, $sorted_lsub_ary, $dm);
+
+ /** Now, lets sort for special folders **/
for ($i = 0; $i < count($boxes); $i++) {
if (strtolower($boxes[$i]["unformatted"]) == "inbox") {
$boxesnew[0] = $boxes[$i];