2 Copyright (C) 2004-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE 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 SOPE 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 SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #include "NGImap4EnvelopeAddress.h"
25 @implementation NGImap4EnvelopeAddress
27 - (id)initWithPersonalName:(NSString *)_pname sourceRoute:(NSString *)_route
28 mailbox:(NSString *)_mbox host:(NSString *)_host
30 /* Note: we expect NSNull for unset values! */
31 if (_pname == nil || _route == nil || _mbox == nil || _host == nil) {
36 if ((self = [super init])) {
37 if ([_pname isNotNull]) self->personalName = [_pname copy];
38 if ([_route isNotNull]) self->sourceRoute = [_route copy];
39 if ([_mbox isNotNull]) self->mailbox = [_mbox copy];
40 if ([_host isNotNull]) self->host = [_host copy];
45 return [self initWithPersonalName:nil sourceRoute:nil mailbox:nil host:nil];
48 - (id)initWithString:(NSString *)_str {
49 // TODO: properly parse string using NGMailAddressParser
50 return [self initWithPersonalName:nil
52 mailbox:_str host:nil];
55 - (id)initWithBodyStructureInfo:(NSDictionary *)_info {
56 if (![_info isNotNull]) {
60 return [self initWithPersonalName:[_info valueForKey:@"personalName"]
61 sourceRoute:[_info valueForKey:@"sourceRoute"]
62 mailbox:[_info valueForKey:@"mailboxName"]
63 host:[_info valueForKey:@"hostName"]];
67 [self->personalName release];
68 [self->sourceRoute release];
69 [self->mailbox release];
76 - (NSString *)personalName {
77 return self->personalName;
79 - (NSString *)sourceRoute {
80 return self->sourceRoute;
82 - (NSString *)mailbox {
91 - (id)copyWithZone:(NSZone *)_zone {
92 /* we are immutable */
96 /* derived accessors */
98 - (NSString *)baseEMail {
101 if (![self->mailbox isNotEmpty])
103 if (![self->host isNotEmpty])
104 return self->mailbox;
106 t = [self->mailbox stringByAppendingString:@"@"];
107 return [t stringByAppendingString:self->host];
109 - (NSString *)email {
112 if (![self->personalName isNotEmpty])
113 return [self baseEMail];
114 if ((t = [self baseEMail]) == nil)
115 return self->personalName;
117 t = [[self->personalName
118 stringByAppendingString:@" <"] stringByAppendingString:t];
119 return [t stringByAppendingString:@">"];
124 - (NSString *)description {
127 ms = [NSMutableString stringWithCapacity:128];
128 [ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
130 if (self->personalName) [ms appendFormat:@" name='%@'", self->personalName];
131 if (self->sourceRoute) [ms appendFormat:@" source='%@'", self->sourceRoute];
132 if (self->mailbox) [ms appendFormat:@" mailbox='%@'", self->mailbox];
133 if (self->host) [ms appendFormat:@" host='%@'", self->host];
135 [ms appendString:@">"];
139 @end /* NGImap4EnvelopeAddress */