| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * right_main.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2003 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 | * $Id$ |
| 13 | */ |
| 14 | |
| 15 | /* Path for SquirrelMail required files. */ |
| 16 | define('SM_PATH','../'); |
| 17 | |
| 18 | /* SquirrelMail required files. */ |
| 19 | require_once(SM_PATH . 'include/validate.php'); |
| 20 | require_once(SM_PATH . 'functions/imap.php'); |
| 21 | require_once(SM_PATH . 'functions/date.php'); |
| 22 | require_once(SM_PATH . 'functions/mime.php'); |
| 23 | require_once(SM_PATH . 'functions/mailbox_display.php'); |
| 24 | require_once(SM_PATH . 'functions/display_messages.php'); |
| 25 | require_once(SM_PATH . 'functions/html.php'); |
| 26 | |
| 27 | /*********************************************************** |
| 28 | * incoming variables from URL: * |
| 29 | * $sort Direction to sort by date * |
| 30 | * values: 0 - descending order * |
| 31 | * values: 1 - ascending order * |
| 32 | * $startMessage Message to start at * |
| 33 | * $mailbox Full Mailbox name * |
| 34 | * * |
| 35 | * incoming from cookie: * |
| 36 | * $key pass * |
| 37 | * incoming from session: * |
| 38 | * $username duh * |
| 39 | * * |
| 40 | ***********************************************************/ |
| 41 | |
| 42 | |
| 43 | /* lets get the global vars we may need */ |
| 44 | $username = $_SESSION['username']; |
| 45 | $key = $_COOKIE['key']; |
| 46 | $onetimepad = $_SESSION['onetimepad']; |
| 47 | $base_uri = $_SESSION['base_uri']; |
| 48 | $delimiter = $_SESSION['delimiter']; |
| 49 | |
| 50 | if (isset($_GET['startMessage'])) { |
| 51 | $startMessage = (int) $_GET['startMessage']; |
| 52 | } elseif (isset($_POST['startMessage'])) { |
| 53 | $startMessage = (int) $_POST['startMessage']; |
| 54 | } |
| 55 | if (isset($_GET['mailbox'])) { |
| 56 | $mailbox = $_GET['mailbox']; |
| 57 | } else if (isset($_POST['mailbox'])) { |
| 58 | $mailbox = $_POST['mailbox']; |
| 59 | } |
| 60 | if (isset($_GET['PG_SHOWNUM'])) { |
| 61 | $PG_SHOWNUM = (int) $_GET['PG_SHOWNUM']; |
| 62 | } |
| 63 | elseif (isset($_SESSION['PG_SHOWNUM'])) { |
| 64 | $PG_SHOWNUM = (int) $_SESSION['PG_SHOWNUM']; |
| 65 | } |
| 66 | if (isset($_GET['PG_SHOWALL'])) { |
| 67 | $PG_SHOWALL = (int) $_GET['PG_SHOWALL']; |
| 68 | } |
| 69 | if (isset($_GET['newsort'])) { |
| 70 | $newsort = (int) $_GET['newsort']; |
| 71 | } |
| 72 | if (isset($_GET['composenew'])) { |
| 73 | $composenew = $_GET['composenew']; |
| 74 | } else { |
| 75 | $composenew = false; |
| 76 | } |
| 77 | |
| 78 | if (isset($_GET['checkall'])) { |
| 79 | $checkall = (int) $_GET['checkall']; |
| 80 | } |
| 81 | if (isset($_GET['set_thread'])) { |
| 82 | $set_thread = (int) $_GET['set_thread']; |
| 83 | } |
| 84 | if (isset($_SESSION['lastTargetMailbox'])) { |
| 85 | $lastTargetMailbox =$_SESSION['lastTargetMailbox']; |
| 86 | } |
| 87 | |
| 88 | if (isset($_GET['session'])) { |
| 89 | $session = $_GET['session']; |
| 90 | } |
| 91 | |
| 92 | if (isset($_GET['note'])) { |
| 93 | $note = $_GET['note']; |
| 94 | } |
| 95 | |
| 96 | /* end of get globals */ |
| 97 | |
| 98 | |
| 99 | /* Open a connection on the imap port (143) */ |
| 100 | |
| 101 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 102 | |
| 103 | if (isset($PG_SHOWALL)) { |
| 104 | if ($PG_SHOWALL) { |
| 105 | $PG_SHOWNUM=999999; |
| 106 | $show_num=$PG_SHOWNUM; |
| 107 | sqsession_register($PG_SHOWNUM, 'PG_SHOWNUM'); |
| 108 | } |
| 109 | else { |
| 110 | sqsession_unregister('PG_SHOWNUM'); |
| 111 | unset($PG_SHOWNUM); |
| 112 | } |
| 113 | } |
| 114 | else if( isset( $PG_SHOWNUM ) ) { |
| 115 | $show_num = $PG_SHOWNUM; |
| 116 | } |
| 117 | |
| 118 | if (isset($newsort) && $newsort != $sort) { |
| 119 | setPref($data_dir, $username, 'sort', $newsort); |
| 120 | } |
| 121 | |
| 122 | |
| 123 | |
| 124 | /* If the page has been loaded without a specific mailbox, */ |
| 125 | /* send them to the inbox */ |
| 126 | if (!isset($mailbox)) { |
| 127 | $mailbox = 'INBOX'; |
| 128 | $startMessage = 1; |
| 129 | } |
| 130 | |
| 131 | |
| 132 | if (!isset($startMessage) || ($startMessage == '')) { |
| 133 | $startMessage = 1; |
| 134 | } |
| 135 | |
| 136 | /* compensate for the UW vulnerability. */ |
| 137 | if ($imap_server_type == 'uw' && (strstr($mailbox, '../') || |
| 138 | substr($mailbox, 0, 1) == '/')) { |
| 139 | $mailbox = 'INBOX'; |
| 140 | } |
| 141 | |
| 142 | /* decide if we are thread sorting or not */ |
| 143 | if ($allow_thread_sort == TRUE) { |
| 144 | if (isset($set_thread)) { |
| 145 | if ($set_thread == 1) { |
| 146 | setPref($data_dir, $username, "thread_$mailbox", 1); |
| 147 | $thread_sort_messages = '1'; |
| 148 | } |
| 149 | elseif ($set_thread == 2) { |
| 150 | setPref($data_dir, $username, "thread_$mailbox", 0); |
| 151 | $thread_sort_messages = '0'; |
| 152 | } |
| 153 | } |
| 154 | else { |
| 155 | $thread_sort_messages = getPref($data_dir, $username, "thread_$mailbox"); |
| 156 | } |
| 157 | } |
| 158 | else { |
| 159 | $thread_sort_messages = 0; |
| 160 | } |
| 161 | |
| 162 | do_hook ('generic_header'); |
| 163 | |
| 164 | sqimap_mailbox_select($imapConnection, $mailbox); |
| 165 | |
| 166 | if ($composenew) { |
| 167 | $comp_uri = SM_PATH . 'src/compose.php?mailbox='. urlencode($mailbox). |
| 168 | "&session=$session"; |
| 169 | displayPageHeader($color, $mailbox, "comp_in_new('$comp_uri');", false); |
| 170 | } else { |
| 171 | displayPageHeader($color, $mailbox); |
| 172 | } |
| 173 | do_hook('right_main_after_header'); |
| 174 | if (isset($note)) { |
| 175 | echo html_tag( 'div', '<b>' . $note .'</b>', 'center' ) . "<br>\n"; |
| 176 | } |
| 177 | |
| 178 | if (isset($_SESSION['just_logged_in'])) { |
| 179 | $just_logged_in = $_SESSION['just_logged_in']; |
| 180 | if ($just_logged_in == true) { |
| 181 | $just_logged_in = false; |
| 182 | |
| 183 | if (strlen(trim($motd)) > 0) { |
| 184 | echo html_tag( 'table', |
| 185 | html_tag( 'tr', |
| 186 | html_tag( 'td', |
| 187 | html_tag( 'table', |
| 188 | html_tag( 'tr', |
| 189 | html_tag( 'td', $motd, 'center' ) |
| 190 | ) , |
| 191 | '', $color[4], 'width="100%" cellpadding="5" cellspacing="1" border="0"' ) |
| 192 | ) |
| 193 | ) , |
| 194 | 'center', $color[9], 'width="70%" cellpadding="0" cellspacing="3" border="0"' ); |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | if (isset($newsort)) { |
| 200 | $sort = $newsort; |
| 201 | sqsession_register($sort, 'sort'); |
| 202 | } |
| 203 | |
| 204 | /********************************************************************* |
| 205 | * Check to see if we can use cache or not. Currently the only time * |
| 206 | * when you will not use it is when a link on the left hand frame is * |
| 207 | * used. Also check to make sure we actually have the array in the * |
| 208 | * registered session data. :) * |
| 209 | *********************************************************************/ |
| 210 | if (! isset($use_mailbox_cache)) { |
| 211 | $use_mailbox_cache = 0; |
| 212 | } |
| 213 | |
| 214 | if ($use_mailbox_cache && sqsession_is_registered('msgs')) { |
| 215 | showMessagesForMailbox($imapConnection, $mailbox, $numMessages, $startMessage, $sort, $color, $show_num, $use_mailbox_cache); |
| 216 | } else { |
| 217 | if (sqsession_is_registered('msgs')) { |
| 218 | unset($msgs); |
| 219 | } |
| 220 | |
| 221 | if (sqsession_is_registered('msort')) { |
| 222 | unset($msort); |
| 223 | } |
| 224 | |
| 225 | if (sqsession_is_registered('numMessages')) { |
| 226 | unset($numMessages); |
| 227 | } |
| 228 | |
| 229 | $numMessages = sqimap_get_num_messages ($imapConnection, $mailbox); |
| 230 | |
| 231 | showMessagesForMailbox($imapConnection, $mailbox, $numMessages, |
| 232 | $startMessage, $sort, $color, $show_num, |
| 233 | $use_mailbox_cache); |
| 234 | |
| 235 | if (sqsession_is_registered('msgs') && isset($msgs)) { |
| 236 | sqsession_register($msgs, 'msgs'); |
| 237 | $_SESSION['msgs'] = $msgs; |
| 238 | } |
| 239 | |
| 240 | if (sqsession_is_registered('msort') && isset($msort)) { |
| 241 | sqsession_register($msort, 'msort'); |
| 242 | $_SESSION['msort'] = $msort; |
| 243 | } |
| 244 | |
| 245 | sqsession_register($numMessages, 'numMessages'); |
| 246 | $_SESSION['numMessages'] = $numMessages; |
| 247 | } |
| 248 | do_hook('right_main_bottom'); |
| 249 | sqimap_logout ($imapConnection); |
| 250 | |
| 251 | echo '</body></html>'; |
| 252 | |
| 253 | ?> |