Replacing HTML "script" element deprecated attribute "language".
[squirrelmail.git] / functions / mailbox_display.php
index 8a6b608ce25946182c8d4a24ab0831d188e6b07f..d5eb6214ca735faf84c96bb6f26399c201864b2d 100644 (file)
@@ -6,7 +6,7 @@
  * This contains functions that display mailbox information, such as the
  * table row that has sender, date, subject, etc...
  *
- * @copyright © 1999-2005 The SquirrelMail Project Team
+ * @copyright © 1999-2006 The SquirrelMail Project Team
  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
@@ -31,6 +31,7 @@ require_once(SM_PATH . 'functions/forms.php');
  * @param array    $aConfig array with system config settings and incoming vars
  * @param array    $aProps mailbox specific properties
  * @return array   $aMailbox mailbox array with all relevant information
+ * @since 1.5.1
  * @author Marc Groot Koerkamp
  */
 function sqm_api_mailbox_select($imapConnection,$account,$mailbox,$aConfig,$aProps) {
@@ -259,11 +260,13 @@ function sqm_api_mailbox_select($imapConnection,$account,$mailbox,$aConfig,$aPro
 
 /**
  * Fetch the message headers for a mailbox. Settings are part of the aMailbox
- * array.
+ * array. Dependent of the mailbox settings it deals with sort, thread and search
+ * If server sort is supported then SORT is also used for retrieving sorted search results
  *
  * @param resource $imapConnection imap socket handle
  * @param array    $aMailbox (reference) mailbox retrieved from sqm_api_mailbox_select
  * @return error   $error error number
+ * @since 1.5.1
  * @author Marc Groot Koerkamp
  */
 function fetchMessageHeaders($imapConnection, &$aMailbox) {
@@ -412,7 +415,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 +518,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 +532,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 +601,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', array($iPageOffset, $sSearch, $aSearch));
                     }
                     $value = (trim($value)) ? $value : _("(no subject)");
                     /* add thread indentation */
@@ -627,9 +651,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 +675,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;
@@ -702,6 +738,7 @@ function setUserPref($username, $pref, $value) {
  * @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) {
@@ -755,6 +792,7 @@ function _get_sorted_msgs_list($imapConnection,&$aMailbox) {
  * @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) {
@@ -799,6 +837,19 @@ function _getSortField($sort,$bServerSort) {
     return $sSortField;
 }
 
+/**
+ * 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;
@@ -842,8 +893,6 @@ function calcFetchColumns(&$aMailbox, &$aProps) {
         }
     }
     $aMailbox['FETCHHEADERS'] =  array_keys($aFetchColumns);
-
-    ;
 }
 
 
@@ -1171,6 +1220,7 @@ 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()) {
@@ -1220,7 +1270,7 @@ 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;
@@ -1329,6 +1379,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;
@@ -1386,4 +1444,4 @@ function attachSelectedMessages($imapConnection,$aMsgHeaders) {
     return $composesession;
 }
 
-?>
\ No newline at end of file
+?>