0673787642140e02e92bcbf1739f6b71e2d3a205
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 function simply deletes the given folder
83 ******************************************************************************/
84 function sqimap_mailbox_delete ($imap_stream, $mailbox) {
85 fputs ($imap_stream, "a001 DELETE \"$mailbox\"\n");
86 echo "mailbox: $mailbox<BR>";
87 $read_ary = sqimap_read_data($imap_stream, "a001", true, $response, $message);
88 sqimap_unsubscribe ($imap_stream, $mailbox);
93 /******************************************************************************
94 ** Returns sorted mailbox lists in several different ways.
95 ** The array returned looks like this:
96 ******************************************************************************/
97 function sqimap_mailbox_list ($imap_stream) {
98 global $special_folders, $list_special_folders_first;
100 if (!function_exists ("ary_sort"))
101 include ("../functions/array.php");
103 $dm = sqimap_get_delimiter ($imap_stream);
105 fputs ($imap_stream, "a001 LIST \"\" INBOX\n");
106 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
109 for ($i = 0; $i < count($read_ary); $i++
) {
110 if (substr ($read_ary[$i], 0, 4) != "a001") {
111 $boxes[$g]["raw"] = $read_ary[$i];
113 $mailbox = find_mailbox_name($read_ary[$i]);
114 $dm_count = countCharInString($mailbox, $dm);
115 if (substr($mailbox, -1) == $dm)
118 for ($j = 0; $j < $dm_count; $j++
)
119 $boxes[$g]["formatted"] = $boxes[$g]["formatted"] . " ";
120 $boxes[$g]["formatted"] .= readShortMailboxName($mailbox, $dm);
122 $boxes[$g]["unformatted-dm"] = $mailbox;
123 if (substr($mailbox, -1) == $dm)
124 $mailbox = substr($mailbox, 0, strlen($mailbox) - 1);
125 $boxes[$g]["unformatted"] = $mailbox;
126 $boxes[$g]["id"] = $g;
128 /** Now lets get the flags for this mailbox **/
129 fputs ($imap_stream, "a002 LIST \"\" \"$mailbox\"\n");
130 $read_mlbx = sqimap_read_data ($imap_stream, "a002", true, $response, $message);
132 $flags = substr($read_mlbx[0], strpos($read_mlbx[0], "(")+
1);
133 $flags = substr($flags, 0, strpos($flags, ")"));
134 $flags = str_replace("\\", "", $flags);
135 $flags = trim(strtolower($flags));
137 $boxes[$g]["flags"] = explode(" ", $flags);
142 if (!$read_ary[$i+
1]) {
143 if ($phase == "inbox") {
144 fputs ($imap_stream, "a001 LSUB \"\" *\n");
145 $read_ary = sqimap_read_data ($imap_stream, "a001", true, $response, $message);
154 /** Get the folders into lower case so sorting is not case sensative */
155 for ($i = 0; $i < count($original); $i++
) {
156 $boxes[$i]["unformatted"] = strtolower($boxes[$i]["unformatted"]);
160 $boxes = ary_sort($boxes, "unformatted", 1);
162 /** Get them back from the original array, still sorted by the id **/
163 for ($i = 0; $i < count($boxes); $i++
) {
164 for ($j = 0; $j < count($original); $j++
) {
165 if ($boxes[$i]["id"] == $original[$j]["id"]) {
166 $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];
175 $boxes[$i]["used"] = true;
179 if ($list_special_folders_first == true) {
180 for ($i = 0; $i < count($boxes); $i++
) {
181 for ($j = 1; $j < count($special_folders); $j++
) {
182 if (substr($boxes[$i]["unformatted"], 0, strlen($special_folders[$j])) == $special_folders[$j]) {
183 $pos = count($boxesnew);
184 $boxesnew[$pos] = $boxes[$i];
185 $boxes[$i]["used"] = true;
191 for ($i = 0; $i < count($boxes); $i++
) {
192 if (($boxes[$i]["unformatted"] != $special_folders[0]) &&
193 ($boxes[$i]["used"] == false)) {
194 $pos = count($boxesnew);
195 $boxesnew[$pos] = $boxes[$i];
196 $boxes[$i]["used"] = true;