diff --git a/ActiveSync/NSString+ActiveSync.h b/ActiveSync/NSString+ActiveSync.h index f3f95b07b..172d71eb1 100644 --- a/ActiveSync/NSString+ActiveSync.h +++ b/ActiveSync/NSString+ActiveSync.h @@ -47,6 +47,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - (NSCalendarDate *) calendarDate; - (NSString *) deviceId; - (NSString *) deviceType; +- (NSString *) attachmentName; - (NSString *) command; - (NSData *) convertHexStringToBytes; diff --git a/ActiveSync/NSString+ActiveSync.m b/ActiveSync/NSString+ActiveSync.m index b1fba0f4c..3d1a2b86b 100644 --- a/ActiveSync/NSString+ActiveSync.m +++ b/ActiveSync/NSString+ActiveSync.m @@ -186,6 +186,23 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. return s; } +// This method extracts the "AttachmentName" from a URI: +// +// /SOGo/Microsoft-Server-ActiveSync?Cmd=GetAttachment&User=sogo&DeviceId=HTCa04b4932597acd3f2dc1a918b9728&DeviceType=htcvision&AttachmentName=mail/TestFldr/8/2 +// +- (NSString *) attachmentName +{ + NSString *s; + + s = [self _valueForParameter: @"ATTACHMENTNAME="]; + + if (!s) + s = @"Unknown"; + + return s; +} + + // // // diff --git a/ActiveSync/SOGoActiveSyncDispatcher.m b/ActiveSync/SOGoActiveSyncDispatcher.m index 63e4b54ee..a6a9eb384 100644 --- a/ActiveSync/SOGoActiveSyncDispatcher.m +++ b/ActiveSync/SOGoActiveSyncDispatcher.m @@ -781,7 +781,51 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - (void) processGetAttachment: (id ) theDocumentElement inResponse: (WOResponse *) theResponse { + NSString *fileReference, *realCollectionId; + SOGoMicrosoftActiveSyncFolderType folderType; + + fileReference = [context objectForKey: @"AttachmentName"]; + + realCollectionId = [fileReference realCollectionIdWithFolderType: &folderType]; + + if (folderType == ActiveSyncMailFolder) + { + id currentFolder, currentCollection, currentBodyPart; + NSString *folderName, *messageName, *pathToPart; + SOGoMailAccounts *accountsFolder; + SOGoUserFolder *userFolder; + SOGoMailObject *mailObject; + + NSRange r1, r2; + + r1 = [realCollectionId rangeOfString: @"/"]; + r2 = [realCollectionId rangeOfString: @"/" options: 0 range: NSMakeRange(NSMaxRange(r1)+1, [realCollectionId length]-NSMaxRange(r1)-1)]; + + folderName = [realCollectionId substringToIndex: r1.location]; + messageName = [realCollectionId substringWithRange: NSMakeRange(NSMaxRange(r1), r2.location-r1.location-1)]; + pathToPart = [realCollectionId substringFromIndex: r2.location+1]; + + userFolder = [[context activeUser] homeFolderInContext: context]; + accountsFolder = [userFolder lookupName: @"Mail" inContext: context acquire: NO]; + currentFolder = [accountsFolder lookupName: @"0" inContext: context acquire: NO]; + + currentCollection = [currentFolder lookupName: [NSString stringWithFormat: @"folder%@", folderName] + inContext: context + acquire: NO]; + + mailObject = [currentCollection lookupName: messageName inContext: context acquire: NO]; + currentBodyPart = [mailObject lookupImap4BodyPartKey: pathToPart inContext: context]; + + [theResponse setHeader: [NSString stringWithFormat: @"%@/%@", [[currentBodyPart partInfo] objectForKey: @"type"], [[currentBodyPart partInfo] objectForKey: @"subtype"]] + forKey: @"Content-Type"]; + + [theResponse setContent: [currentBodyPart fetchBLOB] ]; + } + else + { + [theResponse setStatus: 500]; + } } // @@ -891,7 +935,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. fileReference = [[[(id)[theDocumentElement getElementsByTagName: @"FileReference"] lastObject] textValue] stringByUnescapingURL]; realCollectionId = [fileReference realCollectionIdWithFolderType: &folderType]; - realCollectionId = [self globallyUniqueIDToIMAPFolderName: realCollectionId type: folderType]; if (folderType == ActiveSyncMailFolder) { @@ -1826,6 +1869,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. deviceId = [[theRequest uri] deviceId]; [context setObject: deviceId forKey: @"DeviceId"]; [context setObject: [[theRequest uri] deviceType] forKey: @"DeviceType"]; + [context setObject: [[theRequest uri] attachmentName] forKey: @"AttachmentName"]; + cmdName = [[theRequest uri] command]; @@ -1869,7 +1914,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. { // 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 - if ([cmdName caseInsensitiveCompare: @"Ping"] != NSOrderedSame) + if ([cmdName caseInsensitiveCompare: @"Ping"] != NSOrderedSame && [cmdName caseInsensitiveCompare: @"GetAttachment"] != NSOrderedSame) return [NSException exceptionWithHTTPStatus: 500]; } diff --git a/NEWS b/NEWS index c5d569491..c6086a368 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,7 @@ Enhancements - contacts photos are now synchronized using ActiveSync (#2807) + - implemented the GetAttachment ActiveSync command (#2808) Bug fixes