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