X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=program%2Fsteps%2Fmail%2Ffunc.inc;h=3c93cda1d993acdf1e6c2a9e88726b8223281e98;hb=76507f7c63a660742e76889ad6e3919f3dde3bb0;hp=3a971bd4052387f6c54f55e686fa68b758ac1509;hpb=0af63e79917234f76cfa7ec74e9d97b24fbf9b55;p=roundcube.git diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc index 3a971bd..3c93cda 100644 --- a/program/steps/mail/func.inc +++ b/program/steps/mail/func.inc @@ -4,8 +4,8 @@ +-----------------------------------------------------------------------+ | program/steps/mail/func.inc | | | - | This file is part of the RoundCube Webmail client | - | Copyright (C) 2005, RoundCube Dev. - Switzerland | + | This file is part of the Roundcube Webmail client | + | Copyright (C) 2005-2010, The Roundcube Dev Team | | Licensed under the GNU GPL | | | | PURPOSE: | @@ -15,1514 +15,1599 @@ | Author: Thomas Bruederli | +-----------------------------------------------------------------------+ - $Id: func.inc 429 2006-12-22 22:26:24Z thomasb $ + $Id: func.inc 5601 2011-12-14 09:08:54Z alec $ */ -require_once('lib/html2text.inc'); -require_once('lib/enriched.inc'); +// setup some global vars used by mail steps +$SENT_MBOX = $RCMAIL->config->get('sent_mbox'); +$DRAFTS_MBOX = $RCMAIL->config->get('drafts_mbox'); +$SEARCH_MODS_DEFAULT = array( + '*' => array('subject'=>1, 'from'=>1), + $SENT_MBOX => array('subject'=>1, 'to'=>1), + $DRAFTS_MBOX => array('subject'=>1, 'to'=>1) +); +// actions that do not require imap connection here +$NOIMAP_ACTIONS = array('addcontact', 'autocomplete', 'upload', 'display-attachment', 'remove-attachment', 'get'); -$EMAIL_ADDRESS_PATTERN = '/([a-z0-9][a-z0-9\-\.\+\_]*@[a-z0-9]([a-z0-9\-][.]?)*[a-z0-9]\\.[a-z]{2,5})/i'; +// always instantiate imap object (but not yet connect to server) +$RCMAIL->imap_init(); -if (empty($_SESSION['mbox'])){ - $_SESSION['mbox'] = $IMAP->get_mailbox_name(); -} +// log in to imap server +if (!in_array($RCMAIL->action, $NOIMAP_ACTIONS) && !$RCMAIL->imap_connect()) { + $RCMAIL->kill_session(); -// set imap properties and session vars -if (strlen($_GET['_mbox'])) - { - $IMAP->set_mailbox($_GET['_mbox']); - $_SESSION['mbox'] = $_GET['_mbox']; - } + if ($OUTPUT->ajax_call) + $OUTPUT->redirect(array(), 2000); -if (strlen($_GET['_page'])) - { - $IMAP->set_page($_GET['_page']); - $_SESSION['page'] = $_GET['_page']; - } + $OUTPUT->set_env('task', 'login'); + $OUTPUT->send('login'); +} -// set mailbox to INBOX if not set -if (empty($_SESSION['mbox'])) +// set imap properties and session vars +if (strlen(trim($mbox = get_input_value('_mbox', RCUBE_INPUT_GPC, true)))) + $IMAP->set_mailbox(($_SESSION['mbox'] = $mbox)); +else if ($IMAP) $_SESSION['mbox'] = $IMAP->get_mailbox_name(); +if (!empty($_GET['_page'])) + $IMAP->set_page(($_SESSION['page'] = intval($_GET['_page']))); + // set default sort col/order to session if (!isset($_SESSION['sort_col'])) - $_SESSION['sort_col'] = $CONFIG['message_sort_col']; + $_SESSION['sort_col'] = !empty($CONFIG['message_sort_col']) ? $CONFIG['message_sort_col'] : ''; if (!isset($_SESSION['sort_order'])) - $_SESSION['sort_order'] = $CONFIG['message_sort_order']; - + $_SESSION['sort_order'] = strtoupper($CONFIG['message_sort_order']) == 'ASC' ? 'ASC' : 'DESC'; -// define url for getting message parts -if (strlen($_GET['_uid'])) - $GET_URL = sprintf('%s&_action=get&_mbox=%s&_uid=%d', $COMM_PATH, $IMAP->get_mailbox_name(), $_GET['_uid']); +// set threads mode +$a_threading = $RCMAIL->config->get('message_threading', array()); +if (isset($_GET['_threads'])) { + if ($_GET['_threads']) + $a_threading[$_SESSION['mbox']] = true; + else + unset($a_threading[$_SESSION['mbox']]); + $RCMAIL->user->save_prefs(array('message_threading' => $a_threading)); +} +$IMAP->set_threading($a_threading[$_SESSION['mbox']]); + +// set message set for search result +if (!empty($_REQUEST['_search']) && isset($_SESSION['search']) + && $_SESSION['search_request'] == $_REQUEST['_search'] +) { + $IMAP->set_search_set($_SESSION['search']); + $OUTPUT->set_env('search_request', $_REQUEST['_search']); + $OUTPUT->set_env('search_text', $_SESSION['last_text_search']); +} + +// set main env variables, labels and page title +if (empty($RCMAIL->action) || $RCMAIL->action == 'list') { + $mbox_name = $IMAP->get_mailbox_name(); + if (empty($RCMAIL->action)) { + // initialize searching result if search_filter is used + if ($_SESSION['search_filter'] && $_SESSION['search_filter'] != 'ALL') { + $search_request = md5($mbox_name.$_SESSION['search_filter']); -// set current mailbox in client environment -$OUTPUT->add_script(sprintf("%s.set_env('mailbox', '%s');", $JS_OBJECT_NAME, $IMAP->get_mailbox_name())); + $IMAP->search($mbox_name, $_SESSION['search_filter'], RCMAIL_CHARSET, $_SESSION['sort_col']); + $_SESSION['search'] = $IMAP->get_search_set(); + $_SESSION['search_request'] = $search_request; + $OUTPUT->set_env('search_request', $search_request); + } -if ($CONFIG['trash_mbox']) - $OUTPUT->add_script(sprintf("%s.set_env('trash_mailbox', '%s');", $JS_OBJECT_NAME, $CONFIG['trash_mbox'])); + $search_mods = $RCMAIL->config->get('search_mods', $SEARCH_MODS_DEFAULT); + $OUTPUT->set_env('search_mods', $search_mods); + } -if ($CONFIG['drafts_mbox']) - $OUTPUT->add_script(sprintf("%s.set_env('drafts_mailbox', '%s');", $JS_OBJECT_NAME, $CONFIG['drafts_mbox'])); + // set current mailbox and some other vars in client environment + $OUTPUT->set_env('mailbox', $mbox_name); + $OUTPUT->set_env('pagesize', $IMAP->page_size); + $OUTPUT->set_env('quota', $IMAP->get_capability('QUOTA')); + $OUTPUT->set_env('delimiter', $IMAP->get_hierarchy_delimiter()); + $OUTPUT->set_env('threading', (bool) $IMAP->threading); + $OUTPUT->set_env('threads', $IMAP->threading || $IMAP->get_capability('THREAD')); + $OUTPUT->set_env('preview_pane_mark_read', $RCMAIL->config->get('preview_pane_mark_read', 0)); + + if ($CONFIG['flag_for_deletion']) + $OUTPUT->set_env('flag_for_deletion', true); + if ($CONFIG['read_when_deleted']) + $OUTPUT->set_env('read_when_deleted', true); + if ($CONFIG['skip_deleted']) + $OUTPUT->set_env('skip_deleted', true); + if ($CONFIG['display_next']) + $OUTPUT->set_env('display_next', true); + if ($CONFIG['forward_attachment']) + $OUTPUT->set_env('forward_attachment', true); + if ($CONFIG['trash_mbox']) + $OUTPUT->set_env('trash_mailbox', $CONFIG['trash_mbox']); + if ($CONFIG['drafts_mbox']) + $OUTPUT->set_env('drafts_mailbox', $CONFIG['drafts_mbox']); + if ($CONFIG['junk_mbox']) + $OUTPUT->set_env('junk_mailbox', $CONFIG['junk_mbox']); + + if (!$OUTPUT->ajax_call) + $OUTPUT->add_label('checkingmail', 'deletemessage', 'movemessagetotrash', + 'movingmessage', 'copyingmessage', 'deletingmessage', 'markingmessage', + 'copy', 'move', 'quota'); + + $OUTPUT->set_pagetitle(rcmail_localize_foldername($IMAP->mod_mailbox($mbox_name))); +} -if ($CONFIG['junk_mbox']) - $OUTPUT->add_script(sprintf("%s.set_env('junk_mailbox', '%s');", $JS_OBJECT_NAME, $CONFIG['junk_mbox'])); -// return the mailboxlist in HTML -function rcmail_mailbox_list($attrib) - { - global $IMAP, $CONFIG, $OUTPUT, $JS_OBJECT_NAME, $COMM_PATH; - static $s_added_script = FALSE; - static $a_mailboxes; +/** + * return the message list as HTML table + */ +function rcmail_message_list($attrib) +{ + global $IMAP, $CONFIG, $OUTPUT; // add some labels to client - rcube_add_label('purgefolderconfirm'); - -// $mboxlist_start = rcube_timer(); - - $type = $attrib['type'] ? $attrib['type'] : 'ul'; - $add_attrib = $type=='select' ? array('style', 'class', 'id', 'name', 'onchange') : - array('style', 'class', 'id'); - - if ($type=='ul' && !$attrib['id']) - $attrib['id'] = 'rcmboxlist'; - - // allow the following attributes to be added to the