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];
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 {
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 */