From db1a87cd6c506f2afbd1a37c64cb56ae11120b49 Mon Sep 17 00:00:00 2001 From: thomascube Date: Fri, 17 Dec 2010 15:07:04 +0000 Subject: Update branch for 0.5-rc release --- program/steps/mail/compose.inc | 22 +- program/steps/mail/copy.inc | 4 +- program/steps/mail/folders.inc | 84 +++--- program/steps/mail/func.inc | 93 ++----- program/steps/mail/getunread.inc | 13 +- program/steps/mail/list.inc | 3 +- program/steps/mail/mark.inc | 6 +- program/steps/mail/move_del.inc | 10 +- program/steps/mail/search.inc | 3 +- program/steps/mail/sendmail.inc | 69 +++-- program/steps/mail/show.inc | 7 +- program/steps/settings/edit_folder.inc | 294 ++++++++++++++++++++ program/steps/settings/edit_identity.inc | 3 +- program/steps/settings/folders.inc | 377 +++++++++++++++++++++++++ program/steps/settings/manage_folders.inc | 443 ------------------------------ program/steps/settings/save_folder.inc | 176 ++++++++++++ program/steps/utils/html2text.inc | 7 +- 17 files changed, 1001 insertions(+), 613 deletions(-) create mode 100644 program/steps/settings/edit_folder.inc create mode 100644 program/steps/settings/folders.inc delete mode 100644 program/steps/settings/manage_folders.inc create mode 100644 program/steps/settings/save_folder.inc (limited to 'program/steps') diff --git a/program/steps/mail/compose.inc b/program/steps/mail/compose.inc index 828a94f3b..45b95c937 100644 --- a/program/steps/mail/compose.inc +++ b/program/steps/mail/compose.inc @@ -267,19 +267,11 @@ function rcmail_compose_headers($attrib) $param = 'replyto'; $header = 'reply-to'; - case 'mailreplyto': - case 'mail-reply-to': + case 'followupto': + case 'followup-to': if (!$fname) { - $fname = '_mailreplyto'; - $param = 'mailreplyto'; - $header = 'mail-reply-to'; - } - - case 'mailfollowupto': - case 'mail-followup-to': - if (!$fname) { - $fname = '_mailfollowupto'; - $param = 'mailfollowupto'; + $fname = '_followupto'; + $param = 'followupto'; $header = 'mail-followup-to'; } @@ -354,10 +346,10 @@ function rcmail_compose_headers($attrib) $fvalue = $MESSAGE->get_header('cc'); else if ($header=='bcc' && !empty($MESSAGE->headers->bcc)) $fvalue = $MESSAGE->get_header('bcc'); + else if ($header=='reply-to' && !empty($MESSAGE->headers->others['mail-reply-to'])) + $fvalue = $MESSAGE->get_header('mail-reply-to'); else if ($header=='reply-to' && !empty($MESSAGE->headers->replyto)) $fvalue = $MESSAGE->get_header('reply-to'); - else if ($header=='mail-reply-to' && !empty($MESSAGE->headers->others['mail-reply-to'])) - $fvalue = $MESSAGE->get_header('followup-to'); else if ($header=='mail-followup-to' && !empty($MESSAGE->headers->others['mail-followup-to'])) $fvalue = $MESSAGE->get_header('mail-followup-to'); @@ -742,7 +734,7 @@ function rcmail_create_reply_body($body, $bodyIsHtml) // build reply prefix $from = array_pop($RCMAIL->imap->decode_address_list($MESSAGE->get_header('from'))); $prefix = sprintf("On %s, %s wrote:", - $MESSAGE->headers->date, $from['name'] ? $from['name'] : idn_to_utf8($from['email'])); + $MESSAGE->headers->date, $from['name'] ? $from['name'] : idn_to_utf8($from['mailto'])); if (!$bodyIsHtml) { $body = preg_replace('/\r?\n/', "\n", $body); diff --git a/program/steps/mail/copy.inc b/program/steps/mail/copy.inc index 4cd51d816..8a7c5916b 100644 --- a/program/steps/mail/copy.inc +++ b/program/steps/mail/copy.inc @@ -33,7 +33,7 @@ if (!empty($_POST['_uid']) && !empty($_POST['_target_mbox'])) { if (!$copied) { // send error message - $OUTPUT->show_message('errorcopying', 'error'); + rcmail_display_server_error('errorcopying'); $OUTPUT->send(); exit; } @@ -52,5 +52,3 @@ else { // send response $OUTPUT->send(); - - diff --git a/program/steps/mail/folders.inc b/program/steps/mail/folders.inc index 26f464b0c..3b96dc29c 100644 --- a/program/steps/mail/folders.inc +++ b/program/steps/mail/folders.inc @@ -20,55 +20,61 @@ // only process ajax requests if (!$OUTPUT->ajax_call) - return; + return; $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true); // send EXPUNGE command -if ($RCMAIL->action=='expunge') -{ - $success = $IMAP->expunge($mbox); +if ($RCMAIL->action == 'expunge') { - // reload message list if current mailbox - if ($success && !empty($_REQUEST['_reload'])) - { - $OUTPUT->command('set_quota', rcmail_quota_content()); - $OUTPUT->command('message_list.clear'); - $RCMAIL->action = 'list'; - return; - } - else - $commands = "// expunged: $success\n"; + $success = $IMAP->expunge($mbox); + + // reload message list if current mailbox + if ($success) { + $OUTPUT->show_message('folderexpunged', 'confirmation'); + + if (!empty($_REQUEST['_reload'])) { + $OUTPUT->command('set_quota', rcmail_quota_content()); + $OUTPUT->command('message_list.clear'); + $RCMAIL->action = 'list'; + return; + } + } + else { + rcmail_display_server_error(); + } } // clear mailbox -else if ($RCMAIL->action=='purge') +else if ($RCMAIL->action == 'purge') { - $delimiter = $IMAP->get_hierarchy_delimiter(); - $trash_regexp = '/^' . preg_quote($CONFIG['trash_mbox'] . $delimiter, '/') . '/'; - $junk_regexp = '/^' . preg_quote($CONFIG['junk_mbox'] . $delimiter, '/') . '/'; + $delimiter = $IMAP->get_hierarchy_delimiter(); + $trash_regexp = '/^' . preg_quote($CONFIG['trash_mbox'] . $delimiter, '/') . '/'; + $junk_regexp = '/^' . preg_quote($CONFIG['junk_mbox'] . $delimiter, '/') . '/'; - // we should only be purging trash and junk (or their subfolders) - if ($mbox == $CONFIG['trash_mbox'] || $mbox == $CONFIG['junk_mbox'] - || preg_match($trash_regexp, $mbox) || preg_match($junk_regexp, $mbox)) - { - $success = $IMAP->clear_mailbox($mbox); - - if ($success && !empty($_REQUEST['_reload'])) - { - $OUTPUT->set_env('messagecount', 0); - $OUTPUT->set_env('pagecount', 0); - $OUTPUT->command('message_list.clear'); - $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text()); - $OUTPUT->command('set_unread_count', $mbox, 0); - $OUTPUT->command('set_quota', rcmail_quota_content()); - $_SESSION['unseen_count'][$mbox] = 0; - } - else - $commands = "// purged: $success"; - } -} + // we should only be purging trash and junk (or their subfolders) + if ($mbox == $CONFIG['trash_mbox'] || $mbox == $CONFIG['junk_mbox'] + || preg_match($trash_regexp, $mbox) || preg_match($junk_regexp, $mbox) + ) { + $success = $IMAP->clear_mailbox($mbox); -$OUTPUT->send($commands); + if ($success) { + $OUTPUT->show_message('folderpurged', 'confirmation'); + if (!empty($_REQUEST['_reload'])) { + $OUTPUT->set_env('messagecount', 0); + $OUTPUT->set_env('pagecount', 0); + $OUTPUT->command('message_list.clear'); + $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text()); + $OUTPUT->command('set_unread_count', $mbox, 0); + $OUTPUT->command('set_quota', rcmail_quota_content()); + rcmail_set_unseen_count($mbox, 0); + } + } + else { + rcmail_display_server_error(); + } + } +} +$OUTPUT->send(); diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index c7498d5b1..750cf6f61 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -436,65 +436,6 @@ function rcmail_messagecount_display($attrib) } -function rcmail_quota_display($attrib) - { - global $OUTPUT; - - if (!$attrib['id']) - $attrib['id'] = 'rcmquotadisplay'; - - if(isset($attrib['display'])) - $_SESSION['quota_display'] = $attrib['display']; - - $OUTPUT->add_gui_object('quotadisplay', $attrib['id']); - - $quota = rcmail_quota_content($attrib); - - $OUTPUT->add_script('$(document).ready(function(){ - rcmail.set_quota('.json_serialize($quota).')});', 'foot'); - - return html::span($attrib, ''); - } - - -function rcmail_quota_content($attrib=NULL) - { - global $COMM_PATH, $RCMAIL; - - $quota = $RCMAIL->imap->get_quota(); - $quota = $RCMAIL->plugins->exec_hook('quota', $quota); - - $quota_result = (array) $quota; - $quota_result['type'] = isset($_SESSION['quota_display']) ? $_SESSION['quota_display'] : ''; - - if (!$quota['total'] && $RCMAIL->config->get('quota_zero_as_unlimited')) { - $quota_result['title'] = rcube_label('unlimited'); - $quota_result['percent'] = 0; - } - else if ($quota['total']) { - if (!isset($quota['percent'])) - $quota_result['percent'] = min(100, round(($quota['used']/max(1,$quota['total']))*100)); - - $title = sprintf('%s / %s (%.0f%%)', - show_bytes($quota['used'] * 1024), show_bytes($quota['total'] * 1024), - $quota_result['percent']); - - $quota_result['title'] = $title; - - if ($attrib['width']) - $quota_result['width'] = $attrib['width']; - if ($attrib['height']) - $quota_result['height'] = $attrib['height']; - } - else { - $quota_result['title'] = rcube_label('unknown'); - $quota_result['percent'] = 0; - } - - return $quota_result; - } - - function rcmail_get_messagecount_text($count=NULL, $page=NULL) { global $RCMAIL, $IMAP; @@ -545,7 +486,7 @@ function rcmail_send_unread_count($mbox_name, $force=false, $count=null) { global $RCMAIL; - $old_unseen = $_SESSION['unseen_count'][$mbox_name]; + $old_unseen = rcmail_get_unseen_count($mbox_name); if ($count === null) $unseen = $RCMAIL->imap->messagecount($mbox_name, 'UNSEEN', $force); @@ -555,13 +496,33 @@ function rcmail_send_unread_count($mbox_name, $force=false, $count=null) if ($unseen != $old_unseen || ($mbox_name == 'INBOX')) $RCMAIL->output->command('set_unread_count', $mbox_name, $unseen, ($mbox_name == 'INBOX')); - // @TODO: this data is doubled (session and cache tables) if caching is enabled - $_SESSION['unseen_count'][$mbox_name] = $unseen; + rcmail_set_unseen_count($mbox_name, $unseen); return $unseen; } +function rcmail_set_unseen_count($mbox_name, $count) +{ + // @TODO: this data is doubled (session and cache tables) if caching is enabled + + // Make sure we have an array here (#1487066) + if (!is_array($_SESSION['unseen_count'])) + $_SESSION['unseen_count'] = array(); + + $_SESSION['unseen_count'][$mbox_name] = $count; +} + + +function rcmail_get_unseen_count($mbox_name) +{ + if (is_array($_SESSION['unseen_count']) && array_key_exists($mbox_name, $_SESSION['unseen_count'])) + return $_SESSION['unseen_count'][$mbox_name]; + else + return null; +} + + /** * Sets message is_safe flag according to 'show_images' option value * @@ -966,10 +927,14 @@ function rcmail_message_headers($attrib, $headers=NULL) else $header_value = trim($IMAP->decode_header($value)); - $output_headers[$hkey] = array('title' => rcube_label($hkey), 'value' => $header_value, 'raw' => $value); + $output_headers[$hkey] = array( + 'title' => rcube_label(preg_replace('/(^mail-|-)/', '', $hkey)), + 'value' => $header_value, 'raw' => $value + ); } - $plugin = $RCMAIL->plugins->exec_hook('message_headers_output', array('output' => $output_headers, 'headers' => $MESSAGE->headers)); + $plugin = $RCMAIL->plugins->exec_hook('message_headers_output', + array('output' => $output_headers, 'headers' => $MESSAGE->headers)); // compose html table $table = new html_table(array('cols' => 2)); diff --git a/program/steps/mail/getunread.inc b/program/steps/mail/getunread.inc index a035f5204..e60f36cae 100644 --- a/program/steps/mail/getunread.inc +++ b/program/steps/mail/getunread.inc @@ -28,15 +28,18 @@ if (!empty($a_folders)) $check_all = (bool)$RCMAIL->config->get('check_all_folders'); foreach ($a_folders as $mbox_row) { - if (!$check_all && isset($_SESSION['unseen_count'][$mbox_row]) && $mbox_row != $current) - $unseen = $_SESSION['unseen_count'][$mbox_row]; + $unseen_old = rcmail_get_unseen_count($mbox_row); + + if (!$check_all && $unseen_old !== null && $mbox_row != $current) + $unseen = $unseen_old; else - $unseen = $IMAP->messagecount($mbox_row, 'UNSEEN', !isset($_SESSION['unseen_count'][$mbox_row])); + $unseen = $IMAP->messagecount($mbox_row, 'UNSEEN', $unseen_old === null); - if ($unseen || !isset($_SESSION['unseen_count'][$mbox_row])) { + if ($unseen || $unseen_old === null) { $OUTPUT->command('set_unread_count', $mbox_row, $unseen, $inbox && $mbox_row == 'INBOX'); } - $_SESSION['unseen_count'][$mbox_row] = $unseen; + + rcmail_set_unseen_count($mbox_row, $unseen); } } diff --git a/program/steps/mail/list.inc b/program/steps/mail/list.inc index 6353be7cc..7e6d294c8 100644 --- a/program/steps/mail/list.inc +++ b/program/steps/mail/list.inc @@ -106,8 +106,7 @@ if (isset($a_headers) && count($a_headers)) else { // handle IMAP errors (e.g. #1486905) if ($err_code = $IMAP->get_error_code()) { - $err_str = $IMAP->get_error_str(); - $OUTPUT->show_message('servererrormsg', 'error', array('msg' => $err_str)); + rcmail_display_server_error(); } else if ($search_request) $OUTPUT->show_message('searchnomatch', 'notice'); diff --git a/program/steps/mail/mark.inc b/program/steps/mail/mark.inc index 5411e3f46..1ff4407c5 100644 --- a/program/steps/mail/mark.inc +++ b/program/steps/mail/mark.inc @@ -47,7 +47,7 @@ if (($uids = get_input_value('_uid', RCUBE_INPUT_POST)) && ($flag = get_input_va // send error message if ($_POST['_from'] != 'show') $OUTPUT->command('list_mailbox'); - $OUTPUT->show_message('errormarking', 'error'); + rcmail_display_server_error('errormarking'); $OUTPUT->send(); exit; } @@ -98,11 +98,11 @@ if (($uids = get_input_value('_uid', RCUBE_INPUT_POST)) && ($flag = get_input_va // update mailboxlist $mbox = $IMAP->get_mailbox_name(); $unseen_count = $msg_count ? $IMAP->messagecount($mbox, 'UNSEEN') : 0; - $old_unseen = $_SESSION['unseen_count'][$mbox]; + $old_unseen = rcmail_get_unseen_count($mbox); if ($old_unseen != $unseen_count) { $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX')); - $_SESSION['unseen_count'][$mbox] = $unseen_count; + rcmail_set_unseen_count($mbox, $unseen_count); } $OUTPUT->command('set_rowcount', rcmail_get_messagecount_text($msg_count)); diff --git a/program/steps/mail/move_del.inc b/program/steps/mail/move_del.inc index 3940b6db9..2db3ec31a 100644 --- a/program/steps/mail/move_del.inc +++ b/program/steps/mail/move_del.inc @@ -39,7 +39,7 @@ if ($RCMAIL->action=='moveto' && !empty($_POST['_uid']) && strlen($_POST['_targe // send error message if ($_POST['_from'] != 'show') $OUTPUT->command('list_mailbox'); - $OUTPUT->show_message('errormoving', 'error'); + rcmail_display_server_error('errormoving'); $OUTPUT->send(); exit; } @@ -60,7 +60,7 @@ else if ($RCMAIL->action=='delete' && !empty($_POST['_uid'])) { // send error message if ($_POST['_from'] != 'show') $OUTPUT->command('list_mailbox'); - $OUTPUT->show_message('errordeleting', 'error'); + rcmail_display_server_error('errordeleting'); $OUTPUT->send(); exit; } @@ -109,11 +109,11 @@ else // update mailboxlist $mbox = $IMAP->get_mailbox_name(); $unseen_count = $msg_count ? $IMAP->messagecount($mbox, 'UNSEEN') : 0; - $old_unseen = $_SESSION['unseen_count'][$mbox]; - + $old_unseen = rcmail_get_unseen_count($mbox); + if ($old_unseen != $unseen_count) { $OUTPUT->command('set_unread_count', $mbox, $unseen_count, ($mbox == 'INBOX')); - $_SESSION['unseen_count'][$mbox] = $unseen_count; + rcmail_set_unseen_count($mbox, $unseen_count); } if ($RCMAIL->action=='moveto' && strlen($target)) { diff --git a/program/steps/mail/search.inc b/program/steps/mail/search.inc index 90d1c374c..39fb32fc9 100644 --- a/program/steps/mail/search.inc +++ b/program/steps/mail/search.inc @@ -124,8 +124,7 @@ if (!empty($result_h)) { } // handle IMAP errors (e.g. #1486905) else if ($err_code = $IMAP->get_error_code()) { - $err_str = $IMAP->get_error_str(); - $OUTPUT->show_message('servererrormsg', 'error', array('msg' => $err_str)); + rcmail_display_server_error(); } else { $OUTPUT->show_message('searchnomatch', 'notice'); diff --git a/program/steps/mail/sendmail.inc b/program/steps/mail/sendmail.inc index 796e7782b..09f12ed07 100644 --- a/program/steps/mail/sendmail.inc +++ b/program/steps/mail/sendmail.inc @@ -70,7 +70,7 @@ function rcmail_encrypt_header($what) function rcmail_get_identity($id) { global $USER, $OUTPUT; - + if ($sql_arr = $USER->get_identity($id)) { $out = $sql_arr; $out['mailto'] = $sql_arr['email']; @@ -100,7 +100,7 @@ function rcmail_fix_emoticon_paths(&$mime_message) // remove any null-byte characters before parsing $body = preg_replace('/\x00/', '', $body); - + $searchstr = 'program/js/tiny_mce/plugins/emotions/img/'; $offset = 0; @@ -193,6 +193,7 @@ function rcmail_email_input_format($mailto, $count=false, $check=true) return implode(', ', $result); } + /****** compose message ********/ if (strlen($_POST['_draft_saveid']) > 3) @@ -297,12 +298,12 @@ $headers['From'] = rcube_charset_convert($from_string, RCMAIL_CHARSET, $message_ $headers['To'] = $mailto; // additional recipients -if (!empty($mailcc)) +if (!empty($mailcc)) { $headers['Cc'] = $mailcc; - -if (!empty($mailbcc)) +} +if (!empty($mailbcc)) { $headers['Bcc'] = $mailbcc; - +} if (!empty($identity_arr['bcc'])) { $headers['Bcc'] = ($headers['Bcc'] ? $headers['Bcc'].', ' : '') . $identity_arr['bcc']; $RECIPIENT_COUNT ++; @@ -318,36 +319,43 @@ if (($max_recipients = (int) $RCMAIL->config->get('max_recipients')) > 0) { // add subject $headers['Subject'] = trim(get_input_value('_subject', RCUBE_INPUT_POST, TRUE, $message_charset)); -if (!empty($identity_arr['organization'])) +if (!empty($identity_arr['organization'])) { $headers['Organization'] = $identity_arr['organization']; - -if (!empty($_POST['_replyto'])) +} +if (!empty($_POST['_replyto'])) { $headers['Reply-To'] = rcmail_email_input_format(get_input_value('_replyto', RCUBE_INPUT_POST, TRUE, $message_charset)); -else if (!empty($identity_arr['reply-to'])) +} +else if (!empty($identity_arr['reply-to'])) { $headers['Reply-To'] = rcmail_email_input_format($identity_arr['reply-to'], false, true); - -if (!empty($_POST['_mailfollowupto'])) - $headers['Mail-Followup-To'] = rcmail_email_input_format(get_input_value('_mailfollowupto', RCUBE_INPUT_POST, TRUE, $message_charset)); -if (!empty($_POST['_mailreplyto'])) - $headers['Mail-Reply-To'] = rcmail_email_input_format(get_input_value('_mailreplyto', RCUBE_INPUT_POST, TRUE, $message_charset)); - -if (!empty($_SESSION['compose']['reply_msgid'])) +} +if (!empty($headers['Reply-To'])) { + $headers['Mail-Reply-To'] = $headers['Reply-To']; +} +if (!empty($_POST['_followupto'])) { + $headers['Mail-Followup-To'] = rcmail_email_input_format(get_input_value('_followupto', RCUBE_INPUT_POST, TRUE, $message_charset)); +} +if (!empty($_SESSION['compose']['reply_msgid'])) { $headers['In-Reply-To'] = $_SESSION['compose']['reply_msgid']; +} // remember reply/forward UIDs in special headers -if (!empty($_SESSION['compose']['reply_uid']) && $savedraft) +if (!empty($_SESSION['compose']['reply_uid']) && $savedraft) { $headers['X-Draft-Info'] = array('type' => 'reply', 'uid' => $_SESSION['compose']['reply_uid']); -else if (!empty($_SESSION['compose']['forward_uid']) && $savedraft) +} +else if (!empty($_SESSION['compose']['forward_uid']) && $savedraft) { $headers['X-Draft-Info'] = array('type' => 'forward', 'uid' => $_SESSION['compose']['forward_uid']); +} -if (!empty($_SESSION['compose']['references'])) +if (!empty($_SESSION['compose']['references'])) { $headers['References'] = $_SESSION['compose']['references']; +} if (!empty($_POST['_priority'])) { $priority = intval($_POST['_priority']); $a_priorities = array(1=>'highest', 2=>'high', 4=>'low', 5=>'lowest'); - if ($str_priority = $a_priorities[$priority]) + if ($str_priority = $a_priorities[$priority]) { $headers['X-Priority'] = sprintf("%d (%s)", $priority, ucfirst($str_priority)); + } } if (!empty($_POST['_receipt'])) { @@ -359,11 +367,12 @@ if (!empty($_POST['_receipt'])) { $headers['Message-ID'] = $message_id; $headers['X-Sender'] = $from; -if (is_array($headers['X-Draft-Info'])) +if (is_array($headers['X-Draft-Info'])) { $headers['X-Draft-Info'] = rcmail_draftinfo_encode($headers['X-Draft-Info'] + array('folder' => $_SESSION['compose']['mailbox'])); - -if (!empty($CONFIG['useragent'])) +} +if (!empty($CONFIG['useragent'])) { $headers['User-Agent'] = $CONFIG['useragent']; +} // exec hook for header checking and manipulation $data = $RCMAIL->plugins->exec_hook('message_outgoing_headers', array('headers' => $headers)); @@ -441,13 +450,16 @@ if ($isHtml) { $MAIL_MIME->setHTMLBody($plugin['body']); + // replace emoticons + $plugin['body'] = rcmail_replace_emoticons($plugin['body']); + // add a plain text version of the e-mail as an alternative part. $h2t = new html2text($plugin['body'], false, true, 0); $plainTextPart = rc_wordwrap($h2t->get_text(), $LINE_LENGTH, "\r\n"); $plainTextPart = wordwrap($plainTextPart, 998, "\r\n", true); if (!$plainTextPart) { - // empty message body breaks attachment handling in drafts - $plainTextPart = "\r\n"; + // empty message body breaks attachment handling in drafts + $plainTextPart = "\r\n"; } else { // make sure all line endings are CRLF (#1486712) @@ -513,9 +525,10 @@ if (is_array($_SESSION['compose']['attachments'])) ($attachment['data'] ? false : true), ($ctype == 'message/rfc822' ? '8bit' : 'base64'), ($ctype == 'message/rfc822' ? 'inline' : 'attachment'), - $message_charset, '', '', + '', '', '', $CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL, - $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL + $CONFIG['mime_param_folding'] == 2 ? 'quoted-printable' : NULL, + '', RCMAIL_CHARSET ); } } diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc index e660207cd..45dd8e168 100644 --- a/program/steps/mail/show.inc +++ b/program/steps/mail/show.inc @@ -196,8 +196,11 @@ else if ($MESSAGE && $MESSAGE->headers && !$MESSAGE->headers->seen && ($RCMAIL->action == 'show' || ($RCMAIL->action == 'preview' && intval($CONFIG['preview_pane_mark_read']) == 0))) { - if ($IMAP->set_flag($MESSAGE->uid, 'SEEN') && $_SESSION['unseen_count'][$mbox_name]) - $_SESSION['unseen_count'][$mbox_name] -= 1; + if ($IMAP->set_flag($MESSAGE->uid, 'SEEN')) { + if ($count = rcmail_get_unseen_count($mbox_name)) { + rcmail_set_unseen_count($mbox_name, $count - 1); + } + } } exit; diff --git a/program/steps/settings/edit_folder.inc b/program/steps/settings/edit_folder.inc new file mode 100644 index 000000000..3a7c0d946 --- /dev/null +++ b/program/steps/settings/edit_folder.inc @@ -0,0 +1,294 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +// WARNING: folder names in UI are encoded with RCMAIL_CHARSET + +// init IMAP connection +$RCMAIL->imap_connect(); + +function rcube_folder_form($attrib) +{ + global $RCMAIL; + + // edited folder name (empty in create-folder mode) + $mbox = trim(get_input_value('_mbox', RCUBE_INPUT_GPC, true)); + $mbox_imap = rcube_charset_convert($mbox, RCMAIL_CHARSET, 'UTF7-IMAP'); + + // predefined path for new folder + $parent = trim(get_input_value('_path', RCUBE_INPUT_GPC, true)); + $parent_imap = rcube_charset_convert($parent, RCMAIL_CHARSET, 'UTF7-IMAP'); + + $delimiter = $RCMAIL->imap->get_hierarchy_delimiter(); + $special = (strlen($mbox_imap) && in_array($mbox_imap, (array) $RCMAIL->config->get('default_imap_folders'))); + $protected = ($special && $RCMAIL->config->get('protect_default_folders')); + $threading_supported = $RCMAIL->imap->get_capability('thread=references') + || $IMAP->get_capability('thread=orderedsubject') + || $IMAP->get_capability('thread=refs'); + + // Get mailbox stats (messages count, etc.), mailbox name and parent + if (strlen($mbox)) { + $msgcount = $RCMAIL->imap->messagecount($mbox_imap, 'ALL', true, false); + + $path = explode($delimiter, $mbox_imap); + $folder = array_pop($path); + $path = implode($delimiter, $path); + + $folder = rcube_charset_convert($folder, 'UTF7-IMAP'); + + $hidden_fields = array('name' => '_mbox', 'value' => $mbox); + } + else { + $path = $parent_imap; + } + + $form = array(); + + // General tab + $form['props'] = array( + 'name' => rcube_label('properties'), + ); + + // Location (name) + if ($protected) + $foldername = rcmail_localize_foldername($mbox_imap); + else { + if (isset($_POST['_name'])) + $folder = trim(get_input_value('_name', RCUBE_INPUT_POST, true)); + + $foldername = new html_inputfield(array('name' => '_name', 'id' => '_name', 'size' => 30)); + $foldername = $foldername->show($folder); + + if ($special) + $foldername .= ' (' . rcmail_localize_foldername($mbox_imap) .')'; + } + + $form['props']['fieldsets']['location'] = array( + 'name' => rcube_label('location'), + 'content' => array( + 'name' => array( + 'label' => rcube_label('foldername'), + 'value' => $foldername, + ), + ), + ); + + if (strlen($path)) { + $radio1 = new html_radiobutton(array('name' => '_parent', 'value' => '')); + $radio2 = new html_radiobutton(array('name' => '_parent', 'value' => $path)); + $selected = isset($_POST['_parent']) ? $_POST['_parent'] : $path; + + $html_path = str_replace($delimiter, ' » ', rcmail_localize_folderpath($path)); + + $folderpath = $radio1->show($selected) . Q(rcube_label('none')) . ' ' + .$radio2->show($selected) . Q($html_path); + + $form['props']['fieldsets']['location']['content']['path'] = array( + 'label' => rcube_label('parentfolder'), + 'value' => $folderpath, + ); + } + + // Settings + $form['props']['fieldsets']['settings'] = array( + 'name' => rcube_label('settings'), + ); + + // Settings: threading + if ($threading_supported) { + $select = new html_select(array('name' => '_viewmode', 'id' => '_listmode')); + $select->add(rcube_label('list'), 0); + $select->add(rcube_label('threads'), 1); + + if (isset($_POST['_viewmode'])) { + $value = (int) $_POST['_viewmode']; + } + else if (strlen($mbox_imap)) { + $a_threaded = $RCMAIL->config->get('message_threading', array()); + $value = (int) isset($a_threaded[$mbox_imap]); + } + + $form['props']['fieldsets']['settings']['content']['viewmode'] = array( + 'label' => rcube_label('listmode'), + 'value' => $select->show($value), + ); + } +/* + // Settings: sorting column + $select = new html_select(array('name' => '_sortcol', 'id' => '_sortcol')); + $select->add(rcube_label('nonesort'), ''); + $select->add(rcube_label('arrival'), 'arrival'); + $select->add(rcube_label('sentdate'), 'date'); + $select->add(rcube_label('subject'), 'subject'); + $select->add(rcube_label('fromto'), 'from'); + $select->add(rcube_label('replyto'), 'replyto'); + $select->add(rcube_label('cc'), 'cc'); + $select->add(rcube_label('size'), 'size'); + + $value = isset($_POST['_sortcol']) ? $_POST['_sortcol'] : ''; + + $form['props']['fieldsets']['settings']['content']['sortcol'] = array( + 'label' => rcube_label('listsorting'), + 'value' => $select->show($value), + ); + + // Settings: sorting order + $select = new html_select(array('name' => '_sortord', 'id' => '_sortord')); + $select->add(rcube_label('asc'), 'ASC'); + $select->add(rcube_label('desc'), 'DESC'); + + $value = isset($_POST['_sortord']) ? $_POST['_sortord'] : ''; + + $form['props']['fieldsets']['settings']['content']['sortord'] = array( + 'label' => rcube_label('listorder'), + 'value' => $select->show(), + ); +*/ + // Information (count, size) - Edit mode + if (strlen($mbox)) { + // Number of messages + $form['props']['fieldsets']['info'] = array( + 'name' => rcube_label('info'), + 'content' => array( + 'count' => array( + 'label' => rcube_label('messagecount'), + 'value' => (int) $msgcount, + ), + ), + ); + + // Size + if ($msgcount) { + // create link with folder-size command + $onclick = sprintf("return %s.command('folder-size', '%s', this)", + JS_OBJECT_NAME, JQ($mbox_imap)); + $size = html::a(array('href' => '#', 'onclick' => $onclick, 'id' => 'folder-size'), + rcube_label('getfoldersize')); + } + else { + // no messages -> zero size + $size = 0; + } + $form['props']['fieldsets']['info']['content']['size'] = array( + 'label' => rcube_label('size'), + 'value' => $size, + ); + } + + // Allow plugins to modify folder form content + $plugin = $RCMAIL->plugins->exec_hook('folder_form', array('form' => $form)); + + $form = $plugin['form']; + + // Set form tags and hidden fields + list($form_start, $form_end) = get_form_tags($attrib, 'save-folder', null, $hidden_fields); + + unset($attrib['form']); + + // return the complete edit form as table + $out = "$form_start\n"; + + // Create form output + foreach ($form as $tab) { + if (!empty($tab['fieldsets']) && is_array($tab['fieldsets'])) { + $content = ''; + foreach ($tab['fieldsets'] as $fieldset) { + $subcontent = rcmail_get_form_part($fieldset); + if ($subcontent) { + $content .= html::tag('fieldset', null, html::tag('legend', null, Q($fieldset['name'])) . $subcontent) ."\n"; + } + } + } + else { + $content = rcmail_get_form_part($tab); + } + + if ($content) { + $out .= html::tag('fieldset', null, html::tag('legend', null, Q($tab['name'])) . $content) ."\n"; + } + } + + $out .= "\n$form_end"; + + $RCMAIL->output->set_env('messagecount', (int) $msgcount); + + return $out; +} + +function rcmail_get_form_part($form) +{ + $content = ''; + + if (is_array($form['content']) && !empty($form['content'])) { + $table = new html_table(array('cols' => 2)); + foreach ($form['content'] as $col => $colprop) { + $colprop['id'] = '_'.$col; + $label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col); + + $table->add('title', sprintf('', $colprop['id'], Q($label))); + $table->add(null, $colprop['value']); + } + $content = $table->show(); + } + else { + $content = $tag['content']; + } + + return $content; +} + +function rcmail_localize_folderpath($path) +{ + global $RCMAIL; + + $protect_folders = $RCMAIL->config->get('protect_default_folders'); + $default_folders = (array) $RCMAIL->config->get('default_imap_folders'); + $delimiter = $RCMAIL->imap->get_hierarchy_delimiter(); + $path = explode($delimiter, $path); + $result = array(); + + foreach ($path as $idx => $dir) { + $directory = implode($delimiter, array_slice($path, 0, $idx+1)); + if ($protect_folders && in_array($directory, $default_folders)) { + unset($result); + $result[] = rcmail_localize_foldername($directory); + } + else if ($protect_folders && in_array($dir, $default_folders)) { + $result[] = rcmail_localize_foldername($dir); + } + else { + $result[] = rcube_charset_convert($dir, 'UTF7-IMAP'); + } + } + + return implode($delimiter, $result); +} + + +//$OUTPUT->set_pagetitle(rcube_label('folders')); + +// register UI objects +$OUTPUT->add_handlers(array( + 'folderdetails' => 'rcube_folder_form', +)); + +$OUTPUT->add_label('nonamewarning'); + +$OUTPUT->send('folderedit'); diff --git a/program/steps/settings/edit_identity.inc b/program/steps/settings/edit_identity.inc index ef2be6584..f458cbfee 100644 --- a/program/steps/settings/edit_identity.inc +++ b/program/steps/settings/edit_identity.inc @@ -126,7 +126,8 @@ function rcube_identity_form($attrib) foreach ($fieldset['content'] as $col => $colprop) { $colprop['id'] = 'rcmfd_'.$col; - $label = !empty($colprop['label']) ? $colprop['label'] : rcube_label($col); + $label = !empty($colprop['label']) ? $colprop['label'] : + rcube_label(str_replace('-', '', $col)); $value = !empty($colprop['value']) ? $colprop['value'] : rcmail_get_edit_field($col, $IDENTITY_RECORD[$col], $colprop, $colprop['type']); diff --git a/program/steps/settings/folders.inc b/program/steps/settings/folders.inc new file mode 100644 index 000000000..7ae4fb35d --- /dev/null +++ b/program/steps/settings/folders.inc @@ -0,0 +1,377 @@ + | + | Author: Aleksander Machniak | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +// WARNING: folder names in UI are encoded with RCMAIL_CHARSET + +// init IMAP connection +$RCMAIL->imap_connect(); + +// subscribe mailbox +if ($RCMAIL->action == 'subscribe') +{ + $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true, 'UTF7-IMAP'); + if (strlen($mbox)) { + $result = $IMAP->subscribe(array($mbox)); + + // Handle virtual (non-existing) folders + if (!$result && $IMAP->get_error_code() == -1 && + $IMAP->get_response_code() == rcube_imap::TRYCREATE + ) { + $result = $IMAP->create_mailbox($mbox, true); + if ($result) { + // @TODO: remove 'virtual' class of folder's row + } + } + + if ($result) + $OUTPUT->show_message('foldersubscribed', 'confirmation'); + else + rcmail_display_server_error('errorsaving'); + } +} + +// unsubscribe mailbox +else if ($RCMAIL->action == 'unsubscribe') +{ + $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true, 'UTF7-IMAP'); + if (strlen($mbox)) { + $result = $IMAP->unsubscribe(array($mbox)); + if ($result) + $OUTPUT->show_message('folderunsubscribed', 'confirmation'); + else + rcmail_display_server_error('errorsaving'); + } +} + +// delete an existing mailbox +else if ($RCMAIL->action == 'delete-folder') +{ + $mbox_utf8 = get_input_value('_mbox', RCUBE_INPUT_POST, true); + $mbox = rcube_charset_convert($mbox_utf8, RCMAIL_CHARSET, 'UTF7-IMAP'); + + // get folder's children or all folders if the name contains special characters + $delimiter = $IMAP->get_hierarchy_delimiter(); + if ((strpos($mbox, '%') === false) && (strpos($mbox, '*') === false)) + $a_mboxes = $IMAP->list_unsubscribed('', $mbox.$delimiter.'*'); + else + $a_mboxes = $IMAP->list_unsubscribed(); + + if (strlen($mbox)) + $deleted = $IMAP->delete_mailbox($mbox); + + if ($OUTPUT->ajax_call && $deleted) { + // Remove folder and subfolders rows + $OUTPUT->command('remove_folder_row', $mbox_utf8); + foreach ($a_mboxes as $folder) { + if (preg_match('/^'. preg_quote($mbox.$delimiter, '/') .'/', $folder)) { + $OUTPUT->command('remove_folder_row', rcube_charset_convert($folder, 'UTF7-IMAP')); + } + } + $OUTPUT->show_message('folderdeleted', 'confirmation'); + // Clear content frame + $OUTPUT->command('subscription_select'); + $OUTPUT->command('set_quota', rcmail_quota_content()); + } + else if (!$deleted) { + rcmail_display_server_error('errorsaving'); + } +} + +// rename an existing mailbox +else if ($RCMAIL->action == 'rename-folder') +{ + $name_utf8 = trim(get_input_value('_folder_newname', RCUBE_INPUT_POST, true)); + $oldname_utf8 = trim(get_input_value('_folder_oldname', RCUBE_INPUT_POST, true)); + + if (strlen($name_utf8) && strlen($oldname_utf8)) { + $name = rcube_charset_convert($name_utf8, RCMAIL_CHARSET, 'UTF7-IMAP'); + $oldname = rcube_charset_convert($oldname_utf8, RCMAIL_CHARSET, 'UTF7-IMAP'); + + $rename = rcmail_rename_folder($oldname, $name); + } + + if ($rename && $OUTPUT->ajax_call) { + $folderlist = $IMAP->list_unsubscribed(); + $delimiter = $IMAP->get_hierarchy_delimiter(); + + $regexp = '/^' . preg_quote($name . $delimiter, '/') . '/'; + + // subfolders + for ($x=sizeof($folderlist)-1; $x>=0; $x--) { + if (preg_match($regexp, $folderlist[$x])) { + $oldfolder = $oldname . $delimiter . preg_replace($regexp, '', $folderlist[$x]); + $foldersplit = explode($delimiter, $folderlist[$x]); + $level = count($foldersplit) - 1; + $display_rename = str_repeat('    ', $level) + . rcube_charset_convert($foldersplit[$level], 'UTF7-IMAP'); + + $before = isset($folderlist[$x+1]) ? rcube_charset_convert($folderlist[$x+1], 'UTF7-IMAP') : false; + + $OUTPUT->command('replace_folder_row', rcube_charset_convert($oldfolder, 'UTF7-IMAP'), + rcube_charset_convert($folderlist[$x], 'UTF7-IMAP'), $display_rename, $before); + } + } + + $foldersplit = explode($delimiter, $name); + $level = count($foldersplit) - 1; + $display_rename = str_repeat('    ', $level) . rcube_charset_convert($foldersplit[$level], 'UTF7-IMAP'); + $index = array_search($name, $folderlist); + $before = $index !== false && isset($folderlist[$index+1]) ? rcube_charset_convert($folderlist[$index+1], 'UTF7-IMAP') : false; + + $OUTPUT->command('replace_folder_row', $oldname_utf8, + rcube_charset_convert($name, 'UTF7-IMAP'), $display_rename, $before); + } + else if (!$rename) { + rcmail_display_server_error('errorsaving'); + } +} + +// clear mailbox +else if ($RCMAIL->action == 'purge') +{ + $mbox_utf8 = get_input_value('_mbox', RCUBE_INPUT_POST, true); + $mbox = rcube_charset_convert($mbox_utf8, RCMAIL_CHARSET, 'UTF7-IMAP'); + $delimiter = $IMAP->get_hierarchy_delimiter(); + $trash_regexp = '/^' . preg_quote($CONFIG['trash_mbox'] . $delimiter, '/') . '/'; + + // we should only be purging trash (or their subfolders) + if (!strlen($CONFIG['trash_mbox']) || $mbox == $CONFIG['trash_mbox'] + || preg_match($trash_regexp, $mbox) + ) { + $success = $IMAP->clear_mailbox($mbox); + $delete = true; + } + // copy to Trash + else { + $success = $IMAP->move_message('1:*', $CONFIG['trash_mbox'], $mbox); + $delete = false; + } + + if ($success) { + $OUTPUT->set_env('messagecount', 0); + if ($delete) { + $OUTPUT->show_message('folderpurged', 'confirmation'); + $OUTPUT->command('set_quota', rcmail_quota_content()); + } + else { + $OUTPUT->show_message('messagemoved', 'confirmation'); + } + $_SESSION['unseen_count'][$mbox] = 0; + $OUTPUT->command('show_folder', $mbox_utf8, null, true); + } + else { + rcmail_display_server_error('errorsaving'); + } +} + +// get mailbox size +else if ($RCMAIL->action == 'folder-size') +{ + $name = trim(get_input_value('_mbox', RCUBE_INPUT_POST, true)); + + $size = $IMAP->get_mailbox_size($name); + + // @TODO: check quota and show percentage usage of specified mailbox? + + if ($size !== false) { + $OUTPUT->command('folder_size_update', show_bytes($size)); + } + else { + rcmail_display_server_error(); + } +} + +if ($OUTPUT->ajax_call) + $OUTPUT->send(); + + +// build table with all folders listed by server +function rcube_subscription_form($attrib) +{ + global $RCMAIL, $IMAP, $CONFIG, $OUTPUT; + + list($form_start, $form_end) = get_form_tags($attrib, 'folders'); + unset($attrib['form']); + + if (!$attrib['id']) + $attrib['id'] = 'rcmSubscriptionlist'; + + $table = new html_table(); + + if ($attrib['noheader'] !== true && $attrib['noheader'] != "true") { + // add table header + $table->add_header('name', rcube_label('foldername')); + $table->add_header('subscribed', ''); + } + + // get folders from server + $IMAP->clear_cache('mailboxes'); + + $a_unsubscribed = $IMAP->list_unsubscribed(); + $a_subscribed = $IMAP->list_mailboxes(); + $delimiter = $IMAP->get_hierarchy_delimiter(); + $a_js_folders = array(); + $seen = array(); + $list_folders = array(); + + // pre-process folders list + foreach ($a_unsubscribed as $i => $folder) { + $foldersplit = explode($delimiter, $folder); + $name = rcube_charset_convert(array_pop($foldersplit), 'UTF7-IMAP'); + $parent_folder = join($delimiter, $foldersplit); + $level = count($foldersplit); + + // add any necessary "virtual" parent folders + if ($parent_folder && !$seen[$parent_folder]) { + for ($i=1; $i<=$level; $i++) { + $ancestor_folder = join($delimiter, array_slice($foldersplit, 0, $i)); + if ($ancestor_folder && !$seen[$ancestor_folder]++) { + $ancestor_name = rcube_charset_convert($foldersplit[$i-1], 'UTF7-IMAP'); + $list_folders[] = array( + 'id' => $ancestor_folder, + 'name' => $ancestor_name, + 'level' => $i-1, + 'virtual' => true, + ); + } + } + } + + $seen[$folder]++; + + $list_folders[] = array( + 'id' => $folder, + 'name' => $name, + 'level' => $level, + ); + } + + unset($seen); + + $checkbox_subscribe = new html_checkbox(array( + 'name' => '_subscribed[]', + 'title' => rcube_label('changesubscription'), + 'onclick' => JS_OBJECT_NAME.".command(this.checked?'subscribe':'unsubscribe',this.value)", + )); + + // create list of available folders + foreach ($list_folders as $i => $folder) { + $idx = $i + 1; + $subscribed = in_array($folder['id'], $a_subscribed); + $protected = ($CONFIG['protect_default_folders'] == true && in_array($folder['id'], $CONFIG['default_imap_folders'])); + $classes = array($i%2 ? 'even' : 'odd'); + + $folder_js = Q($folder['id']); + $folder_utf8 = rcube_charset_convert($folder['id'], 'UTF7-IMAP'); + $display_folder = str_repeat('    ', $folder['level']) + . Q($protected ? rcmail_localize_foldername($folder['id']) : $folder['name']); + + if ($folder['virtual']) { + $classes[] = 'virtual'; + } + + if (!$protected) { + $opts = $IMAP->mailbox_options($folder['id']); + $noselect = in_array('\\Noselect', $opts); + } + + $table->add_row(array('id' => 'rcmrow'.$idx, 'class' => join(' ', $classes))); + + $table->add('name', $display_folder); + $table->add('subscribed', $checkbox_subscribe->show(($subscribed ? $folder_utf8 : ''), + array('value' => $folder_utf8, 'disabled' => ($protected || $noselect) ? 'disabled' : ''))); + + $a_js_folders['rcmrow'.$idx] = array($folder_utf8, Q($display_folder), $protected || $folder['virtual']); + } + + $RCMAIL->plugins->exec_hook('folders_list', array('table' => $table)); + + $OUTPUT->add_gui_object('subscriptionlist', $attrib['id']); + $OUTPUT->set_env('subscriptionrows', $a_js_folders); + $OUTPUT->set_env('defaultfolders', $CONFIG['default_imap_folders']); + $OUTPUT->set_env('delimiter', $delimiter); + + return $form_start . $table->show($attrib) . $form_end; +} + +function rcmail_folder_frame($attrib) +{ + global $OUTPUT; + + if (!$attrib['id']) + $attrib['id'] = 'rcmfolderframe'; + + $attrib['name'] = $attrib['id']; + + $OUTPUT->set_env('contentframe', $attrib['name']); + $OUTPUT->set_env('blankpage', $attrib['src'] ? $OUTPUT->abs_url($attrib['src']) : 'program/blank.gif'); + + return html::iframe($attrib); +} + +function rcmail_rename_folder($oldname, $newname) +{ + global $RCMAIL; + + $delimiter = $RCMAIL->imap->get_hierarchy_delimiter(); + $rename = $RCMAIL->imap->rename_mailbox($oldname, $newname); + + // update per-folder options for modified folder and its subfolders + if ($rename !== false) { + $a_threaded = (array) $RCMAIL->config->get('message_threading', array()); + $oldprefix = '/^' . preg_quote($oldname . $delimiter, '/') . '/'; + + foreach ($a_threaded as $key => $val) { + if ($key == $oldname) { + unset($a_threaded[$key]); + $a_threaded[$newname] = true; + } + else if (preg_match($oldprefix, $key)) { + unset($a_threaded[$key]); + $a_threaded[preg_replace($oldprefix, $newname.$delimiter, $key)] = true; + } + } + $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded)); + + return true; + } + + return false; +} + +$OUTPUT->set_pagetitle(rcube_label('folders')); +$OUTPUT->include_script('list.js'); +$OUTPUT->set_env('quota', $IMAP->get_capability('QUOTA')); + +// add some labels to client +$OUTPUT->add_label('deletefolderconfirm', 'purgefolderconfirm', 'folderdeleting', + 'foldermoving', 'foldersubscribing', 'folderunsubscribing', 'quota'); + +// register UI objects +$OUTPUT->add_handlers(array( + 'foldersubscription' => 'rcube_subscription_form', + 'folderframe' => 'rcmail_folder_frame', + 'quotadisplay' => 'rcmail_quota_display', +)); + +$OUTPUT->send('folders'); + diff --git a/program/steps/settings/manage_folders.inc b/program/steps/settings/manage_folders.inc deleted file mode 100644 index 3a5d909e4..000000000 --- a/program/steps/settings/manage_folders.inc +++ /dev/null @@ -1,443 +0,0 @@ - | - +-----------------------------------------------------------------------+ - - $Id$ - -*/ - -// WARNING: folder names in UI are encoded with RCMAIL_CHARSET - -// init IMAP connection -$RCMAIL->imap_connect(); - -// subscribe to one or more mailboxes -if ($RCMAIL->action=='subscribe') - { - $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true, 'UTF7-IMAP'); - if (strlen($mbox)) - $IMAP->subscribe(array($mbox)); - } - -// unsubscribe one or more mailboxes -else if ($RCMAIL->action=='unsubscribe') - { - $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true, 'UTF7-IMAP'); - if (strlen($mbox)) - $IMAP->unsubscribe(array($mbox)); - } - -// enable threading for one or more mailboxes -else if ($RCMAIL->action=='enable-threading') - { - $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true, 'UTF7-IMAP'); - if (strlen($mbox)) - rcube_set_threading($mbox, true); - } - -// enable threading for one or more mailboxes -else if ($RCMAIL->action=='disable-threading') - { - $mbox = get_input_value('_mbox', RCUBE_INPUT_POST, true, 'UTF7-IMAP'); - if (strlen($mbox)) - rcube_set_threading($mbox, false); - } - -// create a new mailbox -else if ($RCMAIL->action=='create-folder') - { - if (strlen(trim($_POST['_name']))) - { - $name = trim(get_input_value('_name', RCUBE_INPUT_POST, true, 'UTF7-IMAP')); - $create = $IMAP->create_mailbox($name, TRUE); - } - - if ($create && $OUTPUT->ajax_call) - { - $delimiter = $IMAP->get_hierarchy_delimiter(); - $folderlist = $IMAP->list_unsubscribed(); - $index = array_search($create, $folderlist); - $before = $index !== false && isset($folderlist[$index+1]) ? rcube_charset_convert($folderlist[$index+1], 'UTF7-IMAP') : false; - - $create = rcube_charset_convert($create, 'UTF7-IMAP'); - $foldersplit = explode($delimiter, $create); - $display_create = str_repeat('    ', substr_count($create, $delimiter)) - . Q($foldersplit[count($foldersplit)-1]); - - $OUTPUT->command('add_folder_row', $create, $display_create, false, $before); - } - else if (!$create) - { - $OUTPUT->show_message('errorsaving', 'error'); - } - } - -// rename a mailbox -else if ($RCMAIL->action=='rename-folder') - { - if (strlen(trim($_POST['_folder_oldname'])) && strlen(trim($_POST['_folder_newname']))) - { - $name_utf8 = trim(get_input_value('_folder_newname', RCUBE_INPUT_POST, true)); - $oldname_utf8 = get_input_value('_folder_oldname', RCUBE_INPUT_POST, true); - $name = rcube_charset_convert($name_utf8, RCMAIL_CHARSET, 'UTF7-IMAP'); - $oldname = rcube_charset_convert($oldname_utf8, RCMAIL_CHARSET, 'UTF7-IMAP'); - - $rename = $IMAP->rename_mailbox($oldname, $name); - } - - // update per-folder options for modified folder and its subfolders - if ($rename) { - $a_threaded = $RCMAIL->config->get('message_threading', array()); - $delimiter = $IMAP->get_hierarchy_delimiter(); - $oldprefix = '/^' . preg_quote($oldname . $delimiter, '/') . '/'; - foreach ($a_threaded as $key => $val) - if ($key == $oldname) { - unset($a_threaded[$key]); - $a_threaded[$name] = true; - } - else if (preg_match($oldprefix, $key)) { - unset($a_threaded[$key]); - $a_threaded[preg_replace($oldprefix, $name.$delimiter, $key)] = true; - } - - $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded)); - } - - if ($rename && $OUTPUT->ajax_call) - { - $folderlist = $IMAP->list_unsubscribed(); - $delimiter = $IMAP->get_hierarchy_delimiter(); - - $regexp = '/^' . preg_quote($rename . $delimiter, '/') . '/'; - - // subfolders - for ($x=sizeof($folderlist)-1; $x>=0; $x--) - { - if (preg_match($regexp, $folderlist[$x])) - { - $oldfolder = $oldname . $delimiter . preg_replace($regexp, '', $folderlist[$x]); - $foldersplit = explode($delimiter, $folderlist[$x]); - $level = count($foldersplit) - 1; - $display_rename = str_repeat('    ', $level) - . Q(rcube_charset_convert($foldersplit[$level], 'UTF7-IMAP')); - - $before = isset($folderlist[$x+1]) ? rcube_charset_convert($folderlist[$x+1], 'UTF7-IMAP') : false; - - $OUTPUT->command('replace_folder_row', rcube_charset_convert($oldfolder, 'UTF7-IMAP'), - rcube_charset_convert($folderlist[$x], 'UTF7-IMAP'), $display_rename, $before); - } - } - - $foldersplit = explode($delimiter, $rename); - $level = count($foldersplit) - 1; - $display_rename = str_repeat('    ', $level) . Q(rcube_charset_convert($foldersplit[$level], 'UTF7-IMAP')); - $index = array_search($rename, $folderlist); - $before = $index !== false && isset($folderlist[$index+1]) ? rcube_charset_convert($folderlist[$index+1], 'UTF7-IMAP') : false; - - $OUTPUT->command('replace_folder_row', $oldname_utf8, rcube_charset_convert($rename, 'UTF7-IMAP'), $display_rename, $before); - $OUTPUT->command('reset_folder_rename'); - } - else if (!$rename && $OUTPUT->ajax_call) - { - $OUTPUT->command('reset_folder_rename'); - $OUTPUT->show_message('errorsaving', 'error'); - } - else if (!$rename) - $OUTPUT->show_message('errorsaving', 'error'); - } - -// delete an existing IMAP mailbox -else if ($RCMAIL->action=='delete-folder') - { - $a_mboxes = $IMAP->list_unsubscribed(); - $delimiter = $IMAP->get_hierarchy_delimiter(); - - $mboxes_utf8 = get_input_value('_mboxes', RCUBE_INPUT_POST, true); - $mboxes = rcube_charset_convert($mboxes_utf8, RCMAIL_CHARSET, 'UTF7-IMAP'); - - if (strlen($mboxes)) - $deleted = $IMAP->delete_mailbox(array($mboxes)); - - if ($OUTPUT->ajax_call && $deleted) - { - $OUTPUT->command('remove_folder_row', $mboxes_utf8); - foreach ($a_mboxes as $mbox) - { - if (preg_match('/^'. preg_quote($mboxes.$delimiter, '/') .'/', $mbox)) - { - $OUTPUT->command('remove_folder_row', rcube_charset_convert($mbox, 'UTF7-IMAP')); - } - } - $OUTPUT->show_message('folderdeleted', 'confirmation'); - } - else if (!$deleted) - { - $OUTPUT->show_message('errorsaving', 'error'); - } - } - -if ($OUTPUT->ajax_call) - $OUTPUT->send(); - - -// build table with all folders listed by server -function rcube_subscription_form($attrib) - { - global $RCMAIL, $IMAP, $CONFIG, $OUTPUT; - - $threading_supported = $IMAP->get_capability('thread=references') - || $IMAP->get_capability('thread=orderedsubject') - || $IMAP->get_capability('thread=refs'); - - list($form_start, $form_end) = get_form_tags($attrib, 'folders'); - unset($attrib['form']); - - if (!$attrib['id']) - $attrib['id'] = 'rcmSubscriptionlist'; - - $table = new html_table(); - - // add table header - $table->add_header('name', rcube_label('foldername')); - $table->add_header('msgcount', rcube_label('messagecount')); - $table->add_header('subscribed', rcube_label('subscribed')); - if ($threading_supported) - $table->add_header('threaded', rcube_label('threaded')); - $table->add_header('rename', ' '); - $table->add_header('delete', ' '); - - // get folders from server - $IMAP->clear_cache('mailboxes'); - - $a_unsubscribed = $IMAP->list_unsubscribed(); - $a_subscribed = $IMAP->list_mailboxes(); - $a_threaded = $a_threaded_copy = $RCMAIL->config->get('message_threading', array()); - $delimiter = $IMAP->get_hierarchy_delimiter(); - $a_js_folders = $seen = $list_folders = array(); - - // pre-process folders list - foreach ($a_unsubscribed as $i => $folder) { - $foldersplit = explode($delimiter, $folder); - $name = rcube_charset_convert(array_pop($foldersplit), 'UTF7-IMAP'); - $parent_folder = join($delimiter, $foldersplit); - $level = count($foldersplit); - - // add any necessary "virtual" parent folders - if ($parent_folder && !$seen[$parent_folder]) { - for ($i=1; $i<=$level; $i++) { - $ancestor_folder = join($delimiter, array_slice($foldersplit, 0, $i)); - if ($ancestor_folder && !$seen[$ancestor_folder]++) { - $ancestor_name = rcube_charset_convert($foldersplit[$i-1], 'UTF7-IMAP'); - $list_folders[] = array('id' => $ancestor_folder, 'name' => $ancestor_name, 'level' => $i-1, 'virtual' => true); - } - } - } - - unset($a_threaded_copy[$folder]); - - $list_folders[] = array('id' => $folder, 'name' => $name, 'level' => $level); - $seen[$folder]++; - } - - unset($seen); - - // remove 'message_threading' option for not existing folders - if ($a_threaded_copy) { - foreach ($a_threaded_copy as $key => $val) - unset($a_threaded[$key]); - unset($a_threaded_copy); - $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded)); - } - - $checkbox_subscribe = new html_checkbox(array( - 'name' => '_subscribed[]', - 'onclick' => JS_OBJECT_NAME.".command(this.checked?'subscribe':'unsubscribe',this.value)", - )); - $checkbox_threaded = new html_checkbox(array( - 'name' => '_threaded[]', - 'onclick' => JS_OBJECT_NAME.".command(this.checked?'enable-threading':'disable-threading',this.value)", - )); - - if (!empty($attrib['deleteicon'])) - $del_button = html::img(array('src' => $CONFIG['skin_path'] . $attrib['deleteicon'], 'alt' => rcube_label('delete'))); - else - $del_button = rcube_label('delete'); - - if (!empty($attrib['renameicon'])) - $edit_button = html::img(array('src' => $CONFIG['skin_path'] . $attrib['renameicon'], 'alt' => rcube_label('rename'))); - else - $edit_button = rcube_label('rename'); - - // create list of available folders - foreach ($list_folders as $i => $folder) { - $idx = $i + 1; - $subscribed = in_array($folder['id'], $a_subscribed); - $threaded = $a_threaded[$folder['id']]; - $protected = ($CONFIG['protect_default_folders'] == true && in_array($folder['id'], $CONFIG['default_imap_folders'])); - $classes = array($i%2 ? 'even' : 'odd'); - $folder_js = Q($folder['id']); - $display_folder = str_repeat('    ', $folder['level']) . Q($protected ? rcmail_localize_foldername($folder['id']) : $folder['name']); - $folder_utf8 = rcube_charset_convert($folder['id'], 'UTF7-IMAP'); - - if ($folder['virtual']) { - $classes[] = 'virtual'; - } - - if (!$protected) { - $opts = $IMAP->mailbox_options($folder['id']); - $noselect = in_array('\\Noselect', $opts); - } - - $table->add_row(array('id' => 'rcmrow'.$idx, 'class' => join(' ', $classes))); - - $table->add('name', $display_folder); - $table->add('msgcount', (($folder['virtual'] || $noselect) ? '' : $IMAP->messagecount($folder['id'], 'ALL', false, false))); - $table->add('subscribed', $checkbox_subscribe->show(($subscribed ? $folder_utf8 : ''), - array('value' => $folder_utf8, 'disabled' => ($protected || $noselect) ? 'disabled' : ''))); - if ($threading_supported) { - $table->add('threaded', $folder['virtual'] ? '' : - $checkbox_threaded->show(($threaded ? $folder_utf8 : ''), array('value' => $folder_utf8))); - } - - // add rename and delete buttons - if (!$protected && !$folder['virtual']) { - $table->add('rename', html::a(array('href' => "#rename", 'title' => rcube_label('renamefolder')), $edit_button)); - $table->add('delete', html::a(array('href' => "#delete", 'title' => rcube_label('deletefolder')), $del_button)); - } - else { - $table->add('rename', ' '); - $table->add('delete', ' '); - } - - $a_js_folders['rcmrow'.$idx] = array($folder_utf8, Q($display_folder), $protected || $folder['virtual']); - } - - rcmail::get_instance()->plugins->exec_hook('folders_list', array('table' => $table)); - - $OUTPUT->add_gui_object('subscriptionlist', $attrib['id']); - $OUTPUT->set_env('subscriptionrows', $a_js_folders); - $OUTPUT->set_env('defaultfolders', $CONFIG['default_imap_folders']); - $OUTPUT->set_env('delimiter', $delimiter); - - return $form_start . $table->show($attrib) . $form_end; - } - - -function rcube_create_folder_form($attrib) - { - global $OUTPUT; - - list($form_start, $form_end) = get_form_tags($attrib, 'create-folder'); - unset($attrib['form']); - - if ($attrib['hintbox']) - $OUTPUT->add_gui_object('createfolderhint', $attrib['hintbox']); - - // return the complete edit form as table - $out = "$form_start\n"; - - $input = new html_inputfield(array('name' => '_folder_name')); - $out .= $input->show(); - - if (get_boolean($attrib['button'])) - { - $button = new html_inputfield(array('type' => 'button', - 'value' => rcube_label('create'), - 'onclick' => JS_OBJECT_NAME.".command('create-folder',this.form)")); - $out .= $button->show(); - } - - $out .= "\n$form_end"; - - return $out; - } - -function rcube_rename_folder_form($attrib) - { - global $CONFIG, $IMAP; - - list($form_start, $form_end) = get_form_tags($attrib, 'rename-folder'); - unset($attrib['form']); - - // return the complete edit form as table - $out = "$form_start\n"; - - $a_unsubscribed = $IMAP->list_unsubscribed(); - $select_folder = new html_select(array('name' => '_folder_oldname', 'id' => 'rcmfd_oldfolder')); - - foreach ($a_unsubscribed as $i => $folder) - { - if ($CONFIG['protect_default_folders'] == TRUE && in_array($folder,$CONFIG['default_imap_folders'])) - continue; - - $select_folder->add($folder); - } - - $out .= $select_folder->show(); - - $out .= " to "; - $inputtwo = new html_inputfield(array('name' => '_folder_newname')); - $out .= $inputtwo->show(); - - if (get_boolean($attrib['button'])) - { - $button = new html_inputfield(array('type' => 'button', - 'value' => rcube_label('rename'), - 'onclick' => JS_OBJECT_NAME.".command('rename-folder',this.form)")); - $out .= $button->show(); - } - - $out .= "\n$form_end"; - - return $out; - } - - -// (un)set 'threading' for selected folder -function rcube_set_threading($mbox, $state=true) - { - global $RCMAIL; - $mbox = (array)$mbox; - $a_prefs = (array)$RCMAIL->config->get('message_threading'); - - if ($state) { - foreach ($mbox as $box) - $a_prefs[$box] = true; - } - else { - foreach ($mbox as $box) - unset($a_prefs[$box]); - } - - $RCMAIL->user->save_prefs(array('message_threading' => $a_prefs)); - } - - -$OUTPUT->set_pagetitle(rcube_label('folders')); -$OUTPUT->include_script('list.js'); - -// register UI objects -$OUTPUT->add_handlers(array( - 'foldersubscription' => 'rcube_subscription_form', - 'createfolder' => 'rcube_create_folder_form', - 'renamefolder' => 'rcube_rename_folder_form' -)); - -// add some labels to client -$OUTPUT->add_label('deletefolderconfirm','addsubfolderhint','forbiddencharacter','folderdeleting','folderrenaming','foldercreating','foldermoving'); - -$OUTPUT->send('managefolders'); - diff --git a/program/steps/settings/save_folder.inc b/program/steps/settings/save_folder.inc new file mode 100644 index 000000000..da646a56e --- /dev/null +++ b/program/steps/settings/save_folder.inc @@ -0,0 +1,176 @@ + | + +-----------------------------------------------------------------------+ + + $Id$ + +*/ + +// WARNING: folder names in UI are encoded with RCMAIL_CHARSET + +// init IMAP connection +$RCMAIL->imap_connect(); + + +$name = trim(get_input_value('_name', RCUBE_INPUT_POST, true)); +$old = trim(get_input_value('_mbox', RCUBE_INPUT_POST, true)); +$path = trim(get_input_value('_parent', RCUBE_INPUT_POST, true)); + +$name_imap = rcube_charset_convert($name, RCMAIL_CHARSET, 'UTF7-IMAP'); +$old_imap = rcube_charset_convert($old, RCMAIL_CHARSET, 'UTF7-IMAP'); +// $path is in UTF7-IMAP already + +$delimiter = $IMAP->get_hierarchy_delimiter(); +$special = (strlen($old_imap) && in_array($old_imap, (array) $RCMAIL->config->get('default_imap_folders'))); +$protected = ($special && $RCMAIL->config->get('protect_default_folders')); + + +// Folder name checks +if ($protected) { +} +else if (!strlen($name)) { + $error = rcube_label('cannotbeempty'); +} +else if (mb_strlen($name) > 128) { + $error = rcube_label('nametoolong'); +} +else { + // these characters are problematic e.g. when used in LIST/LSUB + foreach (array($delimiter, '%', '*') as $char) { + if (strpos($name, $delimiter) !== false) { + $error = rcube_label('forbiddencharacter') . " ($char)"; + break; + } + } +} + +if ($error) { + $OUTPUT->command('display_message', $error, 'error'); +} +else { + if ($protected) { + $name_imap = $old_imap; + } + else if (strlen($path)) { + $name_imap = $path . $delimiter . $name_imap; + } + + $folder['name'] = $name_imap; + $folder['oldname'] = $old_imap; + $folder['settings'] = array( + // List view mode: 0-list, 1-threads + 'view_mode' => (int) get_input_value('_viewmode', RCUBE_INPUT_POST), + 'sort_column' => get_input_value('_sortcol', RCUBE_INPUT_POST), + 'sort_order' => get_input_value('_sortord', RCUBE_INPUT_POST), + ); +} + +// create a new mailbox +if (!$error && !strlen($old)) { + + $plugin = $RCMAIL->plugins->exec_hook('folder_create', array('record' => $folder)); + + $folder = $plugin['record']; + + if (!$plugin['abort']) { + $created = $IMAP->create_mailbox($folder['name'], TRUE); + } + else { + $created = $plugin['result']; + } + + if ($created) { + // Save folder settings + if (isset($_POST['_viewmode'])) { + $a_threaded = (array) $RCMAIL->config->get('message_threading', array()); + + if ($_POST['_viewmode']) + $a_threaded[$folder['name']] = true; + else + unset($a_threaded[$folder['name']]); + + $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded)); + } + + $OUTPUT->show_message('foldercreated', 'confirmation'); + $OUTPUT->command('reload', 250); + $OUTPUT->send('iframe'); + } + else { + // show error message + $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); + } +} + +// update a mailbox +else if (!$error) { + $plugin = $RCMAIL->plugins->exec_hook('folder_update', array('record' => $folder)); + + $folder = $plugin['record']; + $rename = ($folder['oldname'] != $folder['name']); + + if (!$plugin['abort']) { + if ($rename) { + $updated = $RCMAIL->imap->rename_mailbox($folder['oldname'], $folder['name']); + } + else { + $updated = true; + } + } + else { + $updated = $plugin['result']; + } + + if ($updated) { + // Update folder settings, + if (isset($_POST['_viewmode'])) { + $a_threaded = (array) $RCMAIL->config->get('message_threading', array()); + + // In case of name change update names of childrens in settings + if ($rename) { + $delimiter = $RCMAIL->imap->get_hierarchy_delimiter(); + $oldprefix = '/^' . preg_quote($folder['oldname'] . $delimiter, '/') . '/'; + foreach ($a_threaded as $key => $val) { + if ($key == $folder['oldname']) { + unset($a_threaded[$key]); + } + else if (preg_match($oldprefix, $key)) { + unset($a_threaded[$key]); + $a_threaded[preg_replace($oldprefix, $folder['name'].$delimiter, $key)] = true; + } + } + } + if ($_POST['_viewmode']) + $a_threaded[$folder['name']] = true; + else + unset($a_threaded[$folder['name']]); + + $RCMAIL->user->save_prefs(array('message_threading' => $a_threaded)); + } + + $OUTPUT->show_message('folderupdated', 'confirmation'); + if ($rename) { + $OUTPUT->command('reload', 250); + $OUTPUT->send('iframe'); + } + } + else { + // show error message + $OUTPUT->show_message($plugin['message'] ? $plugin['message'] : 'errorsaving', 'error', null, false); + } +} + +rcmail_overwrite_action('edit-folder'); diff --git a/program/steps/utils/html2text.inc b/program/steps/utils/html2text.inc index ef74ec49e..15c6a52a4 100644 --- a/program/steps/utils/html2text.inc +++ b/program/steps/utils/html2text.inc @@ -19,7 +19,12 @@ */ -$converter = new html2text($HTTP_RAW_POST_DATA); +$html = $HTTP_RAW_POST_DATA; + +// Replace emoticon images with its text representation +$html = rcmail_replace_emoticons($html); + +$converter = new html2text($html); header('Content-Type: text/plain; charset=UTF-8'); print rtrim($converter->get_text()); -- cgit v1.2.3