X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=SoObjects%2FMailer%2FSOGoMailObject.m;h=749882e168842f4b78d0bd0d4f840d95e9e075e9;hb=919b686007fc82bd261b0ed8761051f7ec688818;hp=69f1457a0853997d9a071e98a8c3ff2d2308f19a;hpb=a60de03d2f6e709c805c1860781a0b67e3993dd2;p=scalable-opengroupware.org diff --git a/SoObjects/Mailer/SOGoMailObject.m b/SoObjects/Mailer/SOGoMailObject.m index 69f1457a..749882e1 100644 --- a/SoObjects/Mailer/SOGoMailObject.m +++ b/SoObjects/Mailer/SOGoMailObject.m @@ -417,22 +417,13 @@ static BOOL debugSoParts = NO; _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 @@ -569,24 +560,36 @@ static BOOL debugSoParts = NO; /* 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; } @@ -800,6 +803,71 @@ static BOOL debugSoParts = NO; 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