5 ** This impliments all functions that manipulate mailboxes
8 /******************************************************************************
10 ******************************************************************************/
11 function sqimap_mailbox_expunge ($imap_stream, $mailbox) {
12 sqimap_mailbox_select ($imap_stream, $mailbox);
13 fputs ($imap_stream, "a001 EXPUNGE\n");
14 $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
18 /******************************************************************************
19 ** Checks whether or not the specified mailbox exists
20 ******************************************************************************/
21 function sqimap_mailbox_exists ($imap_stream, $mailbox) {
22 $boxes = sqimap_mailbox_list ($imap_stream);
24 for ($i = 0; $i < count ($boxes); $i++
) {
25 if ($boxes[$i]["unformatted"] == $mailbox)
33 /******************************************************************************
35 ******************************************************************************/
36 function sqimap_mailbox_select ($imap_stream, $mailbox) {
37 fputs ($imap_stream, "a001 SELECT \"$mailbox\"\n");
38 $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
43 /******************************************************************************
45 ******************************************************************************/
46 function sqimap_mailbox_create ($imap_stream, $mailbox, $type) {
47 if (strtolower($type) == "noselect") {
48 $dm = sqimap_get_delimiter($imap_stream);
49 $mailbox = $mailbox.$dm;
51 fputs ($imap_stream, "a001 CREATE \"$mailbox\"\n");
52 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
54 sqimap_subscribe ($imap_stream, $mailbox);
59 /******************************************************************************
60 ** Subscribes to an existing folder
61 ******************************************************************************/
62 function sqimap_subscribe ($imap_stream, $mailbox) {
63 fputs ($imap_stream, "a001 SUBSCRIBE \"$mailbox\"\n");
64 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
70 /******************************************************************************
71 ** Unsubscribes to an existing folder
72 ******************************************************************************/
73 function sqimap_unsubscribe ($imap_stream, $mailbox) {
74 fputs ($imap_stream, "a001 UNSUBSCRIBE \"$mailbox\"\n");
75 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
81 /******************************************************************************
82 ** This is a recursive function that checks to see if the folder has any
83 ** subfolders, and if so it calls itself on the subfolders first, then
84 ** removes the parent folder.
85 ******************************************************************************/
86 function sqimap_mailbox_delete ($imap_stream, $mailbox) {
89 $dm = sqimap_get_delimiter($imap_stream);
90 for ($i = 0; $i < count($boxes); $i++
) {
91 if (strstr($boxes[$i]["unformatted"], $mailbox . $dm)) {
92 $new_delete = $boxes[$i]["unformatted"];
93 $boxes = removeElement($boxes, $i);
94 // sqimap_mailbox_delete ($imap_stream, $new_delete);
97 sqimap_unsubscribe ($imap_stream, $mailbox);
98 fputs ($imap_stream, "a001 DELETE \"$mailbox\"\n");
99 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
104 /******************************************************************************
105 ** Returns sorted mailbox lists in several different ways.
106 ** The array returned looks like this:
107 ******************************************************************************/
108 function sqimap_mailbox_list ($imap_stream) {
109 global $special_folders, $list_special_folders_first;
111 if (!function_exists ("ary_sort"))
112 include ("../functions/array.php");
114 $dm = sqimap_get_delimiter ($imap_stream);
116 fputs ($imap_stream, "a001 LIST \"\" INBOX\n");
117 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
120 for ($i = 0; $i < count($read_ary); $i++
) {
121 if (substr ($read_ary[$i], 0, 4) != "a001") {
122 $boxes[$g]["raw"] = $read_ary[$i];
124 $mailbox = find_mailbox_name($read_ary[$i]);
125 $dm_count = countCharInString($mailbox, $dm);
126 if (substr($mailbox, -1) == $dm)
129 for ($j = 0; $j < $dm_count; $j++
)
130 $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
131 $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
133 if (substr($mailbox, -1) == $dm)
134 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
135 $boxes[$g]["unformatted"] = $mailbox;
136 $boxes[$g]["id"] = $g;
138 /** Now lets get the flags for this mailbox **/
139 fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\n");
140 $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
142 $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+
1);
143 $flags = substr($flags, 0, strpos($flags, ")"));
144 $flags = str_replace("\\", "", $flags);
145 $flags = trim(strtolower($flags));
147 $boxes[$g]["flags"] = explode(" ", $flags);
152 if (!$read_ary[$i+
1]) {
153 if ($phase == "inbox") {
154 fputs ($imap_stream, "a001 LSUB \"\" *\n");
155 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
164 /** Get the folders into lower case so sorting is not case sensative */
165 for ($i = 0; $i < count($original); $i++
) {
166 $boxes[$i]["unformatted"] = strtolower($boxes[$i]["unformatted"]);
170 $boxes = ary_sort($boxes, "unformatted", 1);
172 /** Get them back from the original array, still sorted by the id **/
173 for ($i = 0; $i < count($boxes); $i++
) {
174 for ($j = 0; $j < count($original); $j++
) {
175 if ($boxes[$i]["id"] == $original[$j]["id"]) {
176 $boxes[$i] = $original[$j];
182 for ($i = 0; $i < count($boxes); $i++
) {
183 if ($boxes[$i]["unformatted"] == $special_folders[0]) {
184 $boxesnew[0] = $boxes[$i];
185 $boxes[$i]["used"] = true;
189 if ($list_special_folders_first == true) {
190 for ($i = 0; $i < count($boxes); $i++
) {
191 for ($j = 1; $j < count($special_folders); $j++
) {
192 if (substr($boxes[$i]["unformatted"], 0, strlen($special_folders[$j])) == $special_folders[$j]) {
193 $pos = count($boxesnew);
194 $boxesnew[$pos] = $boxes[$i];
195 $boxes[$i]["used"] = true;
201 for ($i = 0; $i < count($boxes); $i++
) {
202 if (($boxes[$i]["unformatted"] != $special_folders[0]) &&
203 ($boxes[$i]["used"] == false)) {
204 $pos = count($boxesnew);
205 $boxesnew[$pos] = $boxes[$i];
206 $boxes[$i]["used"] = true;