1<?php 2 3/** 4 * folders.php 5 * 6 * Handles all interaction between the user and the other folder 7 * scripts which do most of the work. Also handles the Special 8 * Folders. 9 * 10 * @copyright 1999-2021 The SquirrelMail Project Team 11 * @license http://opensource.org/licenses/gpl-license.php GNU Public License 12 * @version $Id: folders.php 14885 2021-02-05 19:19:32Z pdontthink $ 13 * @package squirrelmail 14 */ 15 16/** This is the folders page */ 17define('PAGE_NAME', 'folders'); 18 19/** 20 * Path for SquirrelMail required files. 21 * @ignore 22 */ 23define('SM_PATH','../'); 24 25/* SquirrelMail required files. */ 26require_once(SM_PATH . 'include/validate.php'); 27require_once(SM_PATH . 'functions/imap.php'); 28require_once(SM_PATH . 'functions/plugin.php'); 29require_once(SM_PATH . 'functions/html.php'); 30require_once(SM_PATH . 'functions/forms.php'); 31 32displayPageHeader($color, 'None'); 33 34/* get globals we may need */ 35 36sqgetGlobalVar('username', $username, SQ_SESSION); 37sqgetGlobalVar('key', $key, SQ_COOKIE); 38sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); 39sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION); 40 41sqgetGlobalVar('success', $success, SQ_GET); 42 43/* end of get globals */ 44 45echo '<br />' . 46 html_tag( 'table', '', 'center', $color[0], 'width="95%" cellpadding="1" cellspacing="0" border="0"' ) . 47 html_tag( 'tr' ) . 48 html_tag( 'td', '', 'center' ) . '<b>' . _("Folders") . '</b>' . 49 html_tag( 'table', '', 'center', '', 'width="100%" cellpadding="5" cellspacing="0" border="0"' ) . 50 html_tag( 'tr' ) . 51 html_tag( 'td', '', 'center', $color[4] ); 52 53if ( isset($success) && $success ) { 54 55 $td_str = '<b>'; 56 57 switch ($success) 58 { 59 case 'subscribe': 60 $td_str .= _("Subscribed successfully."); 61 break; 62 case 'unsubscribe': 63 $td_str .= _("Unsubscribed successfully."); 64 break; 65 case 'delete': 66 $td_str .= _("Deleted folder successfully."); 67 break; 68 case 'create': 69 $td_str .= _("Created folder successfully."); 70 break; 71 case 'rename': 72 $td_str .= _("Renamed successfully."); 73 break; 74 case 'subscribe-doesnotexist': 75 $td_str .= _("Subscription Unsuccessful - Folder does not exist."); 76 break; 77 } 78 79 $td_str .= '</b><br />'; 80 81 82 echo html_tag( 'table', 83 html_tag( 'tr', 84 html_tag( 'td', $td_str . 85 '<a href="../src/left_main.php" target="left">' . 86 _("refresh folder list") . '</a>' , 87 'center' ) 88 ) , 89 'center', '', 'width="100%" cellpadding="4" cellspacing="0" border="0"' ); 90} 91 92echo "\n<br />"; 93 94global $imap_stream_options; // in case not defined in config 95$imapConnection = sqimap_login ($username, $key, $imapServerAddress, $imapPort, 0, $imap_stream_options); 96 97// force retrieval of a non cached folderlist 98$boxes = sqimap_mailbox_list($imapConnection,true); 99 100/** CREATING FOLDERS **/ 101echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) . 102 html_tag( 'tr', 103 html_tag( 'td', '<b>' . _("Create Folder") . '</b>', 'center', $color[9] ) 104 ) . 105 html_tag( 'tr' ) . 106 html_tag( 'td', '', 'center', $color[0] ) . 107 addForm('folders_create.php', 'POST', 'cf', '', '', '', TRUE). 108 addInput('folder_name', '', 25). 109 "<br />\n". _("as a subfolder of"). '<br />'. 110 "<tt><select name=\"subfolder\">\n"; 111 112$show_selected = array(); 113$skip_folders = array(); 114$server_type = strtolower($imap_server_type); 115if ( $server_type == 'courier' ) { 116 if ( $default_folder_prefix == 'INBOX.' ) { 117 array_push($skip_folders, 'INBOX'); 118 } 119} elseif ( $server_type == 'bincimap' ) { 120 if ( $default_folder_prefix == 'INBOX/' ) { 121 // We don't need INBOX, since it is top folder 122 array_push($skip_folders, 'INBOX'); 123 } 124} 125 126if ( $default_sub_of_inbox == false ) { 127 echo '<option selected="selected" value="">[ '._("None")." ]</option>\n"; 128} else { 129 echo '<option value="">[ '._("None")." ]</option>\n"; 130 $show_selected = array('inbox'); 131} 132 133// Call sqimap_mailbox_option_list, using existing connection to IMAP server, 134// the arrays of folders to include or skip (assembled above), 135// use 'noinferiors' as a mailbox filter to leave out folders that can not contain other folders. 136// use the long format to show subfolders in an intelligible way if parent is missing (special folder) 137echo sqimap_mailbox_option_list($imapConnection, $show_selected, $skip_folders, $boxes, 'noinferiors', true); 138 139echo "</select></tt>\n"; 140if ($show_contain_subfolders_option) { 141 echo '<br />'. 142 addCheckBox('contain_subs', FALSE, '1') .' ' 143 . _("Let this folder contain subfolders") 144 . '<br />'; 145} 146echo "<input type=\"submit\" value=\""._("Create")."\" />\n"; 147echo "</form></td></tr>\n"; 148 149echo html_tag( 'tr', 150 html_tag( 'td', ' ', 'left', $color[4] ) 151 ) ."\n"; 152 153/** count special folders **/ 154foreach ($boxes as $index => $aBoxData) { 155 if (! in_array($aBoxData['unformatted'],$skip_folders) && 156 isSpecialMailbox($aBoxData['unformatted'],false) ) { 157 $skip_folders[] = $aBoxData['unformatted']; 158 } 159} 160 161/** RENAMING FOLDERS **/ 162echo html_tag( 'tr', 163 html_tag( 'td', '<b>' . _("Rename a Folder") . '</b>', 'center', $color[9] ) 164 ) . 165 html_tag( 'tr' ) . 166 html_tag( 'td', '', 'center', $color[0] ); 167 168if (count($skip_folders) < count($boxes)) { 169 echo addForm('folders_rename_getname.php') 170 . "<tt><select name=\"old\">\n" 171 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n"; 172 173 // use existing IMAP connection, we have no special values to show, 174 // but we do include values to skip. Use the pre-created $boxes to save an IMAP query. 175 // send NULL for the flag - ALL folders are eligible for rename! 176 // use long format to make sure folder names make sense when parents may be missing. 177 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true); 178 179 echo "</select></tt>\n". 180 '<input type="submit" value="'. 181 _("Rename"). 182 "\" />\n". 183 "</form></td></tr>\n"; 184} else { 185 echo _("No folders found") . '<br /><br /></td></tr>'; 186} 187$boxes_sub = $boxes; 188 189echo html_tag( 'tr', 190 html_tag( 'td', ' ', 'left', $color[4] ) 191 ) ."\n"; 192 193/** DELETING FOLDERS **/ 194echo html_tag( 'tr', 195 html_tag( 'td', '<b>' . _("Delete Folder") . '</b>', 'center', $color[9] ) 196 ) . 197 html_tag( 'tr' ) . 198 html_tag( 'td', '', 'center', $color[0] ); 199 200if (count($skip_folders) < count($boxes)) { 201 echo addForm('folders_delete.php') 202 . "<tt><select name=\"mailbox\">\n" 203 . ' <option value="">[ ' . _("Select a folder") . " ]</option>\n"; 204 205 // send NULL for the flag - ALL folders are eligible for delete (except what we've got in skiplist) 206 // use long format to make sure folder names make sense when parents may be missing. 207 echo sqimap_mailbox_option_list($imapConnection, 0, $skip_folders, $boxes, NULL, true); 208 209 echo "</select></tt>\n" 210 . '<input type="submit" value="' 211 . _("Delete") 212 . "\" />\n" 213 . "</form></td></tr>\n"; 214} else { 215 echo _("No folders found") . "<br /><br /></td></tr>"; 216} 217 218echo html_tag( 'tr', 219 html_tag( 'td', ' ', 'left', $color[4] ) 220 ) ."</table>\n"; 221 222 223/** UNSUBSCRIBE FOLDERS **/ 224echo html_tag( 'table', '', 'center', '', 'width="70%" cellpadding="4" cellspacing="0" border="0"' ) . 225 html_tag( 'tr', 226 html_tag( 'td', '<b>' . _("Unsubscribe") . '/' . _("Subscribe") . '</b>', 'center', $color[9], 'colspan="2"' ) 227 ) . 228 html_tag( 'tr' ) . 229 html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); 230 231if (count($skip_folders) < count($boxes)) { 232 echo addForm('folders_subscribe.php?method=unsub', 'post', '', '', '', '', TRUE) 233 . "<tt><select name=\"mailbox[]\" multiple=\"multiple\" size=\"8\">\n"; 234 for ($i = 0; $i < count($boxes); $i++) { 235 $use_folder = true; 236 if (! isSpecialMailbox($boxes[$i]["unformatted"],false)) { 237 $box = $boxes[$i]["unformatted-dm"]; 238 $box2 = str_replace(array(' ','<','>'), array(' ','<','>'), 239 imap_utf7_decode_local($boxes[$i]["unformatted-disp"])); 240 echo " <option value=\"$box\">$box2</option>\n"; 241 } 242 } 243 echo "</select></tt><br /><br />\n" 244 . '<input type="submit" value="' 245 . _("Unsubscribe") 246 . "\" />\n" 247 . "</form></td>\n"; 248} else { 249 echo _("No folders were found to unsubscribe from!") . '</td>'; 250} 251$boxes_sub = $boxes; 252 253/** SUBSCRIBE TO FOLDERS **/ 254echo html_tag( 'td', '', 'center', $color[0], 'width="50%"' ); 255if(!$no_list_for_subscribe) { 256 $boxes_all = sqimap_mailbox_list_all ($imapConnection); 257 258 $box = $box2 = array(); 259 for ($i = 0, $q = 0; $i < count($boxes_all); $i++) { 260 $use_folder = true; 261 for ($p = 0; $p < count ($boxes); $p++) { 262 if ($boxes_all[$i]['unformatted'] == $boxes[$p]['unformatted']) { 263 $use_folder = false; 264 continue; 265 } else if ($boxes_all[$i]['unformatted-dm'] == $folder_prefix) { 266 $use_folder = false; 267 } 268 } 269 if ($use_folder == true) { 270 $box[$q] = $boxes_all[$i]['unformatted-dm']; 271 $box2[$q] = imap_utf7_decode_local($boxes_all[$i]['unformatted-disp']); 272 $q++; 273 } 274 } 275 276 if (count($box) > 0) { 277 echo addForm('folders_subscribe.php?method=sub', 'post', '', '', '', '', TRUE) 278 . '<tt><select name="mailbox[]" multiple="multiple" size="8">'; 279 280 for ($q = 0; $q < count($box); $q++) { 281 echo ' <option value="' . $box[$q] . '">' . 282 str_replace(array(' ','<','>'),array(' ','<','>'),$box2[$q])."</option>\n"; 283 } 284 echo '</select></tt><br /><br />' 285 . '<input type="submit" value="'. _("Subscribe") . "\" />\n" 286 . "</form></td></tr></table><br />\n"; 287 } else { 288 echo _("No folders were found to subscribe to!") . '</td></tr></table>'; 289 } 290} else { 291 /* don't perform the list action -- this is much faster */ 292 echo addForm('folders_subscribe.php?method=sub', 'post', '', '', '', '', TRUE) 293 . _("Subscribe to:") . '<br />' 294 . '<tt><input type="text" name="mailbox[]" size="35" />' 295 . '<input type="submit" value="'. _("Subscribe") . "\" />\n" 296 . "</form></td></tr></table>\n"; 297} 298echo "\n<br /><br />\n"; 299 300do_hook('folders_bottom'); 301?> 302 </td></tr> 303 </table> 304</td></tr> 305</table> 306<?php 307 sqimap_logout($imapConnection); 308?> 309</body></html> 310