]> err.no Git - sope/blob - sope-mime/NGMail/NGMailAddress.m
minor code cleanups
[sope] / sope-mime / NGMail / NGMailAddress.m
1 /*
2   Copyright (C) 2000-2003 SKYRIX Software AG
3
4   This file is part of OGo
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21 // $Id$ 
22
23 #include "NGMailAddress.h"
24 #include "common.h"
25
26 @implementation NGMailAddress
27
28 + (int)version {
29   return 2;
30 }
31
32 + (id)mailAddressWithAddress:(NSString *)_address
33   displayName:(NSString *)_owner
34   route:(NSString *)_route
35 {
36   return [[[NGMailAddress alloc] initWithAddress:_address
37                                  displayName:_owner
38                                  route:_route] autorelease];
39 }
40
41 - (id)initWithAddress:(NSString *)_address
42   displayName:(NSString *)_owner
43   route:(NSString *)_route
44 {
45   if ((self = [self init])) {
46     NSZone *zone = [self zone];
47     self->address     = [_address copyWithZone:zone];
48     self->displayName = [_owner   copyWithZone:zone];
49     self->route       = [_route   copyWithZone:zone];
50   }
51   return self;
52 }
53
54 - (void)dealloc {
55   [self->address     release];
56   [self->displayName release];
57   [self->route       release];
58   [super dealloc];  
59 }
60
61 /* equality */
62
63 - (BOOL)isEqual:(id)_anObject {
64   if ([_anObject isKindOfClass:[NGMailAddress class]]) {
65     NGMailAddress *a = _anObject;
66     
67     return (([self->address     isEqualToString:[a address]])   &&
68             ([self->displayName isEqualToString:[a displayName]]) &&
69             ([self->route       isEqualToString:[a route]]));
70   }
71   return NO;
72 }
73
74 - (unsigned)hash {
75   return [self->address hash];
76 }
77
78 /* NSCoding */
79
80 - (void)encodeWithCoder:(NSCoder *)_encoder {
81   [_encoder encodeObject:address]; 
82   [_encoder encodeObject:displayName];
83   [_encoder encodeObject:route];  
84 }
85
86 - (id)initWithCoder:(NSCoder *)_decoder {
87   id _address, _displayName, _route;
88   
89   _address     = [_decoder decodeObject];
90   _displayName = [_decoder decodeObject];
91   _route       = [_decoder decodeObject];
92   return [self initWithAddress:_address 
93                displayName:_displayName 
94                route:_route];
95 }
96
97 /* NSCopying */
98
99 - (id)copyWithZone:(NSZone *)_zone {
100   return [[NGMailAddress allocWithZone:_zone] initWithAddress:self->address
101                                               displayName:self->displayName
102                                               route:self->route];
103 }
104 - (id)copy {
105   return [self copyWithZone:[self zone]];
106 }
107
108 /* accessors */
109
110 - (void)setAddress:(NSString *)_string {
111   ASSIGN(self->address, _string);
112 }
113 - (NSString *)address {
114   return self->address;
115 }
116
117 - (void)setDisplayName:(NSString *)_displayName {
118   ASSIGN(self->displayName, _displayName);
119 }
120 - (NSString *)displayName {
121  return self->displayName;
122 }
123
124 - (void)setRoute:(NSString *)_route {
125   ASSIGN(self->route, _route);
126 }
127 - (NSString *)route {
128   return self->route;
129 }
130
131 /* description */
132
133 - (NSString *)description {
134   return [NSString stringWithFormat:@"\"%s\" <%s> | route: %s",
135                      [self->displayName cString],
136                      [self->address     cString],
137                      [self->route       cString]];
138 }
139
140 @end /* NGMailAddress */