From: Fredrik J. <jer...@us...> - 2004-08-24 22:08:26
|
Update of /cvsroot/squirrelmail/squirrelmail/functions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5430 Modified Files: Tag: SM-1_4-STABLE imap_messages.php Log Message: Rearranging the functions to match the order in DEVEL (for easier comparision), and some minor cleanups Index: imap_messages.php =================================================================== RCS file: /cvsroot/squirrelmail/squirrelmail/functions/imap_messages.php,v retrieving revision 1.134.2.14 retrieving revision 1.134.2.15 diff -u -w -r1.134.2.14 -r1.134.2.15 --- imap_messages.php 24 Aug 2004 00:51:21 -0000 1.134.2.14 +++ imap_messages.php 24 Aug 2004 22:08:15 -0000 1.134.2.15 @@ -14,13 +14,10 @@ * @subpackage imap */ -/* Copies specified messages to specified folder */ -/* obsolete */ -function sqimap_messages_copy ($imap_stream, $start, $end, $mailbox) { - global $uid_support; - $read = sqimap_run_command ($imap_stream, "COPY $start:$end \"$mailbox\"", true, $response, $message, $uid_support); -} +/** + * Copy a set of messages ($id) to another mailbox ($mailbox) + */ function sqimap_msgs_list_copy ($imap_stream, $id, $mailbox) { global $uid_support; $msgs_id = sqimap_message_list_squisher($id); @@ -29,17 +26,9 @@ } -/* Deletes specified messages and moves them to trash if possible */ -/* obsolete */ -function sqimap_messages_delete ($imap_stream, $start, $end, $mailbox) { - global $move_to_trash, $trash_folder, $auto_expunge, $uid_support; - - if (($move_to_trash == true) && (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder))) { - sqimap_messages_copy ($imap_stream, $start, $end, $trash_folder); - } - sqimap_messages_flag ($imap_stream, $start, $end, "Deleted", true); -} - +/** + * Deletes a message and move it to trash or expunge the mailbox + */ function sqimap_msgs_list_delete ($imap_stream, $mailbox, $id) { global $move_to_trash, $trash_folder, $uid_support; $msgs_id = sqimap_message_list_squisher($id); @@ -50,32 +39,7 @@ } -/* Sets the specified messages with specified flag */ -function sqimap_messages_flag ($imap_stream, $start, $end, $flag, $handle_errors) { - global $uid_support; - $read = sqimap_run_command ($imap_stream, "STORE $start:$end +FLAGS (\\$flag)", $handle_errors, $response, $message, $uid_support); -} - -/* Remove specified flag from specified messages */ -function sqimap_messages_remove_flag ($imap_stream, $start, $end, $flag, $handle_errors) { - global $uid_support; - $read = sqimap_run_command ($imap_stream, "STORE $start:$end -FLAGS (\\$flag)", $handle_errors, $response, $message, $uid_support); -} - -function sqimap_toggle_flag($imap_stream, $id, $flag, $set, $handle_errors) { - global $uid_support; - $msgs_id = sqimap_message_list_squisher($id); - $set_string = ($set ? '+' : '-'); - $read = sqimap_run_command ($imap_stream, "STORE $msgs_id ".$set_string."FLAGS ($flag)", $handle_errors, $response, $message, $uid_support); -} - -// obsolete? -function sqimap_get_small_header ($imap_stream, $id, $sent) { - $res = sqimap_get_small_header_list($imap_stream, $id, $sent); - return $res[0]; -} - -/* +/** * Sort the message list and crunch to be as small as possible * (overflow could happen, so make it small if possible) */ @@ -103,7 +67,10 @@ return $msgs_str; } -/* returns the references header lines */ + +/** + * Returns the references header lines + */ function get_reference_header ($imap_stream, $message) { global $uid_support; $responses = array (); @@ -117,11 +84,9 @@ } -/* get sort order from server and - * return it as the $id array for - * mailbox_display +/** + * Get sort order from server and return it as the $id array for mailbox_display */ - function sqimap_get_sort_order ($imap_stream, $sort, $mbxresponse) { global $default_charset, $thread_sort_messages, $internal_date_sort, $server_sort_array, @@ -246,11 +211,11 @@ } -/* returns an indent array for printMessageinfo() - this represents the amount of indent needed (value) - for this message number (key) +/** + * Returns an indent array for printMessageinfo() + * This represents the amount of indent needed (value), + * for this message number (key) */ - function get_parent_level ($imap_stream) { global $sort_by_ref, $default_charset, $thread_new; $parent = ""; @@ -281,9 +246,10 @@ } $indent_array[$parent] = 0; - /* now the children, checking each thread portion for - ),(, and space, adjusting the level and space values - to get the indent level + /* + * now the children, checking each thread portion for + * ),(, and space, adjusting the level and space values + * to get the indent level */ $level = 0; $spaces = array(); @@ -293,13 +259,13 @@ for ($k=1;$k<(count($thread_new[$i]))-1;$k++) { $chars = count_chars($thread_new[$i][$k], 1); if (isset($chars['40'])) { /* testing for ( */ - $level = $level + $chars['40']; + $level += $chars['40']; } if (isset($chars['41'])) { /* testing for ) */ - $level = $level - $chars['41']; + $level -= $chars['41']; $spaces[$level] = 0; /* if we were faking lets stop, this portion - of the thread is over + * of the thread is over */ if ($level == $cutoff) { $fake = FALSE; @@ -309,16 +275,16 @@ if (!isset($spaces[$level])) { $spaces[$level] = 0; } - $spaces[$level] = $spaces[$level] + $chars['32']; + $spaces[$level] += $chars['32']; } for ($x=0;$x<=$level;$x++) { if (isset($spaces[$x])) { - $spaces_total = $spaces_total + $spaces[$x]; + $spaces_total += $spaces[$x]; } } $indent = $level + $spaces_total; /* must have run into a message that broke the thread - so we are adjusting for that portion + * so we are adjusting for that portion */ if ($fake == TRUE) { $indent = $indent +1; @@ -327,7 +293,7 @@ $child = $regs[1]; } /* the thread must be broken if $indent == 0 - so indent the message once and start faking it + * so indent the message once and start faking it */ if ($indent == 0) { $indent = 1; @@ -335,7 +301,7 @@ $cutoff = $level; } /* dont need abs but if indent was negative - errors would occur + * errors would occur */ $indent_array[$child] = abs($indent); $spaces_total = 0; @@ -345,11 +311,10 @@ } -/* returns an array with each element as a string - representing one message thread as returned by - the IMAP server +/** + * Returns an array with each element as a string representing one + * message-thread as returned by the IMAP server. */ - function get_thread_sort ($imap_stream) { global $thread_new, $sort_by_ref, $default_charset, $server_sort_array, $uid_support; if (sqsession_is_registered('thread_new')) { @@ -361,11 +326,11 @@ $thread_temp = array (); if ($sort_by_ref == 1) { $sort_type = 'REFERENCES'; - } - else { + } else { $sort_type = 'ORDEREDSUBJECT'; } $query = "THREAD $sort_type ".strtoupper($default_charset)." ALL"; + $thread_test = sqimap_run_command ($imap_stream, $query, true, $response, $message, $uid_support); if (isset($thread_test[0])) { for ($i=0,$iCnt=count($thread_test);$i<$iCnt;++$i) { @@ -374,8 +339,7 @@ break; } } - } - else { + } else { $thread_list = ""; } if (!preg_match("/OK/", $response)) { @@ -385,6 +349,7 @@ if (isset($thread_list)) { $thread_temp = preg_split("//", $thread_list, -1, PREG_SPLIT_NO_EMPTY); } + $char_count = count($thread_temp); $counter = 0; $thread_new = array(); @@ -393,17 +358,14 @@ for ($i=0;$i<$char_count;$i++) { if ($thread_temp[$i] != ')' && $thread_temp[$i] != '(') { $thread_new[$k] = $thread_new[$k] . $thread_temp[$i]; - } - elseif ($thread_temp[$i] == '(') { + } elseif ($thread_temp[$i] == '(') { $thread_new[$k] .= $thread_temp[$i]; $counter++; - } - elseif ($thread_temp[$i] == ')') { + } elseif ($thread_temp[$i] == ')') { if ($counter > 1) { $thread_new[$k] .= $thread_temp[$i]; $counter = $counter - 1; - } - else { + } else { $thread_new[$k] .= $thread_temp[$i]; $k++; $thread_new[$k] = ""; @@ -411,6 +373,7 @@ } } } + sqsession_register($thread_new, 'thread_new'); $thread_new = array_reverse($thread_new); $thread_list = implode(" ", $thread_new); @@ -418,6 +381,7 @@ $thread_list = str_replace(")", " ", $thread_list); $thread_list = preg_split("/\s/", $thread_list, -1, PREG_SPLIT_NO_EMPTY); $server_sort_array = $thread_list; + sqsession_register($server_sort_array, 'server_sort_array'); return $thread_list; } @@ -429,7 +393,15 @@ return $timepassed; } -// only used in sqimap_get_small_header_list + +/** + * Parses a string in an imap response. String starts with " or { which means it + * can handle double quoted strings and literal strings + * + * @param string $read imap response + * @param integer $i (reference) offset in string + * @return string $s parsed string without the double quotes or literal count + */ function parseString($read,&$i) { $char = $read{$i}; $s = ''; @@ -472,7 +444,14 @@ return $s; } -// only used in sqimap_get_small_header_list + +/** + * Parses a string containing an array from an imap response. String starts with ( and end with ) + * + * @param string $read imap response + * @param integer $i (reference) offset in string + * @return array $a + */ function parseArray($read,&$i) { $i = strpos($read,'(',$i); $i_pos = strpos($read,')',$i); @@ -486,6 +465,10 @@ } } + +/** + * Retrieves a list with headers, flags, size or internaldate from the imap server + */ function sqimap_get_small_header_list ($imap_stream, $msg_list, $show_num=false) { global $squirrelmail_language, $color, $data_dir, $username, $imap_server_type; global $uid_support, $allow_server_sort; @@ -542,11 +525,11 @@ $fetch = substr($read,$i_space+1,5); if (!is_numeric($id) && $fetch !== 'FETCH') { set_up_language($squirrelmail_language); - echo '<br><b><font color=$color[2]>' . + echo '<br /><b><font color="'.$color[2].'">' . _("ERROR : Could not complete request.") . - '</b><br>' . + '</b><br />' . _("Unknown response from IMAP server: ") . ' 1.' . - htmlspecialchars($read) . "</font><br>\n"; + htmlspecialchars($read) . "</font><br />\n"; break; } $i = strpos($read,'(',$i_space+5); @@ -715,7 +698,10 @@ return $new_messages; } -// obsolete? + +/** + * Obsolete? + */ function sqimap_get_headerfield($imap_stream, $field) { global $uid_support; $sid = sqimap_session_id(false); @@ -739,22 +725,22 @@ if (!$uid_support) { if (!preg_match("/^\\*\s+([0-9]+)\s+FETCH/iAU",$r[0], $regs)) { set_up_language($squirrelmail_language); - echo '<br><b><font color=$color[2]>' . + echo '<br /><b><font color="'.$color[2].'">' . _("ERROR : Could not complete request.") . - '</b><br>' . + '</b><br />' . _("Unknown response from IMAP server: ") . ' 1.' . - $r[0] . "</font><br>\n"; + $r[0] . "</font><br />\n"; } else { $id = $regs[1]; } } else { if (!preg_match("/^\\*\s+([0-9]+)\s+FETCH.*UID\s+([0-9]+)\s+/iAU",$r[0], $regs)) { set_up_language($squirrelmail_language); - echo '<br><b><font color=$color[2]>' . + echo '<br /><b><font color="'.$color[2].'">' . _("ERROR : Could not complete request.") . - '</b><br>' . + '</b><br />' . _("Unknown response from IMAP server: ") . ' 1.' . - $r[0] . "</font><br>\n"; + $r[0] . "</font><br />\n"; } else { $id = $regs[2]; } @@ -767,19 +753,15 @@ } - - - -/* +/** * Returns a message array with all the information about a message. * See the documentation folder for more information about this array. */ function sqimap_get_message ($imap_stream, $id, $mailbox) { global $uid_support; - // prohibit 1:* msgs sets + // typecast to int to prohibit 1:* msgs sets $id = (int) $id; - $flags = array(); $read = sqimap_run_command ($imap_stream, "FETCH $id (FLAGS BODYSTRUCTURE)", true, $response, $message, $uid_support); if ($read) { @@ -807,8 +789,11 @@ return $msg; } -/* Wrapper function that reformats the header information. */ -// obsolete? + +/** + * Wrapper function that reformats the header information. + * Obsolete? + */ function sqimap_get_message_header ($imap_stream, $id, $mailbox) { global $uid_support; $read = sqimap_run_command ($imap_stream, "FETCH $id BODY[HEADER]", true, $response, $message, $uid_support); @@ -818,8 +803,11 @@ return $header; } -/* Wrapper function that reformats the entity header information. */ -// obsolete? + +/** + * Wrapper function that reformats the entity header information. + * Obsolete? + */ function sqimap_get_ent_header ($imap_stream, $id, $mailbox, $ent) { global $uid_support; $read = sqimap_run_command ($imap_stream, "FETCH $id BODY[$ent.HEADER]", true, $response, $message, $uid_support); @@ -829,8 +817,11 @@ return $header; } -/* function to get the mime headers */ -// obsolete? + +/** + * Function to get the mime headers + * Obsolete? + */ function sqimap_get_mime_ent_header ($imap_stream, $id, $mailbox, $ent) { global $uid_support; $read = sqimap_run_command ($imap_stream, "FETCH $id:$id BODY[$ent.MIME]", true, $response, $message, $uid_support); @@ -840,4 +831,61 @@ return $header; } + +/** + * Copies specified messages to specified folder + * Obsolete + */ +function sqimap_messages_copy($imap_stream, $start, $end, $mailbox) { + global $uid_support; + $read = sqimap_run_command ($imap_stream, "COPY $start:$end \"$mailbox\"", true, $response, $message, $uid_support); +} + + +/** + * Deletes specified messages and moves them to trash if possible + * Obsolete + */ +function sqimap_messages_delete($imap_stream, $start, $end, $mailbox) { + global $move_to_trash, $trash_folder, $auto_expunge, $uid_support; + + if (($move_to_trash == true) && (sqimap_mailbox_exists($imap_stream, $trash_folder) && ($mailbox != $trash_folder))) { + sqimap_messages_copy ($imap_stream, $start, $end, $trash_folder); + } + sqimap_messages_flag ($imap_stream, $start, $end, "Deleted", true); +} + + +/** + * Sets the specified messages with specified flag + */ +function sqimap_messages_flag($imap_stream, $start, $end, $flag, $handle_errors) { + global $uid_support; + $read = sqimap_run_command ($imap_stream, "STORE $start:$end +FLAGS (\\$flag)", $handle_errors, $response, $message, $uid_support); +} + + +/* Remove specified flag from specified messages */ +function sqimap_messages_remove_flag($imap_stream, $start, $end, $flag, $handle_errors) { + global $uid_support; + $read = sqimap_run_command ($imap_stream, "STORE $start:$end -FLAGS (\\$flag)", $handle_errors, $response, $message, $uid_support); +} + + +function sqimap_toggle_flag($imap_stream, $id, $flag, $set, $handle_errors) { + global $uid_support; + $msgs_id = sqimap_message_list_squisher($id); + $set_string = ($set ? '+' : '-'); + $read = sqimap_run_command ($imap_stream, "STORE $msgs_id ".$set_string."FLAGS ($flag)", $handle_errors, $response, $message, $uid_support); +} + + +/** + * Obsolete? + */ +function sqimap_get_small_header($imap_stream, $id, $sent) { + $res = sqimap_get_small_header_list($imap_stream, $id, $sent); + return $res[0]; +} + ?> \ No newline at end of file |