]> err.no Git - sope/blob - sope-mime/NGMail/NGSmtpSupport.m
fixed copyrights for 2005
[sope] / sope-mime / NGMail / NGSmtpSupport.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 "NGSmtpSupport.h"
23 #include "common.h"
24
25 NSString *NGSmtpDescriptionForReplyCode(NGSmtpReplyCode _code) {
26   NSString *text = nil;
27   
28   switch (_code) {
29
30     // 100 codes, positive preliminary  reply
31
32     // 200 codes, positive completion reply
33
34     case NGSmtpSystemStatus:            // 211
35       text = @"System status, or system help reply";
36       break;
37     case NGSmtpHelpMessage:             // 214
38       text = @"Help message";
39       break;
40     case NGSmtpServiceReady:            // 220
41       text = @"<domain> Service ready";
42       break;
43     case NGSmtpServiceClosingChannel:   // 221
44       text = @"<domain> Service closing transmission channel";
45       break;
46     case NGSmtpActionCompleted:         // 250
47       text = @"Requested mail action okay, completed";
48       break;
49     case NGSmtpUserNotLocalWillForward: // 251
50       text = @"User not local; will forward to <forward-path>";
51       break;
52
53     // 300 codes, positive intermediate reply
54       
55     case NGSmtpStartMailInput: // 354
56       text = @"Start mail input; end with <CRLF>.<CRLF>";
57       break;
58
59     // 400 codes, transient negative completion reply
60       
61     case NGSmtpServiceNotAvailable: // 421
62       text = @"<domain> Service not available, closing transmission channel";
63       break;
64     case NGSmtpMailboxBusy:         // 450
65       text = @"Requested mail action not taken: mailbox unavailable [E.g., mailbox busy]";
66       break;
67     case NGSmtpErrorInProcessing:   // 451
68       text = @"Requested action aborted: local error in processing";
69       break;
70     case NGSmtpInsufficientStorage: // 452
71       text = @"Requested action not taken: insufficient system storage";
72       break;
73
74     // 500 codes, permanent negative completion reply
75       
76     case NGSmtpInvalidCommand:          // 500
77       text = @"Syntax error, command unrecognized "
78              @"[This may include errors such as command line too long]";
79       break;
80     case NGSmtpInvalidParameter:        // 501
81       text = @"Syntax error in parameters or arguments";
82       break;
83     case NGSmtpCommandNotImplemented:   // 502
84       text = @"Command not implemented";
85       break;
86     case NGSmtpBadCommandSequence:      // 503
87       text = @"Bad sequence of commands";
88       break;
89     case NGSmtpParameterNotImplemented: // 504
90       text = @"Command parameter not implemented";
91       break;
92       
93     case NGSmtpMailboxNotFound:           // 550
94       text = @"Requested action not taken: mailbox unavailable "
95              @"[E.g., mailbox not found, no access]";
96       break;
97     case NGSmtpUserNotLocalTryForward:    // 551
98       text = @"User not local; please try <forward-path>";
99       break;
100     case NGSmtpExceededStorageAllocation: // 552
101       text = @"Requested mail action aborted: exceeded storage allocation";
102       break;
103     case NGSmtpMailboxNameNotAllowed:     // 553
104       text = @"Requested action not taken: mailbox name not allowed"
105              @"[E.g., mailbox syntax incorrect]";
106       break;
107     case NGSmtpTransactionFailed:         // 554
108       text = @"Transaction failed";
109       break;
110     
111     default:
112       text = [NSString stringWithFormat:@"<SMTP ReplyCode: %i>", _code];
113       break;
114   }
115   return text;
116 }
117
118 @implementation NGSmtpResponse
119
120 + (int)version {
121   return 2;
122 }
123
124 - (id)initWithCode:(NGSmtpReplyCode)_code text:(NSString *)_text {
125   if ((self = [super init])) {
126     self->code = _code;
127     self->text = [_text copy];
128   }
129   return self;
130 }
131
132 + (id)responseWithCode:(NGSmtpReplyCode)_code text:(NSString *)_text {
133   return [[[self alloc] initWithCode:_code text:_text] autorelease];
134 }
135
136 - (void)dealloc {
137   [self->text release];
138   [super dealloc];
139 }
140
141 /* accessors */
142
143 - (NGSmtpReplyCode)code {
144   return self->code;
145 }
146
147 - (NSString *)text {
148   return self->text;
149 }
150
151 /* values */
152
153 - (int)intValue {
154   return [self code];
155 }
156 - (NSString *)stringValue {
157   return [self text];
158 }
159
160 /* special accessors */
161
162 - (NSString *)lastLine {
163   const char *cstr = [[self text] cString];
164   unsigned   len   = [[self text] cStringLength];
165
166   if (cstr) {
167     cstr += len;   // goto '\0'
168     cstr--; len--; // goto last char
169     while ((*cstr != '\n') && (len > 0)) {
170       cstr--;
171       len--;
172     }
173   }
174   else
175     len = 0;
176   return (len > 0) ? [NSString stringWithCString:(cstr + 1)] : [self text];
177 }
178
179 - (BOOL)isPositive {
180   return ((self->code >= 200) && (self->code < 300));
181 }
182
183 - (BOOL)isTransientNegative {
184   return ((self->code >= 400) && (self->code < 500));
185 }
186 - (BOOL)isPermanentNegative {
187   return ((self->code >= 500) && (self->code < 600));
188 }
189
190 /* description */
191
192 - (NSString *)description {
193   return [NSString stringWithFormat:@"<SMTP-Reply: code=%i line='%@'>",
194                      [self code], [self lastLine]];
195 }
196
197 @end /* NGSmtpResponse */