Operation "foo_once".
[squirrelmail.git] / src / left_main.php
CommitLineData
59177427 1<?php
21c3249f 2 /**
a09387f4 3 ** left_main.php
ef870322 4 ** Copyright (c) 1999-2000 The SquirrelMail development team
5 ** Licensed under the GNU GPL. For full terms see the file COPYING.
21c3249f 6 **
7 ** This is the code for the left bar. The left bar shows the folders
8 ** available, and has cookie information.
9 **
245a6892 10 ** $Id$
21c3249f 11 **/
12
ff8a98e7 13 require_once('../src/validate.php');
14 require_once('../functions/array.php');
15 require_once('../functions/imap.php');
16 require_once('../functions/plugin.php');
142499d4 17
99ab0367 18 // open a connection on the imap port (143)
19 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10); // the 10 is to hide the output
f7bfc9de 20
2a833d72 21 displayHtmlHeader();
21c3249f 22
7a906c8e 23 if ($auto_create_special && ! isset($auto_create_done)) {
f7bfc9de 24 if (isset ($sent_folder) && $sent_folder != "none") {
25 if (!sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
26 sqimap_mailbox_create ($imapConnection, $sent_folder, "");
8d636967 27 } else if (! sqimap_mailbox_is_subscribed($imapConnection, $sent_folder)) {
99c7a62c 28 sqimap_subscribe($imapConnection, $sent_folder);
f7bfc9de 29 }
30 }
31 if (isset ($trash_folder) && $trash_folder != "none") {
32 if (!sqimap_mailbox_exists ($imapConnection, $trash_folder)) {
33 sqimap_mailbox_create ($imapConnection, $trash_folder, "");
8d636967 34 } else if (! sqimap_mailbox_is_subscribed($imapConnection, $trash_folder)) {
99c7a62c 35 sqimap_subscribe($imapConnection, $trash_folder);
f7bfc9de 36 }
d3b3cda7 37 }
7a906c8e 38 $auto_create_done = true;
39 session_register('auto_create_done');
f7bfc9de 40 }
41
235a65d5 42 function formatMailboxName($imapConnection, $box_array, $delimeter) {
5bdd7223 43 global $folder_prefix, $trash_folder, $sent_folder;
44 global $color, $move_to_sent, $move_to_trash;
235a65d5 45 global $unseen_notify, $unseen_type, $collapse_folders;
46
47 $real_box = $box_array['unformatted'];
d3b3cda7 48 $mailbox = str_replace('&nbsp;',' ',$box_array['formatted']);
5c42b0dd 49 $mailboxURL = urlencode($real_box);
0cd84d75 50
235a65d5 51 $unseen = 0;
4d2c01e3 52
235a65d5 53 if (($unseen_notify == 2 && $real_box == "INBOX") ||
54 $unseen_notify == 3) {
4d2c01e3 55 $unseen = sqimap_unseen_messages($imapConnection, $real_box);
24fc5dd2 56 if ($unseen_type == 1 && $unseen > 0) {
57 $unseen_string = "($unseen)";
58 $unseen_found = true;
59 } else if ($unseen_type == 2) {
60 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
61 $unseen_string = "<font color=\"$color[11]\">($unseen/$numMessages)</font>";
62 $unseen_found = true;
63 }
64 }
5bdd7223 65
7ce342dc 66 $special_color = false;
508ca2d3 67 if ((strtolower($real_box) == "inbox") ||
235a65d5 68 (($real_box == $trash_folder) && ($move_to_trash)) ||
69 (($real_box == $sent_folder) && ($move_to_sent)))
70 $special_color = true;
71
72 $spaces = '';
73 $line = "<NOBR>";
74 if (ereg("^( *)([^ ]*)$", $mailbox, $regs)) {
75 $spaces = $regs[1];
76 $mailbox = $regs[2];
77 }
5bdd7223 78
235a65d5 79 if ($unseen > 0)
345a8a92 80 $line .= '&nbsp;<B>';
235a65d5 81 $line .= str_replace(' ', '&nbsp;', $spaces);
82
83 if ($collapse_folders) {
84 if (isset($box_array['parent']))
85 $line .= FoldLink($box_array['unformatted'], $box_array['parent']);
86 else
345a8a92 87 $line .= '<tt>&nbsp;</tt>&nbsp;&nbsp;';
d92b6f31 88 }
d3b3cda7 89
235a65d5 90 $line .= "<a href=\"right_main.php?sort=0&startMessage=1&mailbox=$mailboxURL\" target=\"right\" style=\"text-decoration:none\">";
91 if ($special_color == true)
92 $line .= "<FONT COLOR=\"$color[11]\">";
d3b3cda7 93 $line .= str_replace(' ','&nbsp;',$mailbox);
235a65d5 94 if ($special_color == true)
95 $line .= "</font>";
345a8a92 96 $line .= '</a>';
7ce342dc 97
d1941f35 98 if ($unseen > 0)
7ce342dc 99 $line .= "</B>";
235a65d5 100
245a6892 101 if (isset($unseen_found) && $unseen_found) {
24fc5dd2 102 $line .= "&nbsp;<small>$unseen_string</small>";
7ce342dc 103 }
104
1e0628fb 105 if (($move_to_trash == true) && ($real_box == $trash_folder)) {
b4cf620b 106 if (! isset($numMessages))
107 $numMessages = sqimap_get_num_messages($imapConnection, $real_box);
108
109 if ($numMessages > 0)
12d61439 110 {
b4cf620b 111 $urlMailbox = urlencode($real_box);
112 $line .= "\n<small>\n";
113 $line .= " &nbsp; (<B><A HREF=\"empty_trash.php\" style=\"text-decoration:none\">"._("purge")."</A></B>)";
114 $line .= "\n</small>\n";
12d61439 115 }
d92b6f31 116 }
1d4fe45e 117 $line .= "</NOBR>";
d92b6f31 118 return $line;
119 }
120
4c34dac5 121 if (isset($left_refresh) && ($left_refresh != "None") && ($left_refresh != "")) {
1d4fe45e 122 echo "<META HTTP-EQUIV=\"Expires\" CONTENT=\"Thu, 01 Dec 1994 16:00:00 GMT\">\n";
123 echo "<META HTTP-EQUIV=\"Pragma\" CONTENT=\"no-cache\">\n";
124 echo "<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"$left_refresh;URL=left_main.php\">\n";
469eb37b 125 }
813eba2f 126
04632dbc 127 echo "\n<BODY BGCOLOR=\"$color[3]\" TEXT=\"$color[6]\" LINK=\"$color[6]\" VLINK=\"$color[6]\" ALINK=\"$color[6]\">\n";
f3d17401 128
9d0c7bee 129 do_hook("left_main_before");
130
813eba2f 131 $boxes = sqimap_mailbox_list($imapConnection);
21c3249f 132
1d4fe45e 133 echo "<CENTER><FONT SIZE=4><B>";
134 echo _("Folders") . "</B><BR></FONT>\n\n";
97afcee9 135
9f2215a1 136 echo "<small>(<A HREF=\"../src/left_main.php\" TARGET=\"left\">";
ad6f805c 137 echo _("refresh folder list");
aae41ae9 138 echo "</A>)</small></CENTER><BR>";
813eba2f 139 $delimeter = sqimap_get_delimiter($imapConnection);
4c34dac5 140
235a65d5 141 if (isset($collapse_folders) && $collapse_folders) {
142 if (isset($fold))
143 setPref($data_dir, $username, 'collapse_folder_' . $fold, 1);
144 if (isset($unfold))
145 setPref($data_dir, $username, 'collapse_folder_' . $unfold, 0);
146 $IAmAParent = array();
147 for ($i = 0; $i < count($boxes); $i ++) {
148 $parts = explode($delimeter, $boxes[$i]['unformatted']);
149 $box_name = array_pop($parts);
150 $box_parent = implode($delimeter, $parts);
151 $hidden = 0;
152 if (isset($box_parent)) {
153 $hidden = getPref($data_dir, $username,
154 'collapse_folder_' . $box_parent);
155 $IAmAParent[$box_parent] = $hidden;
156 }
157 $boxes[$i]['folded'] = $hidden;
158 }
159 }
160
7ce342dc 161 for ($i = 0;$i < count($boxes); $i++) {
235a65d5 162 if (! isset($boxes[$i]['folded']) || ! $boxes[$i]['folded'])
163 {
164 $line = "";
165 $mailbox = $boxes[$i]["formatted"];
166
167 if (isset($collapse_folders) && $collapse_folders && isset($IAmAParent[$boxes[$i]['unformatted']])) {
168 $boxes[$i]['parent'] = $IAmAParent[$boxes[$i]['unformatted']];
169 }
170
171 if (in_array('noselect', $boxes[$i]['flags'])) {
172 $line .= "<FONT COLOR=\"$color[10]\">";
12d61439 173 if (ereg("^( *)([^ ]*)", $mailbox, $regs)) {
174 $line .= str_replace(' ', '&nbsp;', $mailbox);
7161db62 175 if (isset($boxes[$i]['parent']))
12d61439 176 $line .= FoldLink($boxes[$i]['unformatted'], $boxes[$i]['parent']);
7161db62 177 elseif ($collapse_folders)
178 $line .= '<tt>&nbsp;</tt>&nbsp;';
235a65d5 179 }
180 $line .= '</FONT>';
181 } else {
182 $line .= formatMailboxName($imapConnection, $boxes[$i], $delimeter);
183 }
184 echo "$line<BR>\n";
d92b6f31 185 }
d92b6f31 186 }
1195c340 187 sqimap_logout($imapConnection);
6b638171 188 do_hook("left_main_after");
235a65d5 189
190 function FoldLink($mailbox, $folded) {
191 $mailbox = urlencode($mailbox);
345a8a92 192 $link = '&nbsp;<tt><a target="left" style="text-decoration:none" ';
d3b3cda7 193 $link .= 'href="left_main.php?';
235a65d5 194 if ($folded)
d3b3cda7 195 $link .= "unfold=$mailbox\">+";
235a65d5 196 else
d3b3cda7 197 $link .= "fold=$mailbox\">-";
198 $link .= '</a></tt>&nbsp;';
199 return ($link);
235a65d5 200 }
201
21c3249f 202?>
ff8a98e7 203</BODY></HTML>