check mailbox before trying to store emails in it. fix for (#584658).
authortokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 18 Apr 2005 09:43:49 +0000 (09:43 +0000)
committertokul <tokul@7612ce4b-ef26-0410-bec9-ea0150e637f0>
Mon, 18 Apr 2005 09:43:49 +0000 (09:43 +0000)
todo: remove functions from setup.php and move configuration vars to config
file.

git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@9341 7612ce4b-ef26-0410-bec9-ea0150e637f0

plugins/mail_fetch/fetch.php
plugins/mail_fetch/functions.php
plugins/mail_fetch/setup.php

index 0c529d4..bb58e77 100644 (file)
@@ -154,9 +154,6 @@ sqgetGlobalVar('delimiter',  $delimiter,  SQ_SESSION);
         $mailfetch_login  = $mailfetch[$i_loop]['login'];
         $mailfetch_uidl   = $mailfetch[$i_loop]['uidl'];
         $mailfetch_subfolder = $mailfetch[$i_loop]['subfolder'];
-        if($mailfetch_subfolder == '') {
-            $mailfetch_subfolder == 'INBOX';
-        }
 
         $pop3 = new POP3($mailfetch_server, 60);
 
@@ -180,6 +177,12 @@ sqgetGlobalVar('delimiter',  $delimiter,  SQ_SESSION);
         Mail_Fetch_Status(_("Opening IMAP server"));
         $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10);
 
+        // check if destination folder is not set, is not subscribed and is not \noselect folder
+        if($mailfetch_subfolder == '' || 
+           ! mail_fetch_check_folder($imap_stream,$mailfetch_subfolder)) {
+            $mailfetch_subfolder = 'INBOX';
+        }
+
         Mail_Fetch_Status(_("Opening POP server"));
         $Count = $pop3->login($mailfetch_user, $mailfetch_pass);
         if (($Count == false || $Count == -1) && $pop3->ERROR != '') {
index 17800cf..f352a11 100644 (file)
  * @subpackage mail_fetch
  */
 
+/** declare plugin globals */
+global $mail_fetch_allow_unsubscribed;
+
+/**
+ * Controls use of unsubscribed folders in plugin
+ * @global boolean $mail_fetch_allow_unsubscribed
+ * @since 1.5.1
+ */
+$mail_fetch_allow_unsubscribed = false;
+
 /**
  * hex2bin - document me
  */
@@ -79,4 +89,49 @@ function decrypt( $txt ) {
     return $tmp;
 }
 
+/**
+ * check mail folder
+ * @param stream $imap_stream imap connection resource
+ * @param string $imap_folder imap folder name
+ * @return boolean true, when folder can be used to store messages.
+ * @since 1.5.1
+ */
+function mail_fetch_check_folder($imap_stream,$imap_folder) {
+    global $mail_fetch_allow_unsubscribed;
+
+    // check if folder is subscribed or only exists.
+    if (sqimap_mailbox_is_subscribed($imap_stream,$imap_folder)) {
+        $ret = true;
+    } elseif ($mail_fetch_allow_unsubscribed && sqimap_mailbox_exists($imap_stream,$imap_folder)) {
+        $ret = true;
+    } else {
+        $ret = false;
+    }
+
+    // make sure that folder can store messages
+    if ($ret && mail_fetch_check_noselect($imap_stream,$imap_folder)) {
+        $ret = false;
+    }
+
+    return $ret;
+}
+
+/**
+ * Checks if folder is noselect (can't store messages)
+ * 
+ * Function does not check if folder subscribed.
+ * @param stream $imap_stream imap connection resource
+ * @param string $imap_folder imap folder name
+ * @return boolean true, when folder has noselect flag. false in any other case.
+ * @since 1.5.1
+ */
+function mail_fetch_check_noselect($imap_stream,$imap_folder) {
+    $boxes=sqimap_mailbox_list($imap_stream);
+    foreach($boxes as $box) {
+        if ($box['unformatted']==$imap_folder) {
+            return (bool) check_is_noselect($box['raw']);
+        }
+    }
+    return false;
+}
 ?>
\ No newline at end of file
index ddc9dec..0380eb2 100644 (file)
@@ -27,7 +27,7 @@ function squirrelmail_plugin_init_mail_fetch() {
     $squirrelmail_plugin_hooks['login_verified']['mail_fetch'] = 'mail_fetch_setnew';
     $squirrelmail_plugin_hooks['left_main_before']['mail_fetch'] = 'mail_fetch_login';
     $squirrelmail_plugin_hooks['optpage_register_block']['mail_fetch'] = 'mailfetch_optpage_register_block';
-
+    $squirrelmail_plugin_hooks['rename_or_delete_folder']['mail_fetch'] = 'mail_fetch_folderact';
 }
 
 function mail_fetch_link() {
@@ -177,8 +177,10 @@ function mail_fetch_login() {
                 while (list($lineNum, $line) = each ($MessArray)) {
                     $Message .= $line;
                 }
-
-                if ($mailfetch_subfolder=="") {
+                
+                // check if mail folder is not null and subscribed (There is possible issue with /noselect mail folders)
+                if ($mailfetch_subfolder=='' || 
+                    ! mail_fetch_check_folder($imap_stream,$mailfetch_subfolder)) {
                     fputs($imap_stream, "A3$i APPEND INBOX {" . strlen($Message) . "}\r\n");
                 } else {
                     fputs($imap_stream, "A3$i APPEND $mailfetch_subfolder {" . strlen($Message) . "}\r\n");
@@ -235,4 +237,34 @@ function mailfetch_optpage_register_block() {
             );
 }
 
+function mail_fetch_folderact($args) {
+    global $username, $data_dir;
+
+    if (empty($args) || !is_array($args)) {
+        return;
+    }
+
+    /* Should be 3 ars, 1: old folder, 2: action, 3: new folder */
+    if (count($args) != 3) {
+        return;
+    }
+
+    list($old_folder, $action, $new_folder) = $args;
+
+    $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number');
+
+    for ($i = 0; $i < $mailfetch_server_number; $i++) {
+        $mailfetch_subfolder = getPref($data_dir, $username, 'mailfetch_subfolder_' . $i);
+
+        if ($mailfetch_subfolder != $old_folder) {
+            continue;
+        }
+
+        if ($action == 'delete') {
+            setPref($data_dir, $username, 'mailfetch_subfolder_' . $i, 'INBOX');
+        } elseif ($action == 'rename') {
+            setPref($data_dir, $username, 'mailfetch_subfolder_' . $i, $new_folder);
+        }
+    }
+}
 ?>
\ No newline at end of file