~ubuntu-branches/ubuntu/oneiric/gnustep-base/oneiric

« back to all changes in this revision

Viewing changes to Headers/GNUstepBase/GSMime.h

  • Committer: Bazaar Package Importer
  • Author(s): Yavor Doganov
  • Date: 2011-05-31 11:03:16 UTC
  • mfrom: (1.2.12 upstream) (7.2.4 experimental)
  • Revision ID: james.westby@ubuntu.com-20110531110316-0uny1hmsdl3gmn5v
Tags: 1.22.0-1
* New major upstream release:
  + Includes support for the new Objective-C runtime (Closes: #624928).
* debian/control.m4 (Vcs-Arch): Replace with...
  (Vcs-Git): ...since tla-buildpackage is gone.
  (Vcs-Browser): New field.
  (Standards-Version): Bump to 3.9.2; no changes needed.
  (Build-Depends): Add libicu-dev, needed for NSLocale.
  (libgnustep-base`'SOV_BASE-dbg) <Conflicts>: Set to
  libgnustep-base1.20-dbg only.
  <Recommends>: Set to libobjc3-dbg.
* debian/control: Regenerate.
* debian/patches/gnutls-deprecated.patch: New; fix usage of deprecated
  GnuTLS function (Closes: #624054).
* debian/patches/missing-header.patch:
* debian/patches/no-march.patch: Delete; fixed upstream.
* debian/patches/NSBundle-PROCFS_EXE_LINK.patch: Delete; apparently not
  needed anymore.
* debian/patches/manpage-fixes.patch: A few more fixes.
* debian/patches/avoid-nsl-linkage.patch: Refresh.
* debian/patches/autoreconf.patch: Regenerate.
* debian/patches/series: Update.
* debian/rules (v_objc, v_make): Bump to 4:4.6 (for libobjc3) and 2.6
  (for the sake of the testsuite) accordingly.
  (debian/build-shared-stamp): Run the testsuite.
  (install-shared): Do not delete non-existent .swp file.
  (install-common): Use $(sov_base) instead of hardcoded version.
* debian/copyright: Update copyright years.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/** Interface for MIME parsing classes
 
2
 
 
3
   Copyright (C) 2000 Free Software Foundation, Inc.
 
4
 
 
5
   Written by:  Richard Frith-Macdonald  <rfm@gnu.org>
 
6
 
 
7
   Date: October 2000
 
8
   
 
9
   This file is part of the GNUstep Base Library.
 
10
 
 
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.
 
15
   
 
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.
 
20
 
 
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,
 
24
   Boston, MA 02111 USA.
 
25
 
 
26
   AutogsdocSource: Additions/GSMime.m
 
27
*/
 
28
 
 
29
#ifndef __GSMime_h_GNUSTEP_BASE_INCLUDE
 
30
#define __GSMime_h_GNUSTEP_BASE_INCLUDE
 
31
#import <GNUstepBase/GSVersionMacros.h>
 
32
 
 
33
#if     OS_API_VERSION(GS_API_NONE,GS_API_LATEST)
 
34
 
 
35
#ifdef NeXT_Foundation_LIBRARY
 
36
#import <Foundation/Foundation.h>
 
37
#else
 
38
#import <Foundation/NSObject.h>
 
39
#import <Foundation/NSString.h>
 
40
#import <Foundation/NSMapTable.h>
 
41
#endif
 
42
 
 
43
#if     defined(__cplusplus)
 
44
extern "C" {
 
45
#endif
 
46
 
 
47
@class  NSArray;
 
48
@class  NSMutableArray;
 
49
@class  NSData;
 
50
@class  NSMutableData;
 
51
@class  NSDictionary;
 
52
@class  NSMutableDictionary;
 
53
@class  NSScanner;
 
54
 
 
55
/*
 
56
 * A trivial class for mantaining state while decoding/encoding data.
 
57
 * Each encoding type requires its own subclass.
 
58
 */
 
59
@interface      GSMimeCodingContext : NSObject
 
60
{
 
61
  BOOL          atEnd;  /* Flag to say that data has ended.     */
 
62
}
 
63
- (BOOL) atEnd;
 
64
- (BOOL) decodeData: (const void*)sData
 
65
             length: (NSUInteger)length
 
66
           intoData: (NSMutableData*)dData;
 
67
- (void) setAtEnd: (BOOL)flag;
 
68
@end
 
69
 
 
70
@interface      GSMimeHeader : NSObject <NSCopying>
 
71
{
 
72
#if     GS_EXPOSE(GSMimeHeader)
 
73
  NSString              *name;
 
74
  NSString              *value;
 
75
  NSMutableDictionary   *objects;
 
76
  NSMutableDictionary   *params;
 
77
#endif
 
78
#if     GS_NONFRAGILE
 
79
#else
 
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).
 
84
   */
 
85
  @private id _internal GS_UNUSED_IVAR;
 
86
#endif
 
87
}
 
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
 
94
              value: (NSString*)v;
 
95
- (id) initWithName: (NSString*)n
 
96
              value: (NSString*)v
 
97
         parameters: (NSDictionary*)p;
 
98
- (NSString*) name;
 
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;
 
112
- (NSString*) text;
 
113
- (NSString*) value;
 
114
@end
 
115
 
 
116
 
 
117
@interface      GSMimeDocument : NSObject <NSCopying>
 
118
{
 
119
#if     GS_EXPOSE(GSMimeDocument)
 
120
  NSMutableArray        *headers;
 
121
  id                    content;
 
122
#endif
 
123
#if     !GS_NONFRAGILE
 
124
  void                  *_unused;
 
125
#endif
 
126
}
 
127
 
 
128
+ (NSString*) charsetFromEncoding: (NSStringEncoding)enc;
 
129
 
 
130
/**
 
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).
 
134
 */
 
135
+ (NSData*) decodeBase64: (NSData*)source;
 
136
+ (NSString*) decodeBase64String: (NSString*)source;
 
137
+ (GSMimeDocument*) documentWithContent: (id)newContent
 
138
                                   type: (NSString*)type
 
139
                                   name: (NSString*)name;
 
140
/**
 
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.
 
149
 */
 
150
+ (NSData*) encodeBase64: (NSData*)source;
 
151
+ (NSString*) encodeBase64String: (NSString*)source;
 
152
+ (NSStringEncoding) encodingFromCharset: (NSString*)charset;
 
153
 
 
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;
 
160
- (id) content;
 
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;
 
200
 
 
201
@end
 
202
 
 
203
@interface      GSMimeParser : NSObject
 
204
{
 
205
#if     GS_EXPOSE(GSMimeParser)
 
206
  NSMutableData         *data;
 
207
  unsigned char         *bytes;
 
208
  unsigned              dataEnd;
 
209
  unsigned              sectionStart;
 
210
  unsigned              lineStart;
 
211
  unsigned              lineEnd;
 
212
  unsigned              input;
 
213
  unsigned              expect;
 
214
  unsigned              rawBodyLength;
 
215
  struct {
 
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;
 
224
  } flags;
 
225
  NSData                *boundary;      // Also overloaded to hold excess
 
226
  GSMimeDocument        *document;
 
227
  GSMimeParser          *child;
 
228
  GSMimeCodingContext   *context;
 
229
  NSStringEncoding      _defaultEncoding;
 
230
#endif
 
231
#if     !GS_NONFRAGILE
 
232
  void                  *_unused;
 
233
#endif
 
234
}
 
235
 
 
236
+ (GSMimeDocument*) documentFromData: (NSData*)mimeData;
 
237
+ (GSMimeParser*) mimeParser;
 
238
 
 
239
- (GSMimeCodingContext*) contextFor: (GSMimeHeader*)info;
 
240
- (NSData*) data;
 
241
- (BOOL) decodeData: (NSData*)sData
 
242
          fromRange: (NSRange)aRange
 
243
           intoData: (NSMutableData*)dData
 
244
        withContext: (GSMimeCodingContext*)con;
 
245
- (NSData*) excess;
 
246
- (void) expectNoHeaders;
 
247
- (BOOL) isComplete;
 
248
- (BOOL) isHttp;
 
249
- (BOOL) isInBody;
 
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.
 
260
 */
 
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;
 
271
- (void) setIsHttp;
 
272
@end
 
273
 
 
274
 
 
275
/** The error domain for the GSMime system.
 
276
 */
 
277
GS_EXPORT NSString* const GSMimeErrorDomain;
 
278
 
 
279
/** The error codes used in the GSMimeErrorDomain
 
280
 */
 
281
typedef enum {
 
282
  GSMimeSMTPAbort,
 
283
  GSMimeSMTPTimeout,
 
284
  GSMimeSMTPCommsEnd,
 
285
  GSMimeSMTPCommsError,
 
286
  GSMimeSMTPServerResponse
 
287
} GSMimeErrorCode;
 
288
 
 
289
@class  NSError;
 
290
@class  NSStream;
 
291
@class  NSTimer;
 
292
 
 
293
/** The GSMimeSMTPClient class provides the ability to send EMails
 
294
 * ([GSMimeDocument] instances) via an SMTP server.
 
295
 */
 
296
@interface      GSMimeSMTPClient : NSObject
 
297
{
 
298
#if     GS_NONFRAGILE
 
299
#  if   defined(GS_GSMimeSMTPClient_IVARS)
 
300
@public
 
301
GS_GSMimeSMTPClient_IVARS;
 
302
#  endif
 
303
#else
 
304
@private id _internal;
 
305
#endif
 
306
}
 
307
 
 
308
/** Shut down any message send in progress and abort any queued messages.
 
309
 */
 
310
- (void) abort;
 
311
 
 
312
/** Returns the current delegate.
 
313
 */
 
314
- (id) delegate;
 
315
 
 
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
 
320
 * returns NO.
 
321
 */ 
 
322
- (BOOL) flush: (NSDate*)limit;
 
323
 
 
324
/** Returns the last error encountered, or nil if there is none recorded.
 
325
 */
 
326
- (NSError*) lastError;
 
327
 
 
328
/** Add the message to the queue of emails to be sent by the receiver.
 
329
 */
 
330
- (void) send: (GSMimeDocument*)message;
 
331
 
 
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).
 
337
 */
 
338
- (void) send: (GSMimeDocument*)message envelopeID: (NSString*)envid;
 
339
 
 
340
/** Set the delegate to receive callback methods indicating when a message
 
341
 * is sent, failed, or removed from the queue unsent.
 
342
 */
 
343
- (void) setDelegate: (id)d;
 
344
 
 
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.
 
348
 */
 
349
- (void) setHostname: (NSString*)s;
 
350
 
 
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.
 
355
 */
 
356
- (void) setIdentity: (NSString*)s;
 
357
 
 
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.
 
363
 */
 
364
- (void) setOriginator: (NSString*)s;
 
365
 
 
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.
 
369
 */
 
370
- (void) setPort: (NSString*)s;
 
371
 
 
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.
 
376
 */
 
377
- (void) setUsername: (NSString*)s;
 
378
 
 
379
/** returns the receivers current state.
 
380
 */
 
381
- (int) state;
 
382
 
 
383
/** Returns a string describing the receiver's current state
 
384
 */
 
385
- (NSString*) stateDesc;
 
386
 
 
387
@end
 
388
 
 
389
/** Informal protocol for delegates of the GSMimeSMTPClient class.
 
390
 * The default implementations of these methods do nothing.
 
391
 */
 
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) */
 
399
@end
 
400
 
 
401
 
 
402
#if     defined(__cplusplus)
 
403
}
 
404
#endif
 
405
 
 
406
#endif  /* OS_API_VERSION(GS_API_NONE,GS_API_NONE) */
 
407
 
 
408
#endif  /* __GSMime_h_GNUSTEP_BASE_INCLUDE */