View Issue Details

IDProjectCategoryView StatusLast Update
0002669SOGoActiveSyncpublic2014-03-21 17:57
Reportertfu Assigned Toludovic  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platform[Client] MicrosoftOSWindowsOS Version7
Product Version2.2.1 
Fixed in Version2.2.2 
Summary0002669: cannot send mails from a htc desire
Description

Trying to send mails from htc desire via activesync fails because the mail client on this (old) device sends mail as Content-Type: message/rfc822.
This is currently not handled by sogo's activesync. Sogo currently only handles application/vnd.ms-sync.wbxml

For the error which occures see sogo.log (attached).

With the hack in the attached patch the problem could be fixed.

TagsNo tags attached.

Activities

tfu

tfu

2014-03-20 19:55

reporter  

sogo.log (1,984 bytes)
tfu

tfu

2014-03-20 19:55

reporter  

tfu

tfu

2014-03-20 19:55

reporter  

tfu

tfu

2014-03-20 19:56

reporter  

0001-htc-rfc822-mails.patch (2,667 bytes)   
From 30cf92eb68eb00f89577a9d555f79bb3c78c65a9 Mon Sep 17 00:00:00 2001
From: root <root@example.com>
Date: Thu, 20 Mar 2014 14:33:38 -0400
Subject: [PATCH] htc rfc822 mails

---
 ActiveSync/SOGoActiveSyncDispatcher.m |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m
index 1143219..9ade60a 100644
--- a/ActiveSync/SOGoActiveSyncDispatcher.m
+++ b/ActiveSync/SOGoActiveSyncDispatcher.m
@@ -1546,7 +1546,31 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   [context setObject: deviceId  forKey: @"DeviceId"];
   [context setObject: [[theRequest uri] deviceType]  forKey: @"DeviceType"];
 
-  d = [[theRequest content] wbxml2xml];
+   // htc desire z send mail with content-type message/rfc822 base64 encoded
+   if ([[theRequest headerForKey: @"content-type"] isEqualToString: @"message/rfc822"]) {
+        NSMutableString *myRFC822 = [NSMutableString string];
+        NSMutableString *myRFC822_x = [NSMutableString string];
+
+        NSLog(@"tfu  content %@ ",  [theRequest  contentAsString ]);
+        // tfu htc doesn't include date-header causing sogo to show null for the sent-date in sent-folder. Adding Date-Header here if not there
+        if ([ [theRequest  contentAsString ] rangeOfString:@"Date:" options:NSCaseInsensitiveSearch].location == NSNotFound) {
+              NSLog(@"tfu  no-date-header");
+              [ myRFC822_x  appendFormat: @"Date: %@\n%@", [[ NSDate date ]  descriptionWithCalendarFormat: @"%a, %d %b %Y %H:%M:%S %z"  timeZone: [NSTimeZone timeZoneWithName: @"GMT"]  locale: nil ], [theRequest  contentAsString ]];
+              [ myRFC822  appendFormat: @"<?xml version=\"1.0\"?><!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\"><SendMail xmlns=\"ComposeMail:\"><SaveInSentItems/><MIME>%@</MIME></SendMail>", [myRFC822_x stringByEncodingBase64]];
+        } else {
+              NSLog(@"tfu  date-header");
+              [ myRFC822  appendFormat: @"<?xml version=\"1.0\"?><!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\"><SendMail xmlns=\"ComposeMail:\"><SaveInSentItems/><MIME>%@</MIME></SendMail>", [[theRequest  contentAsString ] stringByEncodingBase64]];
+        }
+
+        // tfu convert to wbxml and back to xml to ensure proper formating for further processing
+        d = [[[myRFC822 dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml] wbxml2xml];
+
+   }
+        else
+   {
+       d = [[theRequest content] wbxml2xml];
+   }
+
   documentElement = nil;
 
   if (!d)
-- 
1.7.9.5

0001-htc-rfc822-mails.patch (2,667 bytes)   
ludovic

ludovic

2014-03-20 20:03

administrator   ~0006751

Does it work if you replace:

d = [[[myRFC822 dataUsingEncoding: NSUTF8StringEncoding] xml2wbxml] wbxml2xml];

by:

d = [myRFC822 dataUsingEncoding: NSASCIIStringEncoding]

There shouldn't be any 8-bit characters in myRFC822 string, as the mail content is encoded in base64 and the rest is XML fluff.

tfu

tfu

2014-03-20 21:17

reporter   ~0006752

Yes it works:
d = [[[myRFC822 dataUsingEncoding: NSASCIIStringEncoding] xml2wbxml] wbxml2xml];

ludovic

ludovic

2014-03-20 21:20

administrator   ~0006753

No...

d = [myRFC822 dataUsingEncoding: NSASCIIStringEncoding];

and NOT:

d = [[[myRFC822 dataUsingEncoding: NSASCIIStringEncoding] xml2wbxml] wbxml2xml];

Thanks!

tfu

tfu

2014-03-20 22:15

reporter   ~0006754

Yes it works. Thank You!

ludovic

ludovic

2014-03-21 01:13

administrator   ~0006755

Can you try the attached patch please?

ludovic

ludovic

2014-03-21 01:13

administrator  

sendmail.patch (2,776 bytes)   
diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m
index 1143219..f6ab9f5 100644
--- a/ActiveSync/SOGoActiveSyncDispatcher.m
+++ b/ActiveSync/SOGoActiveSyncDispatcher.m
@@ -1546,15 +1546,50 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   [context setObject: deviceId  forKey: @"DeviceId"];
   [context setObject: [[theRequest uri] deviceType]  forKey: @"DeviceType"];
 
-  d = [[theRequest content] wbxml2xml];
+  cmdName = [[theRequest uri] command];
+
+  //
+  // If the MS-ASProtocolVersion header is set to "12.1", the body of the SendMail request is
+  // is a "message/rfc822" payload - otherwise, it's a WBXML blob.
+  //
+  if ([cmdName caseInsensitiveCompare: @"SendMail"] == NSOrderedSame &&
+      [[theRequest headerForKey: @"content-type"] caseInsensitiveCompare: @"message/rfc822"] == NSOrderedSame)
+    {
+      NSMutableString *myRFC822;
+
+      myRFC822 = [NSMutableString string];
+      
+      if ([[theRequest contentAsString] rangeOfString: @"Date: "
+                                              options: NSCaseInsensitiveSearch].location == NSNotFound)
+        {
+          NSMutableString *myRFC822_x;
+          NSString *value;
+
+          
+          value = [[NSDate date] descriptionWithCalendarFormat: @"%a, %d %b %Y %H:%M:%S %z"  timeZone: [NSTimeZone timeZoneWithName: @"GMT"]  locale: nil];
+          myRFC822_x = [NSMutableString string];
+
+          [myRFC822_x appendFormat: @"Date: %@\n%@", value, [theRequest contentAsString]];
+          [myRFC822  appendFormat: @"<?xml version=\"1.0\"?><!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\"><SendMail xmlns=\"ComposeMail:\"><SaveInSentItems/><MIME>%@</MIME></SendMail>", [myRFC822_x stringByEncodingBase64]];
+        } 
+      else
+        {
+          [myRFC822 appendFormat: @"<?xml version=\"1.0\"?><!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\"><SendMail xmlns=\"ComposeMail:\"><SaveInSentItems/><MIME>%@</MIME></SendMail>", [[theRequest contentAsString ] stringByEncodingBase64]];
+        }
+      
+      d = [myRFC822 dataUsingEncoding: NSASCIIStringEncoding];
+    }
+  else
+    {
+      d = [[theRequest content] wbxml2xml];
+    }
+
   documentElement = nil;
 
   if (!d)
     {
       // We check if it's a Ping command with no body.
-      // See http://msdn.microsoft.com/en-us/library/ee200913(v=exchg.80).aspx for details
-      cmdName = [[theRequest uri] command];
-      
+      // See http://msdn.microsoft.com/en-us/library/ee200913(v=exchg.80).aspx for details      
       if ([cmdName caseInsensitiveCompare: @"Ping"] != NSOrderedSame)
         return [NSException exceptionWithHTTPStatus: 500];
     }
sendmail.patch (2,776 bytes)   
ludovic

ludovic

2014-03-21 12:33

administrator   ~0006757

Any chance you can test it rapidly? I would like to include the "sendmail.patch" in v2.2.2.

Thanks,

ludovic

ludovic

2014-03-21 12:49

administrator  

sendmail-cleaned.patch (2,386 bytes)   
diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m
index 1143219..67fdc7e 100644
--- a/ActiveSync/SOGoActiveSyncDispatcher.m
+++ b/ActiveSync/SOGoActiveSyncDispatcher.m
@@ -1546,15 +1546,45 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   [context setObject: deviceId  forKey: @"DeviceId"];
   [context setObject: [[theRequest uri] deviceType]  forKey: @"DeviceType"];
 
-  d = [[theRequest content] wbxml2xml];
+  cmdName = [[theRequest uri] command];
+
+  //
+  // If the MS-ASProtocolVersion header is set to "12.1", the body of the SendMail request is
+  // is a "message/rfc822" payload - otherwise, it's a WBXML blob.
+  //
+  if ([cmdName caseInsensitiveCompare: @"SendMail"] == NSOrderedSame &&
+      [[theRequest headerForKey: @"content-type"] caseInsensitiveCompare: @"message/rfc822"] == NSOrderedSame)
+    {
+      NSString *s, *xml;
+      
+      if ([[theRequest contentAsString] rangeOfString: @"Date: "
+                                              options: NSCaseInsensitiveSearch].location == NSNotFound)
+        {
+          NSString *value;
+          
+          value = [[NSDate date] descriptionWithCalendarFormat: @"%a, %d %b %Y %H:%M:%S %z"  timeZone: [NSTimeZone timeZoneWithName: @"GMT"]  locale: nil];
+          s = [NSString stringWithFormat: @"Date: %@\n%@", value, [theRequest contentAsString]];
+        } 
+      else
+        {
+          s = [theRequest contentAsString];
+        }
+      
+      xml = [NSString stringWithFormat: @"<?xml version=\"1.0\"?><!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\"><SendMail xmlns=\"ComposeMail:\"><SaveInSentItems/><MIME>%@</MIME></SendMail>", [s stringByEncodingBase64]];
+      
+      d = [xml dataUsingEncoding: NSASCIIStringEncoding];
+    }
+  else
+    {
+      d = [[theRequest content] wbxml2xml];
+    }
+
   documentElement = nil;
 
   if (!d)
     {
       // We check if it's a Ping command with no body.
-      // See http://msdn.microsoft.com/en-us/library/ee200913(v=exchg.80).aspx for details
-      cmdName = [[theRequest uri] command];
-      
+      // See http://msdn.microsoft.com/en-us/library/ee200913(v=exchg.80).aspx for details      
       if ([cmdName caseInsensitiveCompare: @"Ping"] != NSOrderedSame)
         return [NSException exceptionWithHTTPStatus: 500];
     }
sendmail-cleaned.patch (2,386 bytes)   
ludovic

ludovic

2014-03-21 12:49

administrator   ~0006758

Even better, try "sendmail-cleaned.patch".

tfu

tfu

2014-03-21 12:52

reporter   ~0006759

Your patch works after an additional fix - found that [[theRequest uri] command] returns always 'Unknown'.

tfu

tfu

2014-03-21 12:52

reporter  

0001-_valueForParameter-fix.patch (856 bytes)   
From 06a6b2752d76dca63dd75c0452c4771da43a577b Mon Sep 17 00:00:00 2001
From: root <root@example.com>
Date: Fri, 21 Mar 2014 08:50:45 -0400
Subject: [PATCH] _valueForParameter fix

---
 ActiveSync/NSString+ActiveSync.m |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/ActiveSync/NSString+ActiveSync.m b/ActiveSync/NSString+ActiveSync.m
index 1c7a8ba..b1fba0f 100644
--- a/ActiveSync/NSString+ActiveSync.m
+++ b/ActiveSync/NSString+ActiveSync.m
@@ -139,7 +139,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   NSString *s;
   int i;
 
-  components = [[[self componentsSeparatedByString: @"/"] lastObject] componentsSeparatedByString: @"&"];
+  components = [[[self componentsSeparatedByString: @"?"] lastObject] componentsSeparatedByString: @"&"];
   
   for (i = 0; i < [components count]; i++)
     {
-- 
1.7.9.5

ludovic

ludovic

2014-03-21 13:37

administrator   ~0006760

That's obviously an "old bug"... thanks for spotting it.

Can you try the latest patch? (sendmail-cleaned-1.patch).

ludovic

ludovic

2014-03-21 13:39

administrator  

sendmail-cleaned-1.patch (2,953 bytes)   
diff --git a/ActiveSync/NSString+ActiveSync.m b/ActiveSync/NSString+ActiveSync.m
index 1c7a8ba..b1fba0f 100644
--- a/ActiveSync/NSString+ActiveSync.m
+++ b/ActiveSync/NSString+ActiveSync.m
@@ -139,7 +139,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   NSString *s;
   int i;
 
-  components = [[[self componentsSeparatedByString: @"/"] lastObject] componentsSeparatedByString: @"&"];
+  components = [[[self componentsSeparatedByString: @"?"] lastObject] componentsSeparatedByString: @"&"];
   
   for (i = 0; i < [components count]; i++)
     {
diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m
index 1143219..67fdc7e 100644
--- a/ActiveSync/SOGoActiveSyncDispatcher.m
+++ b/ActiveSync/SOGoActiveSyncDispatcher.m
@@ -1546,15 +1546,45 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   [context setObject: deviceId  forKey: @"DeviceId"];
   [context setObject: [[theRequest uri] deviceType]  forKey: @"DeviceType"];
 
-  d = [[theRequest content] wbxml2xml];
+  cmdName = [[theRequest uri] command];
+
+  //
+  // If the MS-ASProtocolVersion header is set to "12.1", the body of the SendMail request is
+  // is a "message/rfc822" payload - otherwise, it's a WBXML blob.
+  //
+  if ([cmdName caseInsensitiveCompare: @"SendMail"] == NSOrderedSame &&
+      [[theRequest headerForKey: @"content-type"] caseInsensitiveCompare: @"message/rfc822"] == NSOrderedSame)
+    {
+      NSString *s, *xml;
+      
+      if ([[theRequest contentAsString] rangeOfString: @"Date: "
+                                              options: NSCaseInsensitiveSearch].location == NSNotFound)
+        {
+          NSString *value;
+          
+          value = [[NSDate date] descriptionWithCalendarFormat: @"%a, %d %b %Y %H:%M:%S %z"  timeZone: [NSTimeZone timeZoneWithName: @"GMT"]  locale: nil];
+          s = [NSString stringWithFormat: @"Date: %@\n%@", value, [theRequest contentAsString]];
+        } 
+      else
+        {
+          s = [theRequest contentAsString];
+        }
+      
+      xml = [NSString stringWithFormat: @"<?xml version=\"1.0\"?><!DOCTYPE ActiveSync PUBLIC \"-//MICROSOFT//DTD ActiveSync//EN\" \"http://www.microsoft.com/\"><SendMail xmlns=\"ComposeMail:\"><SaveInSentItems/><MIME>%@</MIME></SendMail>", [s stringByEncodingBase64]];
+      
+      d = [xml dataUsingEncoding: NSASCIIStringEncoding];
+    }
+  else
+    {
+      d = [[theRequest content] wbxml2xml];
+    }
+
   documentElement = nil;
 
   if (!d)
     {
       // We check if it's a Ping command with no body.
-      // See http://msdn.microsoft.com/en-us/library/ee200913(v=exchg.80).aspx for details
-      cmdName = [[theRequest uri] command];
-      
+      // See http://msdn.microsoft.com/en-us/library/ee200913(v=exchg.80).aspx for details      
       if ([cmdName caseInsensitiveCompare: @"Ping"] != NSOrderedSame)
         return [NSException exceptionWithHTTPStatus: 500];
     }
sendmail-cleaned-1.patch (2,953 bytes)   
ludovic

ludovic

2014-03-21 17:57

administrator   ~0006761

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

Issue History

Date Modified Username Field Change
2014-03-20 19:55 tfu New Issue
2014-03-20 19:55 tfu File Added: sogo.log
2014-03-20 19:55 tfu File Added: sogo_506d_18db7d28_1.data
2014-03-20 19:55 tfu File Added: sogo_506d_18db7d28_2.data
2014-03-20 19:56 tfu File Added: 0001-htc-rfc822-mails.patch
2014-03-20 20:03 ludovic Note Added: 0006751
2014-03-20 21:17 tfu Note Added: 0006752
2014-03-20 21:20 ludovic Note Added: 0006753
2014-03-20 22:15 tfu Note Added: 0006754
2014-03-21 01:13 ludovic Note Added: 0006755
2014-03-21 01:13 ludovic File Added: sendmail.patch
2014-03-21 12:33 ludovic Note Added: 0006757
2014-03-21 12:49 ludovic File Added: sendmail-cleaned.patch
2014-03-21 12:49 ludovic Note Added: 0006758
2014-03-21 12:52 tfu Note Added: 0006759
2014-03-21 12:52 tfu File Added: 0001-_valueForParameter-fix.patch
2014-03-21 13:37 ludovic Note Added: 0006760
2014-03-21 13:39 ludovic File Added: sendmail-cleaned-1.patch
2014-03-21 17:57 ludovic Note Added: 0006761
2014-03-21 17:57 ludovic Status new => closed
2014-03-21 17:57 ludovic Assigned To => ludovic
2014-03-21 17:57 ludovic Resolution open => fixed
2014-03-21 17:57 ludovic Fixed in Version => 2.2.2