Debian Codegraph @

Framework/Pantomime/CWPOP3Folder.m

raw
1 /*
2 ** CWPOP3Folder.m
3 **
4 ** Copyright (c) 2001-2006 Ludovic Marcotte
5 ** Copyright (C) 2014-2022 Riccardo Mottola
6 **
7 ** Author: Ludovic Marcotte <[email protected]>
8 ** Riccardo Mottola <[email protected]>
9 **
10 ** This library is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU Lesser General Public
12 ** License as published by the Free Software Foundation; either
13 ** version 2.1 of the License, or (at your option) any later version.
14 **
15 ** This library is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** Lesser General Public License for more details.
19 **
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #import <Pantomime/CWPOP3Folder.h>
25
26 #import <Pantomime/CWConnection.h>
27 #import <Pantomime/CWConstants.h>
28 #import <Pantomime/CWMessage.h>
29 #import <Pantomime/CWPOP3CacheManager.h>
30 #import <Pantomime/CWPOP3CacheObject.h>
31 #import <Pantomime/CWPOP3Message.h>
32 #import <Pantomime/CWPOP3Store.h>
33 #import <Pantomime/CWTCPConnection.h>
34 #import <Pantomime/NSData+Extensions.h>
35 #import <Pantomime/NSString+Extensions.h>
36
37 #import <Foundation/NSAutoreleasePool.h>
38 #import <Foundation/NSException.h>
39 #import <Foundation/NSValue.h>
40
41 #include <limits.h>
42 #include <stdio.h>
43 #include <string.h>
44
45 #if !defined(UINT_MAX)
46 #define UINT_MAX (unsigned int)~0
47 #endif
48
49 //
50 // Private methods
51 //
52 @interface CWPOP3Folder (Private)
53 - (void) _deleteOldMessages;
54 @end
55
56
57 //
58 //
59 //
60 @implementation CWPOP3Folder
61
62 - (id) initWithName: (NSString *) theName
63 {
64 self = [super initWithName: theName];
65 _leave_on_server = YES;
66 _retain_period = 0;
67 return self;
68 }
69
70
71 //
72 //
73 //
74 - (void) prefetchMessageAtIndex: (NSUInteger) theIndex
75 numberOfLines: (NSUInteger) theNumberOfLines
76 {
77 [_store sendCommand: POP3_TOP arguments: @"TOP %lu %lu", (long unsigned)theIndex, (long unsigned)theNumberOfLines];
78 }
79
80
81 //
82 //
83 //
84 - (void) prefetch
85 {
86 [_store sendCommand: POP3_STAT arguments: @"STAT"];
87 }
88
89
90 //
91 // This method does nothing.
92 //
93 - (void) close
94 {
95 // We do nothing.
96 }
97
98
99 //
100 //
101 //
102 - (BOOL) leaveOnServer
103 {
104 return _leave_on_server;
105 }
106
107
108 //
109 //
110 //
111 - (void) setLeaveOnServer: (BOOL) theBOOL
112 {
113 _leave_on_server = theBOOL;
114 }
115
116
117 //
118 //
119 //
120 - (unsigned int) retainPeriod
121 {
122 return _retain_period;
123 }
124
125
126 //
127 // The retain period is set in days.
128 //
129 - (void) setRetainPeriod: (unsigned int) theRetainPeriod
130 {
131 _retain_period = theRetainPeriod;
132 }
133
134
135 //
136 //
137 //
138 - (PantomimeFolderMode) mode
139 {
140 return PantomimeReadWriteMode;
141 }
142
143
144 //
145 //
146 //
147 - (void) expunge
148 {
149 NSUInteger count;
150
151 count = [self countVisible];
152
153 // We mark it as deleted if we need to
154 if (!_leave_on_server)
155 {
156 NSUInteger i;
157
158 for (i = 1; i <= count; i++)
159 {
160 [_store sendCommand: POP3_DELE arguments: @"DELE %u", (unsigned)i];
161 }
162 }
163 else if (_retain_period > 0)
164 {
165 [self _deleteOldMessages];
166 }
167
168 [_store sendCommand: POP3_EXPUNGE_COMPLETED arguments: @""];
169 }
170
171
172 //
173 // In POP3, we do nothing.
174 //
175 - (void) search: (NSString *) theString
176 mask: (PantomimeSearchMask) theMask
177 options: (PantomimeSearchOption) theOptions
178 {
179 }
180
181 @end
182
183
184 //
185 // Private methods
186 //
187 @implementation CWPOP3Folder (Private)
188
189 - (void) _deleteOldMessages
190 {
191 NSUInteger i, count;
192
193 count = [self countVisible];
194
195 for (i = count; i > 0; i--)
196 {
197 NSDate *aDate;
198
199 aDate = [(CWPOP3CacheManager *)_cacheManager dateForUID: [[_allMessages objectAtIndex: i-1] UID]];
200
201 if (aDate)
202 {
203 NSTimeInterval interval;
204
205 interval = -[aDate timeIntervalSinceNow];
206 if (interval > 0)
207 {
208 NSUInteger days = lround(interval / (24*3600));
209
210 if (days >= _retain_period)
211 {
212 [_store sendCommand: POP3_DELE arguments: @"DELE %d", i];
213 }
214 }
215 }
216 }
217 }
218
219 @end