]> err.no Git - scalable-opengroupware.org/blob - SOGo/SoObjects/Mailer/SOGoMailConnectionEntry.m
a113fda7e0fe5590fdf16fd2d55ea64e9bd001df
[scalable-opengroupware.org] / SOGo / SoObjects / Mailer / SOGoMailConnectionEntry.m
1 /*
2   Copyright (C) 2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
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
22 #include "SOGoMailConnectionEntry.h"
23 #include "common.h"
24
25 @implementation SOGoMailConnectionEntry
26
27 - (id)initWithClient:(NGImap4Client *)_client password:(NSString *)_pwd {
28   if (_client == nil || _pwd == nil) {
29     [self release];
30     return nil;
31   }
32   
33   if ((self = [super init])) {
34     self->client   = [_client retain];
35     self->password = [_pwd    copy];
36     
37     self->creationTime = [[NSDate alloc] init];
38   }
39   return self;
40 }
41 - (id)init {
42   return [self initWithClient:nil password:nil];
43 }
44
45 - (void)dealloc {
46   [self->urlToRights     release];
47   [self->cachedUIDs      release];
48   [self->uidFolderURL    release];
49   [self->uidSortOrdering release];
50   [self->creationTime    release];
51   [self->subfolders      release];
52   [self->password        release];
53   [self->client          release];
54   [super dealloc];
55 }
56
57 /* accessors */
58
59 - (NGImap4Client *)client {
60   return self->client;
61 }
62 - (BOOL)isValidPassword:(NSString *)_pwd {
63   return [self->password isEqualToString:_pwd];
64 }
65
66 - (NSDate *)creationTime {
67   return self->creationTime;
68 }
69
70 - (void)cacheHierarchyResults:(NSDictionary *)_hierarchy {
71   ASSIGNCOPY(self->subfolders, _hierarchy);
72 }
73 - (NSDictionary *)cachedHierarchyResults {
74   return self->subfolders;
75 }
76 - (void)flushFolderHierarchyCache {
77   [self->subfolders  release]; self->subfolders  = nil;
78   [self->urlToRights release]; self->urlToRights = nil;
79 }
80
81 /* rights */
82
83 - (NSString *)cachedMyRightsForURL:(NSURL *)_url {
84   return (_url != nil) ? [self->urlToRights objectForKey:_url] : nil;
85 }
86 - (void)cacheMyRights:(NSString *)_rights forURL:(NSURL *)_url {
87   if (self->urlToRights == nil)
88     self->urlToRights = [[NSMutableDictionary alloc] initWithCapacity:8];
89   [self->urlToRights setObject:_rights forKey:_url];
90 }
91
92 /* UIDs */
93
94 - (id)cachedUIDsForURL:(NSURL *)_url qualifier:(id)_q sortOrdering:(id)_so {
95   if (_q != nil)
96     return nil;
97   if (![_so isEqual:self->uidSortOrdering])
98     return nil;
99   if (![self->uidFolderURL isEqual:_url])
100     return nil;
101   
102   return self->cachedUIDs;
103 }
104
105 - (void)cacheUIDs:(NSArray *)_uids forURL:(NSURL *)_url
106   qualifier:(id)_q sortOrdering:(id)_so
107 {
108   if (_q != nil)
109     return;
110
111   ASSIGNCOPY(self->uidSortOrdering, _so);
112   ASSIGNCOPY(self->uidFolderURL,    _url);
113   ASSIGNCOPY(self->cachedUIDs,      _uids);
114 }
115
116 - (void)flushMailCaches {
117   ASSIGN(self->uidSortOrdering, nil);
118   ASSIGN(self->uidFolderURL,    nil);
119   ASSIGN(self->cachedUIDs,      nil);
120 }
121
122 @end /* SOGoMailConnectionEntry */