From 9de54eca79aefce5ca045eebae662158ebc235f3 Mon Sep 17 00:00:00 2001 From: helge Date: Wed, 20 Jul 2005 10:49:55 +0000 Subject: [PATCH] added some header-access convenience methods git-svn-id: http://svn.opengroupware.org/SOPE/trunk@924 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-mime/ChangeLog | 5 ++ sope-mime/NGImap4/NGImap4DataSource.m | 1 - sope-mime/NGMail/ChangeLog | 5 ++ sope-mime/NGMail/NGMimeMessage.h | 16 +++++- sope-mime/NGMail/NGMimeMessage.m | 76 +++++++++++++++++++++++++-- sope-mime/NGMime/ChangeLog | 5 ++ sope-mime/NGMime/NGMimeBodyPart.h | 12 +++++ sope-mime/NGMime/NGMimeBodyPart.m | 75 ++++++++++++++++++++++++-- sope-mime/Version | 2 +- 9 files changed, 185 insertions(+), 12 deletions(-) diff --git a/sope-mime/ChangeLog b/sope-mime/ChangeLog index cd71f779..177c8e6a 100644 --- a/sope-mime/ChangeLog +++ b/sope-mime/ChangeLog @@ -1,3 +1,8 @@ +2005-07-20 Helge Hess + + * NGMime, NGMail: added some convinience methods to access the header + fields of a part (v4.5.229) + 2005-07-15 Helge Hess * NGImap4: fixed a parsing bug in ACL responses (v4.5.228) diff --git a/sope-mime/NGImap4/NGImap4DataSource.m b/sope-mime/NGImap4/NGImap4DataSource.m index b3d43596..8c4a710e 100644 --- a/sope-mime/NGImap4/NGImap4DataSource.m +++ b/sope-mime/NGImap4/NGImap4DataSource.m @@ -18,7 +18,6 @@ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -//$Id: NGImap4DataSource.m 9 2004-08-20 18:40:42Z helge $ #include "NGImap4DataSource.h" #include diff --git a/sope-mime/NGMail/ChangeLog b/sope-mime/NGMail/ChangeLog index 0a483bf1..1e280cdc 100644 --- a/sope-mime/NGMail/ChangeLog +++ b/sope-mime/NGMail/ChangeLog @@ -1,3 +1,8 @@ +2005-07-20 Helge Hess + + * NGMimeMessage.m: added some convinience methods to access the header + fields of a message + 2005-07-12 Helge Hess * NGMimeMessage.m: copy hashmap on object creation to make it immutable diff --git a/sope-mime/NGMail/NGMimeMessage.h b/sope-mime/NGMail/NGMimeMessage.h index d291ea10..3954bc09 100644 --- a/sope-mime/NGMail/NGMimeMessage.h +++ b/sope-mime/NGMail/NGMimeMessage.h @@ -31,6 +31,10 @@ NGMimeMessage represents a RFC822 message with MIME extensions. */ +@class NSString, NSArray, NSDictionary, NSEnumerator; +@class NGHashMap; +@class NGMimeType; + @interface NGMimeMessage : NSObject < NGMimePart > { @protected @@ -42,7 +46,7 @@ + (id)messageWithHeader:(NGHashMap *)_headers; - (id)initWithHeader:(NGHashMap *)_headers; // designated initializer -// NGPart +/* NGPart */ - (NSEnumerator *)valuesOfHeaderFieldWithName:(NSString *)_name; - (NSEnumerator *)headerFieldNames; @@ -50,7 +54,7 @@ - (void)setBody:(id)_body; - (id)body; -// NGMimePart +/* NGMimePart */ - (NGMimeType *)contentType; - (NSString *)contentId; @@ -59,6 +63,14 @@ - (NSString *)encoding; - (NSString *)contentDescription; +/* convenience */ + +- (NSString *)headerForKey:(NSString *)_key; +- (NSArray *)headersForKey:(NSString *)_key; +- (NSArray *)headerKeys; +- (NSDictionary *)headers; +- (NSString *)headersAsString; + @end #endif /* __NGMail_NGMimeMessage_H__ */ diff --git a/sope-mime/NGMail/NGMimeMessage.m b/sope-mime/NGMail/NGMimeMessage.m index 7c2c180a..0664546e 100644 --- a/sope-mime/NGMail/NGMimeMessage.m +++ b/sope-mime/NGMail/NGMimeMessage.m @@ -140,15 +140,84 @@ static NGMimeType *defaultDataType = nil; return [self->header objectForKey:@"content-description"]; } +/* convenience */ + +- (NSString *)headerForKey:(NSString *)_key { + return [[self->header objectEnumeratorForKey:_key] nextObject]; +} + +- (NSArray *)headersForKey:(NSString *)_key { + NSEnumerator *values; + NSMutableArray *array; + id value; + + if ((values = [self->header objectEnumeratorForKey:_key]) == nil) + return nil; + + array = [NSMutableArray arrayWithCapacity:4]; + while ((value = [values nextObject]) != nil) + [array addObject:value]; + return array; +} + +- (NSArray *)headerKeys { + NSEnumerator *values; + NSMutableArray *array = nil; + id name = nil; + + if ((values = [self->header keyEnumerator]) == nil) + return nil; + + array = [[NSMutableArray alloc] init]; + while ((name = [values nextObject]) != nil) + [array addObject:name]; + + name = [array copy]; + [array release]; + + return [name autorelease]; +} + +- (NSDictionary *)headers { + return [self->header asDictionary]; +} + +- (NSString *)headersAsString { + // TODO: not correct for MIME + NSMutableString *ms; + NSEnumerator *keys; + NSString *key; + + ms = [NSMutableString stringWithCapacity:1024]; + + /* headers */ + keys = [[self headerKeys] objectEnumerator]; + while ((key = [keys nextObject]) != nil) { + NSEnumerator *vals; + id val; + + vals = [[self headersForKey:key] objectEnumerator]; + while ((val = [vals nextObject])) { + [ms appendString:key]; + [ms appendString:@": "]; + [ms appendString:[val stringValue]]; + [ms appendString:@"\r\n"]; + } + } + return ms; +} + /* description */ - (NSString *)description { - NSMutableString *d = [NSMutableString stringWithCapacity:64]; - id b = [self body]; + NSMutableString *d; + id b; + d = [NSMutableString stringWithCapacity:64]; [d appendFormat:@"<%@[0x%08X]: header=%@", NSStringFromClass([self class]), self, self->header]; + b = [self body]; if ([b isKindOfClass:[NSString class]] || [b isKindOfClass:[NSData class]]) { if ([b length] < 512) [d appendFormat:@" body=%@", b]; @@ -157,9 +226,8 @@ static NGMimeType *defaultDataType = nil; } else [d appendFormat:@" body=%@", b]; - + [d appendString:@">"]; - return d; } diff --git a/sope-mime/NGMime/ChangeLog b/sope-mime/NGMime/ChangeLog index 2b7b435f..d4689064 100644 --- a/sope-mime/NGMime/ChangeLog +++ b/sope-mime/NGMime/ChangeLog @@ -1,3 +1,8 @@ +2005-07-20 Helge Hess + + * NGMimeBodyPart.m: added some convinience methods to access the header + fields of a part + 2005-07-13 Marcus Mueller * NGMime.xcodeproj: synced with GNUmakefile diff --git a/sope-mime/NGMime/NGMimeBodyPart.h b/sope-mime/NGMime/NGMimeBodyPart.h index 0f3b6a77..82057b13 100644 --- a/sope-mime/NGMime/NGMimeBodyPart.h +++ b/sope-mime/NGMime/NGMimeBodyPart.h @@ -30,6 +30,10 @@ /* NGMimeBodyPart is a part that is contained in a multipart body. */ + +@class NSString, NSArray, NSDictionary, NSEnumerator; +@class NGHashMap; + @interface NGMimeBodyPart : NSObject < NGMimePart > { @protected @@ -57,6 +61,14 @@ - (NSString *)encoding; - (NSString *)contentDescription; +/* convenience */ + +- (NSString *)headerForKey:(NSString *)_key; +- (NSArray *)headersForKey:(NSString *)_key; +- (NSArray *)headerKeys; +- (NSDictionary *)headers; +- (NSString *)headersAsString; + @end #endif /* __NGMime_NGMimeBodyPart_H__ */ diff --git a/sope-mime/NGMime/NGMimeBodyPart.m b/sope-mime/NGMime/NGMimeBodyPart.m index 99634002..6c0d6fbb 100644 --- a/sope-mime/NGMime/NGMimeBodyPart.m +++ b/sope-mime/NGMime/NGMimeBodyPart.m @@ -80,6 +80,73 @@ static NGMimeType *defaultType = nil; return self->body; } +/* convenience */ + +- (NSString *)headerForKey:(NSString *)_key { + return [[self->header objectEnumeratorForKey:_key] nextObject]; +} + +- (NSArray *)headersForKey:(NSString *)_key { + NSEnumerator *values; + NSMutableArray *array; + id value; + + if ((values = [self->header objectEnumeratorForKey:_key]) == nil) + return nil; + + array = [NSMutableArray arrayWithCapacity:4]; + while ((value = [values nextObject]) != nil) + [array addObject:value]; + return array; +} + +- (NSArray *)headerKeys { + NSEnumerator *values; + NSMutableArray *array = nil; + id name = nil; + + if ((values = [self->header keyEnumerator]) == nil) + return nil; + + array = [[NSMutableArray alloc] init]; + while ((name = [values nextObject]) != nil) + [array addObject:name]; + + name = [array copy]; + [array release]; + + return [name autorelease]; +} + +- (NSDictionary *)headers { + return [self->header asDictionary]; +} + +- (NSString *)headersAsString { + // TODO: not correct for MIME + NSMutableString *ms; + NSEnumerator *keys; + NSString *key; + + ms = [NSMutableString stringWithCapacity:1024]; + + /* headers */ + keys = [[self headerKeys] objectEnumerator]; + while ((key = [keys nextObject]) != nil) { + NSEnumerator *vals; + id val; + + vals = [[self headersForKey:key] objectEnumerator]; + while ((val = [vals nextObject])) { + [ms appendString:key]; + [ms appendString:@": "]; + [ms appendString:[val stringValue]]; + [ms appendString:@"\r\n"]; + } + } + return ms; +} + /* NGMimePart */ - (NGMimeType *)contentType { @@ -128,9 +195,11 @@ static NGMimeType *defaultType = nil; /* description */ - (NSString *)description { - NSMutableString *d = [[NSMutableString alloc] init]; + NSMutableString *d; id b = [self body]; + d = [NSMutableString stringWithCapacity:128]; + [d appendFormat:@"<%@[0x%08X]: header=%@", NSStringFromClass([self class]), self, self->header]; @@ -150,10 +219,8 @@ static NGMimeType *defaultType = nil; else [d appendFormat:@" body=%@", b]; - [d appendString:@">"]; - - return AUTORELEASE(d); + return d; } @end /* NGMimeBodyPart */ diff --git a/sope-mime/Version b/sope-mime/Version index 4948443d..6a6dd3ab 100644 --- a/sope-mime/Version +++ b/sope-mime/Version @@ -2,7 +2,7 @@ MAJOR_VERSION:=4 MINOR_VERSION:=5 -SUBMINOR_VERSION:=228 +SUBMINOR_VERSION:=229 # v4.5.214 requires libNGExtensions v4.5.146 # v4.2.149 requires libNGStreams v4.2.34 -- 2.39.5