7dc1947d8198259084b6b62324cbb5f65587a7bb
[squirrelmail.git] / src / folders.php
1 <HTML><BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#0000EE" ALINK="#0000EE">
2 <?
3 function getBoxForCreate($mailbox) {
4 if (substr($mailbox, 0, 6) == "INBOX.")
5 $box = substr($mailbox, 6, strlen($mailbox));
6 else
7 $box = $mailbox;
8
9 return $box;
10 }
11
12 include("../config/config.php");
13 include("../functions/strings.php");
14 include("../functions/page_header.php");
15 include("../functions/imap.php");
16
17 displayPageHeader("None");
18
19 echo "<TABLE WIDTH=100% COLS=1 ALIGN=CENTER>\n";
20 echo " <TR><TD BGCOLOR=DCDCDC ALIGN=CENTER>\n";
21 echo " <FONT FACE=\"Arial,Helvetica\">Folders</FONT>\n";
22 echo " </TD></TR>\n";
23 echo "</TABLE>\n";
24
25 $imapConnection = fsockopen($imapServerAddress, 143, &$errorNumber, &$errorString);
26 if (!$imapConnection) {
27 echo "Error connecting to IMAP Server.<br>";
28 echo "$errorNumber : $errorString<br>";
29 exit;
30 }
31 $serverInfo = fgets($imapConnection, 256);
32
33 fputs($imapConnection, "1 login $username $key\n");
34 $read = fgets($imapConnection, 1024);
35
36 fputs($imapConnection, "1 list \"\" *\n");
37 $str = imapReadData($imapConnection);
38
39 for ($i = 0;$i < count($str); $i++) {
40 $mailbox = Chop($str[$i]);
41 // find the quote at the begining of the mailbox name.
42 // i subtract 1 from the strlen so it doesn't find the quote at the end of the mailbox name.
43 $mailbox = findMailboxName($mailbox);
44 $periodCount = countCharInString($mailbox, ".");
45
46 // indent the correct number of spaces.
47 for ($j = 0;$j < $periodCount;$j++)
48 $boxes[$i] = "$boxes[$i]&nbsp;&nbsp;&nbsp;";
49
50 $boxes[$i] = $boxes[$i] . readShortMailboxName($mailbox, ".");
51 $long_name_boxes[$i] = $mailbox;
52 }
53
54 /** DELETING FOLDERS **/
55 echo "<FORM ACTION=folders_delete.php METHOD=POST>\n";
56 echo "<SELECT NAME=folder_list><FONT FACE=\"Arial,Helvetica\">\n";
57 for ($i = 0; $i < count($str); $i++) {
58 $use_folder = true;
59 for ($p = 0; $p < count($special_folders); $p++) {
60 if ($special_folders[$p] == $long_name_boxes[$i])
61 $use_folder = false;
62 }
63 if ($use_folder == true)
64 echo " <OPTION>$boxes[$i]\n";
65 }
66 echo "</SELECT>\n";
67 echo "<INPUT TYPE=SUBMIT VALUE=Delete>\n";
68 echo "</FORM><BR>\n";
69
70 /** CREATING FOLDERS **/
71 echo "<FORM ACTION=folders_create.php METHOD=POST>\n";
72 echo "<INPUT TYPE=TEXT SIZE=25 NAME=folder_name>\n";
73 echo "&nbsp;&nbsp;as a subfolder of&nbsp;&nbsp;";
74 echo "<SELECT NAME=subfolder><FONT FACE=\"Arial,Helvetica\">\n";
75 for ($i = 0;$i < count($str); $i++) {
76 $thisbox = Chop($str[$i]);
77 $thisbox = findMailboxName($thisbox);
78 $thisbox = getBoxForCreate($thisbox);
79 echo "<OPTION>$thisbox\n";
80 }
81 echo "</SELECT>\n";
82 echo "<INPUT TYPE=SUBMIT VALUE=Create>\n";
83 echo "</FORM><BR>\n";
84
85 /** RENAMING FOLDERS **/
86 echo "<FORM ACTION=folders_rename.php METHOD=POST>\n";
87 echo "<SELECT NAME=folder_list><FONT FACE=\"Arial,Helvetica\">\n";
88 for ($i = 0; $i < count($str); $i++) {
89 $use_folder = true;
90 for ($p = 0; $p < count($special_folders); $p++) {
91 if ($special_folders[$p] == $long_name_boxes[$i])
92 $use_folder = false;
93 }
94 if ($use_folder == true)
95 echo " <OPTION>$boxes[$i]\n";
96 }
97 echo "</SELECT>\n";
98 echo "<INPUT TYPE=TEXT SIZE=25 NAME=new_folder_name>\n";
99 echo "<INPUT TYPE=SUBMIT VALUE=Rename>\n";
100 echo "</FORM><BR>\n";
101
102 ?>
103 </BODY></HTML>