From 91e03753d502a05c09bdfac463dbc435a9a4e26d Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Fri, 5 Dec 2014 22:05:52 -0500 Subject: [PATCH] Address formatter returns metadata as a dictionary --- UI/MailerUI/UIxEnvelopeAddressFormatter.m | 45 ++++++++++++++++++++--- UI/MailerUI/UIxMailFormatter.h | 4 +- 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/UI/MailerUI/UIxEnvelopeAddressFormatter.m b/UI/MailerUI/UIxEnvelopeAddressFormatter.m index a5a2a20b7..71be98aa3 100644 --- a/UI/MailerUI/UIxEnvelopeAddressFormatter.m +++ b/UI/MailerUI/UIxEnvelopeAddressFormatter.m @@ -20,6 +20,7 @@ */ #import +#import #import #import @@ -81,30 +82,64 @@ static Class StrClass = Nil; return [_address stringValue]; } +- (NSDictionary *) dictionaryForEnvelopeAddress: (NGImap4EnvelopeAddress *)_address { + NSMutableDictionary *meta; + NSString *s; + + meta = [NSMutableDictionary dictionary]; + + s = [_address baseEMail]; + if (s) [meta setObject: s forKey: @"address"]; + + s = [_address personalName]; + if (s) [meta setObject: s forKey: @"name"]; + + return meta; +} + + - (NSString *)stringForArray:(NSArray *)_addresses { NSMutableString *ms; unsigned i, count; - + if ((count = [_addresses count]) == 0) return nil; - + if (count == 1) return [self stringForObjectValue:[_addresses objectAtIndex:0]]; - + ms = [NSMutableString stringWithCapacity:16 * count]; for (i = 0; i < count && [ms length] < [self maxLength]; i++) { NSString *s; - + s = [self stringForObjectValue:[_addresses objectAtIndex:i]]; if (s == nil) continue; - + if ([ms length] > 0) [ms appendString:[self separator]]; [ms appendString:s]; } return ms; } +- (NSArray *)dictionariesForArray:(NSArray *)_addresses { + NSMutableArray *a; + id address; + unsigned i, count; + + if ((count = [_addresses count]) == 0) + return nil; + + a = [NSMutableArray arrayWithCapacity: count]; + for (i = 0; i < count; i++) { + address = [_addresses objectAtIndex: i]; + if ([address isKindOfClass:EnvAddrClass]) + [a addObject: [self dictionaryForEnvelopeAddress: address]]; + } + + return a; +} + /* formatter entry function */ - (NSString *)stringForObjectValue:(id)_address { diff --git a/UI/MailerUI/UIxMailFormatter.h b/UI/MailerUI/UIxMailFormatter.h index 3b29ed261..2accc4b66 100644 --- a/UI/MailerUI/UIxMailFormatter.h +++ b/UI/MailerUI/UIxMailFormatter.h @@ -30,7 +30,7 @@ Formatters which render various mail related fields. */ -@class NSData, NSString, NSCalendarDate, NSTimeZone; +@class NSData, NSString, NSCalendarDate, NSTimeZone, NGImap4EnvelopeAddress; @interface UIxMailFormatter : NSFormatter { @@ -76,6 +76,8 @@ - (id)initWithMaxLength:(unsigned int)_max generateFullEMail:(BOOL)_genFull; - (NSString *)stringForArray:(NSArray *)_addresses; +- (NSDictionary *)dictionaryForEnvelopeAddress: (NGImap4EnvelopeAddress *)_address; +- (NSArray *)dictionariesForArray: (NSArray *)_addresses; @end