X-Git-Url: https://vcs.fsf.org/?p=squirrelmail.git;a=blobdiff_plain;f=functions%2Fmailbox_display.php;h=6fcd104dfb3dcc5b64ac747e19e97c09770d86b5;hp=26290e6813d059359eefd48b301f9e703ee530fb;hb=bcc55e4b9574a2bf4741cbb091196fecff86ce42;hpb=6ab20f61072b628bcad085244158aaa7ca3265ec diff --git a/functions/mailbox_display.php b/functions/mailbox_display.php index 26290e68..6fcd104d 100644 --- a/functions/mailbox_display.php +++ b/functions/mailbox_display.php @@ -1,26 +1,16 @@ $aValue) { + if (!isset($aValue['UID'])) { + unset($aMailbox['MSG_HEADERS'][$iUid]); + } + } $aUidCached = array_keys($aMailbox['MSG_HEADERS']); } else { $aMailbox['MSG_HEADERS'] = array(); @@ -412,7 +414,21 @@ function fetchMessageHeaders($imapConnection, &$aMailbox) { return $iError; } +/** + * Prepares the message headers for display inside a template. The links are calculated, + * color for row highlighting is calculated and optionally the strings are truncated. + * + * @param array $aMailbox (reference) mailbox retrieved from sqm_api_mailbox_select + * @param array $aProps properties + * @return array $aFormattedMessages array with message headers and format info + * @since 1.5.1 + * @author Marc Groot Koerkamp + */ function prepareMessageList(&$aMailbox, $aProps) { + + /* Globalize link attributes so plugins can share in modifying them */ + global $link, $title, $target, $onclick, $link_extra; + /* retrieve the properties */ $my_email_address = (isset($aProps['email'])) ? $aProps['email'] : false; $highlight_list = (isset($aProps['config']['highlight_list'])) ? $aProps['config']['highlight_list'] : false; @@ -501,7 +517,7 @@ function prepareMessageList(&$aMailbox, $aProps) { if (isset($aId[$i])) { $bHighLight = false; - $value = $title = $link = $target = ''; + $value = $title = $link = $target = $onclick = $link_extra = ''; $aQuery = ($aInitQuery !== false) ? $aInitQuery : false; $aMsg = $aHeaders[$aId[$i]]; if (isset($aSearch) && count($aSearch) > 1 && $aQuery) { @@ -515,7 +531,7 @@ function prepareMessageList(&$aMailbox, $aProps) { } foreach ($aCol as $k => $v) { - $link = $target = $title = ''; + $title = $link = $target = $onclick = $link_extra = ''; $aColumns[$k] = array(); $value = (isset($aMsg[$v])) ? $aMsg[$v] : ''; $sUnknown = _("Unknown recipient"); @@ -584,6 +600,13 @@ function prepareMessageList(&$aMailbox, $aProps) { if ($aQuery) { // TODO, $sTargetModule should be a query parameter so that we can use a single entrypoint $link = $sTargetModule.'.php?' . implode('&',$aQuery); + + // see top of this function for which attributes are available + // in the global scope for plugin use (like $link, $target, + // $onclick, $link_extra, $title, and so forth) + // plugins are responsible for sharing nicely (such as for + // setting the target, etc) + do_hook('subject_link', $temp=array(&$iPageOffset, &$sSearch, &$aSearch)); } $value = (trim($value)) ? $value : _("(no subject)"); /* add thread indentation */ @@ -602,8 +625,8 @@ function prepareMessageList(&$aMailbox, $aProps) { 'answered'=>false, 'flagged' => false, 'draft' => false); - - if(!is_array($value)) $value = array(); + + if(!is_array($value)) $value = array(); foreach ($value as $sFlag => $value) { switch ($sFlag) { case '\\seen' : $aFlagColumn['seen'] = true; break; @@ -627,9 +650,11 @@ function prepareMessageList(&$aMailbox, $aProps) { break; default : break; } - if ($title) { $aColumns[$k]['title'] = $title; } - if ($link) { $aColumns[$k]['link'] = $link; } - if ($target) { $aColumns[$k]['target'] = $target; } + if ($title) { $aColumns[$k]['title'] = $title; } + if ($link) { $aColumns[$k]['link'] = $link; } + if ($link_extra) { $aColumns[$k]['link_extra'] = $link_extra; } + if ($onclick) { $aColumns[$k]['onclick'] = $onclick; } + if ($target) { $aColumns[$k]['target'] = $target; } $aColumns[$k]['value'] = $value; } /* columns which will not be displayed but should be inspected @@ -649,7 +674,17 @@ function prepareMessageList(&$aMailbox, $aProps) { } - +/** + * Sets the row color if the provided column value pair matches a hightlight rule + * + * @param string $sCol column name + * @param string $sVal column value + * @param array $highlight_list highlight rules + * @param array $aFormat (reference) array where row color info is stored + * @return bool match found + * @since 1.5.1 + * @author Marc Groot Koerkamp + */ function highlightMessage($sCol, $sVal, $highlight_list, &$aFormat) { if (!is_array($highlight_list) && count($highlight_list) == 0) { return false; @@ -696,14 +731,15 @@ function setUserPref($username, $pref, $value) { } /** -* Execute the sorting for a mailbox -* -* @param resource $imapConnection Imap connection -* @param array $aMailbox (reference) Mailbox retrieved with sqm_api_mailbox_select -* @return int $error (reference) Error number -* @private -* @author Marc Groot Koerkamp -*/ + * Execute the sorting for a mailbox + * + * @param resource $imapConnection Imap connection + * @param array $aMailbox (reference) Mailbox retrieved with sqm_api_mailbox_select + * @return int $error (reference) Error number + * @private + * @since 1.5.1 + * @author Marc Groot Koerkamp + */ function _get_sorted_msgs_list($imapConnection,&$aMailbox) { $iSetIndx = (isset($aMailbox['SETINDEX'])) ? $aMailbox['SETINDEX'] : 0; $bDirection = !($aMailbox['SORT'] % 2); @@ -750,13 +786,14 @@ function _get_sorted_msgs_list($imapConnection,&$aMailbox) { } /** -* Does the $srt $_GET var to field mapping -* -* @param int $srt Field to sort on -* @param bool $bServerSort Server sorting is true -* @return string $sSortField Field to sort on -* @private -*/ + * Does the $srt $_GET var to field mapping + * + * @param int $srt Field to sort on + * @param bool $bServerSort Server sorting is true + * @return string $sSortField Field to sort on + * @since 1.5.1 + * @private + */ function _getSortField($sort,$bServerSort) { switch($sort) { case SQSORT_NONE: @@ -799,55 +836,24 @@ function _getSortField($sort,$bServerSort) { return $sSortField; } - - - /** -* This function loops through a group of messages in the mailbox -* and shows them to the user. -* -* @param resource $imapConnection -* @param array $aMailbox associative array with mailbox related vars -* @param array $aProps -* @param int $iError error code, 0 is no error -*/ -function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { - global $PHP_SELF; - global $boxes; + * This function is a utility function for setting which headers should be + * fetched. It takes into account the highlight list which requires extra + * headers to be fetch in order to make those rules work. It's called before + * the headers are fetched which happens in showMessagesForMailbox and when + * the next and prev links in read_body.php are used. + * + * @param array $aMailbox associative array with mailbox related vars + * @param array $aProps + * @return void + * @since 1.5.1 + */ + +function calcFetchColumns(&$aMailbox, &$aProps) { $highlight_list = (isset($aProps['config']['highlight_list'])) ? $aProps['config']['highlight_list'] : false; - $fancy_index_highlite = (isset($aProps['config']['fancy_index_highlite'])) ? $aProps['config']['fancy_index_highlite'] : true; $aColumnsDesc = (isset($aProps['columns'])) ? $aProps['columns'] : false; - $iAccount = (isset($aProps['account'])) ? (int) $aProps['account'] : 0; - $sMailbox = (isset($aProps['mailbox'])) ? $aProps['mailbox'] : false; - $sTargetModule = (isset($aProps['module'])) ? $aProps['module'] : 'read_body'; - $show_flag_buttons = (isset($aProps['config']['show_flag_buttons'])) ? $aProps['config']['show_flag_buttons'] : true; - $lastTargetMailbox = (isset($aProps['config']['lastTargetMailbox'])) ? $aProps['config']['lastTargetMailbox'] : ''; - $aOrder = array_keys($aProps['columns']); - $trash_folder = (isset($aProps['config']['trash_folder']) && $aProps['config']['trash_folder']) - ? $aProps['config']['trash_folder'] : false; - $sent_folder = (isset($aProps['config']['sent_folder']) && $aProps['config']['sent_folder']) - ? $aProps['config']['sent_folder'] : false; - $draft_folder = (isset($aProps['config']['draft_folder']) && $aProps['config']['draft_folder']) - ? $aProps['config']['draft_folder'] : false; - $page_selector = (isset($aProps['config']['page_selector'])) ? $aProps['config']['page_selector'] : false; - $page_selector_max = (isset($aProps['config']['page_selector_max'])) ? $aProps['config']['page_selector_max'] : 10; - $color = $aProps['config']['color']; - - /* - * Form ID - */ - static $iFormId; - - if (!isset($iFormId)) { - $iFormId=1; - } else { - ++$iFormId; - } - /* - * Remove the checkbox column because we cannot fetch it from the imap server - */ $aFetchColumns = $aColumnsDesc; if (isset($aFetchColumns[SQM_COL_CHECK])) { unset($aFetchColumns[SQM_COL_CHECK]); @@ -885,10 +891,61 @@ function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { $aProps['extra_columns'] = $aExtraColumns; } } - $aFetchColumns = array_keys($aFetchColumns); + $aMailbox['FETCHHEADERS'] = array_keys($aFetchColumns); +} + + +/** + * This function loops through a group of messages in the mailbox + * and shows them to the user. + * + * @param resource $imapConnection + * @param array $aMailbox associative array with mailbox related vars + * @param array $aProps + * @param int $iError error code, 0 is no error + */ +function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { + global $PHP_SELF; + global $boxes, $show_copy_buttons; + + $highlight_list = (isset($aProps['config']['highlight_list'])) ? $aProps['config']['highlight_list'] : false; + $fancy_index_highlite = (isset($aProps['config']['fancy_index_highlite'])) ? $aProps['config']['fancy_index_highlite'] : true; + $aColumnsDesc = (isset($aProps['columns'])) ? $aProps['columns'] : false; + $iAccount = (isset($aProps['account'])) ? (int) $aProps['account'] : 0; + $sMailbox = (isset($aProps['mailbox'])) ? $aProps['mailbox'] : false; + $sTargetModule = (isset($aProps['module'])) ? $aProps['module'] : 'read_body'; + $show_flag_buttons = (isset($aProps['config']['show_flag_buttons'])) ? $aProps['config']['show_flag_buttons'] : true; + + /* allows to control copy button in function call. If array key is not set, code follows user preferences */ + if (isset($aProps['config']['show_copy_buttons'])) + $show_copy_buttons = $aProps['config']['show_copy_buttons']; + + $lastTargetMailbox = (isset($aProps['config']['lastTargetMailbox'])) ? $aProps['config']['lastTargetMailbox'] : ''; + $aOrder = array_keys($aProps['columns']); + $trash_folder = (isset($aProps['config']['trash_folder']) && $aProps['config']['trash_folder']) + ? $aProps['config']['trash_folder'] : false; + $sent_folder = (isset($aProps['config']['sent_folder']) && $aProps['config']['sent_folder']) + ? $aProps['config']['sent_folder'] : false; + $draft_folder = (isset($aProps['config']['draft_folder']) && $aProps['config']['draft_folder']) + ? $aProps['config']['draft_folder'] : false; + $page_selector = (isset($aProps['config']['page_selector'])) ? $aProps['config']['page_selector'] : false; + $page_selector_max = (isset($aProps['config']['page_selector_max'])) ? $aProps['config']['page_selector_max'] : 10; + $color = $aProps['config']['color']; + + + /* + * Form ID + */ + static $iFormId; + + if (!isset($iFormId)) { + $iFormId=1; + } else { + ++$iFormId; + } // store the columns to fetch so we can pick them up in read_body // where we validate the cache. - $aMailbox['FETCHHEADERS'] = $aFetchColumns; + calcFetchColumns($aMailbox ,$aProps); $iError = fetchMessageHeaders($imapConnection, $aMailbox); if ($iError) { @@ -943,7 +1000,6 @@ function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { /* future admin control over displayable buttons */ - $aAdminControl = array( 'markUnflagged' => 1, 'markFlagged' => 1, @@ -954,8 +1010,10 @@ function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { 'undeleteButton'=> 1, 'bypass_trash' => 1, 'expungeButton' => 1, - 'moveButton' => 1 + 'moveButton' => 1, + 'copyButton' => 1 ); + /* user prefs control */ $aUserControl = array ( @@ -968,7 +1026,8 @@ function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { 'undeleteButton'=> 1, 'bypass_trash' => 1, 'expungeButton' => 1, - 'moveButton' => 1 + 'moveButton' => 1, + 'copyButton' => $show_copy_buttons ); @@ -983,6 +1042,8 @@ function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { $showMove = ($aMailbox['RIGHTS'] != 'READ-ONLY') ? true : false; $showExpunge = (!$aMailbox['AUTO_EXPUNGE'] && $aMailbox['RIGHTS'] != 'READ-ONLY' && in_array('\\deleted',$aMailbox['PERMANENTFLAGS'], true)) ? true : false; + + /* Button options that depend on IMAP server and selected folder */ $aImapControl = array ( 'markUnflagged' => in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true), 'markFlagged' => in_array('\\flagged',$aMailbox['PERMANENTFLAGS'], true), @@ -993,8 +1054,10 @@ function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { 'undeleteButton'=> $showUndelete, 'bypass_trash' => $showByPassTrash, 'expungeButton' => $showExpunge, - 'moveButton' => $showMove + 'moveButton' => $showMove, + 'copyButton' => 1 ); + /* Button strings */ $aButtonStrings = array( 'markUnflagged' => _("Unflag"), 'markFlagged' => _("Flag"), @@ -1005,7 +1068,8 @@ function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { 'undeleteButton' => _("Undelete"), 'bypass_trash' => _("Bypass Trash"), 'expungeButton' => _("Expunge"), - 'moveButton' => _("Move") + 'moveButton' => _("Move"), + 'copyButton' => _("Copy") ); @@ -1031,6 +1095,7 @@ function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { $aFormElements[$k] = array($aButtonStrings[$k],'checkbox'); break; case 'moveButton': + case 'copyButton': $aFormElements['targetMailbox'] = array(sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)), 0, $boxes),'select'); $aFormElements['mailbox'] = array($aMailbox['NAME'],'hidden'); @@ -1043,9 +1108,9 @@ function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { } /* - * This is the beginning of the message list table. - * It wraps around all messages - */ + * This is the beginning of the message list table. + * It wraps around all messages + */ $safe_name = preg_replace("/[^0-9A-Za-z_]/", '_', $aMailbox['NAME']); $form_name = "FormMsgs" . $safe_name; @@ -1094,12 +1159,12 @@ function showMessagesForMailbox($imapConnection, &$aMailbox,$aProps, &$iError) { /** -* Truncates a string and take care of html encoded characters -* -* @param string $s string to truncate -* @param int $iTrimAt Trim at nn characters -* @return string Trimmed string -*/ + * Truncates a string and take care of html encoded characters + * + * @param string $s string to truncate + * @param int $iTrimAt Trim at nn characters + * @return string Trimmed string + */ function truncateWithEntities($s, $iTrimAt) { global $languages, $squirrelmail_language; @@ -1112,11 +1177,11 @@ function truncateWithEntities($s, $iTrimAt) { return call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_strimwidth', $s, $iTrimAt); } else { /* - * see if this is entities-encoded string - * If so, Iterate through the whole string, find out - * the real number of characters, and if more - * than $iTrimAt, substr with an updated trim value. - */ + * see if this is entities-encoded string + * If so, Iterate through the whole string, find out + * the real number of characters, and if more + * than $iTrimAt, substr with an updated trim value. + */ $trim_val = $iTrimAt; $ent_offset = 0; $ent_loc = 0; @@ -1141,9 +1206,9 @@ function truncateWithEntities($s, $iTrimAt) { /** -* This should go in imap_mailbox.php -* @param string $mailbox -*/ + * This should go in imap_mailbox.php + * @param string $mailbox + */ function handleAsSent($mailbox) { global $handleAsSent_result; @@ -1167,11 +1232,13 @@ function handleAsSent($mailbox) { * @param string $sButton fake a submit button * @param array $aUid fake the $msg array * @return string $sError error string in case of an error + * @since 1.5.1 * @author Marc Groot Koerkamp */ function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = array()) { /* incoming formdata */ $sButton = (sqgetGlobalVar('moveButton', $sTmp, SQ_POST)) ? 'move' : $sButton; + $sButton = (sqgetGlobalVar('copyButton', $sTmp, SQ_POST)) ? 'copy' : $sButton; $sButton = (sqgetGlobalVar('expungeButton', $sTmp, SQ_POST)) ? 'expunge' : $sButton; $sButton = (sqgetGlobalVar('forward', $sTmp, SQ_POST)) ? 'forward' : $sButton; $sButton = (sqgetGlobalVar('delete', $sTmp, SQ_POST)) ? 'setDeleted' : $sButton; @@ -1216,10 +1283,16 @@ function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = ar $aUpdatedMsgs = sqimap_toggle_flag($imapConnection, $aUid, $sFlag, $bSet, true); break; case 'move': - $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection,$aUid,$targetMailbox); + $aUpdatedMsgs = sqimap_msgs_list_move($imapConnection,$aUid,$targetMailbox,true,$mailbox); sqsession_register($targetMailbox,'lastTargetMailbox'); $bExpunge = true; break; + case 'copy': + // sqimap_msgs_list_copy returns true or false. + // If error happens - fourth argument handles it inside function. + sqimap_msgs_list_copy($imapConnection,$aUid,$targetMailbox,true); + sqsession_register($targetMailbox,'lastTargetMailbox'); + break; case 'forward': $aMsgHeaders = array(); foreach ($aUid as $iUid) { @@ -1233,7 +1306,7 @@ function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = ar break; default: // Hook for plugin buttons - do_hook_function('mailbox_display_button_action', $aUid); + do_hook('mailbox_display_button_action', $aUid); break; } /** @@ -1308,7 +1381,7 @@ function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = ar /** * on expunge we do not know which messages will be deleted * so it's useless to try to sync the cache - + * * Close the mailbox so we do not need to parse the untagged expunge * responses which do not contain uid info. * NB: Closing a mailbox is faster then expunge because the imap @@ -1325,6 +1398,14 @@ function handleMessageListForm($imapConnection,&$aMailbox,$sButton='',$aUid = ar return $sError; } +/** + * Attach messages to a compose session + * + * @param resource $imapConnection imap connection + * @param array $aMsgHeaders + * @return int $composesession unique compose_session_id where the attached messages belong to + * @author Marc Groot Koerkamp + */ function attachSelectedMessages($imapConnection,$aMsgHeaders) { global $username, $attachment_dir, $data_dir; @@ -1381,5 +1462,3 @@ function attachSelectedMessages($imapConnection,$aMsgHeaders) { sqsession_register($compose_messages,'compose_messages'); return $composesession; } - -?>