From 15a9d1ce671fcbc44ea3e4858d7aa6f5b22300c9 Mon Sep 17 00:00:00 2001 From: thomascube Date: Thu, 5 Jan 2006 00:37:10 +0000 Subject: Optimized loading time; added periodic mail check; added EXPUNGE command --- program/steps/mail/check_recent.inc | 47 ++++++++++++++++++++++++++++ program/steps/mail/folders.inc | 61 +++++++++++++++++++++++++++++++++++++ program/steps/mail/func.inc | 29 +++++++++++++----- program/steps/mail/getunread.inc | 36 ++++++++++++++++++++++ program/steps/mail/sendmail.inc | 9 ++++-- program/steps/mail/upload.inc | 2 +- 6 files changed, 173 insertions(+), 11 deletions(-) create mode 100644 program/steps/mail/check_recent.inc create mode 100644 program/steps/mail/folders.inc create mode 100644 program/steps/mail/getunread.inc (limited to 'program/steps/mail') diff --git a/program/steps/mail/check_recent.inc b/program/steps/mail/check_recent.inc new file mode 100644 index 000000000..fbf8871f9 --- /dev/null +++ b/program/steps/mail/check_recent.inc @@ -0,0 +1,47 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +$REMOTE_REQUEST = TRUE; +$mbox = $IMAP->get_mailbox_name(); + +if ($recent_count = $IMAP->messagecount(NULL, 'RECENT')) + { + $count = $IMAP->messagecount(); + $unread_count = $IMAP->messagecount(NULL, 'UNSEEN'); + + $commands = sprintf("this.set_unread_count('%s', %d, true);\n", addslashes($mbox), $unread_count); + $commands .= sprintf("this.set_env('messagecount', %d);\n", $count); + $commands .= sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text()); + + // add new message headers to list + $a_headers = array(); + for ($i=$recent_count, $id=$count-$recent_count+1; $i>0; $i--, $id++) + $a_headers[] = $IMAP->get_headers($id, NULL, FALSE); + + $commands .= rcmail_js_message_list($a_headers, TRUE); + } + +if (strtoupper($mbox)!='INBOX' && $IMAP->messagecount('INBOX', 'RECENT')) + $commands = sprintf("this.set_unread_count('INBOX', %d);\n", $IMAP->messagecount('INBOX', 'UNSEEN')); + + +rcube_remote_response($commands); +?> \ No newline at end of file diff --git a/program/steps/mail/folders.inc b/program/steps/mail/folders.inc new file mode 100644 index 000000000..e1730ef93 --- /dev/null +++ b/program/steps/mail/folders.inc @@ -0,0 +1,61 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +$REMOTE_REQUEST = TRUE; +$mbox = $IMAP->get_mailbox_name(); + + +// send EXPUNGE command +if ($_action=='expunge') + { + $success = $IMAP->expunge(); + + // reload message list if current mailbox + if ($success && $_GET['_reload']) + { + rcube_remote_response('this.clear_message_list();', TRUE); + $_action = 'list'; + return; + } + else + $commands = "// expunged: $success\n"; + } + +// clear mailbox +else if ($_action=='purge') + { + $success = $IMAP->clear_mailbox(); + + if ($success && $_GET['_reload']) + { + $commands = "this.set_env('messagecount', 0);\n"; + $commands .= "this.set_env('pagecount', 0);\n"; + $commands .= sprintf("this.set_rowcount('%s');\n", rcmail_get_messagecount_text()); + $commands .= sprintf("this.set_unread_count('%s', 0);\n", addslashes($mbox)); + } + else + $commands = "// purged: $success"; + } + + + +rcube_remote_response($commands); +?> \ No newline at end of file diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index c430467d1..8ebd1c59c 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -69,6 +69,8 @@ function rcmail_mailbox_list($attrib) static $s_added_script = FALSE; static $a_mailboxes; +// $mboxlist_start = rcube_timer(); + $type = $attrib['type'] ? $attrib['type'] : 'ul'; $add_attrib = $type=='select' ? array('style', 'class', 'id', 'name', 'onchange') : array('style', 'class', 'id'); @@ -100,7 +102,9 @@ function rcmail_mailbox_list($attrib) $a_folders = $IMAP->list_mailboxes(); $delimiter = $IMAP->get_hierarchy_delimiter(); $a_mailboxes = array(); - + +// rcube_print_time($mboxlist_start, 'list_mailboxes()'); + foreach ($a_folders as $folder) rcmail_build_folder_tree($a_mailboxes, $folder, $delimiter); } @@ -112,6 +116,8 @@ function rcmail_mailbox_list($attrib) else $out .= rcmail_render_folder_tree_html($a_mailboxes, $special_mailboxes, $mbox, $attrib['maxlength']); +// rcube_print_time($mboxlist_start, 'render_folder_tree()'); + if ($type=='ul') $OUTPUT->add_script(sprintf("%s.gui_object('mailboxlist', '%s');", $JS_OBJECT_NAME, $attrib['id'])); @@ -181,7 +187,7 @@ function rcmail_render_folder_tree_html(&$arrFolders, &$special, &$mbox, $maxlen } // add unread message count display - if ($unread_count = $IMAP->messagecount($folder['id'], 'UNSEEN', ($folder['id']==$mbox))) + if ($unread_count = $IMAP->messagecount($folder['id'], 'RECENT', ($folder['id']==$mbox))) $foldername .= sprintf(' (%d)', $unread_count); // make folder name safe for ids and class names @@ -397,7 +403,12 @@ function rcmail_message_list($attrib) if ($attrib['attachmenticon'] && preg_match("/multipart\/m/i", $header->ctype)) $attach_icon = $attrib['attachmenticon']; - $out .= sprintf(''."\n", $header->uid); + $out .= sprintf(''."\n", + $header->uid, + $header->seen ? '' : ' unread', + $header->deleted ? ' deleted' : '', + $zebra_class); + $out .= sprintf("%s\n", $message_icon ? sprintf($image_tag, $skin_path, $message_icon, '') : ''); // format each col @@ -495,12 +506,16 @@ function rcmail_js_message_list($a_headers, $insert_top=FALSE) $a_msg_flags['unread'] = $header->seen ? 0 : 1; $a_msg_flags['replied'] = $header->answered ? 1 : 0; + + if ($header->deleted) + $a_msg_flags['deleted'] = 1; - $commands .= sprintf("this.add_message_row(%s, %s, %s, %b);\n", + $commands .= sprintf("this.add_message_row(%s, %s, %s, %b, %b);\n", $header->uid, array2js($a_msg_cols), array2js($a_msg_flags), - preg_match("/multipart\/m/i", $header->ctype)); + preg_match("/multipart\/m/i", $header->ctype), + $insert_top); } return $commands; @@ -1377,11 +1392,11 @@ function rcmail_compose_cleanup() // remove attachment files from temp dir if (is_array($_SESSION['compose']['attachments'])) foreach ($_SESSION['compose']['attachments'] as $attachment) - unlink($attachment['path']); + @unlink($attachment['path']); // kill temp dir if ($_SESSION['compose']['temp_dir']) - rmdir($_SESSION['compose']['temp_dir']); + @rmdir($_SESSION['compose']['temp_dir']); unset($_SESSION['compose']); } diff --git a/program/steps/mail/getunread.inc b/program/steps/mail/getunread.inc new file mode 100644 index 000000000..d35dcf9f1 --- /dev/null +++ b/program/steps/mail/getunread.inc @@ -0,0 +1,36 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +$REMOTE_REQUEST = TRUE; + +$a_folders = $IMAP->list_mailboxes(); + +if (!empty($a_folders)) + { + foreach ($a_folders as $mbox) + { + $commands = sprintf("this.set_unread_count('%s', %d);\n", $mbox, $IMAP->messagecount($mbox, 'UNSEEN')); + rcube_remote_response($commands, TRUE); + } + } + +exit; +?> \ No newline at end of file diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index 3c9f60378..c29fcf1d3 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -224,14 +224,17 @@ else { // unset some headers because they will be added by the mail() function $headers_php = $headers; + $headers_enc = $MAIL_MIME->headers($headers); unset($headers_php['To'], $headers_php['Subject']); + // reset stored headers and overwrite + $MAIL_MIME->_headers = array(); $header_str = $MAIL_MIME->txtHeaders($headers_php); if(ini_get('safe_mode')) - $sent = mail($mailto, $msg_subject, $msg_body, $header_str); - else - $sent = mail($mailto, $msg_subject, $msg_body, $header_str, "-f$from"); + $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str); + else + $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from"); } diff --git a/program/steps/mail/upload.inc b/program/steps/mail/upload.inc index 308ec796e..4cd929d0d 100644 --- a/program/steps/mail/upload.inc +++ b/program/steps/mail/upload.inc @@ -39,7 +39,7 @@ $response = ''; foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) { $tmpfname = tempnam($temp_dir, 'rcmAttmnt'); - if (copy($filepath, $tmpfname)) + if (move_uploaded_file($filepath, $tmpfname)) { $_SESSION['compose']['attachments'][] = array('name' => $_FILES['_attachments']['name'][$i], 'mimetype' => $_FILES['_attachments']['type'][$i], -- cgit v1.2.3