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)

---
 program/lib/imap.inc |   36 ++++++++++++++++++++++--------------
 1 files changed, 22 insertions(+), 14 deletions(-)

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];

--
Gitblit v1.9.1