2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
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
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.
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
22 #include "NGPop3Support.h"
23 #include "NGPop3Client.h"
26 @implementation NGPop3Response
32 - (id)initWithLine:(NSString *)_line {
33 if ((self = [super init])) {
34 self->line = [_line copy];
44 + (id)responseWithLine:(NSString *)_line {
45 return [[[self alloc] initWithLine:_line] autorelease];
51 return [self->line hasPrefix:@"+OK"];
59 - (NSString *)description {
60 return [NSString stringWithFormat:@"<Pop3Reply[0x%08X]: positive=%s line=%@>",
62 [self isPositive] ? "YES" : "NO",
66 @end /* NGPop3Response */
68 @implementation NGPop3MessageInfo
74 - (id)initWithNumber:(int)_num size:(int)_size client:(NGPop3Client *)_client{
75 if ((self = [super init])) {
76 self->messageNumber = _num;
77 self->messageSize = _size;
78 self->client = [_client retain];
83 + (id)infoForMessage:(int)_num size:(int)_size client:(NGPop3Client *)_client {
84 return [[[self alloc] initWithNumber:_num size:_size client:_client] autorelease];
88 [self->client release];
94 - (int)messageNumber {
95 return self->messageNumber;
99 return self->messageSize;
102 - (NGPop3Client *)pop3Client {
108 - (NSString *)description {
109 return [NSString stringWithFormat:@"<Pop3MsgInfo[0x%08X]: number=%i size=%i>",
110 (unsigned)self, [self messageNumber], [self size]];
113 @end /* NGPop3Response */
115 @implementation NGPop3MailDropEnumerator
121 - (id)initWithMessageInfoEnumerator:(NSEnumerator *)_infos {
122 self->msgInfos = [_infos retain];
127 [self->msgInfos release];
132 NGPop3MessageInfo *info = [self->msgInfos nextObject];
133 NGMimeMessage *message = nil;
136 message = [[info pop3Client] messageWithNumber:[info messageNumber]];
137 if (message == nil) {
138 NSLog(@"ERROR: could not retrieve message %i, skipping", [info messageNumber]);
139 message = [self nextObject];
145 @end /* NGPop3MailDropEnumerator */
147 // ******************** Exceptions ********************
149 @implementation NGPop3Exception
155 @end /* NGPop3Exception */
157 @implementation NGPop3StateException
164 return [self initWithClient:nil requiredState:0];
167 - (id)initWithClient:(NGPop3Client *)_client requiredState:(NGPop3State)_state {
168 NSString *stateString = nil;
171 case NGPop3State_unconnected: stateString = @"unconnected"; break;
172 case NGPop3State_AUTHORIZATION: stateString = @"AUTHORIZATION"; break;
173 case NGPop3State_TRANSACTION: stateString = @"TRANSACTION"; break;
174 case NGPop3State_UPDATE: stateString = @"UPDATE"; break;
176 stateString = @"unknown";
180 if ((self = [super initWithFormat:@"operation can only perform in state %@",
182 self->requiredState = _state;
189 - (NGPop3State)requiredState {
190 return self->requiredState;
193 @end /* NGPop3StateException */