6 * This is the code for the left bar. The left bar shows the folders
7 * available, and has cookie information.
9 * @copyright 1999-2017 The SquirrelMail Project Team
10 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
12 * @package squirrelmail
15 /** This is the left_main page */
16 define('PAGE_NAME', 'left_main');
19 * Include the SquirrelMail initialization file.
21 require('../include/init.php');
23 /* SquirrelMail required files. */
24 require_once(SM_PATH
. 'functions/imap_general.php');
25 require_once(SM_PATH
. 'functions/date.php');
26 require_once(SM_PATH
. 'functions/template/folder_list_util.php');
28 /* These constants are used for folder stuff. */
29 define('SM_BOX_UNCOLLAPSED', 0);
30 define('SM_BOX_COLLAPSED', 1);
33 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
35 sqgetGlobalVar('fold', $fold, SQ_GET
);
36 sqgetGlobalVar('unfold', $unfold, SQ_GET
);
39 // open a connection on the imap port (143)
40 // why hide the output?
41 global $imap_stream_options; // in case not defined in config
42 $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, true, $imap_stream_options);
45 * Using stristr since very old preferences may contain "None" and "none".
47 if (!empty($left_refresh) &&
48 !stristr($left_refresh, 'none')){
49 $xtra = "\n<meta http-equiv=\"REFRESH\" content=\"$left_refresh;URL=left_main.php\" />\n";
55 * Include extra javascript files needed by template
57 $js_includes = $oTemplate->get_javascript_includes(TRUE);
58 foreach ($js_includes as $js_file) {
59 $xtra .= '<script src="'.$js_file.'" type="text/javascript"></script>' ."\n";
62 // get mailbox list and cache it
63 $mailboxes=sqimap_get_mailboxes($imapConnection,false,$show_only_subscribed_folders);
65 displayHtmlHeader( $org_title, $xtra );
66 $oErrorHandler->setDelayedErrors(true);
68 sqgetGlobalVar('auto_create_done',$auto_create_done,SQ_SESSION
);
69 /* If requested and not yet complete, attempt to autocreate folders. */
70 if ($auto_create_special && !isset($auto_create_done)) {
71 $autocreate = array($sent_folder, $trash_folder, $draft_folder);
72 $folders_created = false;
73 foreach( $autocreate as $folder ) {
74 if ($folder != '' && $folder != SMPREF_NONE
) {
76 * If $show_only_subscribed_folders is true, don't use
77 * $mailboxes array for checking if mailbox exists.
78 * Mailbox list contains only subscribed folders.
79 * sqimap_mailbox_create() will fail, if folder exists.
81 if ($show_only_subscribed_folders) {
82 $mailbox_cache = false;
84 $mailbox_cache = $mailboxes;
86 if ( !sqimap_mailbox_exists($imapConnection, $folder, $mailbox_cache)) {
87 sqimap_mailbox_create($imapConnection, $folder, '');
88 $folders_created = true;
90 // check for subscription is useless and expensive, just
91 // surpress the NO response. Unless we're on Mecury, which
92 // will just subscribe a folder again if it's already
94 if ( strtolower($imap_server_type) != 'mercury32' ||
95 !sqimap_mailbox_is_subscribed($imapConnection, $folder) ) {
96 sqimap_subscribe($imapConnection, $folder, false);
97 $folders_created = true;
103 /* Let the world know that autocreation is complete! Hurrah! */
104 $auto_create_done = TRUE;
105 sqsession_register($auto_create_done, 'auto_create_done');
106 // reload mailbox list
107 if ($folders_created)
108 $mailboxes=sqimap_get_mailboxes($imapConnection,true,$show_only_subscribed_folders);
112 if ($date_format != 6) {
113 /* First, display the clock. */
114 if ($hour_format == 1) {
116 if ($date_format == 4) {
120 if ($date_format == 4) {
127 switch( $date_format ) {
129 $clk = date('Y-m-d '.$hr. ' T', time());
132 $clk = date('m/d/y '.$hr, time());
135 $clk = date('d/m/y '.$hr, time());
139 $clk = date($hr, time());
142 $clk = getDayAbrv( date( 'w', time() ) ) . date( ', ' . $hr, time() );
144 $clk = str_replace(' ',' ',$clk);
146 //FIXME don't build HTML here - do it in template
147 $clock = '<small><span style="white-space: nowrap;">'
148 . str_replace(' ', ' ', _("Last Refresh"))
149 . ":</span><br /><span style=\"white-space: nowrap;\">$clk</span></small><br />\n";
152 if ( $collapse_folders ) {
153 /* If directed, collapse or uncollapse a folder. */
155 setPref($data_dir, $username, 'collapse_folder_' . $fold, SM_BOX_COLLAPSED
);
156 } else if (isset($unfold)) {
157 setPref($data_dir, $username, 'collapse_folder_' . $unfold, SM_BOX_UNCOLLAPSED
);
161 /* Get unseen/total display prefs */
162 $unseen_type = getPref( $data_dir , $username , 'unseen_type' );
163 $unseen_notify = getPref( $data_dir , $username , 'unseen_notify' );
165 if (empty($unseen_type)) {
166 if (!empty($default_unseen_type)) {
167 $unseen_type = $default_unseen_type;
173 if (empty($unseen_notify)) {
174 if (!empty($default_unseen_notify)) {
175 $unseen_notify = $default_unseen_notify;
182 * pass $mailboxes now instead of $imapconnection - sqimap_get_mailboxes() has been separated from
183 * sqimap_mailbox_tree() so that the cached mailbox list can be used elsewhere in left_main and beyond
185 $boxes = sqimap_mailbox_tree($imapConnection,$mailboxes,$show_only_subscribed_folders);
186 $mailbox_structure = getBoxStructure($boxes);
188 $oTemplate->assign('clock', $clock);
189 $oTemplate->assign('mailboxes', $mailbox_structure);
192 * Build an array to pass user prefs to the template in order to avoid using
193 * globals, which are dirty, filthy things in templates. :)
196 #$settings['imapConnection'] = $imapConnection;
197 $settings['templateID'] = $sTemplateID;
198 $settings['unreadNotificationEnabled'] = $unseen_notify!=1;
199 $settings['unreadNotificationAllFolders'] = $unseen_notify == 3;
200 $settings['unreadNotificationDisplayTotal'] = $unseen_type == 2;
201 $settings['unreadNotificationCummulative'] = $unseen_cum==1;
202 $settings['useSpecialFolderColor'] = $use_special_folder_color;
203 $settings['messageRecyclingEnabled'] = $move_to_trash;
204 $settings['collapsableFoldersEnabled'] = $collapse_folders==1;
205 $oTemplate->assign('settings', $settings);
209 $oTemplate->assign('accesskey_folders_refresh', $accesskey_folders_refresh);
210 $oTemplate->assign('accesskey_folders_purge_trash', $accesskey_folders_purge_trash);
211 $oTemplate->assign('accesskey_folders_inbox', $accesskey_folders_inbox);
213 $oTemplate->display('left_main.tpl');
215 sqimap_logout($imapConnection);
216 $oTemplate->display('footer.tpl');