+/**
+ * Defines special mailboxes: given a mailbox name, it checks if this is a
+ * "special" one: INBOX, Trash, Sent or Draft.
+ *
+ * Since 1.2.5 function includes special_mailbox hook.<br>
+ * Since 1.4.3 hook supports more than one plugin.
+ * @param string $box mailbox name
+ * @param boolean $include_subs (since 1.5.2) if true, subfolders of system
+ * folders are special. if false, subfolders are not special mailboxes
+ * unless they are tagged as special in 'special_mailbox' hook.
+ * @return boolean
+ * @since 1.2.3
+ */
+function isSpecialMailbox($box,$include_subs=true) {
+ $ret = ( (strtolower($box) == 'inbox') ||
+ isTrashMailbox($box,$include_subs) ||
+ isSentMailbox($box,$include_subs) ||
+ isDraftMailbox($box,$include_subs) );
+
+ if ( !$ret ) {
+ $ret = boolean_hook_function('special_mailbox', $box, 1);
+ }
+ return $ret;
+}
+
+/**
+ * Detects if mailbox is a Trash folder or subfolder of Trash
+ * @param string $box mailbox name
+ * @param boolean $include_subs (since 1.5.2) if true, subfolders of system
+ * folders are special. if false, subfolders are not special mailboxes.
+ * @return bool whether this is a Trash folder
+ * @since 1.4.0
+ */
+function isTrashMailbox ($box,$include_subs=true) {
+ global $trash_folder, $move_to_trash;
+ return $move_to_trash && $trash_folder &&
+ ( $box == $trash_folder ||
+ ($include_subs && isBoxBelow($box, $trash_folder)) );
+}
+
+/**
+ * Detects if mailbox is a Sent folder or subfolder of Sent
+ * @param string $box mailbox name
+ * @param boolean $include_subs (since 1.5.2) if true, subfolders of system
+ * folders are special. if false, subfolders are not special mailboxes.
+ * @return bool whether this is a Sent folder
+ * @since 1.4.0
+ */
+function isSentMailbox($box,$include_subs=true) {
+ global $sent_folder, $move_to_sent;
+ return $move_to_sent && $sent_folder &&
+ ( $box == $sent_folder ||
+ ($include_subs && isBoxBelow($box, $sent_folder)) );
+}
+
+/**
+ * Detects if mailbox is a Drafts folder or subfolder of Drafts
+ * @param string $box mailbox name
+ * @param boolean $include_subs (since 1.5.2) if true, subfolders of system
+ * folders are special. if false, subfolders are not special mailboxes.
+ * @return bool whether this is a Draft folder
+ * @since 1.4.0
+ */
+function isDraftMailbox($box,$include_subs=true) {
+ global $draft_folder, $save_as_draft;
+ return $save_as_draft &&
+ ( $box == $draft_folder ||
+ ($include_subs && isBoxBelow($box, $draft_folder)) );
+}
+
+/**
+ * Expunges a mailbox
+ *
+ * WARNING: Select mailbox before calling this function.
+ *
+ * permanently removes all messages that have the \Deleted flag
+ * set from the selected mailbox. See EXPUNGE command chapter in
+ * IMAP RFC.
+ * @param stream $imap_stream imap connection resource
+ * @param string $mailbox mailbox name (unused since 1.1.3).
+ * @param boolean $handle_errors error handling control (displays error_box on error).
+ * @param mixed $id (since 1.3.0) integer message id or array with integer ids
+ * @return integer number of expunged messages
+ * @since 1.0 or older
+ */
+function sqimap_mailbox_expunge ($imap_stream, $mailbox, $handle_errors = true, $id='') {
+ if ($id) {
+ if (is_array($id)) {
+ $id = sqimap_message_list_squisher($id);
+ }
+ $id = ' '.$id;
+ $uid = TRUE;
+ } else {
+ $uid = false;
+ }
+ $read = sqimap_run_command($imap_stream, 'EXPUNGE'.$id, $handle_errors,
+ $response, $message, $uid);
+ $cnt = 0;
+
+ if (is_array($read)) {
+ foreach ($read as $r) {
+ if (preg_match('/^\*\s[0-9]+\sEXPUNGE/AUi',$r,$regs)) {
+ $cnt++;
+ }
+ }
+ }
+ return $cnt;