16b50a2e1d524f7fb0ee9241dbe55f7904ce3033
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 if (!function_exists ("ary_sort"))
111 include ("../functions/array.php");
113 $dm = sqimap_get_delimiter ($imap_stream);
115 fputs ($imap_stream, "a001 LIST \"\" INBOX\n");
116 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
119 for ($i = 0; $i < count($read_ary); $i++
) {
120 if (substr ($read_ary[$i], 0, 4) != "a001") {
121 $boxes[$g]["raw"] = $read_ary[$i];
123 $mailbox = find_mailbox_name($read_ary[$i]);
124 $dm_count = countCharInString($mailbox, $dm);
125 if (substr($mailbox, -1) == $dm)
128 for ($j = 0; $j < $dm_count; $j++
)
129 $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
130 $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
132 if (substr($mailbox, -1) == $dm)
133 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
134 $boxes[$g]["unformatted"] = $mailbox;
135 $boxes[$g]["id"] = $g;
137 /** Now lets get the flags for this mailbox **/
138 fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\n");
139 $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
141 $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+
1);
142 $flags = substr($flags, 0, strpos($flags, ")"));
143 $flags = str_replace("\\", "", $flags);
144 $flags = trim(strtolower($flags));
146 $boxes[$g]["flags"] = explode(" ", $flags);
151 if (!$read_ary[$i+
1]) {
152 if ($phase == "inbox") {
153 fputs ($imap_stream, "a001 LSUB \"\" *\n");
154 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
162 $boxes = ary_sort($boxes, "unformatted", 1);
164 for ($i = 0; $i < count($boxes); $i++
) {
165 for ($j = 0; $j < count($original); $j++
) {
166 if ($boxes[$i]["id"] == $original[$j]["id"]) {
167 $boxes[$i] = $original[$j];
172 for ($i = 0; $i < count($boxes); $i++
) {
173 if ($boxes[$i]["unformatted"] == $special_folders[0]) {
174 $boxesnew[0] = $boxes[$i];
177 if ($list_special_folders_first == true) {
178 for ($i = 0; $i < count($boxes); $i++
) {
179 for ($j = 1; $j < count($special_folders); $j++
) {
180 if (substr($boxes[$i]["unformatted"], 0, strlen($special_folders[$j])) == $special_folders[$j]) {
181 $pos = count($boxesnew);
182 $boxesnew[$pos] = $boxes[$i];
183 $boxes[$i]["used"] = true;
188 for ($i = 0; $i < count($boxes); $i++
) {
189 if (($boxes[$i]["unformatted"] != $special_folders[0]) &&
190 ($boxes[$i]["used"] == false)) {
191 $pos = count($boxesnew);
192 $boxesnew[$pos] = $boxes[$i];
193 $boxes[$i]["used"] = true;