| 1 | <?php |
| 2 | /** |
| 3 | ** left_main.php |
| 4 | ** Copyright (c) 1999-2000 The SquirrelMail development team |
| 5 | ** Licensed under the GNU GPL. For full terms see the file COPYING. |
| 6 | ** |
| 7 | ** This is the code for the left bar. The left bar shows the folders |
| 8 | ** available, and has cookie information. |
| 9 | ** |
| 10 | ** $Id$ |
| 11 | **/ |
| 12 | |
| 13 | session_start(); |
| 14 | |
| 15 | if (!isset($i18n_php)) |
| 16 | include ("../functions/i18n.php"); |
| 17 | |
| 18 | if(!isset($username)) { |
| 19 | set_up_language($squirrelmail_language, true); |
| 20 | include ("../themes/default_theme.php"); |
| 21 | printf('<html><BODY TEXT="%s" BGCOLOR="%s" LINK="%s" VLINK="%s" ALINK="%s">', |
| 22 | $color[8], $color[4], $color[7], $color[7], $color[7]); |
| 23 | echo "</body></html>"; |
| 24 | exit; |
| 25 | } |
| 26 | |
| 27 | |
| 28 | if (!isset($strings_php)) |
| 29 | include("../functions/strings.php"); |
| 30 | if (!isset($config_php)) |
| 31 | include("../config/config.php"); |
| 32 | if (!isset($array_php)) |
| 33 | include("../functions/array.php"); |
| 34 | if (!isset($imap_php)) |
| 35 | include("../functions/imap.php"); |
| 36 | if (!isset($page_header_php)) |
| 37 | include("../functions/page_header.php"); |
| 38 | if (!isset($i18n_php)) |
| 39 | include("../functions/i18n.php"); |
| 40 | if (!isset($plugin_php)) |
| 41 | include("../functions/plugin.php"); |
| 42 | |
| 43 | // open a connection on the imap port (143) |
| 44 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output |
| 45 | |
| 46 | /** If it was a successful login, lets load their preferences **/ |
| 47 | include("../src/load_prefs.php"); |
| 48 | |
| 49 | displayHtmlHeader(); |
| 50 | |
| 51 | function formatMailboxName($imapConnection, $box_array, $delimeter) { |
| 52 | global $folder_prefix, $trash_folder, $sent_folder; |
| 53 | global $color, $move_to_sent, $move_to_trash; |
| 54 | global $unseen_notify, $unseen_type, $collapse_folders; |
| 55 | |
| 56 | $real_box = $box_array['unformatted']; |
| 57 | $mailbox = $box_array['formatted']; |
| 58 | $mailboxURL = urlencode($real_box); |
| 59 | |
| 60 | $unseen = 0; |
| 61 | |
| 62 | if (($unseen_notify == 2 && $real_box == "INBOX") || |
| 63 | $unseen_notify == 3) { |
| 64 | $unseen = sqimap_unseen_messages($imapConnection, $numUnseen, $real_box); |
| 65 | if ($unseen_type == 1 && $unseen > 0) { |
| 66 | $unseen_string = "($unseen)"; |
| 67 | $unseen_found = true; |
| 68 | } else if ($unseen_type == 2) { |
| 69 | $numMessages = sqimap_get_num_messages($imapConnection, $real_box); |
| 70 | $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>"; |
| 71 | $unseen_found = true; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | $special_color = false; |
| 76 | if ((strtolower($real_box) == "inbox") || |
| 77 | (($real_box == $trash_folder) && ($move_to_trash)) || |
| 78 | (($real_box == $sent_folder) && ($move_to_sent))) |
| 79 | $special_color = true; |
| 80 | |
| 81 | $spaces = ''; |
| 82 | $line = "<NOBR>"; |
| 83 | if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) { |
| 84 | $spaces = $regs[1]; |
| 85 | $mailbox = $regs[2]; |
| 86 | } |
| 87 | |
| 88 | if ($unseen > 0) |
| 89 | $line .= "<B>"; |
| 90 | $line .= str_replace(' ', ' ', $spaces); |
| 91 | |
| 92 | if ($collapse_folders) { |
| 93 | if (isset($box_array['parent'])) |
| 94 | $line .= FoldLink($box_array['unformatted'], $box_array['parent']); |
| 95 | else |
| 96 | $line .= '<tt> </tt> '; |
| 97 | } |
| 98 | |
| 99 | $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">"; |
| 100 | if ($special_color == true) |
| 101 | $line .= "<FONT COLOR=\"$color[11]\">"; |
| 102 | $line .= str_replace(' ', ' ', $mailbox); |
| 103 | if ($special_color == true) |
| 104 | $line .= "</font>"; |
| 105 | $line .= "</a>"; |
| 106 | |
| 107 | if ($unseen > 0) |
| 108 | $line .= "</B>"; |
| 109 | |
| 110 | if (isset($unseen_found) && $unseen_found) { |
| 111 | $line .= " <small>$unseen_string</small>"; |
| 112 | } |
| 113 | |
| 114 | if (($move_to_trash == true) && ($real_box == $trash_folder)) { |
| 115 | $urlMailbox = urlencode($real_box); |
| 116 | $line .= "\n<small>\n"; |
| 117 | $line .= " (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)"; |
| 118 | $line .= "\n</small>\n"; |
| 119 | } |
| 120 | $line .= "</NOBR>"; |
| 121 | return $line; |
| 122 | } |
| 123 | |
| 124 | if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) { |
| 125 | echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n"; |
| 126 | echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n"; |
| 127 | echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n"; |
| 128 | } |
| 129 | |
| 130 | echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n"; |
| 131 | |
| 132 | do_hook("left_main_before"); |
| 133 | |
| 134 | $boxes = sqimap_mailbox_list($imapConnection); |
| 135 | |
| 136 | echo "<CENTER><FONT SIZE=4><B>"; |
| 137 | echo _("Folders") . "</B><BR></FONT>\n\n"; |
| 138 | |
| 139 | echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">"; |
| 140 | echo _("refresh folder list"); |
| 141 | echo "</A>)</small></CENTER><BR>"; |
| 142 | $delimeter = sqimap_get_delimiter($imapConnection); |
| 143 | |
| 144 | if (isset($collapse_folders) && $collapse_folders) { |
| 145 | if (isset($fold)) |
| 146 | setPref($data_dir, $username, 'collapse_folder_' . $fold, 1); |
| 147 | if (isset($unfold)) |
| 148 | setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0); |
| 149 | $IAmAParent = array(); |
| 150 | for ($i = 0; $i < count($boxes); $i ++) { |
| 151 | $parts = explode($delimeter, $boxes[$i]['unformatted']); |
| 152 | $box_name = array_pop($parts); |
| 153 | $box_parent = implode($delimeter, $parts); |
| 154 | $hidden = 0; |
| 155 | if (isset($box_parent)) { |
| 156 | $hidden = getPref($data_dir, $username, |
| 157 | 'collapse_folder_' . $box_parent); |
| 158 | $IAmAParent[$box_parent] = $hidden; |
| 159 | } |
| 160 | $boxes[$i]['folded'] = $hidden; |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | for ($i = 0;$i < count($boxes); $i++) { |
| 165 | if (! isset($boxes[$i]['folded']) || ! $boxes[$i]['folded']) |
| 166 | { |
| 167 | $line = ""; |
| 168 | $mailbox = $boxes[$i]["formatted"]; |
| 169 | |
| 170 | if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) { |
| 171 | $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']]; |
| 172 | } |
| 173 | |
| 174 | if (in_array('noselect', $boxes[$i]['flags'])) { |
| 175 | $line .= "<FONT COLOR=\"$color[10]\">"; |
| 176 | if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) { |
| 177 | $line .= str_replace(' ', ' ', $regs[1]); |
| 178 | if (isset($boxes[$i]['parent'])) |
| 179 | $line .= FoldLink($boxes[$i]['unformatted'], |
| 180 | $boxes[$i]['parent']); |
| 181 | elseif ($collapse_folders) |
| 182 | $line .= '<tt> </tt> '; |
| 183 | $line .= str_replace(' ', ' ', $regs[2]); |
| 184 | } |
| 185 | $line .= '</FONT>'; |
| 186 | } else { |
| 187 | $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter); |
| 188 | } |
| 189 | echo "$line<BR>\n"; |
| 190 | } |
| 191 | } |
| 192 | sqimap_logout($imapConnection); |
| 193 | do_hook("left_main_after"); |
| 194 | |
| 195 | function FoldLink($mailbox, $folded) { |
| 196 | $mailbox = urlencode($mailbox); |
| 197 | echo '<tt><a target="left" style="text-decoration:none" '; |
| 198 | echo 'href="left_main.php?'; |
| 199 | if ($folded) |
| 200 | echo "unfold=$mailbox\">+"; |
| 201 | else |
| 202 | echo "fold=$mailbox\">-"; |
| 203 | echo '</a></tt> '; |
| 204 | } |
| 205 | |
| 206 | ?> |
| 207 | </BODY></HTML> |