View Issue Details

IDProjectCategoryView StatusLast Update
0002806SOGoActiveSyncpublic2014-06-09 13:35
Reportertfu Assigned Toludovic  
PrioritynormalSeveritycrashReproducibilityalways
Status resolvedResolutionfixed 
Product Version2.2.4 
Target Version2.2.6Fixed in Version2.2.6 
Summary0002806: sogod crash (signal 6) when unflagging a mail
Description

sogod crashes with signal 6 when unflagging a previously flagged mail:

2014-06-07 23:46:38.794 sogod[15394] -[WEClientCapabilities initWithRequest:]: Unknown WebClient: user-agent='Android-EAS/3.10.000.084109.166'
EXCEPTION: <NSException: 0x7f3e804c4cb0> NAME:NSInvalidArgumentException REASON:GSCInlineString(instance) does not recognize objectForKey: INFO:(null)
Jun 07 23:46:39 sogod [15380]: <0x0x7f3e803037c0[WOWatchDogChild]> child 15394 exited
Jun 07 23:46:39 sogod [15380]: <0x0x7f3e803037c0[WOWatchDogChild]> (terminated due to signal 6)
Jun 07 23:46:39 sogod [15380]: <0x0x7f3e803eff10[WOWatchDog]> child spawned with pid 15651

Reproduced the issue on several android devices.
Please review attached patch. It should fix the issue and implements the synchronization of \Flagged.

Steps To Reproduce

Flag a mail
Sync
UnFlag the mail
Sync
-> Signal 6

TagsNo tags attached.

Activities

tfu

tfu

2014-06-07 22:10

reporter  

0001-Signal6onUnflag.patch (3,342 bytes)   
From f83454d02eb3e79d2d7fa53b5fcdfd02ca6b33f8 Mon Sep 17 00:00:00 2001
From: root <root@example.com>
Date: Sat, 7 Jun 2014 23:57:12 +0200
Subject: [PATCH] Signal6onUnflag

---
 ActiveSync/SOGoActiveSyncDispatcher.m  |    1 +
 ActiveSync/SOGoMailObject+ActiveSync.m |   22 ++++++++++++++++------
 SoObjects/Mailer/SOGoMailObject.h      |    1 +
 SoObjects/Mailer/SOGoMailObject.m      |    5 +++++
 4 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m
index 63e4b54..9c52d79 100644
--- a/ActiveSync/SOGoActiveSyncDispatcher.m
+++ b/ActiveSync/SOGoActiveSyncDispatcher.m
@@ -848,6 +848,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       uids = [currentCollection fetchUIDsMatchingQualifier: qualifier
                                               sortOrdering: @"REVERSE ARRIVAL"
                                                   threaded: NO];
+
       count = [uids count];
     }
   else
diff --git a/ActiveSync/SOGoMailObject+ActiveSync.m b/ActiveSync/SOGoMailObject+ActiveSync.m
index 7b0a008..e5c5790 100644
--- a/ActiveSync/SOGoMailObject+ActiveSync.m
+++ b/ActiveSync/SOGoMailObject+ActiveSync.m
@@ -761,7 +761,7 @@ struct GlobalObjectId {
   
   // Flags
   [s appendString: @"<Flag xmlns=\"Email:\">"];
-  [s appendFormat: @"<FlagStatus>%d</FlagStatus>", 0];
+  [s appendFormat: @"<FlagStatus>%d</FlagStatus>", ([self flagged] ? 2 : 0)];
   [s appendString: @"</Flag>"];
   
   // FIXME - support these in the future
@@ -799,12 +799,22 @@ struct GlobalObjectId {
 
   if ((o = [theValues objectForKey: @"Flag"]))
     {
-      o = [o objectForKey: @"FlagStatus"];
-      
-      if ([o intValue])
-        [self addFlags: @"\\Flagged"];
+      // handle empty flags -> {Flag = ""; }
+      if (([o isKindOfClass: [NSMutableDictionary class]])) {
+         if ((o = [o objectForKey: @"FlagStatus"])) {
+            // 0 = The flag is cleared.
+            // 1 = The status is set to complete.
+            // 2 = The status is set to active.
+            if (([o isEqualToString: @"2"])) {
+               [self addFlags: @"\\Flagged"];
+            }
+            else {
+              [self removeFlags: @"\\Flagged"];
+            }
+         }
+      }
       else
-        [self removeFlags: @"\\Flagged"]; 
+         [self removeFlags: @"\\Flagged"]; 
     }
   
   if ((o = [theValues objectForKey: @"Read"]))
diff --git a/SoObjects/Mailer/SOGoMailObject.h b/SoObjects/Mailer/SOGoMailObject.h
index 46c1d7c..af52334 100644
--- a/SoObjects/Mailer/SOGoMailObject.h
+++ b/SoObjects/Mailer/SOGoMailObject.h
@@ -114,6 +114,7 @@ NSArray *SOGoMailCoreInfoKeys;
 - (NSException *) removeFlags:(id)_f;
 
 - (BOOL) isNewMail;  /* \Recent */
+- (BOOL) flagged;    /* \Flagged */
 - (BOOL) read;       /* \Unseen */
 - (BOOL) replied;    /* \Answered */
 - (BOOL) forwarded;  /* $forwarded */
diff --git a/SoObjects/Mailer/SOGoMailObject.m b/SoObjects/Mailer/SOGoMailObject.m
index f2fa35e..f99bcf4 100644
--- a/SoObjects/Mailer/SOGoMailObject.m
+++ b/SoObjects/Mailer/SOGoMailObject.m
@@ -1464,6 +1464,11 @@ static BOOL debugSoParts       = NO;
   return [self _hasFlag: @"seen"];
 }
 
+- (BOOL) flagged
+{
+  return [self _hasFlag: @"flagged"];
+}
+
 - (BOOL) replied
 {
   return [self _hasFlag: @"answered"];
-- 
1.7.9.5

0001-Signal6onUnflag.patch (3,342 bytes)   
ludovic

ludovic

2014-06-09 12:50

administrator   ~0007160

On my end, I don't get a crash when setting/clearings flags on IMAP messages:

Breakpoint 2, -[SOGoMailObject(ActiveSync) takeActiveSyncValues:inContext:] (self=0x555556362970, _cmd=0x7fffea1103b0, theValues=0x55555635db50, _context=0x5555561ff2d0)
at SOGoMailObject+ActiveSync.m:804
804 if ([o intValue])
(gdb) po o
2
(gdb) po theValues
{Flag = {DueDate = "2014-06-09T00:00:00.000Z"; FlagStatus = 2; FlagType = "Follow up"; OrdinalDate = "2014-06-09T12:48:37.284Z"; ReminderSet = 0; StartDate = "2014-06-09T00:00:00.000Z"; SubOrdinalDate = 5555555; UTCDueDate = "2014-06-09T04:00:00.000Z"; UTCStartDate = "2014-06-09T04:00:00.000Z"; }; }
(gdb) po NSStringFromClass([o class])
GSCInlineString
(gdb)

Are you sure you don't have changes in NGDOMElement+ActiveSync.m?

tfu

tfu

2014-06-09 13:23

reporter   ~0007162

I can repoduce it on e.g. htc desire. It sends
{Flag = ""; } when unflagging. Before producing the patch I did a complete 2.2.5 refresh.

ludovic

ludovic

2014-06-09 13:29

administrator   ~0007164

Ok, so the client sends "broken" content. We should indeed handle this better.

I'll apply the patch and add some comments in the code.

ludovic

ludovic

2014-06-09 13:35

administrator   ~0007165

Patch applied:

https://github.com/inverse-inc/sogo/commit/f48839bf55917cb3a9756134930206b7b15d0279

Nice catch!

Issue History

Date Modified Username Field Change
2014-06-07 22:10 tfu New Issue
2014-06-07 22:10 tfu File Added: 0001-Signal6onUnflag.patch
2014-06-09 12:50 ludovic Note Added: 0007160
2014-06-09 13:23 tfu Note Added: 0007162
2014-06-09 13:29 ludovic Note Added: 0007164
2014-06-09 13:34 ludovic Target Version => 2.2.6
2014-06-09 13:35 ludovic Note Added: 0007165
2014-06-09 13:35 ludovic Status new => resolved
2014-06-09 13:35 ludovic Fixed in Version => 2.2.6
2014-06-09 13:35 ludovic Resolution open => fixed
2014-06-09 13:35 ludovic Assigned To => ludovic