diff --git a/ActiveSync/SOGoMailObject+ActiveSync.m b/ActiveSync/SOGoMailObject+ActiveSync.m index 2545c8c87..7e44d28a3 100644 --- a/ActiveSync/SOGoMailObject+ActiveSync.m +++ b/ActiveSync/SOGoMailObject+ActiveSync.m @@ -33,19 +33,28 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #import #import +#import +#import +#import +#import + + #import #import #import #import #import +#import #include "NSDate+ActiveSync.h" #include "../SoObjects/Mailer/NSString+Mail.h" +#include + @implementation SOGoMailObject (ActiveSync) -- (NSString *) _baseEmailAddressesFrom: (NSArray *) enveloppeAddresses +- (NSString *) _emailAddressesFrom: (NSArray *) enveloppeAddresses { NSMutableArray *addresses; NSString *rc; @@ -62,9 +71,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. for (i = 0; i < max; i++) { address = [enveloppeAddresses objectAtIndex: i]; - email = [NSString stringWithFormat: @"%@", [address baseEMail]]; - - [addresses addObject: email]; + email = [address email]; + + if (email) + [addresses addObject: email]; } rc = [addresses componentsJoinedByString: @", "]; } @@ -187,34 +197,37 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. s = [NSMutableString string]; // From - value = [self _baseEmailAddressesFrom: [[self envelope] from]]; + value = [self _emailAddressesFrom: [[self envelope] from]]; if (value) - [s appendFormat: @"%@", value]; + [s appendFormat: @"%@", [value stringByEscapingHTMLString]]; // To - "The value of this element contains one or more e-mail addresses. // If there are multiple e-mail addresses, they are separated by commas." - value = [self _baseEmailAddressesFrom: [[self envelope] to]]; + value = [self _emailAddressesFrom: [[self envelope] to]]; if (value) - [s appendFormat: @"%@", value]; + [s appendFormat: @"%@", [value stringByEscapingHTMLString]]; + // DisplayTo + [s appendFormat: @"\"%@\"", [[context activeUser] login]]; + // Cc - same syntax as the To field - value = [self _baseEmailAddressesFrom: [[self envelope] cc]]; + value = [self _emailAddressesFrom: [[self envelope] cc]]; if (value) - [s appendFormat: @"%@", value]; + [s appendFormat: @"%@", [value stringByEscapingHTMLString]]; // Subject value = [self decodedSubject]; if (value) - [s appendFormat: @"%@", value]; + { + [s appendFormat: @"%@", [value stringByEscapingHTMLString]]; + [s appendFormat: @"%@", [value stringByEscapingHTMLString]]; + } // DateReceived value = [self date]; if (value) - [s appendFormat: @"%@", [value activeSyncRepresentation]];; - - // DisplayTo - //[s appendFormat: @"\"%@\"", [[context activeUser] login]]; - + [s appendFormat: @"%@", [value activeSyncRepresentation]]; + // Importance - FIXME [s appendFormat: @"%@", @"1"]; @@ -223,14 +236,63 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // MesssageClass [s appendFormat: @"%@", @"IPM.Note"]; - //[s appendFormat: @"%@", @"IPM.Schedule.Meeting"]; + //[s appendFormat: @"%@", @"IPM.Schedule.Meeting.Request"]; + // + // TEST + // +#if 0 + id foo = [self lookupImap4BodyPartKey: @"2" inContext: self->context]; + NSData *calendarData; + iCalCalendar *calendar; + iCalEvent *event; + + calendarData = [foo fetchBLOB]; + calendar = [iCalCalendar parseSingleFromSource: calendarData]; + event = [[calendar events] lastObject]; + + if ([event timeStampAsDate]) + [s appendFormat: @"%@", [[event timeStampAsDate] activeSyncRepresentation]]; + else if ([event created]) + [s appendFormat: @"%@", [[event created] activeSyncRepresentation]]; + + [s appendString: @""]; + + // StartTime -- http://msdn.microsoft.com/en-us/library/ee157132(v=exchg.80).aspx + if ([event startDate]) + [s appendFormat: @"%@", [[event startDate] activeSyncRepresentation]]; + + // EndTime -- http://msdn.microsoft.com/en-us/library/ee157945(v=exchg.80).aspx + if ([event endDate]) + [s appendFormat: @"%@", [[event endDate] activeSyncRepresentation]]; + + // Timezone + iCalTimeZone *tz; + + tz = [(iCalDateTime *)[event firstChildWithTag: @"dtstart"] timeZone]; + + if (!tz) + tz = [iCalTimeZone timeZoneForName: @"Europe/London"]; + + [s appendFormat: @"%@", [[tz activeSyncRepresentation] stringByReplacingString: @"\n" withString: @""]];; + + [s appendFormat: @"%d", 0]; + [s appendFormat: @"%@", @"sogo3@example.com"]; + [s appendFormat: @"%d", 1]; + + [s appendString: @""]; +#endif + // + // TEST + // + + // Reply-To - FIXME //NSArray *replyTo = [[message objectForKey: @"envelope"] replyTo]; //if ([replyTo count]) // [s appendFormat: @"%@", [addressFormatter stringForArray: replyTo]]; - // InternetCPID - FIXME + // InternetCPID - 65001 == UTF-8, we use this all the time for now. [s appendFormat: @"%@", @"65001"]; // Body - namespace 17 @@ -251,7 +313,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. len = [content length]; [s appendString: @""]; - [s appendFormat: @"%d", preferredBodyType]; + [s appendFormat: @"%d", preferredBodyType]; [s appendFormat: @"%d", len]; [s appendFormat: @"%d", 0]; [s appendFormat: @"%@", content]; @@ -289,16 +351,24 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // ContentClass [s appendFormat: @"%@", @"urn:content-classes:message"]; + //[s appendFormat: @"%@", @"urn:content-classes:calendarmessage"]; // Flags [s appendString: @""]; [s appendFormat: @"%d", 0]; [s appendString: @""]; - + + // FIXME - support these in the future + //[s appendString: @"foobar"]; + //[s appendString: @"zot="]; + // NativeBodyType -- http://msdn.microsoft.com/en-us/library/ee218276(v=exchg.80).aspx // This is a required child element. // 1 -> plain/text, 2 -> HTML and 3 -> RTF - [s appendFormat: @"%d", preferredBodyType]; + if (nativeBodyType == 4) + nativeBodyType = 1; + + [s appendFormat: @"%d", nativeBodyType]; return s; }