| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * right_main.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2005 The SquirrelMail Project Team |
| 7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 8 | * |
| 9 | * This is where the mailboxes are listed. This controls most of what |
| 10 | * goes on in SquirrelMail. |
| 11 | * |
| 12 | * @version $Id$ |
| 13 | * @package squirrelmail |
| 14 | */ |
| 15 | |
| 16 | /** |
| 17 | * Path for SquirrelMail required files. |
| 18 | * @ignore |
| 19 | */ |
| 20 | define('SM_PATH','../'); |
| 21 | |
| 22 | /* SquirrelMail required files. */ |
| 23 | require_once(SM_PATH . 'include/validate.php'); |
| 24 | require_once(SM_PATH . 'functions/global.php'); |
| 25 | require_once(SM_PATH . 'functions/imap.php'); |
| 26 | require_once(SM_PATH . 'functions/date.php'); |
| 27 | require_once(SM_PATH . 'functions/mime.php'); |
| 28 | require_once(SM_PATH . 'functions/mailbox_display.php'); |
| 29 | require_once(SM_PATH . 'functions/display_messages.php'); |
| 30 | require_once(SM_PATH . 'functions/html.php'); |
| 31 | require_once(SM_PATH . 'functions/plugin.php'); |
| 32 | |
| 33 | //include_once(SM_PATH . 'templates/default/message_list.tpl'); |
| 34 | include_once(SM_PATH . 'class/template/template.class.php'); |
| 35 | |
| 36 | |
| 37 | /* lets get the global vars we may need */ |
| 38 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
| 39 | sqgetGlobalVar('username', $username, SQ_SESSION); |
| 40 | sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION); |
| 41 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
| 42 | sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); |
| 43 | |
| 44 | sqgetGlobalVar('mailbox', $mailbox); |
| 45 | sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION); |
| 46 | sqgetGlobalVar('targetMailbox', $lastTargetMailbox, SQ_POST); |
| 47 | sqgetGlobalVar('note', $note, SQ_GET); |
| 48 | sqgetGlobalVar('mail_sent', $mail_sent, SQ_GET); |
| 49 | |
| 50 | |
| 51 | if ( sqgetGlobalVar('startMessage', $temp) ) { |
| 52 | $startMessage = (int) $temp; |
| 53 | } else { |
| 54 | $startMessage = 1; |
| 55 | } |
| 56 | // sort => srt because of the changed behaviour which can break new behaviour |
| 57 | if ( sqgetGlobalVar('srt', $temp, SQ_GET) ) { |
| 58 | $srt = (int) $temp; |
| 59 | } |
| 60 | |
| 61 | if ( sqgetGlobalVar('showall', $temp, SQ_GET) ) { |
| 62 | $showall = (int) $temp; |
| 63 | } |
| 64 | |
| 65 | if ( sqgetGlobalVar('checkall', $temp, SQ_GET) ) { |
| 66 | $checkall = (int) $temp; |
| 67 | } |
| 68 | |
| 69 | /* future work */ |
| 70 | if ( sqgetGlobalVar('account', $account, SQ_GET) ) { |
| 71 | $account = (int) $account; |
| 72 | } else { |
| 73 | $account = 0; |
| 74 | } |
| 75 | |
| 76 | /* end of get globals */ |
| 77 | |
| 78 | |
| 79 | /* Open an imap connection */ |
| 80 | |
| 81 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 82 | |
| 83 | $mailbox = (isset($mailbox) && $mailbox) ? $mailbox : 'INBOX'; |
| 84 | |
| 85 | /* compensate for the UW vulnerability. */ |
| 86 | if ($imap_server_type == 'uw' && (strstr($mailbox, '../') || |
| 87 | substr($mailbox, 0, 1) == '/')) { |
| 88 | $mailbox = 'INBOX'; |
| 89 | } |
| 90 | /** |
| 91 | * Set the global settings for a mailbox and merge them with the usersettings |
| 92 | * for the mailbox. In the future we can add more mailbox specific preferences |
| 93 | * preferences. |
| 94 | */ |
| 95 | |
| 96 | |
| 97 | /* not sure if this hook should be capable to alter the global pref array */ |
| 98 | do_hook ('generic_header'); |
| 99 | |
| 100 | $aMailboxPrefSer=getPref($data_dir, $username,'pref_'.$account.'_'.$mailbox); |
| 101 | if ($aMailboxPrefSer) { |
| 102 | $aMailboxPref = unserialize($aMailboxPrefSer); |
| 103 | $aMailboxPref[MBX_PREF_COLUMNS] = $index_order; // index_order contains the columns to show and the order of the columns |
| 104 | } else { |
| 105 | setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($default_mailbox_pref)); |
| 106 | $aMailboxPref = $default_mailbox_pref; |
| 107 | } |
| 108 | if (isset($srt)) { |
| 109 | $aMailboxPref[MBX_PREF_SORT] = (int) $srt; |
| 110 | } |
| 111 | |
| 112 | $trash_folder = (isset($trash_folder)) ? $trash_folder : false; |
| 113 | $sent_folder = (isset($sent_folder)) ? $sent_folder : false; |
| 114 | $draft_folder = (isset($draft_folder)) ? $draft_folder : false; |
| 115 | |
| 116 | |
| 117 | /** |
| 118 | * until there is no per mailbox option screen to set prefs we override |
| 119 | * the mailboxprefs by the default ones |
| 120 | */ |
| 121 | $aMailboxPref[MBX_PREF_LIMIT] = (int) $show_num; |
| 122 | $aMailboxPref[MBX_PREF_AUTO_EXPUNGE] = (bool) $auto_expunge; |
| 123 | $aMailboxPref[MBX_PREF_INTERNALDATE] = (bool) getPref($data_dir, $username, 'internal_date_sort'); |
| 124 | $aMailboxPref[MBX_PREF_COLUMNS] = $index_order; |
| 125 | |
| 126 | /** |
| 127 | * Replace From => To in case it concerns a draft or sent folder |
| 128 | */ |
| 129 | if (($mailbox == $sent_folder || $mailbox == $draft_folder) && |
| 130 | !in_array(SQM_COL_TO,$aMailboxPref[MBX_PREF_COLUMNS])) { |
| 131 | $aNewOrder = array(); // nice var name ;) |
| 132 | foreach($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) { |
| 133 | if ($iCol == SQM_COL_FROM) { |
| 134 | $iCol = SQM_COL_TO; |
| 135 | } |
| 136 | $aNewOrder[] = $iCol; |
| 137 | } |
| 138 | $aMailboxPref[MBX_PREF_COLUMNS] = $aNewOrder; |
| 139 | setUserPref($username,'pref_'.$account.'_'.$mailbox,serialize($aMailboxPref)); |
| 140 | } |
| 141 | |
| 142 | |
| 143 | |
| 144 | /** |
| 145 | * Set the config options for the messages list |
| 146 | */ |
| 147 | $aColumns = array(); // contains settings per column. Switch to key -> value based array, order is the order of the array keys |
| 148 | foreach ($aMailboxPref[MBX_PREF_COLUMNS] as $iCol) { |
| 149 | $aColumns[$iCol] = array(); |
| 150 | switch ($iCol) { |
| 151 | case SQM_COL_SUBJ: |
| 152 | if ($truncate_subject) { |
| 153 | $aColumns[$iCol]['truncate'] = $truncate_subject; |
| 154 | } |
| 155 | break; |
| 156 | case SQM_COL_FROM: |
| 157 | case SQM_COL_TO: |
| 158 | case SQM_COL_CC: |
| 159 | case SQM_COL_BCC: |
| 160 | if ($truncate_sender) { |
| 161 | $aColumns[$iCol]['truncate'] = $truncate_sender; |
| 162 | } |
| 163 | break; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Properties required by showMessagesForMailbox |
| 169 | */ |
| 170 | $aProps = array( |
| 171 | 'columns' => $aColumns, // columns bound settings |
| 172 | 'config' => array('alt_index_colors' => $alt_index_colors, // alternating row colors (should be a template thing) |
| 173 | 'highlight_list' => $message_highlight_list, // row highlighting rules |
| 174 | 'fancy_index_highlite' => $fancy_index_highlite, // highlight rows on hover or on click -> check |
| 175 | 'show_flag_buttons' => (isset($show_flag_buttons)) ? $show_flag_buttons : true, |
| 176 | 'lastTargetMailbox' => (isset($lastTargetMailbox)) ? $lastTargetMailbox : '', // last mailbox where messages are moved/copied to |
| 177 | 'trash_folder' => $trash_folder, |
| 178 | 'sent_folder' => $sent_folder, |
| 179 | 'draft_folder' => $draft_folder, |
| 180 | 'color' => $color, |
| 181 | 'enablesort' => true // enable sorting on columns |
| 182 | ), |
| 183 | 'mailbox' => $mailbox, |
| 184 | 'account' => (isset($account)) ? $account : 0, // future usage if we support multiple imap accounts |
| 185 | 'module' => 'read_body', |
| 186 | 'email' => false); |
| 187 | |
| 188 | |
| 189 | /** |
| 190 | * system wide admin settings and incoming vars. |
| 191 | */ |
| 192 | $aConfig = array( |
| 193 | 'user' => $username, |
| 194 | // incoming vars |
| 195 | 'offset' => $startMessage // offset in paginator |
| 196 | ); |
| 197 | /** |
| 198 | * The showall functionality is for the moment added to the config array |
| 199 | * to avoid storage of the showall link in the mailbox pref. We could change |
| 200 | * this behaviour later and add it to $aMailboxPref instead |
| 201 | */ |
| 202 | if (isset($showall)) { |
| 203 | $aConfig['showall'] = $showall; // show all messages in a mailbox (paginator is disabled) |
| 204 | } else { |
| 205 | $showall = false; |
| 206 | } |
| 207 | |
| 208 | |
| 209 | /** |
| 210 | * Retrieve the mailbox cache from the session. |
| 211 | */ |
| 212 | sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION); |
| 213 | |
| 214 | /** |
| 215 | * Select the mailbox and retrieve the cached info. |
| 216 | */ |
| 217 | $aMailbox = sqm_api_mailbox_select($imapConnection,$account, $mailbox,$aConfig,$aMailboxPref); |
| 218 | |
| 219 | /** |
| 220 | * MOVE THIS to a central init section !!!! |
| 221 | */ |
| 222 | if (!sqgetGlobalVar('align',$align,SQ_SESSION)) { |
| 223 | $dir = ( isset( $languages[$squirrelmail_language]['DIR']) ) ? $languages[$squirrelmail_language]['DIR'] : 'ltr'; |
| 224 | if ( $dir == 'ltr' ) { |
| 225 | $align = array('left' => 'left', 'right' => 'right'); |
| 226 | } else { |
| 227 | $align = array('left' => 'right', 'right' => 'left'); |
| 228 | } |
| 229 | sqsession_register($align, 'align'); |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * After initialisation of the mailbox array it's time to handle the FORM data |
| 234 | */ |
| 235 | $sError = handleMessageListForm($imapConnection,$aMailbox); |
| 236 | if ($sError) { |
| 237 | $note = $sError; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Which templatedir are we using. TODO, add make a config var of this and make it possible to switch templates |
| 242 | */ |
| 243 | $sTplDir = SM_PATH . 'templates/default/'; |
| 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 | if (isset($aMailbox['FORWARD_SESSION'])) { |
| 251 | if ($compose_new_win) { |
| 252 | /* add the mailbox to the cache */ |
| 253 | $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox; |
| 254 | sqsession_register($mailbox_cache,'mailbox_cache'); |
| 255 | // write the session in order to make sure that the compose window has |
| 256 | // access to the composemessages array which is stored in the session |
| 257 | session_write_close(); |
| 258 | // restart the session. Do not use sqsession_is_active because the session_id |
| 259 | // isn't empty after a session_write_close |
| 260 | session_start(); |
| 261 | if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) { |
| 262 | $compose_width = '640'; |
| 263 | } |
| 264 | if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) { |
| 265 | $compose_height = '550'; |
| 266 | } |
| 267 | // do not use &, it will break the query string and $session will not be detected!!! |
| 268 | $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox). |
| 269 | '&session='.$aMailbox['FORWARD_SESSION']; |
| 270 | displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri', $compose_width, $compose_height);", ''); |
| 271 | } else { |
| 272 | $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox; |
| 273 | sqsession_register($mailbox_cache,'mailbox_cache'); |
| 274 | |
| 275 | // save mailboxstate |
| 276 | sqsession_register($aMailbox,'aLastSelectedMailbox'); |
| 277 | session_write_close(); |
| 278 | // we have to redirect to the compose page |
| 279 | $location = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox). |
| 280 | '&session='.$aMailbox['FORWARD_SESSION']; |
| 281 | header("Location: $location"); |
| 282 | exit; |
| 283 | } |
| 284 | } else { |
| 285 | displayPageHeader($color, $mailbox); |
| 286 | } |
| 287 | |
| 288 | do_hook('right_main_after_header'); |
| 289 | |
| 290 | /* display a message to the user that their mail has been sent */ |
| 291 | if (isset($mail_sent) && $mail_sent == 'yes') { |
| 292 | $note = _("Your Message has been sent."); |
| 293 | } |
| 294 | if (isset($note)) { |
| 295 | echo html_tag( 'div', '<b>' . htmlspecialchars($note) .'</b>', 'center' ) . "<br />\n"; |
| 296 | } |
| 297 | |
| 298 | if ( sqgetGlobalVar('just_logged_in', $just_logged_in, SQ_SESSION) ) { |
| 299 | if ($just_logged_in == true) { |
| 300 | $just_logged_in = false; |
| 301 | sqsession_register($just_logged_in, 'just_logged_in'); |
| 302 | |
| 303 | if (strlen(trim($motd)) > 0) { |
| 304 | echo html_tag( 'table', |
| 305 | html_tag( 'tr', |
| 306 | html_tag( 'td', |
| 307 | html_tag( 'table', |
| 308 | html_tag( 'tr', |
| 309 | html_tag( 'td', $motd, 'center' ) |
| 310 | ) , |
| 311 | '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' ) |
| 312 | ) |
| 313 | ) , |
| 314 | 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' ); |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * In the future, move this the the initialisation area |
| 321 | */ |
| 322 | |
| 323 | |
| 324 | $oTemplate = new Template($sTplDir); |
| 325 | |
| 326 | if ($aMailbox['EXISTS'] > 0) { |
| 327 | $aTemplateVars =& showMessagesForMailbox($imapConnection,$aMailbox,$aProps,$iError); |
| 328 | if ($iError) { |
| 329 | |
| 330 | } |
| 331 | foreach ($aTemplateVars as $k => $v) { |
| 332 | $oTemplate->assign($k, $v); |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | * TODO: To many config related vars. We should move all config related vars to |
| 337 | * one single associative array and assign that to the template |
| 338 | */ |
| 339 | $oTemplate->assign('page_selector', $page_selector); |
| 340 | $oTemplate->assign('page_selector_max', $page_selector_max); |
| 341 | $oTemplate->assign('compact_paginator', $compact_paginator); |
| 342 | $oTemplate->assign('javascript_on', $javascript_on); |
| 343 | $oTemplate->assign('enablesort', (isset($aProps['config']['enablesort'])) ? $aProps['config']['enablesort'] : false); |
| 344 | // Aaaaaahhhhhhh FIX ME DO NOT USE the string "none" for a var when you mean the boolean false or null |
| 345 | $oTemplate->assign('icon_theme', (isset($icon_theme) && $icon_theme !== 'none') ? $icon_theme : false); |
| 346 | $oTemplate->assign('use_icons', (isset($use_icons)) ? $use_icons : false); |
| 347 | $oTemplate->assign('aOrder', array_keys($aColumns)); |
| 348 | $oTemplate->assign('alt_index_colors', isset($alt_index_colors) ? $alt_index_colors: false); |
| 349 | $oTemplate->assign('color', $color); |
| 350 | $oTemplate->assign('align', $align); |
| 351 | |
| 352 | $oTemplate->display('message_list.tpl'); |
| 353 | |
| 354 | } else { |
| 355 | $string = '<b>' . _("THIS FOLDER IS EMPTY") . '</b>'; |
| 356 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">'; |
| 357 | echo ' <tr><td>'; |
| 358 | echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">'; |
| 359 | echo ' <tr><td><br />'; |
| 360 | echo ' <table cellpadding="1" cellspacing="5" align="center" border="0">'; |
| 361 | echo ' <tr>' . html_tag( 'td', $string."\n", 'left') |
| 362 | . '</tr>'; |
| 363 | echo ' </table>'; |
| 364 | echo ' <br /></td></tr>'; |
| 365 | echo ' </table></td></tr>'; |
| 366 | echo ' </table>'; |
| 367 | } |
| 368 | |
| 369 | do_hook('right_main_bottom'); |
| 370 | sqimap_logout ($imapConnection); |
| 371 | echo '</body></html>'; |
| 372 | |
| 373 | /* add the mailbox to the cache */ |
| 374 | $mailbox_cache[$account.'_'.$aMailbox['NAME']] = $aMailbox; |
| 375 | sqsession_register($mailbox_cache,'mailbox_cache'); |
| 376 | ?> |