| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * folders.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
| 7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 8 | * |
| 9 | * Handles all interaction between the user and the other folder |
| 10 | * scripts which do most of the work. Also handles the Special |
| 11 | * Folders. |
| 12 | * |
| 13 | * $Id$ |
| 14 | */ |
| 15 | |
| 16 | /* Path for SquirrelMail required files. */ |
| 17 | define('SM_PATH','../'); |
| 18 | |
| 19 | /* SquirrelMail required files. */ |
| 20 | require_once(SM_PATH . 'include/validate.php'); |
| 21 | require_once(SM_PATH . 'functions/imap_utf7_decode_local.php'); |
| 22 | require_once(SM_PATH . 'functions/imap.php'); |
| 23 | require_once(SM_PATH . 'functions/array.php'); |
| 24 | require_once(SM_PATH . 'functions/plugin.php'); |
| 25 | require_once(SM_PATH . 'functions/html.php'); |
| 26 | |
| 27 | displayPageHeader($color, 'None'); |
| 28 | |
| 29 | /* get globals we may need */ |
| 30 | |
| 31 | $username = $_SESSION['username']; |
| 32 | $key = $_COOKIE['key']; |
| 33 | $delimiter = $_SESSION['delimiter']; |
| 34 | $onetimepad = $_SESSION['onetimepad']; |
| 35 | if (isset($_GET['success'])) { |
| 36 | $success = $_GET['success']; |
| 37 | } |
| 38 | |
| 39 | /* end of get globals */ |
| 40 | |
| 41 | echo '<br>' . |
| 42 | html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . |
| 43 | html_tag( 'tr' ) . |
| 44 | html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' . |
| 45 | html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . |
| 46 | html_tag( 'tr' ) . |
| 47 | html_tag( 'td', '', 'center', $color[4] ); |
| 48 | |
| 49 | if ((isset($success) && $success) || |
| 50 | (isset($sent_create) && $sent_create == 'true') || |
| 51 | (isset($trash_create) && $trash_create == 'true')) { |
| 52 | if ($success == "subscribe") { |
| 53 | $td_str = "<b>" . _("Subscribed successfully!") . "</b><br>"; |
| 54 | } else if ($success == "unsubscribe") { |
| 55 | $td_str = "<b>" . _("Unsubscribed successfully!") . "</b><br>"; |
| 56 | } else if ($success == "delete") { |
| 57 | $td_str = "<b>" . _("Deleted folder successfully!") . "</b><br>"; |
| 58 | } else if ($success == "create") { |
| 59 | $td_str = "<b>" . _("Created folder successfully!") . "</b><br>"; |
| 60 | } else if ($success == "rename") { |
| 61 | $td_str = "<b>" . _("Renamed successfully!") . "</b><br>"; |
| 62 | } else if ($success == "subscribe-doesnotexist") { |
| 63 | $td_str = "<b>" . |
| 64 | _("Subscription Unsuccessful - Folder does not exist.") . |
| 65 | "</b><br>"; |
| 66 | } |
| 67 | |
| 68 | echo html_tag( 'table', |
| 69 | html_tag( 'tr', |
| 70 | html_tag( 'td', $td_str . |
| 71 | "<a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>" , |
| 72 | 'center' ) |
| 73 | ) , |
| 74 | 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ) . "<br>\n"; |
| 75 | } else { |
| 76 | echo "<br>"; |
| 77 | } |
| 78 | $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0); |
| 79 | $boxes = sqimap_mailbox_list($imapConnection); |
| 80 | |
| 81 | /** CREATING FOLDERS **/ |
| 82 | echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) . |
| 83 | html_tag( 'tr', |
| 84 | html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] ) |
| 85 | ) . |
| 86 | html_tag( 'tr' ) . |
| 87 | html_tag( 'td', '', 'center', $color[0] ) . |
| 88 | |
| 89 | "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n". |
| 90 | "<input type=TEXT SIZE=25 NAME=folder_name><BR>\n". |
| 91 | _("as a subfolder of"). |
| 92 | "<BR>". |
| 93 | "<TT><SELECT NAME=subfolder>\n"; |
| 94 | if ($default_sub_of_inbox == false) { |
| 95 | echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n"; |
| 96 | } else { |
| 97 | echo '<OPTION VALUE="">[ '._("None")." ]\n"; |
| 98 | } |
| 99 | |
| 100 | for ($i = 0; $i < count($boxes); $i++) { |
| 101 | if (!in_array('noinferiors', $boxes[$i]['flags'])) { |
| 102 | if ((strtolower($boxes[$i]['unformatted']) == 'inbox') && |
| 103 | $default_sub_of_inbox) { |
| 104 | |
| 105 | $box = $boxes[$i]['unformatted']; |
| 106 | $box2 = str_replace(' ', ' ', |
| 107 | imap_utf7_decode_local($boxes[$i]['unformatted-disp'])); |
| 108 | echo "<OPTION SELECTED VALUE=\"$box\">$box2</option>\n"; |
| 109 | } else { |
| 110 | $box = $boxes[$i]['unformatted']; |
| 111 | $box2 = str_replace(' ', ' ', |
| 112 | imap_utf7_decode_local($boxes[$i]['unformatted-disp'])); |
| 113 | if (strtolower($imap_server_type) != 'courier' || |
| 114 | strtolower($box) != "inbox.trash") |
| 115 | echo "<OPTION VALUE=\"$box\">$box2</option>\n"; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | echo "</SELECT></TT>\n"; |
| 120 | if ($show_contain_subfolders_option) { |
| 121 | echo "<br><input type=CHECKBOX NAME=\"contain_subs\"> "; |
| 122 | echo _("Let this folder contain subfolders"); |
| 123 | echo "<BR>"; |
| 124 | } |
| 125 | echo "<input type=SUBMIT VALUE=\""._("Create")."\">\n"; |
| 126 | echo "</FORM></td></tr>\n"; |
| 127 | |
| 128 | echo html_tag( 'tr', |
| 129 | html_tag( 'td', ' ', 'left', $color[4] ) |
| 130 | ) ."\n"; |
| 131 | |
| 132 | /** count special folders **/ |
| 133 | $count_special_folders = 0; |
| 134 | $num_max = 1; |
| 135 | if (strtolower($imap_server_type) == "courier" || $move_to_trash) { |
| 136 | $num_max++; |
| 137 | } |
| 138 | if ($move_to_sent) { |
| 139 | $num_max++; |
| 140 | } |
| 141 | if ($save_as_draft) { |
| 142 | $num_max++; |
| 143 | } |
| 144 | for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) { |
| 145 | if (strtolower($boxes[$p]['unformatted']) == 'inbox') |
| 146 | $count_special_folders++; |
| 147 | else if (strtolower($imap_server_type) == 'courier' && |
| 148 | strtolower($boxes[$p]['unformatted']) == 'inbox.trash') |
| 149 | $count_special_folders++; |
| 150 | else if ($boxes[$p]['unformatted'] == $trash_folder && $trash_folder) |
| 151 | $count_special_folders++; |
| 152 | else if ($boxes[$p]['unformatted'] == $sent_folder && $sent_folder) |
| 153 | $count_special_folders++; |
| 154 | else if ($boxes[$p]['unformatted'] == $draft_folder && $draft_folder) |
| 155 | $count_special_folders++; |
| 156 | } |
| 157 | |
| 158 | |
| 159 | /** RENAMING FOLDERS **/ |
| 160 | echo html_tag( 'tr', |
| 161 | html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] ) |
| 162 | ) . |
| 163 | html_tag( 'tr' ) . |
| 164 | html_tag( 'td', '', 'center', $color[0] ); |
| 165 | |
| 166 | if ($count_special_folders < count($boxes)) { |
| 167 | echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n" |
| 168 | . "<TT><SELECT NAME=old>\n" |
| 169 | . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n"; |
| 170 | for ($i = 0; $i < count($boxes); $i++) { |
| 171 | $use_folder = true; |
| 172 | |
| 173 | if ((strtolower($boxes[$i]['unformatted']) != 'inbox') && |
| 174 | ($boxes[$i]['unformatted'] != $trash_folder) && |
| 175 | ($boxes[$i]['unformatted'] != $sent_folder) && |
| 176 | ($boxes[$i]['unformatted'] != $draft_folder)) { |
| 177 | $box = $boxes[$i]['unformatted-dm']; |
| 178 | |
| 179 | $box2 = str_replace(' ', ' ', |
| 180 | imap_utf7_decode_local($boxes[$i]['unformatted-disp'])); |
| 181 | if (strtolower($imap_server_type) != 'courier' || strtolower($box) != 'inbox.trash') { |
| 182 | echo "<OPTION VALUE=\"$box\">$box2</option>\n"; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | echo "</SELECT></TT>\n". |
| 187 | "<input type=SUBMIT VALUE=\"". |
| 188 | _("Rename"). |
| 189 | "\">\n". |
| 190 | "</FORM></td></tr>\n"; |
| 191 | } else { |
| 192 | echo _("No folders found") . "<br><br></td></tr>"; |
| 193 | } |
| 194 | $boxes_sub = $boxes; |
| 195 | |
| 196 | echo html_tag( 'tr', |
| 197 | html_tag( 'td', ' ', 'left', $color[4] ) |
| 198 | ) ."\n"; |
| 199 | |
| 200 | /** DELETING FOLDERS **/ |
| 201 | echo html_tag( 'tr', |
| 202 | html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] ) |
| 203 | ) . |
| 204 | html_tag( 'tr' ) . |
| 205 | html_tag( 'td', '', 'center', $color[0] ); |
| 206 | |
| 207 | if ($count_special_folders < count($boxes)) { |
| 208 | echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n" |
| 209 | . "<TT><SELECT NAME=mailbox>\n" |
| 210 | . ' <OPTION VALUE="">[ ' . _("Select a folder") . " ]</OPTION>\n"; |
| 211 | for ($i = 0; $i < count($boxes); $i++) { |
| 212 | $use_folder = true; |
| 213 | if ((strtolower($boxes[$i]['unformatted']) != 'inbox') && |
| 214 | ($boxes[$i]['unformatted'] != $trash_folder) && |
| 215 | ($boxes[$i]['unformatted'] != $sent_folder) && |
| 216 | ($boxes[$i]['unformatted'] != $draft_folder) && |
| 217 | (!in_array('noselect', $boxes[$i]['flags'])) && |
| 218 | ((strtolower($imap_server_type) != 'courier') || |
| 219 | (strtolower($boxes[$i]['unformatted']) != 'inbox.trash'))) { |
| 220 | $box = $boxes[$i]['unformatted-dm']; |
| 221 | $box2 = str_replace(' ', ' ', |
| 222 | imap_utf7_decode_local($boxes[$i]['unformatted-disp'])); |
| 223 | echo " <OPTION VALUE=\"$box\">$box2</option>\n"; |
| 224 | } |
| 225 | } |
| 226 | echo "</SELECT></TT>\n"; |
| 227 | echo "<input type=SUBMIT VALUE=\""; |
| 228 | echo _("Delete"); |
| 229 | echo "\">\n"; |
| 230 | echo "</form></td></tr>\n"; |
| 231 | } else { |
| 232 | echo _("No folders found") . "<br><br></td></tr>"; |
| 233 | } |
| 234 | |
| 235 | echo html_tag( 'tr', |
| 236 | html_tag( 'td', ' ', 'left', $color[4] ) |
| 237 | ) ."</table>\n"; |
| 238 | |
| 239 | |
| 240 | /** UNSUBSCRIBE FOLDERS **/ |
| 241 | echo html_tag( 'table', '', 'center', '', 'width="70%" cols="2" cellpadding="4" cellspacing="0" border="0"' ) . |
| 242 | html_tag( 'tr', |
| 243 | html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' ) |
| 244 | ) . |
| 245 | html_tag( 'tr' ) . |
| 246 | html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
| 247 | |
| 248 | if ($count_special_folders < count($boxes)) { |
| 249 | echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"; |
| 250 | echo "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n"; |
| 251 | for ($i = 0; $i < count($boxes); $i++) { |
| 252 | $use_folder = true; |
| 253 | if ((strtolower($boxes[$i]["unformatted"]) != "inbox") && |
| 254 | ($boxes[$i]["unformatted"] != $trash_folder) && |
| 255 | ($boxes[$i]["unformatted"] != $sent_folder) && |
| 256 | ($boxes[$i]["unformatted"] != $draft_folder)) { |
| 257 | $box = $boxes[$i]["unformatted-dm"]; |
| 258 | $box2 = str_replace(' ', ' ', |
| 259 | imap_utf7_decode_local($boxes[$i]["unformatted-disp"])); |
| 260 | echo " <OPTION VALUE=\"$box\">$box2\n"; |
| 261 | } |
| 262 | } |
| 263 | echo "</SELECT></TT><br><br>\n"; |
| 264 | echo "<input type=SUBMIT VALUE=\""; |
| 265 | echo _("Unsubscribe"); |
| 266 | echo "\">\n"; |
| 267 | echo "</FORM></td>\n"; |
| 268 | } else { |
| 269 | echo _("No folders were found to unsubscribe from!") . "</td>"; |
| 270 | } |
| 271 | $boxes_sub = $boxes; |
| 272 | |
| 273 | /** SUBSCRIBE TO FOLDERS **/ |
| 274 | echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); |
| 275 | if(!$no_list_for_subscribe) { |
| 276 | $imap_stream = sqimap_login ($username, $key, $imapServerAddress, |
| 277 | $imapPort, 1); |
| 278 | $boxes_all = sqimap_mailbox_list_all ($imap_stream); |
| 279 | |
| 280 | $box = ""; |
| 281 | $box2 = ""; |
| 282 | for ($i = 0, $q = 0; $i < count($boxes_all); $i++) { |
| 283 | $use_folder = true; |
| 284 | for ($p = 0; $p < count ($boxes); $p++) { |
| 285 | if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) { |
| 286 | $use_folder = false; |
| 287 | continue; |
| 288 | } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) { |
| 289 | $use_folder = false; |
| 290 | } |
| 291 | } |
| 292 | if ($use_folder == true) { |
| 293 | $box[$q] = $boxes_all[$i]["unformatted-dm"]; |
| 294 | $box2[$q] = imap_utf7_decode_local($boxes_all[$i]["unformatted-disp"]); |
| 295 | $q++; |
| 296 | } |
| 297 | } |
| 298 | sqimap_logout($imap_stream); |
| 299 | |
| 300 | if ($box && $box2) { |
| 301 | echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"; |
| 302 | echo "<tt><select name=\"mailbox[]\" multiple size=8>"; |
| 303 | |
| 304 | for ($q = 0; $q < count($box); $q++) { |
| 305 | echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n"; |
| 306 | } |
| 307 | echo "</select></tt><br><br>"; |
| 308 | echo "<input type=SUBMIT VALUE=\"". _("Subscribe") . "\">\n"; |
| 309 | echo "</FORM></td></tr></table><BR>\n"; |
| 310 | } else { |
| 311 | echo _("No folders were found to subscribe to!") . "</td></tr></table>"; |
| 312 | } |
| 313 | } else { |
| 314 | /* don't perform the list action -- this is much faster */ |
| 315 | echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"; |
| 316 | echo _("Subscribe to:") . "<br>"; |
| 317 | echo "<tt><input type=\"text\" name=\"mailbox[]\" size=35>"; |
| 318 | echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n"; |
| 319 | echo "</FORM></TD></TR></TABLE><BR>\n"; |
| 320 | } |
| 321 | |
| 322 | do_hook("folders_bottom"); |
| 323 | ?> |
| 324 | |
| 325 | |
| 326 | </td></tr> |
| 327 | </table> |
| 328 | |
| 329 | </td></tr> |
| 330 | </table> |
| 331 | |
| 332 | <?php |
| 333 | sqimap_logout($imapConnection); |
| 334 | ?> |
| 335 | |
| 336 | </body></html> |