Minor tweak in case some mail clients require mime version header before other

mime headers.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@14009 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-07-03 10:00:39 +00:00
parent 70c11f66f6
commit 08acf85331
2 changed files with 85 additions and 1 deletions

View file

@ -1,3 +1,8 @@
2002-07-03 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSMime.m: Ensure mime-version header appears
before other headers.
2002-07-02 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/gdomap.c: Don't write to pidfile until *after* setuid away

View file

@ -2759,6 +2759,10 @@ static NSCharacterSet *tokenSet = nil;
@interface GSMimeDocument (Private)
- (unsigned) _indexOfHeaderNamed: (NSString*)name;
@end
/**
* <p>
* This class is intended to provide a wrapper for MIME messages
@ -3127,6 +3131,14 @@ static NSCharacterSet *tokenSet = nil;
* The header must be a mutable dictionary object that contains
* at least the fields that are standard for all headers.
* </p>
* <p>
* Certain well-known headers are restricted to one occurrance in
* an email, and when extra copies are added they replace originals.
* </p>
* <p>
* The mime-version header is special ... it is inserted before any
* other mime headers rather than being added at the end.
* </p>
*/
- (void) addHeader: (GSMimeHeader*)info
{
@ -3138,7 +3150,49 @@ static NSCharacterSet *tokenSet = nil;
format: @"[%@ -%@:] header with invalid name",
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
}
[headers addObject: info];
if ([name isEqualToString: @"mime-version"] == YES
|| [name isEqualToString: @"content-disposition"] == YES
|| [name isEqualToString: @"content-transfer-encoding"] == YES
|| [name isEqualToString: @"content-type"] == YES
|| [name isEqualToString: @"subject"] == YES)
{
unsigned index = [self _indexOfHeaderNamed: name];
if (index != NSNotFound)
{
[headers replaceObjectAtIndex: index withObject: info];
}
else if ([name isEqualToString: @"mime-version"] == YES)
{
unsigned tmp;
index = [headers count];
tmp = [self _indexOfHeaderNamed: @"content-disposition"];
if (tmp != NSNotFound && tmp < index)
{
index = tmp;
}
tmp = [self _indexOfHeaderNamed: @"content-transfer-encoding"];
if (tmp != NSNotFound && tmp < index)
{
index = tmp;
}
tmp = [self _indexOfHeaderNamed: @"content-type"];
if (tmp != NSNotFound && tmp < index)
{
index = tmp;
}
[headers insertObject: info atIndex: index];
}
else
{
[headers addObject: info];
}
}
else
{
[headers addObject: info];
}
}
/**
@ -3894,6 +3948,31 @@ static NSCharacterSet *tokenSet = nil;
@end
@implementation GSMimeDocument (Private)
/**
* Returns the index of the first header matching the specified name
* or NSNotFound if no match is found.<br />
* NB. The supplied name <em>must</em> be lowercase.<br />
* This method is for internal use
*/
- (unsigned) _indexOfHeaderNamed: (NSString*)name
{
unsigned count = [headers count];
unsigned index;
for (index = 0; index < count; index++)
{
GSMimeHeader *hdr = [headers objectAtIndex: index];
if ([name isEqualToString: [hdr name]] == YES)
{
return index;
}
}
return NSNotFound;
}
@end