From 5b3dd412d2e28f80fb2d12dbdcab992cc6f219a5 Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Tue, 15 Jul 2008 12:48:20 -0400
Subject: [PATCH] Check PERMANENTFLAGS before saving MDNSent flag (#1484963, #1485163)

---
 CHANGELOG                      |    1 
 program/include/html.php       |    7 ++-
 program/include/rcube_imap.php |   15 +++++++
 program/steps/mail/func.inc    |    2 
 program/steps/mail/show.inc    |    7 ++-
 program/lib/imap.inc           |   36 +++++++++++-------
 6 files changed, 48 insertions(+), 20 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index eccc4ec..03ce3f7 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -4,6 +4,7 @@
 2008/07/14 (thomasb)
 ----------
 - Re-enable autocomplete attribute for login form (#1485211)
+- Check PERMANENTFLAGS before saving $MDNSent flag (#1484963, #1485163)
 
 2008/06/30 (alec)
 ----------
diff --git a/program/include/html.php b/program/include/html.php
index 6a88925..a11a1a4 100644
--- a/program/include/html.php
+++ b/program/include/html.php
@@ -248,7 +248,7 @@
 {
     protected $tagname = 'input';
     protected $type = 'text';
-    protected $allowed = array('type','name','value','size','tabindex','autocomplete','checked');
+    protected $allowed = array('type','name','value','size','tabindex','autocomplete','checked','onchange');
 
     public function __construct($attrib = array())
     {
@@ -416,7 +416,7 @@
 class html_textarea extends html
 {
     protected $tagname = 'textarea';
-    protected $allowed = array('name','rows','cols','wrap','tabindex');
+    protected $allowed = array('name','rows','cols','wrap','tabindex','onchange');
 
     /**
      * Get HTML code for this object
@@ -473,6 +473,7 @@
 {
     protected $tagname = 'select';
     protected $options = array();
+    protected $allowed = array('name','size','tabindex','autocomplete','multiple','onchange');
     
     /**
      * Add a new option to this drop-down
@@ -513,7 +514,7 @@
             $attr = array(
                 'value' => $option['value'],
                 'selected' => (in_array($option['value'], $select, true) ||
-            in_array($option['text'], $select, true)) ? 1 : null);
+                  in_array($option['text'], $select, true)) ? 1 : null);
 
             $this->content .= self::tag('option', $attr, Q($option['text']));
         }
diff --git a/program/include/rcube_imap.php b/program/include/rcube_imap.php
index 395a1b3..3daea0c 100644
--- a/program/include/rcube_imap.php
+++ b/program/include/rcube_imap.php
@@ -346,6 +346,21 @@
 
 
   /**
+   * Checks the PERMANENTFLAGS capability of the current mailbox
+   * and returns true if the given flag is supported by the IMAP server
+   *
+   * @param   string  Permanentflag name
+   * @return  mixed   True if this flag is supported
+   * @access  public
+   */
+  function check_permflag($flag)
+    {
+    $flagsmap = $GLOBALS['IMAP_FLAGS'];
+    return (($imap_flag = $flagsmap[strtoupper($flag)]) && in_array_nocase($imap_flag, $this->conn->permanentflags));
+    }
+
+
+  /**
    * Returns the delimiter that is used by the IMAP server for folder separation
    *
    * @return  string  Delimiter string
diff --git a/program/lib/imap.inc b/program/lib/imap.inc
index e3df356..757fbf6 100644
--- a/program/lib/imap.inc
+++ b/program/lib/imap.inc
@@ -90,6 +90,16 @@
 
 $GLOBALS['IMAP_SERVER_TZ'] = date('Z');
 
+$GLOBALS['IMAP_FLAGS'] = array(
+    'SEEN'     => '\\Seen',
+    'DELETED'  => '\\Deleted',
+    'RECENT'   => '\\Recent',
+    'ANSWERED' => '\\Answered',
+    'DRAFT'    => '\\Draft',
+    'FLAGGED'  => '\\Flagged',
+    'FORWARDED' => '$Forwarded',
+    'MDNSENT'  => '$MDNSent');
+
 $iil_error;
 $iil_errornum;
 $iil_selected;
@@ -113,6 +123,7 @@
 	var $rootdir;
 	var $delimiter;
 	var $capability = array();
+	var $permanentflags = array();
 }
 
 /**
@@ -142,7 +153,7 @@
 	var $priority;
 	var $mdn_to;
 	var $mdn_sent = false;
-	var $is_reply = false;
+	var $is_draft = false;
 	var $seen = false;
 	var $deleted = false;
 	var $recent = false;
@@ -716,7 +727,7 @@
 		return false;
 	}
 	if (strcmp($conn->selected, $mailbox) == 0) {
-    		return true;
+		return true;
 	}
     
 	iil_C_LoadCache($conn, $mailbox);
@@ -729,9 +740,12 @@
 				if (strcasecmp($a[2], 'EXISTS') == 0) {
 					$conn->exists = (int) $a[1];
 				}
-            			if (strcasecmp($a[2], 'RECENT') == 0) {
-                			$conn->recent = (int) $a[1];
-            			}
+				if (strcasecmp($a[2], 'RECENT') == 0) {
+					$conn->recent = (int) $a[1];
+				}
+			}
+			else if (preg_match('/\[?PERMANENTFLAGS\s+\(([^\)]+)\)\]/U', $line, $match)) {
+				$conn->permanentflags = explode(' ', $match[1]);
 			}
 		} while (!iil_StartsWith($line, 'sel1'));
 
@@ -1757,6 +1771,8 @@
 							    $result[$id]->answered = true;
 							} else if (strcasecmp($val, '$Forwarded') == 0) {
 							    $result[$id]->forwarded = true;
+							} else if (strcasecmp($val, 'Draft') == 0) {
+							    $result[$id]->is_draft = true;
 							} else if (strcasecmp($val, '$MDNSent') == 0) {
 							    $result[$id]->mdn_sent = true;
 							} else if (strcasecmp($val, 'Flagged') == 0) {
@@ -1909,15 +1925,7 @@
 	}
     
 	$fp    = $conn->fp;
-	$flags = array(
-        'SEEN'     => '\\Seen',
-        'DELETED'  => '\\Deleted',
-        'RECENT'   => '\\Recent',
-        'ANSWERED' => '\\Answered',
-        'DRAFT'    => '\\Draft',
-        'FLAGGED'  => '\\Flagged',
-        'FORWARDED' => '$Forwarded',
-        'MDNSENT'  => '$MDNSent');
+	$flags = $GLOBALS['IMAP_FLAGS'];
         
 	$flag = strtoupper($flag);
 	$flag = $flags[$flag];
diff --git a/program/steps/mail/func.inc b/program/steps/mail/func.inc
index 02419be..6ba3d16 100644
--- a/program/steps/mail/func.inc
+++ b/program/steps/mail/func.inc
@@ -1069,7 +1069,7 @@
 
   $message = new rcube_message($uid);
   
-  if ($message->headers->mdn_to && !$message->headers->mdn_sent)
+  if ($message->headers->mdn_to && !$message->headers->mdn_sent && $IMAP->check_permflag('MDNSENT'))
   {
     $identity = $RCMAIL->user->get_identity();
     $sender = format_email_recipient($identity['email'], $identity['name']);
diff --git a/program/steps/mail/show.inc b/program/steps/mail/show.inc
index bff4e68..ef88c7b 100644
--- a/program/steps/mail/show.inc
+++ b/program/steps/mail/show.inc
@@ -82,8 +82,11 @@
   $OUTPUT->set_env('sender', $MESSAGE->sender['string']);
   
   // check for unset disposition notification
-  if ($MESSAGE->headers->mdn_to && !$MESSAGE->headers->mdn_sent &&
-      $mbox_name != $CONFIG['drafts_mbox'] && $mbox_name != $CONFIG['sent_mbox'])
+  if ($MESSAGE->headers->mdn_to &&
+      !$MESSAGE->headers->mdn_sent &&
+      $IMAP->check_permflag('MDNSENT') &&
+      $mbox_name != $CONFIG['drafts_mbox'] &&
+      $mbox_name != $CONFIG['sent_mbox'])
   {
     if (intval($CONFIG['mdn_requests']) === 1)
     {

--
Gitblit v1.9.1