- /**
- ** imap_mailbox.php
- **
- ** This impliments all functions that manipulate mailboxes
- **/
-
- /******************************************************************************
- ** Expunges a mailbox
- ******************************************************************************/
- function sqimap_mailbox_expunge ($imap_stream, $mailbox) {
- sqimap_mailbox_select ($imap_stream, $mailbox);
- fputs ($imap_stream, "a001 EXPUNGE\r\n");
- $read = sqimap_read_data($imap_stream, "a001", true, $response, $message);
- sqimap_mailbox_close ($imap_stream);
- }
-
-
- /******************************************************************************
- ** Checks whether or not the specified mailbox exists
- ******************************************************************************/
- function sqimap_mailbox_exists ($imap_stream, $mailbox) {
- fputs ($imap_stream, "a001 LIST \"\" \"$mailbox\"\r\n");
- $mbx = sqimap_read_data($imap_stream, "a001", true, $response, $message);
- if ($mailbox) {
- if (ereg ("$mailbox", $mbx[0])) {
+
+/**
+ * imap_mailbox.php
+ *
+ * Copyright (c) 1999-2001 The SquirrelMail Development Team
+ * Licensed under the GNU GPL. For full terms see the file COPYING.
+ *
+ * This impliments all functions that manipulate mailboxes
+ *
+ * $Id$
+ */
+
+/*************************
+ ** Expunges a mailbox **
+ *************************/
+function sqimap_mailbox_expunge ($imap_stream, $mailbox,$handle_errors = true)
+{
+ fputs ($imap_stream, sqimap_session_id() . " EXPUNGE\r\n");
+ $read = sqimap_read_data($imap_stream, sqimap_session_id(),
+ $handle_errors, $response, $message);
+}
+
+
+/******************************************************************************
+ ** Checks whether or not the specified mailbox exists
+ ******************************************************************************/
+function sqimap_mailbox_exists ($imap_stream, $mailbox)
+{
+ if (! isset($mailbox)) {
+ return false;
+ }
+ fputs ($imap_stream, sqimap_session_id() . " LIST \"\" \"$mailbox\"\r\n");
+ $mbx = sqimap_read_data($imap_stream, sqimap_session_id(),
+ true, $response, $message);
+ return isset($mbx[0]);
+}
+
+/******************************************************************************
+ ** Selects a mailbox
+ ******************************************************************************/
+function sqimap_mailbox_select ($imap_stream, $mailbox,
+ $hide=true, $recent=false)
+{
+ global $auto_expunge;
+
+ if ( $mailbox == 'None' ) {
+ return;
+ }
+
+ fputs ($imap_stream, sqimap_session_id() . " SELECT \"$mailbox\"\r\n");
+ $read = sqimap_read_data($imap_stream, sqimap_session_id(),
+ true, $response, $message);
+ if ($recent) {
+ for ($i=0; $i<count($read); $i++) {
+ if (strpos(strtolower($read[$i]), 'recent')) {
+ $r = explode(' ', $read[$i]);
+ }
+ }
+ return $r[1];
+ }
+ if ($auto_expunge) {
+ fputs ($imap_stream, sqimap_session_id() . " EXPUNGE\r\n");
+ $tmp = sqimap_read_data($imap_stream, sqimap_session_id(),
+ false, $a, $b);
+ }
+}
+
+
+
+/******************************************************************************
+ ** Creates a folder
+ ******************************************************************************/
+function sqimap_mailbox_create ($imap_stream, $mailbox, $type)
+{
+ global $delimiter;
+ if (strtolower($type) == 'noselect') {
+ $mailbox = $mailbox.$delimiter;
+ }
+ fputs ($imap_stream, sqimap_session_id() . " CREATE \"$mailbox\"\r\n");
+ $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(),
+ true, $response, $message);
+
+ sqimap_subscribe ($imap_stream, $mailbox);
+}
+
+
+
+/******************************************************************************
+ ** Subscribes to an existing folder
+ ******************************************************************************/
+function sqimap_subscribe ($imap_stream, $mailbox)
+{
+ fputs ($imap_stream, sqimap_session_id() . " SUBSCRIBE \"$mailbox\"\r\n");
+ $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(),
+ true, $response, $message);
+}
+
+
+
+/******************************************************************************
+ ** Unsubscribes to an existing folder
+ ******************************************************************************/
+function sqimap_unsubscribe ($imap_stream, $mailbox)
+{
+ global $imap_server_type;
+
+ fputs ($imap_stream, sqimap_session_id() . " UNSUBSCRIBE \"$mailbox\"\r\n");
+ $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(),
+ true, $response, $message);
+}
+
+
+
+/******************************************************************************
+ ** This function simply deletes the given folder
+ ******************************************************************************/
+function sqimap_mailbox_delete ($imap_stream, $mailbox)
+{
+ fputs ($imap_stream, sqimap_session_id() . " DELETE \"$mailbox\"\r\n");
+ $read_ary = sqimap_read_data($imap_stream, sqimap_session_id(),
+ true, $response, $message);
+ sqimap_unsubscribe ($imap_stream, $mailbox);
+}
+
+/***********************************************************************
+ ** Determines if the user is subscribed to the folder or not
+ **********************************************************************/
+function sqimap_mailbox_is_subscribed($imap_stream, $folder)
+{
+ $boxes = sqimap_mailbox_list ($imap_stream);
+ foreach ($boxes as $ref) {
+ if ($ref['unformatted'] == $folder) {