_type = [_type lowercaseString];
_subtype = [_subtype lowercaseString];
- if ([_type isEqualToString:@"text"]) {
- if ([_subtype isEqualToString:@"plain"])
- return YES;
-
- if ([_subtype isEqualToString:@"calendar"]) /* we also fetch calendars */
- return YES;
- }
-
- if ([_type isEqualToString:@"application"]) {
- if ([_subtype isEqualToString:@"pgp-signature"])
- return YES;
- if ([_subtype hasPrefix:@"x-vnd.kolab."])
- return YES;
- }
-
- return NO;
+ return (([_type isEqualToString:@"text"]
+ && ([_subtype isEqualToString:@"plain"]
+ || [_subtype isEqualToString:@"html"]
+ || [_subtype isEqualToString:@"calendar"]))
+ || ([_type isEqualToString:@"application"]
+ && ([_subtype isEqualToString:@"pgp-signature"]
+ || [_subtype hasPrefix:@"x-vnd.kolab."])));
}
- (void)addRequiredKeysOfStructure:(id)_info path:(NSString *)_p
/* convert parts to strings */
-- (NSString *)stringForData:(NSData *)_data partInfo:(NSDictionary *)_info {
- NSString *charset;
- NSString *s;
+- (NSString *)stringForData:(NSData *)_data partInfo:(NSDictionary *)_info
+{
+ NSString *charset, *encoding, *s;
+ NSData *mailData;
if (![_data isNotNull])
return nil;
s = nil;
-
- charset = [[_info valueForKey:@"parameterList"] valueForKey:@"charset"];
- if ([charset isNotNull] && [charset length] > 0)
- s = [NSString stringWithData:_data usingEncodingNamed:charset];
-
- if (s == nil) { /* no charset provided, fall back to UTF-8 */
- s = [[NSString alloc] initWithData:_data encoding:NSUTF8StringEncoding];
- s = [s autorelease];
- }
-
+
+ encoding = [[_info objectForKey:@"encoding"] lowercaseString];
+
+ if ([encoding isEqualToString: @"7bit"]
+ || [encoding isEqualToString: @"8bit"])
+ mailData = _data;
+ else if ([encoding isEqualToString: @"base64"])
+ mailData = [_data dataByDecodingBase64];
+ else if ([encoding isEqualToString: @"quoted-printable"])
+ mailData = [_data dataByDecodingQuotedPrintable];
+
+ charset = [[_info valueForKey:@"parameterList"] valueForKey: @"charset"];
+ if (![charset length])
+ {
+ s = [[NSString alloc] initWithData:mailData encoding:NSUTF8StringEncoding];
+ [s autorelease];
+ }
+ else
+ s = [NSString stringWithData: mailData
+ usingEncodingNamed: charset];
+
return s;
}
return nil;
}
+- (NSException *) moveToFolderNamed: (NSString *) folderName
+ inContext: (id)_ctx
+{
+ /*
+ Trashing is three actions:
+ a) copy to trash folder
+ b) mark mail as deleted
+ c) expunge folder
+
+ In case b) or c) fails, we can't do anything because IMAP4 doesn't tell us
+ the ID used in the trash folder.
+ */
+ SOGoMailAccounts *destFolder;
+ NSEnumerator *folders;
+ NSString *currentFolderName, *reason;
+ NSException *error;
+
+ // TODO: check for safe HTTP method
+
+ destFolder = [self mailAccountsFolder];
+ folders = [[folderName componentsSeparatedByString: @"/"] objectEnumerator];
+ currentFolderName = [folders nextObject];
+ currentFolderName = [folders nextObject];
+
+ while (currentFolderName)
+ {
+ destFolder = [destFolder lookupName: currentFolderName
+ inContext: _ctx
+ acquire: NO];
+ if ([destFolder isKindOfClass: [NSException class]])
+ return (NSException *) destFolder;
+ currentFolderName = [folders nextObject];
+ }
+
+ if (!([destFolder isKindOfClass: [SOGoMailFolder class]]
+ && [destFolder isNotNull]))
+ {
+ reason = [NSString stringWithFormat: @"Did not find folder name '%@'!",
+ folderName];
+ return [NSException exceptionWithHTTPStatus:500 /* Server Error */
+ reason: reason];
+ }
+ [destFolder flushMailCaches];
+
+ /* a) copy */
+
+ error = [self davCopyToTargetObject: destFolder
+ newName:@"fakeNewUnusedByIMAP4" /* autoassigned */
+ inContext:_ctx];
+ if (error != nil) return error;
+
+ /* b) mark deleted */
+
+ error = [[self imap4Connection] markURLDeleted: [self imap4URL]];
+ if (error != nil) return error;
+
+ /* c) expunge */
+
+ error = [[self imap4Connection] expungeAtURL:[[self container] imap4URL]];
+ if (error != nil) return error; // TODO: unflag as deleted?
+ [self flushMailCaches];
+
+ return nil;
+}
+
- (NSException *)delete {
/*
Note: delete is different to DELETEAction: for mails! The 'delete' runs