+2005-07-20 Helge Hess <helge.hess@opengroupware.org>
+
+ * NGMime, NGMail: added some convinience methods to access the header
+ fields of a part (v4.5.229)
+
2005-07-15 Helge Hess <helge.hess@opengroupware.org>
* NGImap4: fixed a parsing bug in ACL responses (v4.5.228)
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 <NGStreams/NGSocketExceptions.h>
+2005-07-20 Helge Hess <helge.hess@opengroupware.org>
+
+ * NGMimeMessage.m: added some convinience methods to access the header
+ fields of a message
+
2005-07-12 Helge Hess <helge.hess@opengroupware.org>
* NGMimeMessage.m: copy hashmap on object creation to make it immutable
NGMimeMessage represents a RFC822 message with MIME extensions.
*/
+@class NSString, NSArray, NSDictionary, NSEnumerator;
+@class NGHashMap;
+@class NGMimeType;
+
@interface NGMimeMessage : NSObject < NGMimePart >
{
@protected
+ (id)messageWithHeader:(NGHashMap *)_headers;
- (id)initWithHeader:(NGHashMap *)_headers; // designated initializer
-// NGPart
+/* NGPart */
- (NSEnumerator *)valuesOfHeaderFieldWithName:(NSString *)_name;
- (NSEnumerator *)headerFieldNames;
- (void)setBody:(id)_body;
- (id)body;
-// NGMimePart
+/* NGMimePart */
- (NGMimeType *)contentType;
- (NSString *)contentId;
- (NSString *)encoding;
- (NSString *)contentDescription;
+/* convenience */
+
+- (NSString *)headerForKey:(NSString *)_key;
+- (NSArray *)headersForKey:(NSString *)_key;
+- (NSArray *)headerKeys;
+- (NSDictionary *)headers;
+- (NSString *)headersAsString;
+
@end
#endif /* __NGMail_NGMimeMessage_H__ */
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];
}
else
[d appendFormat:@" body=%@", b];
-
+
[d appendString:@">"];
-
return d;
}
+2005-07-20 Helge Hess <helge.hess@opengroupware.org>
+
+ * NGMimeBodyPart.m: added some convinience methods to access the header
+ fields of a part
+
2005-07-13 Marcus Mueller <znek@mulle-kybernetik.com>
* NGMime.xcodeproj: synced with GNUmakefile
/*
NGMimeBodyPart is a part that is contained in a multipart body.
*/
+
+@class NSString, NSArray, NSDictionary, NSEnumerator;
+@class NGHashMap;
+
@interface NGMimeBodyPart : NSObject < NGMimePart >
{
@protected
- (NSString *)encoding;
- (NSString *)contentDescription;
+/* convenience */
+
+- (NSString *)headerForKey:(NSString *)_key;
+- (NSArray *)headersForKey:(NSString *)_key;
+- (NSArray *)headerKeys;
+- (NSDictionary *)headers;
+- (NSString *)headersAsString;
+
@end
#endif /* __NGMime_NGMimeBodyPart_H__ */
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 {
/* 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];
else
[d appendFormat:@" body=%@", b];
-
[d appendString:@">"];
-
- return AUTORELEASE(d);
+ return d;
}
@end /* NGMimeBodyPart */
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