1
/** Interface for MIME parsing classes
3
Copyright (C) 2000 Free Software Foundation, Inc.
5
Written by: Richard Frith-Macdonald <rfm@gnu.org>
9
This file is part of the GNUstep Base Library.
11
This library is free software; you can redistribute it and/or
12
modify it under the terms of the GNU Lesser General Public
13
License as published by the Free Software Foundation; either
14
version 2 of the License, or (at your option) any later version.
16
This library is distributed in the hope that it will be useful,
17
but WITHOUT ANY WARRANTY; without even the implied warranty of
18
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19
Library General Public License for more details.
21
You should have received a copy of the GNU Lesser General Public
22
License along with this library; if not, write to the Free
23
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26
AutogsdocSource: Additions/GSMime.m
29
#ifndef __GSMime_h_GNUSTEP_BASE_INCLUDE
30
#define __GSMime_h_GNUSTEP_BASE_INCLUDE
31
#import <GNUstepBase/GSVersionMacros.h>
33
#if OS_API_VERSION(GS_API_NONE,GS_API_LATEST)
35
#ifdef NeXT_Foundation_LIBRARY
36
#import <Foundation/Foundation.h>
38
#import <Foundation/NSObject.h>
39
#import <Foundation/NSString.h>
40
#import <Foundation/NSMapTable.h>
43
#if defined(__cplusplus)
48
@class NSMutableArray;
52
@class NSMutableDictionary;
56
* A trivial class for mantaining state while decoding/encoding data.
57
* Each encoding type requires its own subclass.
59
@interface GSMimeCodingContext : NSObject
61
BOOL atEnd; /* Flag to say that data has ended. */
64
- (BOOL) decodeData: (const void*)sData
65
length: (NSUInteger)length
66
intoData: (NSMutableData*)dData;
67
- (void) setAtEnd: (BOOL)flag;
70
@interface GSMimeHeader : NSObject <NSCopying>
72
#if GS_EXPOSE(GSMimeHeader)
75
NSMutableDictionary *objects;
76
NSMutableDictionary *params;
80
/* Pointer to private additional data used to avoid breaking ABI
81
* when we don't have the non-fragile ABI available.
82
* Use this mechanism rather than changing the instance variable
83
* layout (see Source/GSInternal.h for details).
85
@private id _internal GS_UNUSED_IVAR;
88
+ (NSString*) makeQuoted: (NSString*)v always: (BOOL)flag;
89
+ (NSString*) makeToken: (NSString*)t preservingCase: (BOOL)preserve;
90
+ (NSString*) makeToken: (NSString*)t;
91
- (id) copyWithZone: (NSZone*)z;
92
- (NSString*) fullValue;
93
- (id) initWithName: (NSString*)n
95
- (id) initWithName: (NSString*)n
97
parameters: (NSDictionary*)p;
99
- (NSString*) namePreservingCase: (BOOL)preserve;
100
- (id) objectForKey: (NSString*)k;
101
- (NSDictionary*) objects;
102
- (NSString*) parameterForKey: (NSString*)k;
103
- (NSDictionary*) parameters;
104
- (NSDictionary*) parametersPreservingCase: (BOOL)preserve;
105
- (NSMutableData*) rawMimeData;
106
- (NSMutableData*) rawMimeDataPreservingCase: (BOOL)preserve;
107
- (void) setName: (NSString*)s;
108
- (void) setObject: (id)o forKey: (NSString*)k;
109
- (void) setParameter: (NSString*)v forKey: (NSString*)k;
110
- (void) setParameters: (NSDictionary*)d;
111
- (void) setValue: (NSString*)s;
117
@interface GSMimeDocument : NSObject <NSCopying>
119
#if GS_EXPOSE(GSMimeDocument)
120
NSMutableArray *headers;
128
+ (NSString*) charsetFromEncoding: (NSStringEncoding)enc;
131
* Decode the source data from base64 encoding and return the result.<br />
132
* The source data is expected to be ASCII text and may be multiple
133
* lines or a line of any length (decoding is very tolerant).
135
+ (NSData*) decodeBase64: (NSData*)source;
136
+ (NSString*) decodeBase64String: (NSString*)source;
137
+ (GSMimeDocument*) documentWithContent: (id)newContent
138
type: (NSString*)type
139
name: (NSString*)name;
141
* Encode the source data to base64 encoding and return the result.<br />
142
* The resulting data is ASCII text and contains only the base64 encoded
143
* values with no line breaks or extraneous data. This is base64 encoded
144
* data in it's general format as mandated in RFC 3548. If the data is
145
* to be used as part of a MIME document body, line breaks must be
146
* introduced at 76 byte intervals (GSMime does this when automatically
147
* encoding data for you). If the data is to be used in a PEM document
148
* line breaks must be introduced at 74 byte intervals.
150
+ (NSData*) encodeBase64: (NSData*)source;
151
+ (NSString*) encodeBase64String: (NSString*)source;
152
+ (NSStringEncoding) encodingFromCharset: (NSString*)charset;
154
- (void) addContent: (id)newContent;
155
- (void) addHeader: (GSMimeHeader*)info;
156
- (GSMimeHeader*) addHeader: (NSString*)name
157
value: (NSString*)value
158
parameters: (NSDictionary*)parameters;
159
- (NSArray*) allHeaders;
161
- (id) contentByID: (NSString*)key;
162
- (id) contentByLocation: (NSString*)key;
163
- (id) contentByName: (NSString*)key;
164
- (id) copyWithZone: (NSZone*)z;
165
- (NSString*) contentFile;
166
- (NSString*) contentID;
167
- (NSString*) contentLocation;
168
- (NSString*) contentName;
169
- (NSString*) contentSubtype;
170
- (NSString*) contentType;
171
- (NSArray*) contentsByName: (NSString*)key;
172
- (void) convertToBase64;
173
- (void) convertToBinary;
174
- (NSData*) convertToData;
175
- (NSString*) convertToText;
176
- (void) deleteContent: (GSMimeDocument*)aPart;
177
- (void) deleteHeader: (GSMimeHeader*)aHeader;
178
- (void) deleteHeaderNamed: (NSString*)name;
179
- (GSMimeHeader*) headerNamed: (NSString*)name;
180
- (NSArray*) headersNamed: (NSString*)name;
181
- (NSString*) makeBoundary;
182
- (GSMimeHeader*) makeContentID;
183
- (GSMimeHeader*) makeHeader: (NSString*)name
184
value: (NSString*)value
185
parameters: (NSDictionary*)parameters;
186
- (GSMimeHeader*) makeMessageID;
187
- (NSMutableData*) rawMimeData;
188
- (NSMutableData*) rawMimeData: (BOOL)isOuter;
189
- (void) setContent: (id)newContent;
190
- (void) setContent: (id)newContent
191
type: (NSString*)type;
192
- (void) setContent: (id)newContent
193
type: (NSString*)type
194
name: (NSString*)name;
195
- (void) setContentType: (NSString*)newType;
196
- (void) setHeader: (GSMimeHeader*)info;
197
- (GSMimeHeader*) setHeader: (NSString*)name
198
value: (NSString*)value
199
parameters: (NSDictionary*)parameters;
203
@interface GSMimeParser : NSObject
205
#if GS_EXPOSE(GSMimeParser)
207
unsigned char *bytes;
209
unsigned sectionStart;
214
unsigned rawBodyLength;
216
unsigned int inBody:1;
217
unsigned int isHttp:1;
218
unsigned int complete:1;
219
unsigned int hadErrors:1;
220
unsigned int buggyQuotes:1;
221
unsigned int wantEndOfLine:1;
222
unsigned int excessData:1;
223
unsigned int headersOnly:1;
225
NSData *boundary; // Also overloaded to hold excess
226
GSMimeDocument *document;
228
GSMimeCodingContext *context;
229
NSStringEncoding _defaultEncoding;
236
+ (GSMimeDocument*) documentFromData: (NSData*)mimeData;
237
+ (GSMimeParser*) mimeParser;
239
- (GSMimeCodingContext*) contextFor: (GSMimeHeader*)info;
241
- (BOOL) decodeData: (NSData*)sData
242
fromRange: (NSRange)aRange
243
intoData: (NSMutableData*)dData
244
withContext: (GSMimeCodingContext*)con;
246
- (void) expectNoHeaders;
250
- (BOOL) isInHeaders;
251
- (GSMimeDocument*) mimeDocument;
252
- (BOOL) parse: (NSData*)d;
253
/** Parses headers from the supplied data returning YES if more data is
254
* needed before the end of thge headers are reached.<br />
255
* If body is not NULL and the end of the headers were reached leaving
256
* some unused data, that remaining data is returned.<br />
257
* NB. The returned data is a reference to part of the original memory
258
* buffer provided in d, so you must copy it if you intend to use it after
259
* modifying or deallocating the original data.
261
- (BOOL) parseHeaders: (NSData*)d remaining: (NSData**)body;
262
- (BOOL) parseHeader: (NSString*)aHeader;
263
- (BOOL) scanHeaderBody: (NSScanner*)scanner into: (GSMimeHeader*)info;
264
- (NSString*) scanName: (NSScanner*)scanner;
265
- (BOOL) scanPastSpace: (NSScanner*)scanner;
266
- (NSString*) scanSpecial: (NSScanner*)scanner;
267
- (NSString*) scanToken: (NSScanner*)scanner;
268
- (void) setBuggyQuotes: (BOOL)flag;
269
- (void) setDefaultCharset: (NSString*)aName;
270
- (void) setHeadersOnly;
275
/** The error domain for the GSMime system.
277
GS_EXPORT NSString* const GSMimeErrorDomain;
279
/** The error codes used in the GSMimeErrorDomain
285
GSMimeSMTPCommsError,
286
GSMimeSMTPServerResponse
293
/** The GSMimeSMTPClient class provides the ability to send EMails
294
* ([GSMimeDocument] instances) via an SMTP server.
296
@interface GSMimeSMTPClient : NSObject
299
# if defined(GS_GSMimeSMTPClient_IVARS)
301
GS_GSMimeSMTPClient_IVARS;
304
@private id _internal;
308
/** Shut down any message send in progress and abort any queued messages.
312
/** Returns the current delegate.
316
/** Tries to flush any queued messages to the SMTP server, completing by the
317
* specified limit date.<br />
318
* If limit is nil then a date in the distant future is used.<br />
319
* If the queue is emptied in time, this method returns YES, otherwise it
322
- (BOOL) flush: (NSDate*)limit;
324
/** Returns the last error encountered, or nil if there is none recorded.
326
- (NSError*) lastError;
328
/** Add the message to the queue of emails to be sent by the receiver.
330
- (void) send: (GSMimeDocument*)message;
332
/** Add the message to the queue of emails to be sent by the receiver.<br />
333
* Also adds an envelope ID string to be used to uniquely identify the
334
* message for delivery receipting purposes.<br />
335
* For this to work, the SMTP gateway being used must support the SMTP
336
* service extension for delivery status notification (RFC 3460).
338
- (void) send: (GSMimeDocument*)message envelopeID: (NSString*)envid;
340
/** Set the delegate to receive callback methods indicating when a message
341
* is sent, failed, or removed from the queue unsent.
343
- (void) setDelegate: (id)d;
345
/** Set the host for the SMTP server. If this is not set (or is set to nil)
346
* then the GSMimeSMTPClientHost user default is used. If the host is nil
347
* or an empty string then 'localhost' is used.
349
- (void) setHostname: (NSString*)s;
351
/** Set the host for the SMTP client to identify itsself to the server.
352
* If this is not set (or is set to nil) then the GSMimeSMTPClientIdentity
353
* user default is used. If the identity is nil or an empty string then
354
* a name of the current host is use.
356
- (void) setIdentity: (NSString*)s;
358
/** Set the originator for any emails sent by the SMTP client.<br />
359
* This overrides the value in the 'from' header of an email.<br />
360
* If this is not set (or is set to nil) then the GSMimeSMTPClientOriginator
361
* user default is used. If the originator is nil or an empty string then
362
* the value in the 'from' header of the email is used.
364
- (void) setOriginator: (NSString*)s;
366
/** Set the port for the SMTP server. If this is not set (or is set to nil)
367
* then the GSMimeSMTPClientPort user default is used. If the port is not an
368
* integer in the 1-65535 range, then '25' (the default SMTP port) is used.
370
- (void) setPort: (NSString*)s;
372
/** Set the username for authentication to the SMTP server.
373
* If this is not set (or is set to nil) then the GSMimeSMTPClientUsername
374
* user default is used. If the username is nil or an empty string then
375
* authentication is not attempted.
377
- (void) setUsername: (NSString*)s;
379
/** returns the receivers current state.
383
/** Returns a string describing the receiver's current state
385
- (NSString*) stateDesc;
389
/** Informal protocol for delegates of the GSMimeSMTPClient class.
390
* The default implementations of these methods do nothing.
392
@interface NSObject (GSMimeSMTPClient)
393
- (void) smtpClient: (GSMimeSMTPClient*)client
394
mimeFailed: (GSMimeDocument*)doc; /* Failed to send */
395
- (void) smtpClient: (GSMimeSMTPClient*)client
396
mimeSent: (GSMimeDocument*)doc; /* Sent successfully */
397
- (void) smtpClient: (GSMimeSMTPClient*)client
398
mimeUnsent: (GSMimeDocument*)doc; /* Aborted (not sent) */
402
#if defined(__cplusplus)
406
#endif /* OS_API_VERSION(GS_API_NONE,GS_API_NONE) */
408
#endif /* __GSMime_h_GNUSTEP_BASE_INCLUDE */