From f9b3e5d9902a047bfa8995c1d795cae2226a857a Mon Sep 17 00:00:00 2001 From: fidian Date: Mon, 23 Oct 2000 16:17:52 +0000 Subject: [PATCH] Added numerous changes from embeejay Added an expunge button, shown only when needed Better flag handling ereg() calls instead of lots of other calls git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@819 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/imap_mailbox.php | 49 +++++++++--------- functions/imap_messages.php | 10 ++++ functions/mailbox_display.php | 93 ++++++++++++++++++++--------------- functions/mime.php | 2 +- functions/strings.php | 44 ++++++----------- src/move_messages.php | 38 +++++++++++++- 6 files changed, 141 insertions(+), 95 deletions(-) diff --git a/functions/imap_mailbox.php b/functions/imap_mailbox.php index a8b8ed1a..de9ce022 100755 --- a/functions/imap_mailbox.php +++ b/functions/imap_mailbox.php @@ -23,11 +23,7 @@ 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 } } @@ -136,10 +132,8 @@ $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); } @@ -153,8 +147,8 @@ ******************************************************************************/ 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; @@ -167,7 +161,12 @@ /** 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++) { @@ -187,18 +186,18 @@ } /** 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) { @@ -212,9 +211,9 @@ $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]; diff --git a/functions/imap_messages.php b/functions/imap_messages.php index 1f4d57d4..98449ad9 100755 --- a/functions/imap_messages.php +++ b/functions/imap_messages.php @@ -37,6 +37,16 @@ $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 ******************************************************************************/ diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 95ea1b95..30f51a9b 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -12,7 +12,7 @@ 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; @@ -80,6 +80,11 @@ echo "!\n"; $stuff = true; } + if ($msg["FLAG_DELETED"]) { + echo "D\n"; + $stuff = true; + } + if (!$stuff) echo " \n"; echo "\n"; break; @@ -98,7 +103,7 @@ **/ 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; @@ -110,20 +115,20 @@ 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); } } @@ -141,7 +146,7 @@ $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]; @@ -159,38 +164,43 @@ 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) @@ -204,7 +214,7 @@ if (($sort == 4) || ($sort == 5)) $msort = array_cleave ($msgs, "SUBJECT-SORT"); - if(($sort % 2) == 1) { + if($sort % 2) { asort($msort); } else { arsort($msort); @@ -218,7 +228,7 @@ // 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 @@ -249,7 +259,7 @@ $Message = ''; if ($startMessage < $endMessage) { $Message = _("Viewing messages") ." $startMessage ". _("to") ." $endMessage ($numMessages " . _("total") . ")\n"; - } else if ($startMessage == $endMessage) { + } elseif ($startMessage == $endMessage) { $Message = _("Viewing message") ." $startMessage ($numMessages " . _("total") . ")\n"; } @@ -258,11 +268,11 @@ $More = "". _("Previous") ." | \n"; $More .= "". _("Next") ."\n"; } - else if (($nextGroup > $numMessages) && ($prevGroup >= 0)) { + elseif (($nextGroup > $numMessages) && ($prevGroup >= 0)) { $More = "". _("Previous") ." | \n"; $More .= ""._("Next")."\n"; } - else if (($nextGroup <= $numMessages) && ($prevGroup < 0)) { + elseif (($nextGroup <= $numMessages) && ($prevGroup < 0)) { $More = ""._("Previous")." | \n"; $More .= "". _("Next") ."\n"; } @@ -277,7 +287,7 @@ if ($numMessages == 0) { // if there's no messages in this folder echo "

". _("THIS FOLDER IS EMPTY") ."
 
"; - } 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 { @@ -327,7 +337,7 @@ 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 ""; @@ -366,6 +376,9 @@ echo " \n"; echo " \n"; echo " \n"; echo " \n"; @@ -394,9 +407,9 @@ if ($sort == 2) echo " \n"; - else if ($sort == 3) + elseif ($sort == 3) echo " \n"; - else if ($sort != -1) + elseif ($sort != -1) echo " \n"; break; @@ -404,9 +417,9 @@ echo " \n"; - else if ($sort == 1) + elseif ($sort == 1) echo " \n"; - else if ($sort != -1) + elseif ($sort != -1) echo " \n"; break; @@ -414,9 +427,9 @@ echo " \n"; - else if ($sort == 5) + elseif ($sort == 5) echo " \n"; - else if ($sort != -1) + elseif ($sort != -1) echo " \n"; break; diff --git a/functions/mime.php b/functions/mime.php index e60bcb62..13a453a9 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -455,7 +455,7 @@ // 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); } diff --git a/functions/strings.php b/functions/strings.php index ecd423b5..bee3eaa0 100644 --- a/functions/strings.php +++ b/functions/strings.php @@ -6,29 +6,17 @@ // 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 @@ -120,15 +108,8 @@ 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 **/ @@ -160,8 +141,7 @@ // 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); @@ -208,6 +188,7 @@ function find_mailbox_name ($mailbox) { +/* $mailbox = trim($mailbox); if (substr($mailbox, strlen($mailbox)-1, strlen($mailbox)) == "\"") { $mailbox = substr($mailbox, 0, strlen($mailbox) - 1); @@ -217,6 +198,13 @@ $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) { diff --git a/src/move_messages.php b/src/move_messages.php index 8b6a5f54..87fb326c 100644 --- a/src/move_messages.php +++ b/src/move_messages.php @@ -49,8 +49,44 @@ $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; -- 2.25.1
\n"; + if (! $move_to_trash && ! $auto_expunge) { + echo "  ". _("mailbox") ."  \n"; + } echo "  ". _("checked messages") ."\n"; echo "
". _("Date") .""; if ($sort == 0) echo " ". _("Subject") ."\n"; if ($sort == 4) echo "