| 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 | /*****************************************************************/ |
| 17 | /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ |
| 18 | /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ |
| 19 | /*** + Base level indent should begin at left margin, as ***/ |
| 20 | /*** the require_once below looks. ***/ |
| 21 | /*** + All identation should consist of four space blocks ***/ |
| 22 | /*** + Tab characters are evil. ***/ |
| 23 | /*** + all comments should use "slash-star ... star-slash" ***/ |
| 24 | /*** style -- no pound characters, no slash-slash style ***/ |
| 25 | /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ |
| 26 | /*** ALWAYS USE { AND } CHARACTERS!!! ***/ |
| 27 | /*** + Please use ' instead of ", when possible. Note " ***/ |
| 28 | /*** should always be used in _( ) function calls. ***/ |
| 29 | /*** Thank you for your help making the SM code more readable. ***/ |
| 30 | /*****************************************************************/ |
| 31 | |
| 32 | require_once('../src/validate.php'); |
| 33 | require_once('../functions/imap.php'); |
| 34 | require_once('../functions/array.php'); |
| 35 | require_once('../functions/plugin.php'); |
| 36 | |
| 37 | displayPageHeader($color, 'None'); |
| 38 | |
| 39 | ?> |
| 40 | |
| 41 | <br> |
| 42 | <table bgcolor="<?php echo $color[0] ?>" width="95%" align="center" cellpadding="2" cellspacing="0" border="0"> |
| 43 | <tr><td align="center"> |
| 44 | |
| 45 | <b><?php echo _("Folders"); ?></b> |
| 46 | |
| 47 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
| 48 | <tr><td bgcolor="<?php echo $color[4] ?>" align="center"> |
| 49 | |
| 50 | <?php |
| 51 | |
| 52 | if ((isset($success) && $success) || |
| 53 | (isset($sent_create) && $sent_create == "true") || |
| 54 | (isset($trash_create) && $trash_create == "true")) { |
| 55 | echo "<table width=\"100%\" align=center cellpadding=4 cellspacing=0 border=0>\n"; |
| 56 | echo " <tr><td align=center>\n"; |
| 57 | if ($success == "subscribe") { |
| 58 | echo "<b>" . _("Subscribed successfully!") . "</b><br>"; |
| 59 | } else if ($success == "unsubscribe") { |
| 60 | echo "<b>" . _("Unsubscribed successfully!") . "</b><br>"; |
| 61 | } else if ($success == "delete") { |
| 62 | echo "<b>" . _("Deleted folder successfully!") . "</b><br>"; |
| 63 | } else if ($success == "create") { |
| 64 | echo "<b>" . _("Created folder successfully!") . "</b><br>"; |
| 65 | } else if ($success == "rename") { |
| 66 | echo "<b>" . _("Renamed successfully!") . "</b><br>"; |
| 67 | } |
| 68 | |
| 69 | echo " <a href=\"../src/left_main.php\" target=left>" . _("refresh folder list") . "</a>"; |
| 70 | echo " </td></tr>\n"; |
| 71 | echo "</table><br>\n"; |
| 72 | } else { |
| 73 | echo "<br>"; |
| 74 | } |
| 75 | $imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0); |
| 76 | $boxes = sqimap_mailbox_list($imapConnection); |
| 77 | |
| 78 | /** CREATING FOLDERS **/ |
| 79 | echo "<TABLE WIDTH=\"70%\" COLS=1 ALIGN=CENTER cellpadding=4 cellspacing=0 border=0>\n"; |
| 80 | |
| 81 | echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>"; |
| 82 | echo _("Create Folder"); |
| 83 | echo "</B></TD></TR>"; |
| 84 | echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>"; |
| 85 | echo "<FORM NAME=cf ACTION=\"folders_create.php\" METHOD=\"POST\">\n"; |
| 86 | echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name><BR>\n"; |
| 87 | echo _("as a subfolder of"); |
| 88 | echo "<BR>"; |
| 89 | echo "<TT><SELECT NAME=subfolder>\n"; |
| 90 | if ($default_sub_of_inbox == false) { |
| 91 | echo '<OPTION SELECTED VALUE="">[ '._("None")." ]\n"; |
| 92 | } else { |
| 93 | echo '<OPTION VALUE="">[ '._("None")." ]\n"; |
| 94 | } |
| 95 | |
| 96 | for ($i = 0; $i < count($boxes); $i++) { |
| 97 | if (!in_array('noinferiors', $boxes[$i]['flags'])) { |
| 98 | if ((strtolower($boxes[$i]["unformatted"]) == "inbox") && ($default_sub_of_inbox == true)) { |
| 99 | $box = $boxes[$i]["unformatted"]; |
| 100 | $box2 = str_replace(' ', ' ', $boxes[$i]["unformatted-disp"]); |
| 101 | echo "<OPTION SELECTED VALUE=\"$box\">$box2\n"; |
| 102 | } else { |
| 103 | $box = $boxes[$i]["unformatted"]; |
| 104 | $box2 = str_replace(' ', ' ', $boxes[$i]["unformatted-disp"]); |
| 105 | if (strtolower($imap_server_type) != "courier" || |
| 106 | strtolower($box) != "inbox.trash") |
| 107 | echo "<OPTION VALUE=\"$box\">$box2\n"; |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | echo "</SELECT></TT>\n"; |
| 112 | if ($show_contain_subfolders_option) { |
| 113 | echo "<br><INPUT TYPE=CHECKBOX NAME=\"contain_subs\"> "; |
| 114 | echo _("Let this folder contain subfolders"); |
| 115 | echo "<BR>"; |
| 116 | } |
| 117 | echo "<INPUT TYPE=SUBMIT VALUE=\""._("Create")."\">\n"; |
| 118 | echo "</FORM></TD></TR>\n"; |
| 119 | |
| 120 | echo "<tr><td bgcolor=\"$color[4]\"> </td></tr>\n"; |
| 121 | |
| 122 | /** RENAMING FOLDERS **/ |
| 123 | echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>"; |
| 124 | echo _("Rename a Folder"); |
| 125 | echo "</B></TD></TR>"; |
| 126 | echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>"; |
| 127 | if ($count_special_folders < count($boxes)) { |
| 128 | echo "<FORM ACTION=\"folders_rename_getname.php\" METHOD=\"POST\">\n"; |
| 129 | echo "<TT><SELECT NAME=old>\n"; |
| 130 | for ($i = 0; $i < count($boxes); $i++) { |
| 131 | $use_folder = true; |
| 132 | |
| 133 | if ((strtolower($boxes[$i]["unformatted"]) != "inbox") && |
| 134 | ($boxes[$i]["unformatted"] != $trash_folder) && |
| 135 | ($boxes[$i]["unformatted"] != $sent_folder) && |
| 136 | ($boxes[$i]["unformatted"] != $draft_folder)) { |
| 137 | $box = $boxes[$i]["unformatted-dm"]; |
| 138 | $box2 = str_replace(' ', ' ', $boxes[$i]["unformatted-disp"]); |
| 139 | if (strtolower($imap_server_type) != "courier" || strtolower($box) != "inbox.trash") |
| 140 | echo "<OPTION VALUE=\"$box\">$box2\n"; |
| 141 | } |
| 142 | } |
| 143 | echo "</SELECT></TT>\n"; |
| 144 | echo "<INPUT TYPE=SUBMIT VALUE=\""; |
| 145 | echo _("Rename"); |
| 146 | echo "\">\n"; |
| 147 | echo "</FORM></TD></TR>\n"; |
| 148 | } else { |
| 149 | echo _("No folders found") . "<br><br></td></tr>"; |
| 150 | } |
| 151 | $boxes_sub = $boxes; |
| 152 | |
| 153 | echo "<tr><td bgcolor=\"$color[4]\"> </td></tr>\n"; |
| 154 | |
| 155 | /** DELETING FOLDERS **/ |
| 156 | echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER><B>"; |
| 157 | echo _("Delete Folder"); |
| 158 | echo "</B></TD></TR>"; |
| 159 | echo "<TR><TD BGCOLOR=\"$color[0]\" ALIGN=CENTER>"; |
| 160 | |
| 161 | $count_special_folders = 0; |
| 162 | $num_max = 1; |
| 163 | if (strtolower($imap_server_type) == "courier" || $move_to_trash) |
| 164 | $num_max++; |
| 165 | if ($move_to_sent) |
| 166 | $num_max++; |
| 167 | if ($save_as_draft) |
| 168 | $num_max++; |
| 169 | |
| 170 | for ($p = 0; $p < count($boxes) && $count_special_folders < $num_max; $p++) { |
| 171 | if (strtolower($boxes[$p]["unformatted"]) == "inbox") |
| 172 | $count_special_folders++; |
| 173 | else if (strtolower($imap_server_type) == "courier" && |
| 174 | strtolower($boxes[$p]["unformatted"]) == "inbox.trash") |
| 175 | $count_special_folders++; |
| 176 | else if ($boxes[$p]["unformatted"] == $trash_folder && $trash_folder) |
| 177 | $count_special_folders++; |
| 178 | else if ($boxes[$p]["unformatted"] == $sent_folder && $sent_folder) |
| 179 | $count_special_folders++; |
| 180 | else if ($boxes[$p]["unformatted"] == $draft_folder && $draft_folder) |
| 181 | $count_special_folders++; |
| 182 | } |
| 183 | |
| 184 | if ($count_special_folders < count($boxes)) { |
| 185 | echo "<FORM ACTION=\"folders_delete.php\" METHOD=\"POST\">\n"; |
| 186 | echo "<TT><SELECT NAME=mailbox>\n"; |
| 187 | for ($i = 0; $i < count($boxes); $i++) { |
| 188 | $use_folder = true; |
| 189 | if ((strtolower($boxes[$i]["unformatted"]) != "inbox") && |
| 190 | ($boxes[$i]["unformatted"] != $trash_folder) && |
| 191 | ($boxes[$i]["unformatted"] != $sent_folder) && |
| 192 | ($boxes[$i]["unformatted"] != $draft_folder) && |
| 193 | ((strtolower($imap_server_type) != "courier") || |
| 194 | (strtolower($boxes[$i]["unformatted"]) != "inbox.trash"))) { |
| 195 | $box = $boxes[$i]["unformatted-dm"]; |
| 196 | $box2 = str_replace(' ', ' ', $boxes[$i]["unformatted-disp"]); |
| 197 | echo " <OPTION VALUE=\"$box\">$box2\n"; |
| 198 | } |
| 199 | } |
| 200 | echo "</SELECT></TT>\n"; |
| 201 | echo "<INPUT TYPE=SUBMIT VALUE=\""; |
| 202 | echo _("Delete"); |
| 203 | echo "\">\n"; |
| 204 | echo "</FORM></TD></TR>\n"; |
| 205 | } else { |
| 206 | echo _("No folders found") . "<br><br></td><tr>"; |
| 207 | } |
| 208 | echo "<tr><td bgcolor=\"$color[4]\"> </td></tr></table>\n"; |
| 209 | |
| 210 | /** UNSUBSCRIBE FOLDERS **/ |
| 211 | echo "<TABLE WIDTH=\"70%\" COLS=2 ALIGN=CENTER cellpadding=4 cellspacing=0 border=0>\n"; |
| 212 | echo "<TR><TD BGCOLOR=\"$color[9]\" ALIGN=CENTER colspan=2><B>"; |
| 213 | echo _("Unsubscribe") . "/" . _("Subscribe"); |
| 214 | echo "</B></TD></TR>\n"; |
| 215 | echo "<TR><TD BGCOLOR=\"$color[0]\" width=\"50%\" ALIGN=CENTER>\n"; |
| 216 | if ($count_special_folders < count($boxes)) { |
| 217 | echo "<FORM ACTION=\"folders_subscribe.php?method=unsub\" METHOD=\"POST\">\n"; |
| 218 | echo "<TT><SELECT NAME=\"mailbox[]\" multiple size=8>\n"; |
| 219 | for ($i = 0; $i < count($boxes); $i++) { |
| 220 | $use_folder = true; |
| 221 | if ((strtolower($boxes[$i]["unformatted"]) != "inbox") && |
| 222 | ($boxes[$i]["unformatted"] != $trash_folder) && |
| 223 | ($boxes[$i]["unformatted"] != $sent_folder) && |
| 224 | ($boxes[$i]["unformatted"] != $draft_folder)) { |
| 225 | $box = $boxes[$i]["unformatted-dm"]; |
| 226 | $box2 = str_replace(' ', ' ', $boxes[$i]["unformatted-disp"]); |
| 227 | echo " <OPTION VALUE=\"$box\">$box2\n"; |
| 228 | } |
| 229 | } |
| 230 | echo "</SELECT></TT><br><br>\n"; |
| 231 | echo "<INPUT TYPE=SUBMIT VALUE=\""; |
| 232 | echo _("Unsubscribe"); |
| 233 | echo "\">\n"; |
| 234 | echo "</FORM></TD>\n"; |
| 235 | } else { |
| 236 | echo _("No folders were found to unsubscribe from!") . "</td>"; |
| 237 | } |
| 238 | $boxes_sub = $boxes; |
| 239 | |
| 240 | /** SUBSCRIBE TO FOLDERS **/ |
| 241 | echo "<TD BGCOLOR=\"$color[0]\" width=\"50%\" ALIGN=CENTER>"; |
| 242 | $imap_stream = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 1); |
| 243 | $boxes_all = sqimap_mailbox_list_all ($imap_stream); |
| 244 | |
| 245 | $box = ""; |
| 246 | $box2 = ""; |
| 247 | for ($i = 0, $q = 0; $i < count($boxes_all); $i++) { |
| 248 | $use_folder = true; |
| 249 | for ($p = 0; $p < count ($boxes); $p++) { |
| 250 | if ($boxes_all[$i]["unformatted"] == $boxes[$p]["unformatted"]) { |
| 251 | $use_folder = false; |
| 252 | continue; |
| 253 | } else if ($boxes_all[$i]["unformatted-dm"] == $folder_prefix) { |
| 254 | $use_folder = false; |
| 255 | } |
| 256 | } |
| 257 | if ($use_folder == true) { |
| 258 | $box[$q] = $boxes_all[$i]["unformatted-dm"]; |
| 259 | $box2[$q] = $boxes_all[$i]["unformatted-disp"]; |
| 260 | $q++; |
| 261 | } |
| 262 | } |
| 263 | sqimap_logout($imap_stream); |
| 264 | |
| 265 | if ($box && $box2) { |
| 266 | echo "<FORM ACTION=\"folders_subscribe.php?method=sub\" METHOD=\"POST\">\n"; |
| 267 | echo "<tt><select name=\"mailbox[]\" multiple size=8>"; |
| 268 | |
| 269 | for ($q = 0; $q < count($box); $q++) { |
| 270 | echo " <OPTION VALUE=\"$box[$q]\">".$box2[$q]."\n"; |
| 271 | } |
| 272 | echo "</select></tt><br><br>"; |
| 273 | echo "<INPUT TYPE=SUBMIT VALUE=\"". _("Subscribe") . "\">\n"; |
| 274 | echo "</FORM></TD></TR></TABLE><BR>\n"; |
| 275 | } else { |
| 276 | echo _("No folders were found to subscribe to!") . "</td></tr></table>"; |
| 277 | } |
| 278 | |
| 279 | do_hook("folders_bottom"); |
| 280 | ?> |
| 281 | |
| 282 | |
| 283 | </td></tr> |
| 284 | </table> |
| 285 | |
| 286 | </td></tr> |
| 287 | </table> |
| 288 | |
| 289 | <?php |
| 290 | sqimap_logout($imapConnection); |
| 291 | ?> |
| 292 | |
| 293 | </body></html> |