From: helge Date: Fri, 29 Oct 2004 22:46:18 +0000 (+0000) Subject: added GET action for mail objects X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c97b59942f56d8b2de75d6935e035633ff167fb0;p=scalable-opengroupware.org added GET action for mail objects git-svn-id: http://svn.opengroupware.org/SOGo/trunk@443 d1b88da0-ebda-0310-925b-ed51d893ca5b --- diff --git a/SOGo/SoObjects/Mailer/ChangeLog b/SOGo/SoObjects/Mailer/ChangeLog index a3f9a319..9e437e9c 100644 --- a/SOGo/SoObjects/Mailer/ChangeLog +++ b/SOGo/SoObjects/Mailer/ChangeLog @@ -1,3 +1,9 @@ +2004-10-30 Helge Hess + + * SOGoMailObject.m: added -content and -contentAsString method to + retrieve raw IMAP4 message content, added GETAction to query a + message (v0.9.46) + 2004-10-29 Helge Hess * SOGoDraftObject.m: add 'name' parameter to content-type, properly diff --git a/SOGo/SoObjects/Mailer/SOGoMailFolder.m b/SOGo/SoObjects/Mailer/SOGoMailFolder.m index 0bb25c35..e4149f3c 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailFolder.m +++ b/SOGo/SoObjects/Mailer/SOGoMailFolder.m @@ -65,9 +65,9 @@ keys = [[NSMutableArray alloc] initWithCapacity:count]; for (i = 0; i < count; i++) { NSString *k; - - k = [[[uids objectAtIndex:i] stringValue] - stringByAppendingString:@".mail"]; + + k = [[uids objectAtIndex:i] stringValue]; + k = [k stringByAppendingString:@".mail"]; [keys addObject:k]; } self->filenames = [keys copy]; diff --git a/SOGo/SoObjects/Mailer/SOGoMailObject.m b/SOGo/SoObjects/Mailer/SOGoMailObject.m index 2ea6d67c..b7822ec7 100644 --- a/SOGo/SoObjects/Mailer/SOGoMailObject.m +++ b/SOGo/SoObjects/Mailer/SOGoMailObject.m @@ -200,6 +200,65 @@ static BOOL heavyDebug = NO; return [info isNotNull] ? info : nil; } +- (NSData *)content { + NSData *content; + id result, fullResult; + + fullResult = [self fetchParts:[NSArray arrayWithObject:@"RFC822"]]; + if (fullResult == nil) + return nil; + + if ([fullResult isKindOfClass:[NSException class]]) + return fullResult; + + /* extract fetch result */ + + result = [fullResult valueForKey:@"fetch"]; + if (![result isKindOfClass:[NSArray class]]) { + [self logWithFormat: + @"ERROR: unexpected IMAP4 result (missing 'fetch'): %@", + fullResult]; + return [NSException exceptionWithHTTPStatus:500 /* server error */ + reason:@"unexpected IMAP4 result"]; + } + if ([result count] == 0) + return nil; + + result = [result objectAtIndex:0]; + + /* extract message */ + + if ((content = [result valueForKey:@"message"]) == nil) { + [self logWithFormat: + @"ERROR: unexpected IMAP4 result (missing 'message'): %@", + result]; + return [NSException exceptionWithHTTPStatus:500 /* server error */ + reason:@"unexpected IMAP4 result"]; + } + + return [[content copy] autorelease]; +} + +- (NSString *)contentAsString { + NSString *s; + NSData *content; + + if ((content = [self content]) == nil) + return nil; + if ([content isKindOfClass:[NSException class]]) + return content; + + s = [[NSString alloc] initWithData:content + encoding:NSISOLatin1StringEncoding]; + if (s == nil) { + [self logWithFormat: + @"ERROR: could not convert data of length %d to string", + [content length]]; + return nil; + } + return [s autorelease]; +} + /* name lookup */ - (BOOL)isBodyPartKey:(NSString *)_key inContext:(id)_ctx { @@ -258,4 +317,24 @@ static BOOL heavyDebug = NO; return [self davCreationDate]; } +/* actions */ + +- (id)GETAction:(WOContext *)_ctx { + WOResponse *r; + NSData *content; + + content = [self content]; + if ([content isKindOfClass:[NSException class]]) + return content; + if (content == nil) { + return [NSException exceptionWithHTTPStatus:404 /* Not Found */ + reason:@"did not find IMAP4 message"]; + } + + r = [_ctx response]; + [r setHeader:@"message/rfc822" forKey:@"content-type"]; + [r setContent:content]; + return r; +} + @end /* SOGoMailObject */ diff --git a/SOGo/SoObjects/Mailer/Version b/SOGo/SoObjects/Mailer/Version index a02a1955..89add11f 100644 --- a/SOGo/SoObjects/Mailer/Version +++ b/SOGo/SoObjects/Mailer/Version @@ -1,6 +1,6 @@ # Version file -SUBMINOR_VERSION:=45 +SUBMINOR_VERSION:=46 # v0.9.44 requires NGMime v4.3.194 # v0.9.41 requires NGMime v4.3.190