]> err.no Git - sope/blob - sope-mime/NGMail/NGMailAddressList.m
added support for some ACL IMAP4 commands
[sope] / sope-mime / NGMail / NGMailAddressList.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include "NGMailAddressList.h"
23 #include "common.h"
24
25 @implementation NGMailAddressList
26
27 + (int)version {
28   return 2;
29 }
30
31 + (id)mailAddressListWithAddresses:(NSSet *)_addresses
32   groupName:(NSString *)_groupName {
33   return [[[NGMailAddressList alloc] initWithAddresses:_addresses
34                                      groupName:_groupName] autorelease];
35 }
36
37 - (id)init {
38   if ((self = [super init])) {
39     self->addresses = [[NSMutableSet alloc] init];
40   }
41   return self;
42 }
43
44 - (id)initWithAddresses:(NSSet *)_addresses groupName:(NSString *)_groupName {
45   if ((self = [self init])) {
46     if (_addresses)
47       [self->addresses unionSet:_addresses];
48     self->groupName = [_groupName copy];;
49   }
50   return self;
51 }
52
53 - (void)dealloc {
54   [self->addresses release];
55   [self->groupName release];
56   [super dealloc];
57 }
58
59 - (void)addAddress:(NGMailAddress *)_address {
60   [self->addresses addObject:_address];
61 }
62
63 /* equality */
64
65 - (BOOL)isEqual:(id)_anObject {
66   if ([_anObject isKindOfClass:[NGMailAddressList class]]) {
67     BOOL  result = NO;
68     NSSet *set   = nil;
69
70     if (![self->groupName isEqualToString:[_anObject groupName]])
71       return NO;
72
73     set = [[NSSet alloc]
74                   initWithObjectsFromEnumerator:
75                     [(NGMailAddressList *)_anObject addresses]];
76     result = [self->addresses isEqualToSet:set];
77     [set release]; set = nil;
78     return result;
79   }
80   return NO;
81 }
82
83 /* NSCoding */
84
85 - (void)encodeWithCoder:(NSCoder *)_encoder {
86   [_encoder encodeObject:self->addresses];
87   [_encoder encodeObject:self->groupName];
88 }
89
90 - (id)initWithCoder:(NSCoder *)_decoder {
91   id _addresses, _groupName;
92
93   _addresses   = [_decoder decodeObject];
94   _groupName   = [_decoder decodeObject];
95
96   return [self initWithAddresses:_addresses groupName:_groupName];
97 }
98
99 /* NSCopying */
100
101 - (id)copyWithZone:(NSZone *)_zone {
102   return [[NGMailAddressList allocWithZone:_zone]
103                              initWithAddresses:self->addresses
104                              groupName:self->groupName];
105 }
106
107 /* accessors */
108
109 - (NSEnumerator *)addresses {
110   return [self->addresses objectEnumerator];
111 }
112
113 - (void)setGroupName:(NSString *)_name {
114   ASSIGN(self->groupName, _name);
115 }
116 - (NSString *)groupName {
117  return self->groupName;
118 }
119
120 /* description */
121
122 - (NSString *)description {
123   return [NSString stringWithFormat:@"GroupName: %s \n %@\n",
124                      [self->groupName cString],
125                      self->addresses];
126 }
127
128 @end /* NGMailAddressList */