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 "NGSmtpSupport.h"
25 NSString *NGSmtpDescriptionForReplyCode(NGSmtpReplyCode _code) {
30 // 100 codes, positive preliminary reply
32 // 200 codes, positive completion reply
34 case NGSmtpSystemStatus: // 211
35 text = @"System status, or system help reply";
37 case NGSmtpHelpMessage: // 214
38 text = @"Help message";
40 case NGSmtpServiceReady: // 220
41 text = @"<domain> Service ready";
43 case NGSmtpServiceClosingChannel: // 221
44 text = @"<domain> Service closing transmission channel";
46 case NGSmtpActionCompleted: // 250
47 text = @"Requested mail action okay, completed";
49 case NGSmtpUserNotLocalWillForward: // 251
50 text = @"User not local; will forward to <forward-path>";
53 // 300 codes, positive intermediate reply
55 case NGSmtpStartMailInput: // 354
56 text = @"Start mail input; end with <CRLF>.<CRLF>";
59 // 400 codes, transient negative completion reply
61 case NGSmtpServiceNotAvailable: // 421
62 text = @"<domain> Service not available, closing transmission channel";
64 case NGSmtpMailboxBusy: // 450
65 text = @"Requested mail action not taken: mailbox unavailable [E.g., mailbox busy]";
67 case NGSmtpErrorInProcessing: // 451
68 text = @"Requested action aborted: local error in processing";
70 case NGSmtpInsufficientStorage: // 452
71 text = @"Requested action not taken: insufficient system storage";
74 // 500 codes, permanent negative completion reply
76 case NGSmtpInvalidCommand: // 500
77 text = @"Syntax error, command unrecognized "
78 @"[This may include errors such as command line too long]";
80 case NGSmtpInvalidParameter: // 501
81 text = @"Syntax error in parameters or arguments";
83 case NGSmtpCommandNotImplemented: // 502
84 text = @"Command not implemented";
86 case NGSmtpBadCommandSequence: // 503
87 text = @"Bad sequence of commands";
89 case NGSmtpParameterNotImplemented: // 504
90 text = @"Command parameter not implemented";
93 case NGSmtpMailboxNotFound: // 550
94 text = @"Requested action not taken: mailbox unavailable "
95 @"[E.g., mailbox not found, no access]";
97 case NGSmtpUserNotLocalTryForward: // 551
98 text = @"User not local; please try <forward-path>";
100 case NGSmtpExceededStorageAllocation: // 552
101 text = @"Requested mail action aborted: exceeded storage allocation";
103 case NGSmtpMailboxNameNotAllowed: // 553
104 text = @"Requested action not taken: mailbox name not allowed"
105 @"[E.g., mailbox syntax incorrect]";
107 case NGSmtpTransactionFailed: // 554
108 text = @"Transaction failed";
112 text = [NSString stringWithFormat:@"<SMTP ReplyCode: %i>", _code];
118 @implementation NGSmtpResponse
124 - (id)initWithCode:(NGSmtpReplyCode)_code text:(NSString *)_text {
125 if ((self = [super init])) {
127 self->text = [_text copy];
132 + (id)responseWithCode:(NGSmtpReplyCode)_code text:(NSString *)_text {
133 return [[[self alloc] initWithCode:_code text:_text] autorelease];
137 [self->text release];
143 - (NGSmtpReplyCode)code {
156 - (NSString *)stringValue {
160 /* special accessors */
162 - (NSString *)lastLine {
163 const char *cstr = [[self text] cString];
164 unsigned len = [[self text] cStringLength];
167 cstr += len; // goto '\0'
168 cstr--; len--; // goto last char
169 while ((*cstr != '\n') && (len > 0)) {
176 return (len > 0) ? [NSString stringWithCString:(cstr + 1)] : [self text];
180 return ((self->code >= 200) && (self->code < 300));
183 - (BOOL)isTransientNegative {
184 return ((self->code >= 400) && (self->code < 500));
186 - (BOOL)isPermanentNegative {
187 return ((self->code >= 500) && (self->code < 600));
192 - (NSString *)description {
193 return [NSString stringWithFormat:@"<SMTP-Reply: code=%i line='%@'>",
194 [self code], [self lastLine]];
197 @end /* NGSmtpResponse */