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