File: CWPart.m

package info (click to toggle)
pantomime 1.4.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,288 kB
  • sloc: objc: 22,039; makefile: 11; sh: 4
file content (828 lines) | stat: -rw-r--r-- 18,767 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
/*
**  CWPart.m
**
**  Copyright (c) 2001-2007 Ludovic Marcotte
**  Copyright (C) 2017-2018 Riccardo Mottola
**
**  Author: Ludovic Marcotte <ludovic@Sophos.ca>
**          Riccardo Mottola <rm@gnu.org>
**
**  This library is free software; you can redistribute it and/or
**  modify it under the terms of the GNU Lesser General Public
**  License as published by the Free Software Foundation; either
**  version 2.1 of the License, or (at your option) any later version.
**  
**  This library is distributed in the hope that it will be useful,
**  but WITHOUT ANY WARRANTY; without even the implied warranty of
**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
**  Lesser General Public License for more details.
**  
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#import <Pantomime/CWPart.h>

#import <Pantomime/CWConstants.h>
#import <Pantomime/CWMessage.h>
#import <Pantomime/CWMIMEMultipart.h>
#import <Pantomime/CWMIMEUtility.h>
#import <Pantomime/NSData+Extensions.h>
#import <Pantomime/NSString+Extensions.h>
#import <Pantomime/CWParser.h>

#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSException.h>
#import <Foundation/NSValue.h>

#include <string.h>

#define LF "\n"

static int currentPartVersion = 2;

//
//
//
@implementation CWPart

+ (void) initialize
{
  [CWPart setVersion: currentPartVersion];
}

- (id) init
{
  self = [super init];
  if (self)
    {
      // We initialize our dictionary that will hold all our headers with a capacity of 25.
      // This is an empirical number that is used to speedup the addition of headers w/o 
      // reallocating our array everytime we add a new element.
      _headers = [[NSMutableDictionary alloc] initWithCapacity: 25];
      _parameters = [[NSMutableDictionary alloc] init];
      _line_length = 0;
      _size = 0;
      _content = nil;
    }
  
  return self;
}


//
//
//
- (void) dealloc
{
  RELEASE(_defaultCharset);
  RELEASE(_parameters);
  RELEASE(_headers);
  RELEASE(_content);

  [super dealloc];
}


//
//
//
- (id) initWithData: (NSData *) theData
{
  NSRange aRange;

  aRange = [theData rangeOfCString: "\n\n"];
  
  if (aRange.length == 0)
    {
      AUTORELEASE(self);
      return nil;
    }

  // We initialize our message with the headers and the content
  self = [self init];
  if (self)
    {
      // We verify if we have an empty body part content like:
      // X-UID: 5dc5aa4b82240000
      //
      // This is a MIME Message
      //
      // ------=_NextPart_000_007F_01BDF6C7.FABAC1B0
      //
      //
      // ------=_NextPart_000_007F_01BDF6C7.FABAC1B0
      // Content-Type: text/html; name="7english.co.kr.htm"
      if ([theData length] == 2)
	{
	  [self setContent: [NSData data]];
	}
      else
	{
	  [self setHeadersFromData:
		  [theData subdataWithRange: NSMakeRange(0,aRange.location)]];
	  [CWMIMEUtility setContentFromRawSource:
		       [theData subdataWithRange:
				  NSMakeRange(aRange.location + 2,
					      [theData length]-(aRange.location+2))]
					  inPart: self];
	}
    }
  return self;
}


//
//
//
- (id) initWithData: (NSData *) theData
            charset: (NSString *) theCharset
{
  self = [self initWithData: theData];
  if (self)
    {
      [self setDefaultCharset: theCharset];
    }
  return self;
}


//
// NSCoding protocol
//
- (void) encodeWithCoder: (NSCoder *) theCoder
{
  [theCoder encodeObject: [self contentType]];
  [theCoder encodeObject: [self contentID]];
  [theCoder encodeObject: [self contentDescription]];
  [theCoder encodeObject: [NSNumber numberWithUnsignedInt: (unsigned)[self contentDisposition]]];
  [theCoder encodeObject: [self filename]];
 
  [theCoder encodeObject: [NSNumber numberWithUnsignedInt: (unsigned)[self contentTransferEncoding]]];
  [theCoder encodeObject: [NSNumber numberWithUnsignedInt: (unsigned)[self format]]];
  [theCoder encodeObject: [NSNumber numberWithUnsignedLong: _size]];

  [theCoder encodeObject: [self boundary]];
  [theCoder encodeObject: [self charset]];
  [theCoder encodeObject: _defaultCharset];
}


- (id) initWithCoder: (NSCoder *) theCoder
{
  self = [super init];
  if (self)
    {
      _headers = [[NSMutableDictionary alloc] initWithCapacity: 25];
      _parameters = [[NSMutableDictionary alloc] init];

      [self setContentType: [theCoder decodeObject]];
      [self setContentID: [theCoder decodeObject]];
      [self setContentDescription: [theCoder decodeObject]];
      [self setContentDisposition: (PantomimeContentDisposition)[[theCoder decodeObject] unsignedIntValue]];
      [self setFilename: [theCoder decodeObject]];

      [self setContentTransferEncoding: (PantomimeEncoding)[[theCoder decodeObject] unsignedIntValue]];
      [self setFormat: (PantomimeMessageFormat)[[theCoder decodeObject] unsignedIntValue]];
      [self setSize: [[theCoder decodeObject] unsignedLongValue]];

      [self setBoundary: [theCoder decodeObject]];
      [self setCharset: [theCoder decodeObject]];
      [self setDefaultCharset: [theCoder decodeObject]];
  
      _content = nil;
  }
  return self;
}


//
// access / mutation methods
//
- (NSObject *) content
{
  return _content;
}


//
//
//
- (void) setContent: (NSObject *) theContent
{
  if (theContent && !([theContent isKindOfClass: [NSData class]] ||
		      [theContent isKindOfClass: [CWMessage class]] ||
		      [theContent isKindOfClass: [CWMIMEMultipart class]]))
    {
      [NSException raise: NSInvalidArgumentException
		   format: @"Invalid argument to CWPart: -setContent:  The content MUST be either a NSData, CWMessage or CWMIMEMessage instance."];
    }

  ASSIGN(_content, theContent);
}

//
//
//
- (NSString *) contentType
{
  return [_headers objectForKey: @"Content-Type"];
}

- (void) setContentType: (NSString*) theContentType
{
  if (theContentType)
    {
      [_headers setObject: theContentType  forKey: @"Content-Type"];
    }
}

//
//
//
- (NSString *) contentID
{
  return [_headers objectForKey: @"Content-Id"];
}        

- (void) setContentID: (NSString *) theContentID
{ 
  if (theContentID)
    {
      [_headers setObject: theContentID  forKey: @"Content-Id"];
    }  
}

//
//
//
- (NSString *) contentDescription
{
  return [_headers objectForKey: @"Content-Description"];
}

- (void) setContentDescription: (NSString *) theContentDescription
{
  if (theContentDescription)
    {
      [_headers setObject: theContentDescription  forKey: @"Content-Description"];
    }  
}


//
//
//
- (PantomimeContentDisposition) contentDisposition
{
  id o;

  o = [_headers objectForKey: @"Content-Disposition"];

  return (o ? (PantomimeContentDisposition)[o intValue] : PantomimeInlineDisposition);
}

- (void) setContentDisposition: (PantomimeContentDisposition) theContentDisposition
{
  [_headers setObject: [NSNumber numberWithUnsignedInt: (unsigned)theContentDisposition]  forKey: @"Content-Disposition"];
}


//
//
//
- (PantomimeEncoding) contentTransferEncoding
{
  id o;
  
  o = [_headers objectForKey: @"Content-Transfer-Encoding"];

  if (o)
    {
      return [o unsignedIntValue];
    }
 
  // Default value for the Content-Transfer-Encoding.
  // See RFC2045 - 6.1. Content-Transfer-Encoding Syntax.
  return PantomimeEncodingNone;
}

- (void) setContentTransferEncoding: (PantomimeEncoding) theEncoding
{
  [_headers setObject: [NSNumber numberWithUnsignedInt: (unsigned)theEncoding]  forKey: @"Content-Transfer-Encoding"];
}


//
//
//
- (NSString *) filename
{
  return [_parameters objectForKey: @"filename"];
  //return _filename;
}

- (void) setFilename: (NSString *) theFilename
{
  if (theFilename && ([theFilename length] > 0))
    {
      //ASSIGN(_filename, theFilename);
      [_parameters setObject: theFilename  forKey: @"filename"];
    }
  else
    {
      //ASSIGN(_filename, @"unknown");
      [_parameters setObject: @"unknown"  forKey: @"filename"];
    }
}


//
//
//
- (PantomimeMessageFormat) format
{
  id o;

  o = [_parameters objectForKey: @"format"];

  if (o)
    {
      return [o unsignedIntValue];
    }

  return PantomimeFormatUnknown;
}

- (void) setFormat: (PantomimeMessageFormat) theFormat
{
  [_parameters setObject: [NSNumber numberWithUnsignedInt: theFormat]  forKey: @"format"];
}


//
//
//
- (NSUInteger) lineLength
{
  return _line_length;
}

- (void) setLineLength: (NSUInteger) theLineLength
{
  _line_length = theLineLength;
}


//
// This method is used to verify if the part is of the following primaryType / subType
//
- (BOOL) isMIMEType: (NSString *) thePrimaryType
	    subType: (NSString *) theSubType 
{
  NSString *aString;

  if (![self contentType]) 
    {
      NSDebugLog(@"CWPart isMimeType: %@ subType: %@ - contentType is nil", thePrimaryType, theSubType);
      return NO;
    }

  if ([theSubType compare: @"*"] == NSOrderedSame)
    {
      if ([[self contentType] hasCaseInsensitivePrefix: thePrimaryType])
	{
	  return YES;
	}
    }
  else
    {
      aString = [NSString stringWithFormat: @"%@/%@", thePrimaryType, theSubType];
     
      if ([aString caseInsensitiveCompare: [self contentType]] == NSOrderedSame)
	{
	  return YES;
	}
    }
  
  return NO;
}


//
//
//
- (unsigned long) size
{
  return _size;
}

- (void) setSize: (unsigned long) theSize
{
  _size = theSize;
}


//
//
//
- (NSData *) dataValue
{
  NSMutableData *aMutableData;
  NSMutableArray *allKeys;
  NSData *aDataToSend;
  NSArray *allLines;
  NSString *aFilename; 
  NSUInteger i, count;

  aMutableData = [[NSMutableData alloc] init];
  
  // We start off by exactring the filename of the part.
  if ([[self filename] is7bitSafe])
    {
      aFilename = [self filename];
    }
  else
    {
      aFilename = [[NSString alloc] initWithData: [CWMIMEUtility encodeWordUsingQuotedPrintable: [self filename]
								 prefixLength: 0]
				    encoding: NSASCIIStringEncoding];
      AUTORELEASE(aFilename);
    }

  // We encode our Content-Transfer-Encoding header.
  if ([self contentTransferEncoding] != PantomimeEncodingNone)
    {
      [aMutableData appendCFormat: @"Content-Transfer-Encoding: %@%s",
		    [NSString stringValueOfTransferEncoding: [self contentTransferEncoding]],
		    LF];
    }

  // We encode our Content-ID header.
  if ([self contentID])
    {
      [aMutableData appendCFormat: @"Content-ID: %@%s", [self contentID], LF];
    }
  
  // We encode our Content-Description header.
  if ([self contentDescription])
    {
      [aMutableData appendCString: "Content-Description: "];
      [aMutableData appendData: [CWMIMEUtility encodeWordUsingQuotedPrintable: [self contentDescription]
					       prefixLength: 21]];
      [aMutableData appendCString: LF];
    }

  // We now encode the Content-Type header with its parameters.
  [aMutableData appendCFormat: @"Content-Type: %@", [self contentType]];

  if ([self charset])
    {
      [aMutableData appendCFormat: @"; charset=\"%@\"", [self charset]];
    }

  if ([self format] == PantomimeFormatFlowed &&
      ([self contentTransferEncoding] == PantomimeEncodingNone || [self contentTransferEncoding] == PantomimeEncoding8bit))
    {
      [aMutableData appendCString: "; format=\"flowed\""];
    }

  if (aFilename && [aFilename length])
    {
      [aMutableData appendCFormat: @"; name=\"%@\"", aFilename];
    }

  // Before checking for all other parameters, we check for the boundary one
  // If we got a CWMIMEMultipart instance as the content but no boundary
  // was set, we create a boundary and we set it.
  if ([self boundary] || [_content isKindOfClass: [CWMIMEMultipart class]])
    {
      if (![self boundary])
	{
	  [self setBoundary: [CWMIMEUtility globallyUniqueBoundary]];
	}

      [aMutableData appendCFormat: @";%s\tboundary=\"",LF];
      [aMutableData appendData: [self boundary]];
      [aMutableData appendCString: "\""];
    }
  
  // We now check for any other additional parameters. If we have some,
  // we add them one per line. We first REMOVE what we have added! We'll
  // likely and protocol= here.
  allKeys = [NSMutableArray arrayWithArray: [_parameters allKeys]];
  [allKeys removeObject: @"boundary"];
  [allKeys removeObject: @"charset"];
  [allKeys removeObject: @"filename"];
  [allKeys removeObject: @"format"];
  
  for (i = 0; i < [allKeys count]; i++)
    {
      [aMutableData appendCFormat: @";%s", LF];
      [aMutableData appendCFormat: @"\t%@=\"%@\"", [allKeys objectAtIndex: i], [_parameters objectForKey: [allKeys objectAtIndex: i]]];
    }

  [aMutableData appendCString: LF];

  // We encode our Content-Disposition header. We ignore other parameters
  // (other than the filename one) since they are pretty much worthless.
  // See RFC2183 for details.
  if ([self contentDisposition] == PantomimeAttachmentDisposition)
    {
      [aMutableData appendCString: "Content-Disposition: attachment"];

      if (aFilename && [aFilename length])
	{
	  [aMutableData appendCFormat: @"; filename=\"%@\"", aFilename];
	}
      
      [aMutableData appendCString: LF];
    }

  if ([_content isKindOfClass: [CWMessage class]])
    {
      aDataToSend = [(CWMessage *)_content rawSource];
    }
  else if ([_content isKindOfClass: [CWMIMEMultipart class]])
    {
      CWMIMEMultipart *aMimeMultipart;
      NSMutableData *md;
      CWPart *aPart;
      
      md = [[NSMutableData alloc] init];
      aMimeMultipart = (CWMIMEMultipart *)_content;
      count = [aMimeMultipart count];
      
      for (i = 0; i < count; i++)
	{
	  aPart = [aMimeMultipart partAtIndex: i];
	  
	  if (i > 0)
	    {
	      [md appendBytes: LF  length: strlen(LF)];
	    }
	  
	  [md appendBytes: "--"  length: 2];
	  [md appendData: [self boundary]];
	  [md appendBytes: LF  length: strlen(LF)];
	  [md appendData: [aPart dataValue]];
	}
      
      [md appendBytes: "--"  length: 2];
      [md appendData: [self boundary]];
      [md appendBytes: "--"  length: 2];
      [md appendBytes: LF  length: strlen(LF)];
	  
      aDataToSend = AUTORELEASE(md);
    }
  else
    {
      aDataToSend = (NSData *)_content;
    }

  // We separe our part's headers from the content
  [aMutableData appendCFormat: @"%s", LF];

  // We now encode our content the way it was specified
  if ([self contentTransferEncoding] == PantomimeEncodingQuotedPrintable)
    {
      aDataToSend = [aDataToSend encodeQuotedPrintableWithLineLength: 72  inHeader: NO];
    }
  else if ([self contentTransferEncoding] == PantomimeEncodingBase64)
    {
      aDataToSend = [aDataToSend encodeBase64WithLineLength: 72];
    }
  else if (([self contentTransferEncoding] == PantomimeEncodingNone || [self contentTransferEncoding] == PantomimeEncoding8bit) &&
	   [self format] == PantomimeFormatFlowed)
    {
      NSUInteger limit;
      
      limit = _line_length;
      
      if (limit < 2 || limit > 998)
	{
	  limit = 72;
	}
      
      aDataToSend = [aDataToSend wrapWithLimit: limit];
    }

  allLines = [aDataToSend componentsSeparatedByCString: "\n"];
  count = [allLines count];

  for (i = 0; i < count; i++)
    {
      if (i == count-1 && [[allLines objectAtIndex: i] length] == 0)
	{
	  break;
	}
      
      [aMutableData appendData: [allLines objectAtIndex: i]];
      [aMutableData appendBytes: LF  length: 1];
    }
  
  return AUTORELEASE(aMutableData);
}


//
//
//
- (NSData *) boundary
{
  return [_parameters objectForKey: @"boundary"];
}

- (void) setBoundary: (NSData *) theBoundary
{
  if (theBoundary)
    {
      [_parameters setObject: theBoundary  forKey: @"boundary"];
    }
}


//
//
//
- (NSData *) protocol
{
  return [_parameters objectForKey: @"protocol"];
  //return _protocol;
}

- (void) setProtocol: (NSData *) theProtocol
{
  //ASSIGN(_protocol, theProtocol);
  if (theProtocol)
    {
      [_parameters setObject: theProtocol  forKey: @"protocol"];
    }
}


//
//
//
- (NSString *) charset
{
  return [_parameters objectForKey: @"charset"];
}

- (void) setCharset: (NSString *) theCharset
{
  if (theCharset)
    {
      [_parameters setObject: theCharset  forKey: @"charset"];
    }
}


//
//
//
- (NSString *) defaultCharset
{
  return _defaultCharset;
}


//
//
//
- (void) setDefaultCharset: (NSString *) theCharset
{
  ASSIGN(_defaultCharset, theCharset);
}


//
//
//
- (void) setHeadersFromData: (NSData *) theHeaders
{
  NSAutoreleasePool *pool;
  NSArray *allLines;
  NSUInteger i, count;
  
  if (!theHeaders || [theHeaders length] == 0)
    {
      return;
    }

  // We initialize a local autorelease pool
  pool = [[NSAutoreleasePool alloc] init];

  // We MUST be sure to unfold all headers properly before
  // decoding the headers
  theHeaders = [theHeaders unfoldLines];

  allLines = [theHeaders componentsSeparatedByCString: "\n"];
  count = [allLines count];

  for (i = 0; i < count; i++)
    {
      NSData *aLine = [allLines objectAtIndex: i];

      // We stop if we found the header separator. (\n\n) since someone could
      // have called this method with the entire rawsource of a message.
      if ([aLine length] == 0)
	{
	  break;
	}

      if ([aLine hasCaseInsensitiveCPrefix: "Content-Description"])
	{
	  [CWParser parseContentDescription: aLine  inPart: self];
	}
      else if ([aLine hasCaseInsensitiveCPrefix: "Content-Disposition"])
	{
	  [CWParser parseContentDisposition: aLine  inPart: self];
	}
      else if ([aLine hasCaseInsensitiveCPrefix: "Content-ID"])
	{
	  [CWParser parseContentID: aLine  inPart: self];
	}
      else if ([aLine hasCaseInsensitiveCPrefix: "Content-Length"])
	{
	  // We just ignore that for now.
	}
      else if ([aLine hasCaseInsensitiveCPrefix: "Content-Transfer-Encoding"])
	{
	  [CWParser parseContentTransferEncoding: aLine  inPart: self];
	}
      else if ([aLine hasCaseInsensitiveCPrefix: "Content-Type"])
	{
	  [CWParser parseContentType: aLine  inPart: self];
	}
    }

  RELEASE(pool);
}


//
//
//
- (id) parameterForKey: (NSString *) theKey
{
  return [_parameters objectForKey: theKey];
}

- (void) setParameter: (id) theParameter  forKey: (NSString *) theKey
{
  if (theParameter)
    {
      [_parameters setObject: theParameter  forKey: theKey];
    }
  else
    {
      [_parameters removeObjectForKey: theKey];
    }
}

//
//
//
- (NSDictionary *) allHeaders
{
  return _headers;
}

//
//
//
- (id) headerValueForName: (NSString *) theName
{
  NSArray *allKeys;
  NSUInteger count;

  allKeys = [_headers allKeys];
  count = [allKeys count];

  while (count--)
    {
      if ([[allKeys objectAtIndex: count] caseInsensitiveCompare: theName] == NSOrderedSame)
	{
	  return [_headers objectForKey: [allKeys objectAtIndex: count]];
	}
    }
  
  return nil;
}

//
//
//
- (void) setHeaders: (NSDictionary *) theHeaders
{
  if (theHeaders)
    {
      [_headers addEntriesFromDictionary: theHeaders];
    }
  else
    {
      [_headers removeAllObjects];
    }
}
@end