5 ** This impliments all functions that manipulate mailboxes
9 /******************************************************************************
11 ******************************************************************************/
12 function sqimap_mailbox_expunge ($imap_stream, $mailbox) {
13 sqimap_mailbox_select ($imap_stream, $mailbox);
14 fputs ($imap_stream, "a001 EXPUNGE\n");
15 $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
19 /******************************************************************************
20 ** Checks whether or not the specified mailbox exists
21 ******************************************************************************/
22 function sqimap_mailbox_exists ($imap_stream, $mailbox) {
23 $boxes = sqimap_mailbox_list ($imap_stream);
25 for ($i = 0; $i < count ($boxes); $i++
) {
26 if ($boxes[$i]["unformatted"] == $mailbox)
34 /******************************************************************************
36 ******************************************************************************/
37 function sqimap_mailbox_select ($imap_stream, $mailbox) {
38 fputs ($imap_stream, "a001 SELECT \"$mailbox\"\n");
39 $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
44 /******************************************************************************
46 ******************************************************************************/
47 function sqimap_mailbox_create ($imap_stream, $mailbox, $type) {
48 if (strtolower($type) == "noselect") {
49 $dm = sqimap_get_delimiter($imap_stream);
50 $mailbox = $mailbox.$dm;
52 fputs ($imap_stream, "a001 CREATE \"$mailbox\"\n");
53 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
55 sqimap_subscribe ($imap_stream, $mailbox);
60 /******************************************************************************
61 ** Subscribes to an existing folder
62 ******************************************************************************/
63 function sqimap_subscribe ($imap_stream, $mailbox) {
64 fputs ($imap_stream, "a001 SUBSCRIBE \"$mailbox\"\n");
65 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
71 /******************************************************************************
72 ** Unsubscribes to an existing folder
73 ******************************************************************************/
74 function sqimap_unsubscribe ($imap_stream, $mailbox) {
75 fputs ($imap_stream, "a001 UNSUBSCRIBE \"$mailbox\"\n");
76 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
82 /******************************************************************************
83 ** This is a recursive function that checks to see if the folder has any
84 ** subfolders, and if so it calls itself on the subfolders first, then
85 ** removes the parent folder.
86 ******************************************************************************/
87 function sqimap_mailbox_delete ($imap_stream, $mailbox) {
90 $dm = sqimap_get_delimiter($imap_stream);
91 for ($i = 0; $i < count($boxes); $i++
) {
92 if (strstr($boxes[$i]["unformatted"], $mailbox . $dm)) {
93 $new_delete = $boxes[$i]["unformatted"];
94 $boxes = removeElement($boxes, $i);
95 // sqimap_mailbox_delete ($imap_stream, $new_delete);
98 sqimap_unsubscribe ($imap_stream, $mailbox);
99 fputs ($imap_stream, "a001 DELETE \"$mailbox\"\n");
100 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
105 /******************************************************************************
106 ** Returns sorted mailbox lists in several different ways.
107 ** The array returned looks like this:
108 ******************************************************************************/
109 function sqimap_mailbox_list ($imap_stream) {
110 global $special_folders, $list_special_folders_first;
112 if (!function_exists ("ary_sort"))
113 include ("../functions/array.php");
115 $dm = sqimap_get_delimiter ($imap_stream);
117 fputs ($imap_stream, "a001 LIST \"\" INBOX\n");
118 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
121 for ($i = 0; $i < count($read_ary); $i++
) {
122 if (substr ($read_ary[$i], 0, 4) != "a001") {
123 $boxes[$g]["raw"] = $read_ary[$i];
125 $mailbox = find_mailbox_name($read_ary[$i]);
126 $dm_count = countCharInString($mailbox, $dm);
127 if (substr($mailbox, -1) == $dm)
130 for ($j = 0; $j < $dm_count; $j++
)
131 $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
132 $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
134 if (substr($mailbox, -1) == $dm)
135 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
136 $boxes[$g]["unformatted"] = $mailbox;
137 $boxes[$g]["id"] = $g;
139 /** Now lets get the flags for this mailbox **/
140 fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\n");
141 $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
143 $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+
1);
144 $flags = substr($flags, 0, strpos($flags, ")"));
145 $flags = str_replace("\\", "", $flags);
146 $flags = trim(strtolower($flags));
148 $boxes[$g]["flags"] = explode(" ", $flags);
153 if (!$read_ary[$i+
1]) {
154 if ($phase == "inbox") {
155 fputs ($imap_stream, "a001 LSUB \"\" *\n");
156 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
165 /** Get the folders into lower case so sorting is not case sensative */
166 for ($i = 0; $i < count($original); $i++
) {
167 $boxes[$i]["unformatted"] = strtolower($boxes[$i]["unformatted"]);
171 $boxes = ary_sort($boxes, "unformatted", 1);
173 /** Get them back from the original array, still sorted by the id **/
174 for ($i = 0; $i < count($boxes); $i++
) {
175 for ($j = 0; $j < count($original); $j++
) {
176 if ($boxes[$i]["id"] == $original[$j]["id"]) {
177 $boxes[$i] = $original[$j];
183 for ($i = 0; $i < count($boxes); $i++
) {
184 if ($boxes[$i]["unformatted"] == $special_folders[0]) {
185 $boxesnew[0] = $boxes[$i];
186 $boxes[$i]["used"] = true;
190 if ($list_special_folders_first == true) {
191 for ($i = 0; $i < count($boxes); $i++
) {
192 for ($j = 1; $j < count($special_folders); $j++
) {
193 if (substr($boxes[$i]["unformatted"], 0, strlen($special_folders[$j])) == $special_folders[$j]) {
194 $pos = count($boxesnew);
195 $boxesnew[$pos] = $boxes[$i];
196 $boxes[$i]["used"] = true;
202 for ($i = 0; $i < count($boxes); $i++
) {
203 if (($boxes[$i]["unformatted"] != $special_folders[0]) &&
204 ($boxes[$i]["used"] == false)) {
205 $pos = count($boxesnew);
206 $boxesnew[$pos] = $boxes[$i];
207 $boxes[$i]["used"] = true;