diff --git a/ChangeLog b/ChangeLog index 9cc24ef9f..42ab637ac 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-10-25 Wolfgang Sourdeau + + * SoObjects/Mailer/NSData+Mail.[hm]: new extension module that + extends the NSData class with utility methods useful for handling + mail. + 2007-10-23 Wolfgang Sourdeau * SoObjects/SOGo/NSArray+Utilities.m diff --git a/SoObjects/Mailer/NSData+Mail.h b/SoObjects/Mailer/NSData+Mail.h new file mode 100644 index 000000000..45e033f74 --- /dev/null +++ b/SoObjects/Mailer/NSData+Mail.h @@ -0,0 +1,36 @@ +/* NSData+Mail.h - this file is part of SOGo + * + * Copyright (C) 2007 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#ifndef NSDATA_MAIL_H +#define NSDATA_MAIL_H + +#import + +@class NSString; + +@interface NSData (SOGoMailUtilities) + +- (NSData *) bodyDataFromEncoding: (NSString *) encoding; + +@end + +#endif /* NSDATA_MAIL_H */ diff --git a/SoObjects/Mailer/NSData+Mail.m b/SoObjects/Mailer/NSData+Mail.m new file mode 100644 index 000000000..eb3051f6f --- /dev/null +++ b/SoObjects/Mailer/NSData+Mail.m @@ -0,0 +1,55 @@ +/* NSData+Mail.m - this file is part of SOGo + * + * Copyright (C) 2007 Inverse groupe conseil + * + * Author: Wolfgang Sourdeau + * + * This file is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#import + +#import +#import + +#import "NSData+Mail.h" + +@implementation NSData (SOGoMailUtilities) + +- (NSData *) bodyDataFromEncoding: (NSString *) encoding +{ + NSString *realEncoding; + NSData *decodedData; + + realEncoding = [encoding lowercaseString]; + + if ([realEncoding isEqualToString: @"7bit"] + || [realEncoding isEqualToString: @"8bit"]) + decodedData = self; + else if ([realEncoding isEqualToString: @"base64"]) + decodedData = [self dataByDecodingBase64]; + else if ([realEncoding isEqualToString: @"quoted-printable"]) + decodedData = [self dataByDecodingQuotedPrintable]; + else + { + decodedData = nil; + NSLog (@"encoding '%@' unknown, returning nil data", realEncoding); + } + + return decodedData; +} + +@end