fputs ($imap_stream, "a001 LIST \"\" \"$mailbox\"\r\n");
$mbx = sqimap_read_data($imap_stream, "a001", true, $response, $message);
if ($mailbox) {
- if (ereg ("$mailbox", $mbx[0])) {
- return true;
- } else {
- return false;
- }
+ return !!(ereg ("$mailbox", $mbx[0])); // To force into true/false
}
}
$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, $imap_server_type;
+ global $move_to_trash, $move_to_sent;
$inbox_in_list = false;
$inbox_subscribed = false;
/** LSUB array **/
$inbox_subscribed = false;
- fputs ($imap_stream, "a001 LSUB \"\" \"*\"\r\n");
+ if ($imap_server_type == "uw") {
+ fputs ($imap_stream, "a001 LSUB \"~\" \"*\"\r\n");
+ }
+ else {
+ 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++) {
}
/** 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];
$read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
}
+
+ /******************************************************************************
+ ** Remove specified flag from specified messages
+ ******************************************************************************/
+ function sqimap_messages_remove_flag ($imap_stream, $start, $end, $flag) {
+ fputs ($imap_stream, "a001 STORE $start:$end -FLAGS (\\$flag)\r\n");
+ $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
+ }
+
+
/******************************************************************************
** Returns some general header information -- FROM, DATE, and SUBJECT
******************************************************************************/
function printMessageInfo($imapConnection, $t, $i, $key, $mailbox, $sort, $startMessage, $where, $what) {
global $color, $msgs, $msort;
- global $sent_folder;
+ global $sent_folder;
global $message_highlight_list;
global $index_order;
echo "<font color=$color[1]>!</font>\n";
$stuff = true;
}
+ if ($msg["FLAG_DELETED"]) {
+ echo "<font color=\"$color[1]\">D</font>\n";
+ $stuff = true;
+ }
+
if (!$stuff) echo " \n";
echo "</small></b></td>\n";
break;
**/
function showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color,$show_num, $use_cache) {
global $msgs, $msort;
- global $sent_folder;
+ global $sent_folder;
global $message_highlight_list;
global $auto_expunge;
if (!$use_cache) {
if ($numMessages >= 1) {
for ($q = 0; $q < $numMessages; $q++) {
- if ($mailbox == $sent_folder)
- $hdr = sqimap_get_small_header ($imapConnection, $q+1, true);
- else
- $hdr = sqimap_get_small_header ($imapConnection, $q+1, false);
+ if($mailbox == $sent_folder)
+ $hdr = sqimap_get_small_header ($imapConnection, $q+1, true);
+ else
+ $hdr = sqimap_get_small_header ($imapConnection, $q+1, false);
+
- $from[$q] = $hdr->from;
- $date[$q] = $hdr->date;
- $subject[$q] = $hdr->subject;
+ $from[$q] = $hdr->from;
+ $date[$q] = $hdr->date;
+ $subject[$q] = $hdr->subject;
$to[$q] = $hdr->to;
$priority[$q] = $hdr->priority;
$cc[$q] = $hdr->cc;
$size[$q] = $hdr->size;
$type[$q] = $hdr->type0;
-
$flags[$q] = sqimap_get_flags ($imapConnection, $q+1);
}
}
$messages[$j]["SUBJECT"] = decodeHeader($subject[$j]);
$messages[$j]["SUBJECT-SORT"] = strtolower(decodeHeader($subject[$j]));
$messages[$j]["TO"] = decodeHeader($to[$j]);
- $messages[$j]["PRIORITY"] = $priority[$j];
+ $messages[$j]["PRIORITY"] = $priority[$j];
$messages[$j]["CC"] = $cc[$j];
$messages[$j]["SIZE"] = $size[$j];
$messages[$j]["TYPE0"] = $type[$j];
if ($flags[$j][$num] == "Deleted") {
$messages[$j]["FLAG_DELETED"] = true;
}
- else if ($flags[$j][$num] == "Answered") {
+ elseif ($flags[$j][$num] == "Answered") {
$messages[$j]["FLAG_ANSWERED"] = true;
}
- else if ($flags[$j][$num] == "Seen") {
+ elseif ($flags[$j][$num] == "Seen") {
$messages[$j]["FLAG_SEEN"] = true;
}
- else if ($flags[$j][$num] == "Flagged") {
+ elseif ($flags[$j][$num] == "Flagged") {
$messages[$j]["FLAG_FLAGGED"] = true;
}
$num++;
}
$j++;
}
-
- /** Find and remove the ones that are deleted */
- $i = 0;
- $j = 0;
- while ($j < $numMessages) {
- if ($messages[$j]["FLAG_DELETED"] == true) {
+
+ /* Only ignore messages flagged as deleted if we are using a
+ * trash folder or auto_expunge */
+ if ($move_to_trash || $auto_expunge)
+ {
+ /** Find and remove the ones that are deleted */
+ $i = 0;
+ $j = 0;
+ while ($j < $numMessages) {
+ if ($messages[$j]["FLAG_DELETED"] == true) {
+ $j++;
+ continue;
+ }
+ $msgs[$i] = $messages[$j];
+
+ $i++;
$j++;
- continue;
}
- $msgs[$i] = $messages[$j];
-
- $i++;
- $j++;
+ $numMessages = $i;
}
- $numMessages = $i;
}
// There's gotta be messages in the array for it to sort them.
- if (($numMessages > 0) && (!$use_cache)) {
+ if ($numMessages > 0 && ! $use_cache) {
/** 0 = Date (up) 4 = Subject (up)
** 1 = Date (dn) 5 = Subject (dn)
** 2 = Name (up)
if (($sort == 4) || ($sort == 5))
$msort = array_cleave ($msgs, "SUBJECT-SORT");
- if(($sort % 2) == 1) {
+ if($sort % 2) {
asort($msort);
} else {
arsort($msort);
// generic function to convert the msgs array into an HTML table
function displayMessageArray($imapConnection, $numMessages, $startMessage, &$msgs, $msort, $mailbox, $sort, $color,$show_num) {
global $folder_prefix, $sent_folder;
- global $imapServerAddress;
+ global $imapServerAddress;
global $index_order;
// if cache isn't already set, do it now
$Message = '';
if ($startMessage < $endMessage) {
$Message = _("Viewing messages") ." <B>$startMessage</B> ". _("to") ." <B>$endMessage</B> ($numMessages " . _("total") . ")\n";
- } else if ($startMessage == $endMessage) {
+ } elseif ($startMessage == $endMessage) {
$Message = _("Viewing message") ." <B>$startMessage</B> ($numMessages " . _("total") . ")\n";
}
$More = "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
$More .= "<A HREF=\"right_main.php?use_mailbox_cache=1&&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
}
- else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
+ elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) {
$More = "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$prevGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Previous") ."</A> | \n";
$More .= "<FONT COLOR=\"$color[9]\">"._("Next")."</FONT>\n";
}
- else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
+ elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) {
$More = "<FONT COLOR=\"$color[9]\">"._("Previous")."</FONT> | \n";
$More .= "<A HREF=\"right_main.php?use_mailbox_cache=1&startMessage=$nextGroup&mailbox=$urlMailbox\" TARGET=\"right\">". _("Next") ."</A>\n";
}
if ($numMessages == 0) { // if there's no messages in this folder
echo "<TR><TD BGCOLOR=\"$color[4]\" COLSPAN=" . count($index_order);
echo "><CENTER><BR><B>". _("THIS FOLDER IS EMPTY") ."</B><BR> </CENTER></TD></TR>";
- } else if ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
+ } elseif ($startMessage == $endMessage) { // if there's only one message in the box, handle it different.
$i = $startMessage;
reset($msort);
do {
function mail_message_listing_beginning($imapConnection, $moveURL,
$mailbox = '', $sort = -1, $Message = '', $More = '')
{
- global $color, $index_order;
+ global $color, $index_order, $auto_expunge, $move_to_trash;
/** This is the beginning of the message list table. It wraps around all messages */
echo "<TABLE WIDTH=100% BORDER=0 CELLPADDING=2 CELLSPACING=0>";
echo " <SMALL><INPUT TYPE=SUBMIT NAME=\"moveButton\" VALUE=\"". _("Move") ."\"></SMALL></NOBR>\n";
echo " </TD>\n";
echo " <TD WIDTH=40% ALIGN=RIGHT>\n";
+ if (! $move_to_trash && ! $auto_expunge) {
+ echo " <NOBR><SMALL><INPUT TYPE=SUBMIT NAME=\"expungeButton\" VALUE=\"". _("Expunge") ."\"> ". _("mailbox") ."</SMALL></NOBR> \n";
+ }
echo " <NOBR><SMALL><INPUT TYPE=SUBMIT VALUE=\"". _("Delete") ."\"> ". _("checked messages") ."</SMALL></NOBR>\n";
echo " </TD>\n";
echo " </TR>\n";
if ($sort == 2)
echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
- else if ($sort == 3)
+ elseif ($sort == 3)
echo " <A HREF=\"right_main.php?newsort=2&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
- else if ($sort != -1)
+ elseif ($sort != -1)
echo " <A HREF=\"right_main.php?newsort=3&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
break;
echo " <TD nowrap WIDTH=1%><B>". _("Date") ."</B>";
if ($sort == 0)
echo " <A HREF=\"right_main.php?newsort=1&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
- else if ($sort == 1)
+ elseif ($sort == 1)
echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
- else if ($sort != -1)
+ elseif ($sort != -1)
echo " <A HREF=\"right_main.php?newsort=0&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
break;
echo " <TD WIDTH=%><B>". _("Subject") ."</B>\n";
if ($sort == 4)
echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/up_pointer.gif\" BORDER=0></A></TD>\n";
- else if ($sort == 5)
+ elseif ($sort == 5)
echo " <A HREF=\"right_main.php?newsort=4&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/down_pointer.gif\" BORDER=0></A></TD>\n";
- else if ($sort != -1)
+ elseif ($sort != -1)
echo " <A HREF=\"right_main.php?newsort=5&startMessage=1&mailbox=$urlMailbox\" TARGET=\"right\"><IMG SRC=\"../images/sort_none.gif\" BORDER=0></A></TD>\n";
break;
// If there are other types that shouldn't be formatted, add
// them here
- if ($message->header->type1 != "html") {
+ if ($body_message->header->type1 != "html") {
translateText($body, $wrap_at, $body_message->header->charset);
}
// Count the number of occurances of $needle are in $haystack.
//*************************************************************************
function countCharInString($haystack, $needle) {
- $len = strlen($haystack);
- for ($i = 0; $i < $len; $i++) {
- if ($haystack[$i] == $needle)
- $count++;
- }
- return $count;
+ $haystack = ereg_replace("[^$needle]","",$haystack);
+ return strlen($haystack);
}
//*************************************************************************
// Read from the back of $haystack until $needle is found, or the begining
- // of the $haystack is reached.
+ // of the $haystack is reached. $needle is a single character
//*************************************************************************
function readShortMailboxName($haystack, $needle) {
- if (substr($haystack, -1) == $needle)
- $haystack = substr($haystack, 0, strlen($haystack) - 1);
-
- if (strrpos($haystack, $needle)) {
- $pos = strrpos($haystack, $needle) + 1;
- $data = substr($haystack, $pos, strlen($haystack));
- } else {
- $data = $haystack;
- }
- return $data;
+ ereg("^$needle?([^$needle]+)$needle*",strrev($haystack),$regs);
+ return strrev($regs[1]);
}
// Searches for the next position in a string minus white space
if (trim($text) == "") {
return;
}
- $text = str_replace(" ", "", $text);
- $text = ereg_replace( '"[^"]*"', "", $text);
- $text = str_replace(",", ";", $text);
- $array = explode(";", $text);
- for ($i = 0; $i < count ($array); $i++) {
- $array[$i] = eregi_replace ("^.*[<]", "", $array[$i]);
- $array[$i] = eregi_replace ("[>].*$", "", $array[$i]);
- }
- return $array;
+ $text=ereg_replace("[;,][^<]*<* *([^>]*) *>*",";\\1",",$text");
+ return split("[;]", substr($text,1));
}
/** Returns a line of comma separated email addresses from an array **/
// We need to do it twice to catch times where there
// are an odd number of spaces
- if (ereg("^ (.*)$", $line, $regs))
- $line = " " . $regs[1];
+ $line = ereg_replace("^ ", " ", $line);
$line = str_replace(' ', ' ', $line);
$line = str_replace(' ', ' ', $line);
$line = nl2br($line);
function find_mailbox_name ($mailbox) {
+/*
$mailbox = trim($mailbox);
if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") {
$mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
$box = substr($mailbox, strrpos($mailbox, " ")+1, strlen($mailbox));
}
return $box;
+*/
+
+ if (ereg(" *\"([^\r\n\"]*)\"[ \r\n]*$", $mailbox, $regs))
+ return $regs[1];
+ ereg(" *([^ \r\n\"]*)[ \r\n]*$",$mailbox,$regs);
+ return $regs[1];
+
}
function replace_spaces ($string) {
$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
sqimap_mailbox_select($imapConnection, $mailbox);
+ // expunge-on-demand if user isn't using move_to_trash or auto_expunge
+ if($expungeButton) {
+ sqimap_mailbox_expunge($imapConnection, $mailbox);
+ $location = get_location();
+ if ($where && $what)
+ header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
+ else
+ header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
+ }
+ // undelete messages if user isn't using move_to_trash or auto_expunge
+ elseif($undeleteButton) {
+ if (is_array($msg) == 1) {
+ // Removes \Deleted flag from selected messages
+ $j = 0;
+ $i = 0;
+
+ // If they have selected nothing msg is size one still, but will be an infinite
+ // loop because we never increment j. so check to see if msg[0] is set or not to fix this.
+ while ($j < count($msg)) {
+ if ($msg[$i]) {
+ sqimap_messages_remove_flag ($imapConnection, $msg[$i], $msg[$i], "Deleted");
+ $j++;
+ }
+ $i++;
+ }
+ $location = get_location();
+
+ if ($where && $what)
+ header ("Location: $location/search.php?mailbox=".urlencode($mailbox)."&what=".urlencode($what)."&where=".urlencode($where));
+ else
+ header ("Location: $location/right_main.php?sort=$sort&startMessage=$startMessage&mailbox=". urlencode($mailbox));
+ } else {
+ displayPageHeader($color, $mailbox);
+ error_message(_("No messages were selected."), $mailbox, $sort, $startMessage, $color);
+ }
+ }
// If the delete button was pressed, the moveButton variable will not be set.
- if (!$moveButton) {
+ elseif (!$moveButton) {
if (is_array($msg) == 1) {
// Marks the selected messages ad 'Deleted'
$j = 0;