Source for file right_main.php

Documentation is available at right_main.php

  1. <?php
  2.  
  3. /**
  4.  * right_main.php
  5.  *
  6.  * This is where the mailboxes are listed. This controls most of what
  7.  * goes on in SquirrelMail.
  8.  *
  9.  * @copyright 1999-2020 The SquirrelMail Project Team
  10.  * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.  * @version $Id: right_main.php 14845 2020-01-07 08:09:34Z pdontthink $
  12.  * @package squirrelmail
  13.  */
  14.  
  15. /** This is the right_main page */
  16. define('PAGE_NAME', 'right_main');
  17.  
  18. //xdebug_start_profiling("/var/spool/xdebug/right_main.txt");
  19.  
  20. /**
  21.  * Include the SquirrelMail initialization file.
  22.  */
  23. include('../include/init.php');
  24.  
  25. /* If email_address not set and admin wants us to ask user for it,
  26.  * redirect to options page. */
  27. if ( $ask_user_info && getPref($data_dir, $username,'email_address') == "" ) {
  28.     header("Location: " . get_location() . "/options.php?optpage=personal");
  29.     exit;
  30. }
  31.  
  32. /* SquirrelMail required files. */
  33. require_once(SM_PATH . 'functions/imap_asearch.php');
  34. require_once(SM_PATH . 'functions/imap_general.php');
  35. require_once(SM_PATH . 'functions/imap_messages.php');
  36. require_once(SM_PATH . 'functions/date.php');
  37. require_once(SM_PATH . 'functions/mime.php');
  38. require_once(SM_PATH . 'functions/mailbox_display.php');
  39. require_once(SM_PATH . 'functions/compose.php');
  40.  
  41. /* lets get the global vars we may need */
  42. sqgetGlobalVar('delimiter', $delimiter,     SQ_SESSION);
  43. sqgetGlobalVar('delayed_errors',  $delayed_errors,  SQ_SESSION);
  44. if (is_array($delayed_errors)) {
  45.     $oErrorHandler->AssignDelayedErrors($delayed_errors);
  46.     sqsession_unregister("delayed_errors");
  47. }
  48. sqgetGlobalVar('mailbox',   $mailbox);
  49. sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
  50. sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST);
  51. sqgetGlobalVar('note',              $note,              SQ_GET);
  52. sqgetGlobalVar('mail_sent',         $mail_sent,         SQ_GET);
  53.  
  54.  
  55. if ( sqGetGlobalVarMultiple('startMessage', $temp, 'paginator_submit') ) {
  56.     $startMessage = (int) $temp;
  57. } else {
  58.     $startMessage = 1;
  59. }
  60. // sort => srt because of the changed behaviour which can break new behaviour
  61. if ( sqgetGlobalVar('srt', $temp, SQ_GET) ) {
  62.     $srt = (int) $temp;
  63. }
  64.  
  65. if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) {
  66.     $showall = (int) $temp;
  67. }
  68.  
  69. if (!sqgetGlobalVar('checkall',$checkall,SQ_GET)) {
  70.     $checkall = false;
  71. }
  72.  
  73. if (!sqgetGlobalVar('preselected', $preselected, SQ_GET) || !is_array($preselected)) {
  74.     $preselected = array();
  75. } else {
  76.     $preselected = array_keys($preselected);
  77. }
  78.  
  79. /* future work */
  80. if ( sqgetGlobalVar('account', $account, SQ_GET) ) {
  81.   $account = (int) $account;
  82. } else {
  83.   $account = 0;
  84. }
  85.  
  86. /* end of get globals */
  87.  
  88.  
  89. /* Open an imap connection */
  90.  
  91. global $imap_stream_options; // in case not defined in config
  92. $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0, $imap_stream_options);
  93.  
  94. $mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX';
  95.  
  96. /**
  97.  * Set the global settings for a mailbox and merge them with the usersettings
  98.  * for the mailbox. In the future we can add more mailbox specific preferences
  99.  * preferences.
  100.  */
  101.  
  102. $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox);
  103. if ($aMailboxPrefSer) {
  104.     $aMailboxPref = unserialize($aMailboxPrefSer);
  105.     $aMailboxPref[MBX_PREF_COLUMNS] = $index_order; // index_order contains the columns to show and the order of the columns
  106. } else {
  107.     setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref));
  108.     $aMailboxPref = $default_mailbox_pref;
  109. }
  110. if (isset($srt)) {
  111.     $aMailboxPref[MBX_PREF_SORT] = (int) $srt;
  112. }
  113.  
  114. $trash_folder = (isset($trash_folder)) ? $trash_folder : false;
  115. $sent_folder = (isset($sent_folder)) ? $sent_folder : false;
  116. $draft_folder = (isset($draft_folder)) ? $draft_folder : false;
  117.  
  118.  
  119. /**
  120.  * until there is no per mailbox option screen to set prefs we override
  121.  * the mailboxprefs by the default ones
  122.  */
  123. $aMailboxPref[MBX_PREF_LIMIT] = (int)  $show_num;
  124. $aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge;
  125. $aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort');
  126. $aMailboxPref[MBX_PREF_COLUMNS] = $index_order;
  127.  
  128. /**
  129.  * Replace From => To  in case it concerns a draft or sent folder
  130.  */
  131. if (handleAsSent($mailbox)
  132.  && !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) {
  133.     $aNewOrder = array(); // nice var name ;)
  134.     foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
  135.         if ($iCol == SQM_COL_FROM) {
  136.             $iCol = SQM_COL_TO;
  137.         }
  138.         $aNewOrder[] = $iCol;
  139.    }
  140.    $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder;
  141.    setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref));
  142. }
  143.  
  144.  
  145.  
  146. /**
  147.  * Set the config options for the messages list
  148.  */
  149. $aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys
  150. foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) {
  151.     $aColumns[$iCol] = array();
  152.     switch ($iCol) {
  153.         case SQM_COL_SUBJ:
  154.             if ($truncate_subject) {
  155.                 $aColumns[$iCol]['truncate'] = $truncate_subject;
  156.             }
  157.             break;
  158.         case SQM_COL_FROM:
  159.         case SQM_COL_TO:
  160.         case SQM_COL_CC:
  161.         case SQM_COL_BCC:
  162.             if ($truncate_sender) {
  163.                 $aColumns[$iCol]['truncate'] = $truncate_sender;
  164.             }
  165.             break;
  166.    }
  167. }
  168.  
  169. /**
  170.  * Properties required by showMessagesForMailbox
  171.  */
  172. $aProps = array(
  173.     'columns' => $aColumns, // columns bound settings
  174.     'config'  => array('alt_index_colors'       => $alt_index_colors,       // alternating row colors (should be a template thing)
  175.                         'highlight_list'        => $message_highlight_list, // row highlighting rules
  176.                         'fancy_index_highlite'  => $fancy_index_highlite,   // highlight rows on hover or on click -> check
  177.                         'show_flag_buttons'     => (isset($show_flag_buttons)) ? $show_flag_buttons : true,
  178.                         'lastTargetMailbox'     => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '', // last mailbox where messages are moved/copied to
  179.                         'trash_folder'          => $trash_folder,
  180.                         'sent_folder'           => $sent_folder,
  181.                         'draft_folder'          => $draft_folder,
  182.                         'color'                 => $color,
  183.                         'enablesort'            => true // enable sorting on columns
  184.                 ),
  185.     'mailbox' => $mailbox,
  186.     'account' => (isset($account)) ? $account : 0, // future usage if we support multiple imap accounts
  187.     'module' => 'read_body',
  188.     'email'  => false);
  189.  
  190.  
  191. /**
  192.  * system wide admin settings and incoming vars.
  193.  */
  194. $aConfig = array(
  195.                 'user'              => $username,
  196.                 // incoming vars
  197.                 'offset' => $startMessage // offset in paginator
  198.                 );
  199. /**
  200.  * The showall functionality is for the moment added to the config array
  201.  * to avoid storage of the showall link in the mailbox pref. We could change
  202.  * this behaviour later and add it to $aMailboxPref instead
  203.  */
  204. if (isset($showall)) {
  205.     $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled)
  206. } else {
  207.     $showall = false;
  208. }
  209.  
  210.  
  211. /**
  212.  * Retrieve the mailbox cache from the session.
  213.  */
  214. sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION);
  215.  
  216. /**
  217.  * Select the mailbox and retrieve the cached info.
  218.  */
  219. $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref);
  220.  
  221. /**
  222.  * MOVE THIS to a central init section !!!!
  223.  */
  224. if (!sqgetGlobalVar('align',$align,SQ_SESSION)) {
  225.     $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ? $languages[$squirrelmail_language]['DIR'] : 'ltr';
  226.     if ( $dir == 'ltr' ) {
  227.         $align = array('left' => 'left', 'right' => 'right');
  228.     } else {
  229.         $align = array('left' => 'right', 'right' => 'left');
  230.     }
  231.     sqsession_register($align, 'align');
  232. }
  233.  
  234. /*
  235.  * After initialisation of the mailbox array it's time to handle the FORM data
  236.  */
  237. $sError = handleMessageListForm($imapConnection,$aMailbox);
  238. if ($sError) {
  239.    $note = $sError;
  240. } else if (sqgetGlobalVar('REQUEST_METHOD', $req_method, SQ_SERVER) && $req_method == 'POST') {
  241.    $preselected = array(); // clear pre-checked checkboxes when action succeeded
  242. }
  243.  
  244.  
  245.  
  246. /*
  247.  * If we try to forward messages as attachment we have to open a new window
  248.  * in case of compose in new window or redirect to compose.php
  249.  */
  250. $onload = '';
  251. if (isset($aMailbox['FORWARD_SESSION'])) {
  252.     if ($compose_new_win) {
  253.         /* add the mailbox to the cache */
  254.         $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
  255.         sqsession_register($mailbox_cache,'mailbox_cache');
  256.         // write the session in order to make sure that the compose window has
  257.         // access to the composemessages array which is stored in the session
  258.         session_write_close();
  259.         // restart the session. Do not use sqsession_is_active because the session_id
  260.         // isn't empty after a session_write_close
  261.         sqsession_start();
  262.         if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) {
  263.             $compose_width = '640';
  264.         }
  265.         if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) {
  266.             $compose_height = '550';
  267.         }
  268.         // do not use &amp;, it will break the query string and $session will not be detected!!!
  269.         $comp_uri = $base_uri . 'src/compose.php?mailbox='. urlencode($mailbox)
  270.                   . '&session='.urlencode($aMailbox['FORWARD_SESSION']['SESSION_NUMBER'])
  271.                   . '&smaction=forward_as_attachment'
  272.                   . '&fwduid=' . implode('_', $aMailbox['FORWARD_SESSION']['UIDS']);
  273.         $onload = "comp_in_new('$comp_uri', $compose_width, $compose_height);";
  274.     } else {
  275.         $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
  276.         sqsession_register($mailbox_cache,'mailbox_cache');
  277.  
  278.         // save mailboxstate
  279.         sqsession_register($aMailbox,'aLastSelectedMailbox');
  280.         session_write_close();
  281.         // we have to redirect to the compose page
  282.         $location = $base_uri . 'src/compose.php?mailbox='. urlencode($mailbox)
  283.                   . '&session='.$aMailbox['FORWARD_SESSION']['SESSION_NUMBER']
  284.                   . '&smaction=forward_as_attachment'
  285.                   . '&fwduid=' . implode('_', $aMailbox['FORWARD_SESSION']['UIDS']);
  286.         header("Location: $location");
  287.         exit;
  288.     }
  289. }
  290.  
  291. // plugins can operate normally here (don't output anything, of course!),
  292. // but can also return TRUE if they want to enable the MOTD display
  293. // even when SM's MOTD is empty (there is plugin output that can
  294. // be then hooked into in motd.tpl)  
  295. // NOTE a TRUE return value here will cause the display of the MOTD on 
  296. // *every* page view; if a plugin wants to support true MOTD (one-time 
  297. // message display upon login), it should also check the value of 
  298. // "just_logged_in" in the PHP session before returning TRUE.
  299. //
  300. $show_motd = boolean_hook_function('right_main_after_header', $null, 1);
  301.  
  302.  
  303. // get "just_logged_in" from PHP session, save it in a temp variable
  304. // for use below, and reset its value in PHP session
  305. //
  306. if (!sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION))
  307.     $just_logged_in = false;
  308. $temp_just_logged_in = $just_logged_in;
  309. $just_logged_in = false;
  310. sqsession_register($just_logged_in, 'just_logged_in');
  311.  
  312.  
  313. // now we're done with the PHP session, can send output to browser
  314. //
  315. displayPageHeader($color, $mailbox, $onload);
  316.  
  317.  
  318. /* display a message to the user that their mail has been sent */
  319. if (isset($mail_sent) && $mail_sent == 'yes') {
  320.     $note = _("Your mail has been sent.");
  321. }
  322. if (isset($note)) {
  323.     $oTemplate->assign('note', sm_encode_html_special_chars($note));
  324.     $oTemplate->display('note.tpl');
  325. }
  326.  
  327. if ($temp_just_logged_in || $show_motd) {
  328.     $motd = trim($motd);
  329.     if ($show_motd || strlen($motd) > 0) {
  330.         $oTemplate->assign('motd', $motd);
  331.         $oTemplate->display('motd.tpl');
  332.     }
  333. }
  334.  
  335.  
  336. if ($aMailbox['EXISTS'] > 0) {
  337.     $aTemplateVars = showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError);
  338.     if ($iError) {
  339.  
  340.     }
  341.     foreach ($aTemplateVars as $k => $v) {
  342.         $oTemplate->assign($k, $v);
  343.     }
  344.  
  345.     /*
  346.      * TODO: To many config related vars. We should move all config related vars to
  347.      * one single associative array and assign that to the template
  348.      */
  349.     $oTemplate->assign('page_selector',  $page_selector);
  350.     $oTemplate->assign('page_selector_max', $page_selector_max);
  351.     $oTemplate->assign('compact_paginator', $compact_paginator);
  352.     $oTemplate->assign('javascript_on', checkForJavascript());
  353.     $oTemplate->assign('base_uri', sqm_baseuri());
  354.     $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false);
  355.     $oTemplate->assign('icon_theme_path', $icon_theme_path);
  356.     $oTemplate->assign('aOrder', array_keys($aColumns));
  357.     $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false);
  358.     $oTemplate->assign('color', $color);
  359.     $oTemplate->assign('align', $align);
  360.     $oTemplate->assign('checkall', $checkall);
  361.     $oTemplate->assign('preselected', $preselected);
  362.  
  363.     global $show_personal_names;
  364.     $oTemplate->assign('show_personal_names', $show_personal_names);
  365.  
  366.     global $accesskey_mailbox_toggle_selected, $accesskey_mailbox_thread;
  367.     $oTemplate->assign('accesskey_mailbox_toggle_selected', $accesskey_mailbox_toggle_selected);
  368.     $oTemplate->assign('accesskey_mailbox_thread', $accesskey_mailbox_thread);
  369.  
  370.     $oTemplate->display('message_list.tpl');
  371.  
  372. } else {
  373.     $oTemplate->display('empty_folder.tpl');
  374. }
  375.  
  376. do_hook('right_main_bottom', $null);
  377. sqimap_logout ($imapConnection);
  378. $oTemplate->display('footer.tpl');
  379.  
  380.  
  381. /* add the mailbox to the cache */
  382. $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox;
  383. sqsession_register($mailbox_cache,'mailbox_cache');

Documentation generated on Mon, 13 Jan 2020 04:23:29 +0100 by phpDocumentor 1.4.3