]> err.no Git - sope/blob - sope-mime/NGMail/NGPop3Support.m
fixed copyrights for 2005
[sope] / sope-mime / NGMail / NGPop3Support.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 "NGPop3Support.h"
23 #include "NGPop3Client.h"
24 #include "common.h"
25
26 @implementation NGPop3Response
27
28 + (int)version {
29   return 2;
30 }
31
32 - (id)initWithLine:(NSString *)_line {
33   if ((self = [super init])) {
34     self->line = [_line copy];
35   }
36   return self;
37 }
38
39 - (void)dealloc {
40   [self->line release];
41   [super dealloc];
42 }
43
44 + (id)responseWithLine:(NSString *)_line {
45   return [[[self alloc] initWithLine:_line] autorelease];
46 }
47
48 /* accessors */
49
50 - (BOOL)isPositive {
51   return [self->line hasPrefix:@"+OK"];
52 }
53 - (NSString *)line {
54   return self->line;
55 }
56
57 /* description */
58
59 - (NSString *)description {
60   return [NSString stringWithFormat:@"<Pop3Reply[0x%08X]: positive=%s line=%@>",
61                      (unsigned)self,
62                      [self isPositive] ? "YES" : "NO",
63                      [self line]];
64 }
65
66 @end /* NGPop3Response */
67
68 @implementation NGPop3MessageInfo
69
70 + (int)version {
71   return 2;
72 }
73
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];
79   }
80   return self;
81 }
82
83 + (id)infoForMessage:(int)_num size:(int)_size client:(NGPop3Client *)_client {
84   return [[[self alloc] initWithNumber:_num size:_size client:_client] autorelease];
85 }
86
87 - (void)dealloc {
88   [self->client release];
89   [super dealloc];
90 }
91
92 /* accessors */
93
94 - (int)messageNumber {
95   return self->messageNumber;
96 }
97
98 - (int)size {
99   return self->messageSize;
100 }
101
102 - (NGPop3Client *)pop3Client {
103   return self->client;
104 }
105
106 /* description */
107
108 - (NSString *)description {
109   return [NSString stringWithFormat:@"<Pop3MsgInfo[0x%08X]: number=%i size=%i>",
110                      (unsigned)self, [self messageNumber], [self size]];
111 }
112
113 @end /* NGPop3Response */
114
115 @implementation NGPop3MailDropEnumerator
116
117 + (int)version {
118   return 2;
119 }
120
121 - (id)initWithMessageInfoEnumerator:(NSEnumerator *)_infos {
122   self->msgInfos = [_infos retain];
123   return self;
124 }
125
126 - (void)dealloc {
127   [self->msgInfos release];
128   [super dealloc];
129 }
130
131 - (id)nextObject {
132   NGPop3MessageInfo *info    = [self->msgInfos nextObject];
133   NGMimeMessage     *message = nil;
134
135   if (info != 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];
140     }
141   }
142   return message;
143 }
144
145 @end /* NGPop3MailDropEnumerator */
146
147 // ******************** Exceptions ********************
148
149 @implementation NGPop3Exception
150
151 + (int)version {
152   return 2;
153 }
154
155 @end /* NGPop3Exception */
156
157 @implementation NGPop3StateException
158
159 + (int)version {
160   return 2;
161 }
162
163 - (id)init {
164   return [self initWithClient:nil requiredState:0];
165 }
166
167 - (id)initWithClient:(NGPop3Client *)_client requiredState:(NGPop3State)_state {
168   NSString *stateString = nil;
169
170   switch(_state) {
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;
175     default:
176       stateString = @"unknown";
177       break;
178   }
179   
180   if ((self = [super initWithFormat:@"operation can only perform in state %@",
181                      stateString])) {
182     self->requiredState = _state;
183   }
184   return self;
185 }
186
187 // accessors
188
189 - (NGPop3State)requiredState {
190   return self->requiredState;
191 }
192
193 @end /* NGPop3StateException */