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\r\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\"\r\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\"\r\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\"\r\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\"\r\n");
75 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
81 /******************************************************************************
82 ** This function simply deletes the given folder
83 ******************************************************************************/
84 function sqimap_mailbox_delete ($imap_stream, $mailbox) {
85 fputs ($imap_stream, "a001 DELETE \"$mailbox\"\r\n");
86 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
87 sqimap_unsubscribe ($imap_stream, $mailbox);
92 /******************************************************************************
93 ** Returns sorted mailbox lists in several different ways.
94 ** The array returned looks like this:
95 ******************************************************************************/
96 function sqimap_mailbox_list ($imap_stream) {
97 global $load_prefs_php, $prefs_php, $config_php, $data_dir, $username;
98 if (!isset($load_prefs_php))
99 include "../src/load_prefs.php";
101 global $folder_prefix;
102 global $special_folders, $list_special_folders_first, $default_folder_prefix;
104 if (!function_exists ("ary_sort"))
105 include ("../functions/array.php");
107 $dm = sqimap_get_delimiter ($imap_stream);
109 fputs ($imap_stream, "a001 LIST \"\" INBOX\r\n");
110 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
113 for ($i = 0; $i < count($read_ary); $i++
) {
114 if (substr ($read_ary[$i], 0, 4) != "a001") {
115 $boxes[$g]["raw"] = $read_ary[$i];
117 $mailbox = find_mailbox_name($read_ary[$i]);
118 $dm_count = countCharInString($mailbox, $dm);
119 if (substr($mailbox, -1) == $dm)
122 for ($j = 0; $j < $dm_count; $j++
)
123 $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
124 $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
126 $boxes[$g]["unformatted-dm"] = $mailbox;
127 if (substr($mailbox, -1) == $dm)
128 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
129 $boxes[$g]["unformatted"] = $mailbox;
130 $boxes[$g]["id"] = $g;
132 /** Now lets get the flags for this mailbox **/
133 fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\r\n");
134 $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
136 $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+
1);
137 $flags = substr($flags, 0, strpos($flags, ")"));
138 $flags = str_replace("\\", "", $flags);
139 $flags = trim(strtolower($flags));
141 $boxes[$g]["flags"] = explode(" ", $flags);
146 if (!$read_ary[$i+
1]) {
147 if ($phase == "inbox") {
148 if ($folder_prefix && (substr($folder_prefix, -1) != $dm))
149 $folder_prefix = $folder_prefix . $dm;
151 fputs ($imap_stream, "a001 LSUB \"$folder_prefix\" *\r\n");
152 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
161 /** Get the folders into lower case so sorting is not case sensative */
162 for ($i = 0; $i < count($original); $i++
) {
163 $boxes[$i]["unformatted"] = strtolower($boxes[$i]["unformatted"]);
167 $boxes = ary_sort($boxes, "unformatted", 1);
169 /** Get them back from the original array, still sorted by the id **/
170 for ($i = 0; $i < count($boxes); $i++
) {
171 for ($j = 0; $j < count($original); $j++
) {
172 if ($boxes[$i]["id"] == $original[$j]["id"]) {
173 $boxes[$i] = $original[$j];
179 for ($i = 0; $i < count($boxes); $i++
) {
180 if ($boxes[$i]["unformatted"] == $special_folders[0]) {
181 $boxesnew[0] = $boxes[$i];
182 $boxes[$i]["used"] = true;
186 if ($list_special_folders_first == true) {
187 for ($i = 0; $i < count($boxes); $i++
) {
188 for ($j = 1; $j < count($special_folders); $j++
) {
189 if (substr($boxes[$i]["unformatted"], 0, strlen($special_folders[$j])) == $special_folders[$j]) {
190 $pos = count($boxesnew);
191 $boxesnew[$pos] = $boxes[$i];
192 $boxes[$i]["used"] = true;
198 for ($i = 0; $i < count($boxes); $i++
) {
199 if (($boxes[$i]["unformatted"] != $special_folders[0]) &&
200 ($boxes[$i]["used"] == false)) {
201 $pos = count($boxesnew);
202 $boxesnew[$pos] = $boxes[$i];
203 $boxes[$i]["used"] = true;
211 /******************************************************************************
212 ** Returns a list of all folders, subscribed or not
213 ******************************************************************************/
214 function sqimap_mailbox_list_all ($imap_stream) {
215 global $special_folders, $list_special_folders_first;
217 if (!function_exists ("ary_sort"))
218 include ("../functions/array.php");
220 $dm = sqimap_get_delimiter ($imap_stream);
222 fputs ($imap_stream, "a001 LIST \"INBOX\" *\r\n");
223 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
226 for ($i = 0; $i < count($read_ary); $i++
) {
227 if (substr ($read_ary[$i], 0, 4) != "a001") {
228 $boxes[$g]["raw"] = $read_ary[$i];
230 $mailbox = find_mailbox_name($read_ary[$i]);
231 $dm_count = countCharInString($mailbox, $dm);
232 if (substr($mailbox, -1) == $dm)
235 for ($j = 0; $j < $dm_count; $j++
)
236 $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
237 $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
239 $boxes[$g]["unformatted-dm"] = $mailbox;
240 if (substr($mailbox, -1) == $dm)
241 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
242 $boxes[$g]["unformatted"] = $mailbox;
243 $boxes[$g]["id"] = $g;
245 /** Now lets get the flags for this mailbox **/
246 fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\r\n");
247 $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
249 $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+
1);
250 $flags = substr($flags, 0, strpos($flags, ")"));
251 $flags = str_replace("\\", "", $flags);
252 $flags = trim(strtolower($flags));
254 $boxes[$g]["flags"] = explode(" ", $flags);
259 $boxes = ary_sort ($boxes, "unformatted", 1);