ee858ed5d9fdf8bd11387ee4dccd9bb1beda7a56
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 fputs ($imap_stream, "a001 LIST \"\" \"$mailbox\"\r\n");
23 $mbx = sqimap_read_data($imap_stream, "a001", true, $response, $message);
25 if (ereg ("$mailbox", $mbx[0])) {
35 /******************************************************************************
37 ******************************************************************************/
38 function sqimap_mailbox_select ($imap_stream, $mailbox, $hide=true, $recent=false) {
39 fputs ($imap_stream, "a001 SELECT \"$mailbox\"\r\n");
40 $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
42 for ($i=0; $i<count($read); $i++
) {
43 if (strpos(strtolower($read[$i]), "recent")) {
44 $r = explode(" ", $read[$i]);
53 /******************************************************************************
55 ******************************************************************************/
56 function sqimap_mailbox_create ($imap_stream, $mailbox, $type) {
57 if (strtolower($type) == "noselect") {
58 $dm = sqimap_get_delimiter($imap_stream);
59 $mailbox = $mailbox.$dm;
61 fputs ($imap_stream, "a001 CREATE \"$mailbox\"\r\n");
62 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
64 sqimap_subscribe ($imap_stream, $mailbox);
69 /******************************************************************************
70 ** Subscribes to an existing folder
71 ******************************************************************************/
72 function sqimap_subscribe ($imap_stream, $mailbox) {
73 fputs ($imap_stream, "a001 SUBSCRIBE \"$mailbox\"\r\n");
74 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
80 /******************************************************************************
81 ** Unsubscribes to an existing folder
82 ******************************************************************************/
83 function sqimap_unsubscribe ($imap_stream, $mailbox) {
84 global $imap_server_type;
86 fputs ($imap_stream, "a001 UNSUBSCRIBE \"$mailbox\"\r\n");
87 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
93 /******************************************************************************
94 ** This function simply deletes the given folder
95 ******************************************************************************/
96 function sqimap_mailbox_delete ($imap_stream, $mailbox) {
97 fputs ($imap_stream, "a001 DELETE \"$mailbox\"\r\n");
98 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
99 sqimap_unsubscribe ($imap_stream, $mailbox);
103 /******************************************************************************
104 ** Formats a mailbox into 4 parts for the $boxes array
105 ******************************************************************************/
106 function sqimap_mailbox_parse ($line, $line_lsub, $dm) {
107 global $folder_prefix;
108 for ($g=0; $g < count($line); $g++
) {
109 $boxes[$g]["raw"] = $line[$g];
111 $mailbox = $line_lsub[$g];
112 $dm_count = countCharInString($mailbox, $dm);
113 if (substr($mailbox, -1) == $dm)
116 for ($j = 0; $j < $dm_count - (countCharInString($folder_prefix, $dm)); $j++
)
117 $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
118 $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
120 $boxes[$g]["unformatted-dm"] = $mailbox;
121 if (substr($mailbox, -1) == $dm)
122 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
123 $boxes[$g]["unformatted"] = $mailbox;
124 $boxes[$g]["id"] = $g;
126 $flags = substr($line[$g], strpos($line[$g], "(")+
1);
127 $flags = substr($flags, 0, strpos($flags, ")"));
128 $flags = str_replace("\\", "", $flags);
129 $flags = trim(strtolower($flags));
131 $boxes[$g]["flags"] = explode(" ", $flags);
137 /******************************************************************************
138 ** Returns sorted mailbox lists in several different ways.
139 ** The array returned looks like this:
140 ******************************************************************************/
141 function sqimap_mailbox_list ($imap_stream) {
142 global $load_prefs_php, $prefs_php, $config_php, $data_dir, $username, $list_special_folders_first;
143 global $trash_folder, $sent_folder;
144 global $move_to_trash, $move_to_sent;
146 $inbox_in_list = false;
147 $inbox_subscribed = false;
149 if (!isset($load_prefs_php)) include "../src/load_prefs.php";
150 else global $folder_prefix;
151 if (!function_exists ("ary_sort")) include "../functions/array.php";
153 $dm = sqimap_get_delimiter ($imap_stream);
156 $inbox_subscribed = false;
157 fputs ($imap_stream, "a001 LSUB \"\" \"*\"\r\n");
158 $lsub_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
160 for ($i=0;$i < count($lsub_ary); $i++
) {
161 $sorted_lsub_ary[$i] = find_mailbox_name($lsub_ary[$i]);
162 if ($sorted_lsub_ary[$i] == "INBOX")
163 $inbox_subscribed = true;
165 if (isset($sorted_lsub_ary)) {
166 sort($sorted_lsub_ary);
170 for ($i=0; $i < count($sorted_lsub_ary); $i++
) {
171 if (substr($sorted_lsub_ary[$i], -1) == $dm)
172 $mbx = substr($sorted_lsub_ary[$i], 0, strlen($sorted_lsub_ary[$i])-1);
174 $mbx = $sorted_lsub_ary[$i];
176 fputs ($imap_stream, "a001 LIST \"\" \"$mbx\"\r\n");
177 $read = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
178 $sorted_list_ary[$i] = $read[0];
179 if (find_mailbox_name($sorted_list_ary[$i]) == "INBOX")
180 $inbox_in_list = true;
183 /** Just in case they're not subscribed to their inbox, we'll get it for them anyway **/
184 if ($inbox_subscribed == false ||
$inbox_in_list == false) {
185 fputs ($imap_stream, "a001 LIST \"\" \"INBOX\"\r\n");
186 $inbox_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
188 $pos = count($sorted_list_ary);
189 $sorted_list_ary[$pos] = $inbox_ary[0];
191 $pos = count($sorted_lsub_ary);
192 $sorted_lsub_ary[$pos] = find_mailbox_name($inbox_ary[0]);
195 $boxes = sqimap_mailbox_parse ($sorted_list_ary, $sorted_lsub_ary, $dm);
197 /** Now, lets sort for special folders **/
198 for ($i = 0; $i < count($boxes); $i++
) {
199 if (strtolower($boxes[$i]["unformatted"]) == "inbox") {
200 $boxesnew[0] = $boxes[$i];
201 $boxes[$i]["used"] = true;
206 if ($list_special_folders_first == true) {
207 for ($i = count($boxes)-1; $i >= 0 ; $i--) {
208 if (($boxes[$i]["unformatted"] == $trash_folder) && ($move_to_trash)) {
209 $pos = count($boxesnew);
210 $boxesnew[$pos] = $boxes[$i];
211 $boxes[$i]["used"] = true;
214 else if (($boxes[$i]["unformatted"] == $sent_folder) && ($move_to_sent)) {
215 $pos = count($boxesnew);
216 $boxesnew[$pos] = $boxes[$i];
217 $boxes[$i]["used"] = true;
221 if (($sent_found && $trash_found) ||
($sent_found && !$move_to_trash) ||
($trash_found && !$move_to_sent) ||
(!$move_to_sent && !$move_to_trash))
226 for ($i = 0; $i < count($boxes); $i++
) {
227 if ((strtolower($boxes[$i]["unformatted"]) != "inbox") &&
228 ($boxes[$i]["used"] == false)) {
229 $pos = count($boxesnew);
230 $boxesnew[$pos] = $boxes[$i];
231 $boxes[$i]["used"] = true;
238 /******************************************************************************
239 ** Returns a list of all folders, subscribed or not
240 ******************************************************************************/
241 function sqimap_mailbox_list_all ($imap_stream) {
242 global $list_special_folders_first, $folder_prefix;
244 if (!function_exists ("ary_sort"))
245 include ("../functions/array.php");
247 $dm = sqimap_get_delimiter ($imap_stream);
249 fputs ($imap_stream, "a001 LIST \"$folder_prefix\" *\r\n");
250 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
253 for ($i = 0; $i < count($read_ary); $i++
) {
254 if (substr ($read_ary[$i], 0, 4) != "a001") {
255 $boxes[$g]["raw"] = $read_ary[$i];
257 $mailbox = find_mailbox_name($read_ary[$i]);
258 $dm_count = countCharInString($mailbox, $dm);
259 if (substr($mailbox, -1) == $dm)
262 for ($j = 0; $j < $dm_count; $j++
)
263 $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
264 $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
266 $boxes[$g]["unformatted-dm"] = $mailbox;
267 if (substr($mailbox, -1) == $dm)
268 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
269 $boxes[$g]["unformatted"] = $mailbox;
270 $boxes[$g]["id"] = $g;
272 /** Now lets get the flags for this mailbox **/
273 fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\r\n");
274 $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
276 $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+
1);
277 $flags = substr($flags, 0, strpos($flags, ")"));
278 $flags = str_replace("\\", "", $flags);
279 $flags = trim(strtolower($flags));
281 $boxes[$g]["flags"] = explode(" ", $flags);
287 $boxes = ary_sort ($boxes, "unformatted", 1);