| 1 | /* |
| 2 | ** CWSMTP.h |
| 3 | ** |
| 4 | ** Copyright (c) 2001-2006 Ludovic Marcotte |
| 5 | ** |
| 6 | ** Author: Ludovic Marcotte <[email protected]> |
| 7 | ** |
| 8 | ** This library is free software; you can redistribute it and/or |
| 9 | ** modify it under the terms of the GNU Lesser General Public |
| 10 | ** License as published by the Free Software Foundation; either |
| 11 | ** version 2.1 of the License, or (at your option) any later version. |
| 12 | ** |
| 13 | ** This library is distributed in the hope that it will be useful, |
| 14 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | ** Lesser General Public License for more details. |
| 17 | ** |
| 18 | ** You should have received a copy of the GNU General Public License |
| 19 | ** along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
| 22 | #ifndef _Pantomime_H_CWSMTP |
| 23 | #define _Pantomime_H_CWSMTP |
| 24 | |
| 25 | #include <Pantomime/CWService.h> |
| 26 | #include <Pantomime/CWTransport.h> |
| 27 | |
| 28 | #import <Foundation/NSArray.h> |
| 29 | #import <Foundation/NSData.h> |
| 30 | #import <Foundation/NSObject.h> |
| 31 | #import <Foundation/NSString.h> |
| 32 | |
| 33 | /*! |
| 34 | @const PantomimeTransactionInitiationCompleted |
| 35 | */ |
| 36 | extern NSString* PantomimeTransactionInitiationCompleted; |
| 37 | |
| 38 | /*! |
| 39 | @const PantomimeTransactionInitiationFailed |
| 40 | */ |
| 41 | extern NSString* PantomimeTransactionInitiationFailed; |
| 42 | |
| 43 | /*! |
| 44 | @const PantomimeRecipientIdentificationCompleted |
| 45 | */ |
| 46 | extern NSString* PantomimeRecipientIdentificationCompleted; |
| 47 | |
| 48 | /*! |
| 49 | @const PantomimeRecipientIdentificationFailed |
| 50 | */ |
| 51 | extern NSString* PantomimeRecipientIdentificationFailed; |
| 52 | |
| 53 | /*! |
| 54 | @const PantomimeTransactionResetCompleted |
| 55 | */ |
| 56 | extern NSString* PantomimeTransactionResetCompleted; |
| 57 | |
| 58 | /*! |
| 59 | @const PantomimeTransactionResetFailed |
| 60 | */ |
| 61 | extern NSString* PantomimeTransactionResetFailed; |
| 62 | |
| 63 | |
| 64 | @class CWMessage; |
| 65 | |
| 66 | /*! |
| 67 | @category NSObject (SMTPClient) |
| 68 | @discussion This informal protocol defines methods that can implemented in |
| 69 | SMTP's delegate to control the behavior of the class |
| 70 | or to obtain status information. |
| 71 | */ |
| 72 | @interface NSObject (SMTPClient) |
| 73 | |
| 74 | /*! |
| 75 | @method transactionInitiationCompleted: |
| 76 | @discussion This method is automatically invoked on the delegate |
| 77 | after the SMTP MAIL FROM command has completed. The userInfo's |
| 78 | part of the notification contains the message that has |
| 79 | been sent. The key to obtain it is "Message". |
| 80 | A PantomimeTransactionInitiationCompleted notification is also posted. |
| 81 | @param theNotification The notification holding the information. |
| 82 | */ |
| 83 | - (void) transactionInitiationCompleted: (NSNotification *) theNotification; |
| 84 | |
| 85 | /*! |
| 86 | @method transactionInitiationFailed: |
| 87 | @discussion This method is automatically invoked on the delegate |
| 88 | after the SMTP MAIL FROM command has failed. The userInfo's |
| 89 | part of the notification contains the message that has |
| 90 | not been sent. The key to obtain it is "Message". |
| 91 | A PantomimeTransactionInitiatioFailed notification is also posted. |
| 92 | @param theNotification The notification holding the information. |
| 93 | */ |
| 94 | - (void) transactionInitiationFailed: (NSNotification *) theNotification; |
| 95 | |
| 96 | /*! |
| 97 | @method recipientIdentificationCompleted: |
| 98 | @discussion This method is automatically invoked on the delegate |
| 99 | after the SMTP RCPT TO command has completed. The userInfo's |
| 100 | part of the notification contains the recipients (CWInternetAddress |
| 101 | instances) that were sucessfully sent. The key to obtain it is "Recipients". |
| 102 | A PantomimeRecipientIdentificationCompleted notification is also posted. |
| 103 | @param theNotification The notification holding the information. |
| 104 | */ |
| 105 | - (void) recipientIdentificationCompleted: (NSNotification *) theNotification; |
| 106 | |
| 107 | /*! |
| 108 | @method recipientIdentificationFailed: |
| 109 | @discussion This method is automatically invoked on the delegate |
| 110 | after the SMTP RCPT TO command has failed. The userInfo's |
| 111 | part of the notification contains the recipient (CWInternetAddress |
| 112 | instance) that was not sucessfully sent. The key to obtain it is "Recipient". |
| 113 | A PantomimeRecipientIdentificationFailed notification is also posted. |
| 114 | @param theNotification The notification holding the information. |
| 115 | */ |
| 116 | - (void) recipientIdentificationFailed: (NSNotification *) theNotification; |
| 117 | |
| 118 | /*! |
| 119 | @method transactionResetCompleted: |
| 120 | @discussion This method is automatically invoked on the delegate |
| 121 | after the SMTP RSET command has completed. |
| 122 | A PantomimeTransactionResetCompleted notification is |
| 123 | also posted. |
| 124 | @param theNotification The notification holding the information. |
| 125 | */ |
| 126 | - (void) transactionResetCompleted: (NSNotification *) theNotification; |
| 127 | |
| 128 | /*! |
| 129 | @method transactionResetFailed: |
| 130 | @discussion This method is automatically invoked on the delegate |
| 131 | after the SMTP RSET command has completed and failed. |
| 132 | This should never really happen but this method could |
| 133 | be invoked, if the SMTP server isnt RFC-strict. |
| 134 | A PantomimeTransactionResetFailed notification is |
| 135 | also posted. |
| 136 | @param theNotification The notification holding the information. |
| 137 | */ |
| 138 | - (void) transactionResetFailed: (NSNotification *) theNotification; |
| 139 | |
| 140 | @end |
| 141 | |
| 142 | /*! |
| 143 | @typedef SMTPCommand |
| 144 | @abstract Supported SMTP commands. |
| 145 | @discussion This enum lists the supported SMTP commands available |
| 146 | in Pantomime's SMTP client code. |
| 147 | @constant SMTP_AUTH_CRAM_MD5 CRAM-MD5 authentication. |
| 148 | @constant SMTP_AUTH_LOGIN LOGIN authentication. |
| 149 | @constant SMTP_AUTH_LOGIN_CHALLENGE Challenge during the LOGIN authentication. |
| 150 | @constant SMTP_AUTH_PLAIN PLAIN authentication. |
| 151 | @constant SMTP_DATA The DATA SMTP command - see 4.1.1.4 DATA (DATA) of RFC 2821. |
| 152 | @constant SMTP_EHLO The EHLO SMTP command - see 4.1.1.1 Extended HELLO (EHLO) or HELLO (HELO) of RFC 2821. |
| 153 | @constant SMTP_HELO The HELO SMTP command - see 4.1.1.1 Extended HELLO (EHLO) or HELLO (HELO) of RFC 2821. |
| 154 | @constant SMTP_MAIL The MAIL SMTP command - see 4.1.1.2 MAIL (MAIL) of RFC 2821. |
| 155 | @constant SMTP_NOOP The NOOP SMTP command - see 4.1.1.9 NOOP (NOOP) of RFC 2821. |
| 156 | @constant SMTP_QUIT The QUIT SMTP command - see 4.1.1.10 QUIT (QUIT) of RFC 2821. |
| 157 | @constant SMTP_RCPT The RCPT SMTP command - see 4.1.1.3 RECIPIENT (RCPT) of RFC 2821. |
| 158 | @constant SMTP_RSET The RSET SMTP command - see 4.1.1.5 RESET (RSET) of RFC 2821. |
| 159 | @constant SMTP_STARTTLS The STARTTLS SMTP command - see RFC2487. |
| 160 | @constant SMTP_AUTHORIZATION Special command to know we are in the autorization state. |
| 161 | @constant SMTP_EMPTY_QUEUE Special command to empty the command queue. |
| 162 | */ |
| 163 | typedef enum { |
| 164 | SMTP_AUTH_CRAM_MD5 = 0x1000, |
| 165 | SMTP_AUTH_LOGIN, |
| 166 | SMTP_AUTH_LOGIN_CHALLENGE, |
| 167 | SMTP_AUTH_PLAIN, |
| 168 | SMTP_DATA, |
| 169 | SMTP_EHLO, |
| 170 | SMTP_HELO, |
| 171 | SMTP_MAIL, |
| 172 | SMTP_NOOP, |
| 173 | SMTP_QUIT, |
| 174 | SMTP_RCPT, |
| 175 | SMTP_RSET, |
| 176 | SMTP_STARTTLS, |
| 177 | SMTP_AUTHORIZATION, |
| 178 | SMTP_EMPTY_QUEUE, |
| 179 | } SMTPCommand; |
| 180 | |
| 181 | /*! |
| 182 | @class CWSMTP |
| 183 | @abstract Pantomime SMTP client code. |
| 184 | @discussion This class, which extends the CWService class and implements |
| 185 | the CWTransport protocol, is Pantomime's SMTP client code. |
| 186 | */ |
| 187 | @interface CWSMTP : CWService <CWTransport> |
| 188 | { |
| 189 | @private |
| 190 | NSMutableArray *_sent_recipients; |
| 191 | NSMutableArray *_recipients; |
| 192 | CWMessage *_message; |
| 193 | NSData *_data; |
| 194 | |
| 195 | unsigned int _max_size; |
| 196 | BOOL _redirected; |
| 197 | } |
| 198 | |
| 199 | /*! |
| 200 | @method lastResponse |
| 201 | @discussion This method is used to obtain the last response |
| 202 | received from the SMTP server. If the server |
| 203 | sent a multi-line response, only the last line |
| 204 | will be returned. |
| 205 | @result The last response in its complete form, nil if no |
| 206 | response was read. |
| 207 | */ |
| 208 | - (NSData *) lastResponse; |
| 209 | |
| 210 | /*! |
| 211 | @method lastResponseCode |
| 212 | @discussion This method is used to obtain the last response code |
| 213 | received from the SMTP server. If the server |
| 214 | sent a multi-line response, only the code of the |
| 215 | last line will be returned. |
| 216 | @result The last response code in its complete form, 0 if |
| 217 | no response was read. |
| 218 | */ |
| 219 | - (int) lastResponseCode; |
| 220 | |
| 221 | /*! |
| 222 | @method reset |
| 223 | @discussion This method is used to send the RSET SMTP command. |
| 224 | See 4.1.1.5 RESET (RSET) of RFC 2821 for a full description |
| 225 | of this command. It will NOT reset to nil the previously |
| 226 | used recipients, message or message data. If you wish |
| 227 | to change either of them, call the corresponding |
| 228 | accessor method between your -sendMessage calls. |
| 229 | */ |
| 230 | - (void) reset; |
| 231 | |
| 232 | /*! |
| 233 | @method sendCommand: arguments: ... |
| 234 | @discussion This method is used to send commands to the SMTP server. |
| 235 | Normally, you should not call this method directly. |
| 236 | @param theCommand The SMTP command to send. |
| 237 | @param theFormat The format defining the variable arguments list. |
| 238 | */ |
| 239 | - (void) sendCommand: (SMTPCommand) theCommand arguments: (NSString *) theFormat, ...; |
| 240 | |
| 241 | @end |
| 242 | |
| 243 | #endif // _Pantomime_H_CWSMTP |