2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 OGo is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "UIxMailFormatter.h"
23 #include <NGImap4/NGImap4EnvelopeAddress.h>
26 @implementation UIxEnvelopeAddressFormatter
28 static Class EnvAddrClass = Nil;
29 static Class StrClass = Nil;
32 EnvAddrClass = [NGImap4EnvelopeAddress class];
33 StrClass = [NSString class];
36 - (id)initWithMaxLength:(unsigned int)_max generateFullEMail:(BOOL)_genFull {
37 if ((self = [super init])) {
38 self->maxLength = _max;
39 self->separator = @", ";
41 self->eafFlags.fullEMail = _genFull ? 1 : 0;
46 return [self initWithMaxLength:128 generateFullEMail:NO];
51 - (unsigned)maxLength {
52 return self->maxLength;
54 - (NSString *)separator {
55 return self->separator;
57 - (BOOL)generateFullEMail {
58 return self->eafFlags.fullEMail ? YES : NO;
61 /* formatting envelope addresses */
63 - (NSString *)stringForEnvelopeAddress:(NGImap4EnvelopeAddress *)_address {
66 if ([self generateFullEMail])
67 return [_address email];
69 s = [_address personalName];
70 if ([s isNotNull]) return s;
72 s = [_address baseEMail];
73 if ([s isNotNull]) return s;
75 [self warnWithFormat:@"unexpected envelope address: %@", _address];
76 return [_address stringValue];
79 - (NSString *)stringForArray:(NSArray *)_addresses {
83 if ((count = [_addresses count]) == 0)
87 return [self stringForObjectValue:[_addresses objectAtIndex:0]];
89 ms = [NSMutableString stringWithCapacity:16 * count];
90 for (i = 0; i < count && [ms length] < [self maxLength]; i++) {
93 s = [self stringForObjectValue:[_addresses objectAtIndex:i]];
97 if ([ms length] > 0) [ms appendString:[self separator]];
103 /* formatter entry function */
105 - (NSString *)stringForObjectValue:(id)_address {
106 if (![_address isNotNull])
109 if ([_address isKindOfClass:StrClass]) /* preformatted? */
112 if ([_address isKindOfClass:EnvAddrClass])
113 return [self stringForEnvelopeAddress:_address];
115 if ([_address isKindOfClass:[NSArray class]])
116 return [self stringForArray:_address];
118 [self debugWithFormat:
119 @"NOTE: unexpected object for envelope formatter: %@<%@>",
120 _address, NSStringFromClass([_address class])];
121 return [_address stringValue];
124 @end /* UIxEnvelopeAddressFormatter */