Browse Source

auto indents code (cosmetic)

1.1.260
Andreas Buff 4 months ago
parent
commit
ff069a87cd
3 changed files with 1051 additions and 1054 deletions
  1. +257
    -257
      PantomimeFramework/PantomimeFramework/CWPart.h
  2. +546
    -546
      pantomime-lib/Framework/Pantomime/CWParser.m
  3. +248
    -251
      pantomime-lib/Framework/Pantomime/CWPart.m

+ 257
- 257
PantomimeFramework/PantomimeFramework/CWPart.h View File

@ -1,24 +1,24 @@
/*
** CWPart.h
**
** Copyright (c) 2001-2007
**
** Author: Ludovic Marcotte <ludovic@Sophos.ca>
**
** 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 Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
** CWPart.h
**
** Copyright (c) 2001-2007
**
** Author: Ludovic Marcotte <ludovic@Sophos.ca>
**
** 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 Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _Pantomime_H_CWPart
#define _Pantomime_H_CWPart
@ -32,16 +32,16 @@
#import <PantomimeFramework/CWConstants.h>
/*!
@class CWPart
@discussion This class defines what Internet messages are composed of.
An Internet message is composed of various parts which can
be text parts, images, PDF documents and so on. Even a message
is a part, with additional headers (like "From:", "Subject:"
and so on). CWMessage is a superclass of CWPart.
*/
@class CWPart
@discussion This class defines what Internet messages are composed of.
An Internet message is composed of various parts which can
be text parts, images, PDF documents and so on. Even a message
is a part, with additional headers (like "From:", "Subject:"
and so on). CWMessage is a superclass of CWPart.
*/
@interface CWPart : NSObject <NSCoding>
{
@protected
@protected
NSMutableDictionary *_parameters;
NSMutableDictionary *_headers;
NSString *_defaultCharset;
@ -52,127 +52,127 @@
}
/*!
@method initWithData:
@discussion This method is used to initialize the CWPart instance
with the specified data. It splits the header
part with the content part and calls -setHeadersFromData:
with the header part and CWMIMEUtility: +setContentFromRawSource: inPart:
with the content part. This method will recursively go in
sub-parts (if needed) and initilize them also.
@param theData The bytes to use.
@result A CWPart instance, nil on error.
*/
@method initWithData:
@discussion This method is used to initialize the CWPart instance
with the specified data. It splits the header
part with the content part and calls -setHeadersFromData:
with the header part and CWMIMEUtility: +setContentFromRawSource: inPart:
with the content part. This method will recursively go in
sub-parts (if needed) and initilize them also.
@param theData The bytes to use.
@result A CWPart instance, nil on error.
*/
- (id _Nullable) initWithData: (NSData * _Nonnull) theData;
/*!
@method initWithData: charset:
@discussion This method acts like -initWithData: but it uses
<i>theCharset</i> instead of the Part's charset
(found in theData).
@param theData The bytes to use.
@param theCharset The charset to force.
@result A CWPart instance, nil on error.
*/
@method initWithData: charset:
@discussion This method acts like -initWithData: but it uses
<i>theCharset</i> instead of the Part's charset
(found in theData).
@param theData The bytes to use.
@param theCharset The charset to force.
@result A CWPart instance, nil on error.
*/
- (id _Nullable) initWithData: (NSData * _Nonnull) theData
charset: (NSString * _Nonnull) theCharset;
charset: (NSString * _Nonnull) theCharset;
/*!
@method setHeadersFromData:
@discussion This method initalize all the headers of a part
from the raw data source. It replaces previously
defined values of headers found in <i>theHeaders</i>.
@param theHeaders The bytes to use.
*/
@method setHeadersFromData:
@discussion This method initalize all the headers of a part
from the raw data source. It replaces previously
defined values of headers found in <i>theHeaders</i>.
@param theHeaders The bytes to use.
*/
- (void) setHeadersFromData: (NSData * _Nonnull) theHeaders;
/*!
@method contentType
@discussion This method is used to get the value of the
receiver's "Content-Type" header. If none is
specified, nil will be returned. It's up to the
callee to use whatever charset it wants. Section
5.2 or RFC2045 recommends to use "text/plain" in
this case.
@result The value. If none was set, nil will
be returned.
*/
@method contentType
@discussion This method is used to get the value of the
receiver's "Content-Type" header. If none is
specified, nil will be returned. It's up to the
callee to use whatever charset it wants. Section
5.2 or RFC2045 recommends to use "text/plain" in
this case.
@result The value. If none was set, nil will
be returned.
*/
- (NSString * _Nullable) contentType;
/*!
@method setContentType:
@discussion This method is used to set the value of
the receiver's "Content-Type" header.
@param theContentType The "Content-Type" value.
*/
@method setContentType:
@discussion This method is used to set the value of
the receiver's "Content-Type" header.
@param theContentType The "Content-Type" value.
*/
- (void) setContentType: (NSString * _Nullable) theContentType;
/*!
@method contentID
@discussion This method is used to get the value of the
receiver's "Content-ID" header.
@result The value. If none was set, nil will
be returned.
*/
@method contentID
@discussion This method is used to get the value of the
receiver's "Content-ID" header.
@result The value. If none was set, nil will
be returned.
*/
- (NSString * _Nullable) contentID;
/*!
@method setContentID:
@discussion This method is used to set the value of
the receiver's "Content-ID" header.
@param theContentID The "Content-ID" value.
*/
@method setContentID:
@discussion This method is used to set the value of
the receiver's "Content-ID" header.
@param theContentID The "Content-ID" value.
*/
- (void) setContentID: (NSString * _Nullable) theContentID;
/*!
@method contentDescription
@discussion This method is used to get the value of the
receiver's "Content-Description" header.
@result The value. If none was set, nil will
be returned.
*/
/*!
@method contentDescription
@discussion This method is used to get the value of the
receiver's "Content-Description" header.
@result The value. If none was set, nil will
be returned.
*/
- (NSString * _Nullable) contentDescription;
/*!
@method setContentDescription:
@discussion This method is used to set the value of
the receiver's "Content-Description" header.
@param theContentDescription The "Content-Description" value.
*/
@method setContentDescription:
@discussion This method is used to set the value of
the receiver's "Content-Description" header.
@param theContentDescription The "Content-Description" value.
*/
- (void) setContentDescription: (NSString * _Nullable) theContentDescription;
/*!
@method contentDisposition
@discussion This method is used to get the value of the
receiver's "Content-Disposition" header.
@result The value. If none was set, PantomimeInlineDisposition
will be returned.
*/
@method contentDisposition
@discussion This method is used to get the value of the
receiver's "Content-Disposition" header.
@result The value. If none was set, PantomimeInlineDisposition
will be returned.
*/
- (PantomimeContentDisposition) contentDisposition;
/*!
@method setContentDisposition:
@discussion This method is used to set the value of
the receiver's "Content-Disposition" header.
@param theContentDisposition The "Content-Disposition" value.
*/
@method setContentDisposition:
@discussion This method is used to set the value of
the receiver's "Content-Disposition" header.
@param theContentDisposition The "Content-Disposition" value.
*/
- (void) setContentDisposition: (PantomimeContentDisposition) theContentDisposition;
/*!
@method contentTransferEncoding
@discussion This method is used to get the value of the
receiver's "Content-Transfer-Encoding" header.
@result The value. If none was set, PantomimeEncodingNone
will be returned.
*/
@method contentTransferEncoding
@discussion This method is used to get the value of the
receiver's "Content-Transfer-Encoding" header.
@result The value. If none was set, PantomimeEncodingNone
will be returned.
*/
- (PantomimeEncoding) contentTransferEncoding;
/*!
@method setContentTransferEndocing:
@discussion This method is used to set the value of
the receiver's "Content-Transfer-Encoding" header.
@param theEncoding The "Content-Transfer-Encoding" value. Accepted
values are part of the PantomimeEncoding enum.
*/
@method setContentTransferEndocing:
@discussion This method is used to set the value of
the receiver's "Content-Transfer-Encoding" header.
@param theEncoding The "Content-Transfer-Encoding" value. Accepted
values are part of the PantomimeEncoding enum.
*/
- (void) setContentTransferEncoding: (PantomimeEncoding) theEncoding;
/**
@ -191,215 +191,215 @@
- (void)setFilename:(NSString *_Nullable)theFilename;
/*!
@method format
@discussion This method is used to obtain the format of the receiver.
Possible values are part of the PantomimeMessageFormat.
See RFC 2646 for a detailed description of the "flowed" format.
@result The format, PantomimeFormatUnknown if no value was previously set.
*/
@method format
@discussion This method is used to obtain the format of the receiver.
Possible values are part of the PantomimeMessageFormat.
See RFC 2646 for a detailed description of the "flowed" format.
@result The format, PantomimeFormatUnknown if no value was previously set.
*/
- (PantomimeMessageFormat) format;
/*!
@method setFormat:
@discussion This method is used to set the format of the receiver.
Accepted values are part of the PantomimeMessageFormat enum.
@param theFormat The format to use.
*/
@method setFormat:
@discussion This method is used to set the format of the receiver.
Accepted values are part of the PantomimeMessageFormat enum.
@param theFormat The format to use.
*/
- (void) setFormat: (PantomimeMessageFormat) theFormat;
/*!
@method lineLength
@discussion This method is used to return the maximum length that
a line can use in a text part.
@result The length, 0 if not defined.
*/
@method lineLength
@discussion This method is used to return the maximum length that
a line can use in a text part.
@result The length, 0 if not defined.
*/
- (NSUInteger) lineLength;
/*!
@method setLineLength:
@discussion This method is used to set the maximum length of a
line that can be used for a text part.
@param theLineLength The length.
*/
@method setLineLength:
@discussion This method is used to set the maximum length of a
line that can be used for a text part.
@param theLineLength The length.
*/
- (void) setLineLength: (int) theLineLength;
/*!
@method isMIMEType: subType:
@discussion This method is used to verify if the receiver matches
a specific MIME type. The "*" wildcard can be used
for the sub-type.
@param thePrimaryType The left part of the MIME type.
@param theSubType The right part of the MIME type.
@result YES if it matches, NO otherwise.
*/
@method isMIMEType: subType:
@discussion This method is used to verify if the receiver matches
a specific MIME type. The "*" wildcard can be used
for the sub-type.
@param thePrimaryType The left part of the MIME type.
@param theSubType The right part of the MIME type.
@result YES if it matches, NO otherwise.
*/
- (BOOL) isMIMEType: (NSString * _Nonnull) thePrimaryType
subType: (NSString * _Nonnull) theSubType;
/*!
@method content
@discussion This method is used to obtain the decoded content
of the receiver. The returned value can be a NSString
instance, a NSData instance, a CWMIMEMultipart instance
or a CWMessage instance.
@result The decoded content of the part.
*/
@method content
@discussion This method is used to obtain the decoded content
of the receiver. The returned value can be a NSString
instance, a NSData instance, a CWMIMEMultipart instance
or a CWMessage instance.
@result The decoded content of the part.
*/
- (NSObject * _Nullable) content;
/*!
@method setContent:
@discussion This method is used to set the content of the receiver.
The content will later be correctly encoded before the
message is submitted or saved on disk (using -dataValue).
Accepted values are instances of NSData, CWMIMEMultipart
or CWMessage otherwise, a NSInvalidArgumentException
will be thrown.
@param theContent The content of the part.
*/
@method setContent:
@discussion This method is used to set the content of the receiver.
The content will later be correctly encoded before the
message is submitted or saved on disk (using -dataValue).
Accepted values are instances of NSData, CWMIMEMultipart
or CWMessage otherwise, a NSInvalidArgumentException
will be thrown.
@param theContent The content of the part.
*/
- (void) setContent: (NSObject * _Nullable) theContent;
/*!
@method size
@discussion This method is used to obtain the receiver's size
(total number of bytes of its raw representation).
@result The size of the receiver.
*/
@method size
@discussion This method is used to obtain the receiver's size
(total number of bytes of its raw representation).
@result The size of the receiver.
*/
- (long) size;
/*!
@method setSize:
@discussion This method is used to set the receiver's size.
@param theSize The value of the size.
*/
@method setSize:
@discussion This method is used to set the receiver's size.
@param theSize The value of the size.
*/
- (void) setSize: (NSInteger) theSize;
/*!
@method dataValue
@discussion This method is used to encoded the receiver's using
the MIME standard before it is ready for submisssion
(using a Transport method) or being saved on disk.
The CWMessage class overwrites this method in order
to add Message-specific headers such as "From",
"Subject" and so on.
@result The encoded CWPart instance, as a NSData instance.
*/
@method dataValue
@discussion This method is used to encoded the receiver's using
the MIME standard before it is ready for submisssion
(using a Transport method) or being saved on disk.
The CWMessage class overwrites this method in order
to add Message-specific headers such as "From",
"Subject" and so on.
@result The encoded CWPart instance, as a NSData instance.
*/
- (NSData * _Nullable)dataValue;
/*!
@method boundary
@discussion This method is used to get the boundary that separates
parts that compose a multipart composite part.
@result The boundary as a NSData instance, nil if none was set.
*/
@method boundary
@discussion This method is used to get the boundary that separates
parts that compose a multipart composite part.
@result The boundary as a NSData instance, nil if none was set.
*/
- (NSData * _Nullable) boundary;
/*!
@method setBoundary:
@discussion This method is used to set the boundary used to separate
parts that compose a multipart composite part message.
@param theBoundary The value of the boundary.
*/
@method setBoundary:
@discussion This method is used to set the boundary used to separate
parts that compose a multipart composite part message.
@param theBoundary The value of the boundary.
*/
- (void) setBoundary: (NSData * _Nullable) theBoundary;
/*!
@method protocol
@discussion This method is used to obtain the value of the "protocol"
parameter found in some Content-Type headers. This parameter
is often present in PGP encoded messages.
@result The value of the "protocol" parameter, nil if none was set.
*/
@method protocol
@discussion This method is used to obtain the value of the "protocol"
parameter found in some Content-Type headers. This parameter
is often present in PGP encoded messages.
@result The value of the "protocol" parameter, nil if none was set.
*/
- (NSData * _Nullable) protocol;
/*!
@method setProtocol:
@discussion This method is used to set the value of the "protocol"
parameter. This parameter will be added to the ones
found in the Content-Type header in -dataValue.
@param theProtocol The value of the "protocol" parameter.
*/
@method setProtocol:
@discussion This method is used to set the value of the "protocol"
parameter. This parameter will be added to the ones
found in the Content-Type header in -dataValue.
@param theProtocol The value of the "protocol" parameter.
*/
- (void) setProtocol: (NSData * _Nullable) theProtocol;
/*!
@method charset
@discussion This method is used to obtain the value of the "charset"
parameter found in the Content-Type header.
@result The value of the "charset" parameter, "us-ascii" if none was set.
*/
@method charset
@discussion This method is used to obtain the value of the "charset"
parameter found in the Content-Type header.
@result The value of the "charset" parameter, "us-ascii" if none was set.
*/
- (NSString * _Nullable) charset;
/*!
@method setCharset:
@discussion This method is used to set the value of the "charset" parameter
found in the Content-Type header.
@param theCharset The charset to use.
*/
@method setCharset:
@discussion This method is used to set the value of the "charset" parameter
found in the Content-Type header.
@param theCharset The charset to use.
*/
- (void) setCharset: (NSString * _Nullable) theCharset;
/*!
@method defaultCharset
@discussion This method is used to get the charset that will be
enforced for usage when decoding the part.
@result The enforced charset.
*/
@method defaultCharset
@discussion This method is used to get the charset that will be
enforced for usage when decoding the part.
@result The enforced charset.
*/
- (NSString * _Nullable) defaultCharset;
/*!
@method setDefaultCharset:
@discussion This method is used to set the charset that will be
enforced for usage when the part is being decoded.
@param theCharset The charset to force.
*/
@method setDefaultCharset:
@discussion This method is used to set the charset that will be
enforced for usage when the part is being decoded.
@param theCharset The charset to force.
*/
- (void) setDefaultCharset: (NSString * _Nullable) theCharset;
/*!
@method parameterForKey:
@discussion This method is used to obtain a parameter value
based on its name. The name serves as the key.
Parameters are only part of the Content-Type
header field.They are NOT part of the
Content-Disposition header.
@param theKey The key for which the value will be returned.
@result The parameter value, nil if non-existent.
*/
@method parameterForKey:
@discussion This method is used to obtain a parameter value
based on its name. The name serves as the key.
Parameters are only part of the Content-Type
header field.They are NOT part of the
Content-Disposition header.
@param theKey The key for which the value will be returned.
@result The parameter value, nil if non-existent.
*/
- (id _Nullable) parameterForKey: (NSString * _Nullable) theKey;
/*!
@method setPrameter:forKey:
@discussion This method is used to set a parameter value
based on its name. The name serves as the key.
Parameters are only part of the Content-Type
header field. They are NOT part of the
Content-Disposition header.
@param theParameter The value of the parameter. A nil value
will remove any existing defined value
for the specified key,
@param theKey The key for which the value will be set.
*/
@method setPrameter:forKey:
@discussion This method is used to set a parameter value
based on its name. The name serves as the key.
Parameters are only part of the Content-Type
header field. They are NOT part of the
Content-Disposition header.
@param theParameter The value of the parameter. A nil value
will remove any existing defined value
for the specified key,
@param theKey The key for which the value will be set.
*/
- (void) setParameter: (NSString * _Nullable) theParameter forKey: (NSString * _Nonnull) theKey;
/*!
@method allHeaders
@discussion This method is used to return all header names / values.
@result The NSDictionary holding everything.
*/
@method allHeaders
@discussion This method is used to return all header names / values.
@result The NSDictionary holding everything.
*/
- (NSDictionary * _Nonnull) allHeaders;
/*!
@method headerValueForName:
@discussion This method is used to obtain the value
of the header specified by <i>theName</i>. The search
is performed in a case-insensitive way.
@param theName The name of the header. For example, it could be "Date".
@result The value of the header or nil if not found.
*/
@method headerValueForName:
@discussion This method is used to obtain the value
of the header specified by <i>theName</i>. The search
is performed in a case-insensitive way.
@param theName The name of the header. For example, it could be "Date".
@result The value of the header or nil if not found.
*/
- (id _Nullable) headerValueForName: (NSString * _Nonnull) theName;
/*!
@method setHeaders:
@discussion This method is used to add the headers of
<i>theHeaders</i> to the list of headers
of the receiver.
@param theHeaders The headers to add.
*/
@method setHeaders:
@discussion This method is used to add the headers of
<i>theHeaders</i> to the list of headers
of the receiver.
@param theHeaders The headers to add.
*/
- (void) setHeaders: (NSDictionary * _Nonnull) theHeaders;
@end


+ 546
- 546
pantomime-lib/Framework/Pantomime/CWParser.m
File diff suppressed because it is too large
View File


+ 248
- 251
pantomime-lib/Framework/Pantomime/CWPart.m View File

@ -1,24 +1,24 @@
/*
** CWPart.m
**
** Copyright (c) 2001-2007
**
** Author: Ludovic Marcotte <ludovic@Sophos.ca>
**
** 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 Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
** CWPart.m
**
** Copyright (c) 2001-2007
**
** Author: Ludovic Marcotte <ludovic@Sophos.ca>
**
** 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 Lesser General Public
** License along with this library; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#import "CWPart.h"
@ -49,19 +49,19 @@ static int currentPartVersion = 2;
- (id) init
{
self = [super init];
[CWPart setVersion: currentPartVersion];
self = [super init];
// 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 = _size = 0;
_content = nil;
return self;
[CWPart setVersion: currentPartVersion];
// 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 = _size = 0;
_content = nil;
return self;
}
@ -70,12 +70,12 @@ static int currentPartVersion = 2;
//
- (void) dealloc
{
RELEASE(_defaultCharset);
RELEASE(_parameters);
RELEASE(_headers);
RELEASE(_content);
RELEASE(_defaultCharset);
RELEASE(_parameters);
RELEASE(_headers);
RELEASE(_content);
//[super dealloc];
//[super dealloc];
}
@ -84,46 +84,43 @@ static int currentPartVersion = 2;
//
- (id) initWithData: (NSData *) theData
{
NSRange aRange;
NSRange aRange;
aRange = [theData rangeOfCString: "\n\n"];
if (aRange.length == 0)
aRange = [theData rangeOfCString: "\n\n"];
if (aRange.length == 0)
{
AUTORELEASE_VOID(self);
return nil;
}
// We initialize our message with the headers and the content
self = [self init];
[CWPart setVersion: currentPartVersion];
// 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)
AUTORELEASE_VOID(self);
return nil;
}
// We initialize our message with the headers and the content
self = [self init];
[CWPart setVersion: currentPartVersion];
// 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]];
return self;
[self setContent: [NSData data]];
return self;
}
[self setHeadersFromData:
[theData subdataWithRange: NSMakeRange(0,aRange.location)]];
[CWMIMEUtility setContentFromRawSource:
[theData subdataWithRange:
NSMakeRange(aRange.location + 2,
[theData length]-(aRange.location+2))]
inPart: self];
[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;
return self;
}
@ -133,11 +130,11 @@ static int currentPartVersion = 2;
- (id) initWithData: (NSData *) theData
charset: (NSString *) theCharset
{
[CWPart setVersion: currentPartVersion];
[CWPart setVersion: currentPartVersion];
[self setDefaultCharset: theCharset];
[self setDefaultCharset: theCharset];
return [self initWithData: theData];
return [self initWithData: theData];
}
@ -146,48 +143,48 @@ static int currentPartVersion = 2;
//
- (void) encodeWithCoder: (NSCoder *) theCoder
{
[CWPart setVersion: currentPartVersion];
[CWPart setVersion: currentPartVersion];
[theCoder encodeObject: [self contentType]];
[theCoder encodeObject: [self contentID]];
[theCoder encodeObject: [self contentDescription]];
[theCoder encodeObject: [NSNumber numberWithInt: [self contentDisposition]]];
[theCoder encodeObject: [self filename]];
[theCoder encodeObject: [NSNumber numberWithInteger: [self contentTransferEncoding]]];
[theCoder encodeObject: [self contentType]];
[theCoder encodeObject: [self contentID]];
[theCoder encodeObject: [self contentDescription]];
[theCoder encodeObject: [NSNumber numberWithInt: [self contentDisposition]]];
[theCoder encodeObject: [self filename]];
[theCoder encodeObject: [NSNumber numberWithInteger: [self contentTransferEncoding]]];
[theCoder encodeObject: [NSNumber numberWithInteger: [self format]]];
[theCoder encodeObject: [NSNumber numberWithInteger: _size]];
[theCoder encodeObject: [NSNumber numberWithInteger: _size]];
[theCoder encodeObject: [self boundary]];
[theCoder encodeObject: [self charset]];
[theCoder encodeObject: _defaultCharset];
[theCoder encodeObject: [self boundary]];
[theCoder encodeObject: [self charset]];
[theCoder encodeObject: _defaultCharset];
}
- (id) initWithCoder: (NSCoder *) theCoder
{
self = [super init];
self = [super init];
_headers = [[NSMutableDictionary alloc] initWithCapacity: 25];
_parameters = [[NSMutableDictionary alloc] init];
_headers = [[NSMutableDictionary alloc] initWithCapacity: 25];
_parameters = [[NSMutableDictionary alloc] init];
[self setContentType: [theCoder decodeObject]];
[self setContentID: [theCoder decodeObject]];
[self setContentDescription: [theCoder decodeObject]];
[self setContentDisposition: [[theCoder decodeObject] intValue]];
[self setFilename: [theCoder decodeObject]];
[self setContentType: [theCoder decodeObject]];
[self setContentID: [theCoder decodeObject]];
[self setContentDescription: [theCoder decodeObject]];
[self setContentDisposition: [[theCoder decodeObject] intValue]];
[self setFilename: [theCoder decodeObject]];
[self setContentTransferEncoding: [[theCoder decodeObject] intValue]];
[self setFormat: [[theCoder decodeObject] intValue]];
[self setSize: [[theCoder decodeObject] intValue]];
[self setContentTransferEncoding: [[theCoder decodeObject] intValue]];
[self setFormat: [[theCoder decodeObject] intValue]];
[self setSize: [[theCoder decodeObject] intValue]];
[self setBoundary: [theCoder decodeObject]];
[self setCharset: [theCoder decodeObject]];
[self setDefaultCharset: [theCoder decodeObject]];
[self setBoundary: [theCoder decodeObject]];
[self setCharset: [theCoder decodeObject]];
[self setDefaultCharset: [theCoder decodeObject]];
_content = nil;
_content = nil;
return self;
return self;
}
@ -196,7 +193,7 @@ static int currentPartVersion = 2;
//
- (NSObject *) content
{
return _content;
return _content;
}
@ -205,15 +202,15 @@ static int currentPartVersion = 2;
//
- (void) setContent: (NSObject *) theContent
{
if (theContent && !([theContent isKindOfClass: [NSData class]] ||
[theContent isKindOfClass: [CWMessage class]] ||
[theContent isKindOfClass: [CWMIMEMultipart class]]))
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."];
[NSException raise: NSInvalidArgumentException
format: @"Invalid argument to CWPart: -setContent: The content MUST be either a NSData, CWMessage or CWMIMEMessage instance."];
}
ASSIGN(_content, theContent);
ASSIGN(_content, theContent);
}
//
@ -221,14 +218,14 @@ static int currentPartVersion = 2;
//
- (NSString *) contentType
{
return [_headers objectForKey: @"Content-Type"];
return [_headers objectForKey: @"Content-Type"];
}
- (void) setContentType: (NSString*) theContentType
{
if (theContentType)
if (theContentType)
{
[_headers setObject: theContentType forKey: @"Content-Type"];
[_headers setObject: theContentType forKey: @"Content-Type"];
}
}
@ -237,15 +234,15 @@ static int currentPartVersion = 2;
//
- (NSString *) contentID
{
return [_headers objectForKey: @"Content-Id"];
return [_headers objectForKey: @"Content-Id"];
}
- (void) setContentID: (NSString *) theContentID
{
if (theContentID)
if (theContentID)
{
[_headers setObject: theContentID forKey: @"Content-Id"];
}
[_headers setObject: theContentID forKey: @"Content-Id"];
}
}
//
@ -253,15 +250,15 @@ static int currentPartVersion = 2;
//
- (NSString *) contentDescription
{
return [_headers objectForKey: @"Content-Description"];
return [_headers objectForKey: @"Content-Description"];
}
- (void) setContentDescription: (NSString *) theContentDescription
{
if (theContentDescription)
if (theContentDescription)
{
[_headers setObject: theContentDescription forKey: @"Content-Description"];
}
[_headers setObject: theContentDescription forKey: @"Content-Description"];
}
}
@ -270,16 +267,16 @@ static int currentPartVersion = 2;
//
- (PantomimeContentDisposition) contentDisposition
{
id o;
id o;
o = [_headers objectForKey: @"Content-Disposition"];
o = [_headers objectForKey: @"Content-Disposition"];
return (o ? [o intValue] : PantomimeAttachmentDisposition);
return (o ? [o intValue] : PantomimeAttachmentDisposition);
}
- (void) setContentDisposition: (PantomimeContentDisposition) theContentDisposition
{
[_headers setObject: [NSNumber numberWithInt: theContentDisposition] forKey: @"Content-Disposition"];
[_headers setObject: [NSNumber numberWithInt: theContentDisposition] forKey: @"Content-Disposition"];
}
@ -288,28 +285,28 @@ static int currentPartVersion = 2;
//
- (PantomimeEncoding) contentTransferEncoding
{
id o;
o = [_headers objectForKey: @"Content-Transfer-Encoding"];
id o;
if (o)
o = [_headers objectForKey: @"Content-Transfer-Encoding"];
if (o)
{
return [o intValue];
return [o intValue];
}
// Default value for the Content-Transfer-Encoding.
// See RFC2045 - 6.1. Content-Transfer-Encoding Syntax.
return PantomimeEncodingNone;
// Default value for the Content-Transfer-Encoding.
// See RFC2045 - 6.1. Content-Transfer-Encoding Syntax.
return PantomimeEncodingNone;
}
- (void) setContentTransferEncoding: (PantomimeEncoding) theEncoding
{
[_headers setObject: [NSNumber numberWithInt: theEncoding] forKey: @"Content-Transfer-Encoding"];
[_headers setObject: [NSNumber numberWithInt: theEncoding] forKey: @"Content-Transfer-Encoding"];
}
- (NSString *)filename
{
return [_parameters objectForKey: @"filename"];
return [_parameters objectForKey: @"filename"];
}
- (void)setFilename:(NSString *)theFilename
@ -327,21 +324,21 @@ static int currentPartVersion = 2;
//
- (PantomimeMessageFormat) format
{
id o;
id o;
o = [_parameters objectForKey: @"format"];
o = [_parameters objectForKey: @"format"];
if (o)
if (o)
{
return [o intValue];
return [o intValue];
}
return PantomimeFormatUnknown;
return PantomimeFormatUnknown;
}
- (void) setFormat: (PantomimeMessageFormat) theFormat
{
[_parameters setObject: [NSNumber numberWithInt: theFormat] forKey: @"format"];
[_parameters setObject: [NSNumber numberWithInt: theFormat] forKey: @"format"];
}
@ -350,12 +347,12 @@ static int currentPartVersion = 2;
//
- (NSUInteger) lineLength
{
return _line_length;
return _line_length;
}
- (void) setLineLength: (int) theLineLength
{
_line_length = theLineLength;
_line_length = theLineLength;
}
@ -363,33 +360,33 @@ static int currentPartVersion = 2;
// This method is used to very if the part is of the following primaryType / subType
//
- (BOOL) isMIMEType: (NSString *) thePrimaryType
subType: (NSString *) theSubType
subType: (NSString *) theSubType
{
NSString *aString;
NSString *aString;
if (![self contentType])
if (![self contentType])
{
return NO;//[self setContentType: @"text/plain"];
return NO;//[self setContentType: @"text/plain"];
}
if ([theSubType compare: @"*"] == NSOrderedSame)
if ([theSubType compare: @"*"] == NSOrderedSame)
{
if ([[self contentType] hasCaseInsensitivePrefix: thePrimaryType])
{
return YES;
}
if ([[self contentType] hasCaseInsensitivePrefix: thePrimaryType])
{
return YES;
}
}
else
else
{
aString = [NSString stringWithFormat: @"%@/%@", thePrimaryType, theSubType];
if ([aString caseInsensitiveCompare: [self contentType]] == NSOrderedSame)
{
return YES;
}
aString = [NSString stringWithFormat: @"%@/%@", thePrimaryType, theSubType];
if ([aString caseInsensitiveCompare: [self contentType]] == NSOrderedSame)
{
return YES;
}
}
return NO;
return NO;
}
@ -398,12 +395,12 @@ static int currentPartVersion = 2;
//
- (long) size
{
return _size;
return _size;
}
- (void) setSize: (NSInteger) theSize
{
_size = theSize;
_size = theSize;
}
- (NSData *)dataValue
@ -416,8 +413,8 @@ static int currentPartVersion = 2;
filename = [self filename];
} else {
filename = [[NSString alloc] initWithData: [CWMIMEUtility encodeWordUsingQuotedPrintable: [self filename]
prefixLength: 0]
encoding: NSASCIIStringEncoding];
prefixLength: 0]
encoding: NSASCIIStringEncoding];
}
// We encode our Content-Transfer-Encoding header.
@ -436,7 +433,7 @@ static int currentPartVersion = 2;
if ([self contentDescription]) {
[dataValue appendCString: "Content-Description: "];
[dataValue appendData: [CWMIMEUtility encodeWordUsingQuotedPrintable: [self contentDescription]
prefixLength: 21]];
prefixLength: 21]];
[dataValue appendCString: LF];
}
@ -545,7 +542,7 @@ static int currentPartVersion = 2;
} else if ([self contentTransferEncoding] == PantomimeEncodingBase64) {
dataToSend = [dataToSend encodeBase64WithLineLength: 72];
} else if (([self contentTransferEncoding] == PantomimeEncodingNone || [self contentTransferEncoding] == PantomimeEncoding8bit) &&
[self format] == PantomimeFormatFlowed) {
[self format] == PantomimeFormatFlowed) {
NSUInteger limit = _line_length;
if (limit < 2 || limit > 998) {
limit = 72;
@ -571,14 +568,14 @@ static int currentPartVersion = 2;
//
- (NSData *) boundary
{
return [_parameters objectForKey: @"boundary"];
return [_parameters objectForKey: @"boundary"];
}
- (void) setBoundary: (NSData *) theBoundary
{
if (theBoundary)
if (theBoundary)
{
[_parameters setObject: theBoundary forKey: @"boundary"];
[_parameters setObject: theBoundary forKey: @"boundary"];
}
}
@ -588,16 +585,16 @@ static int currentPartVersion = 2;
//
- (NSData *) protocol
{
return [_parameters objectForKey: @"protocol"];
//return _protocol;
return [_parameters objectForKey: @"protocol"];
//return _protocol;
}
- (void) setProtocol: (NSData *) theProtocol
{
//ASSIGN(_protocol, theProtocol);
if (theProtocol)
//ASSIGN(_protocol, theProtocol);
if (theProtocol)
{
[_parameters setObject: theProtocol forKey: @"protocol"];
[_parameters setObject: theProtocol forKey: @"protocol"];
}
}
@ -607,14 +604,14 @@ static int currentPartVersion = 2;
//
- (NSString *) charset
{
return [_parameters objectForKey: @"charset"];
return [_parameters objectForKey: @"charset"];
}
- (void) setCharset: (NSString *) theCharset
{
if (theCharset)
if (theCharset)
{
[_parameters setObject: theCharset forKey: @"charset"];
[_parameters setObject: theCharset forKey: @"charset"];
}
}
@ -624,7 +621,7 @@ static int currentPartVersion = 2;
//
- (NSString *) defaultCharset
{
return _defaultCharset;
return _defaultCharset;
}
@ -633,7 +630,7 @@ static int currentPartVersion = 2;
//
- (void) setDefaultCharset: (NSString *) theCharset
{
ASSIGN(_defaultCharset, theCharset);
ASSIGN(_defaultCharset, theCharset);
}
@ -642,61 +639,61 @@ static int currentPartVersion = 2;
//
- (void) setHeadersFromData: (NSData *) theHeaders
{
//NSAutoreleasePool *pool;
NSArray *allLines;
NSUInteger i, count;
if (!theHeaders || [theHeaders length] == 0)
//NSAutoreleasePool *pool;
NSArray *allLines;
NSUInteger i, count;
if (!theHeaders || [theHeaders length] == 0)
{
return;
return;
}
// We initialize a local autorelease pool
// We initialize a local autorelease pool
@autoreleasepool {
// We MUST be sure to unfold all headers properly before
// decoding the headers
theHeaders = [theHeaders unfoldLines];
// We MUST be sure to unfold all headers properly before
// decoding the headers
theHeaders = [theHeaders unfoldLines];
allLines = [theHeaders componentsSeparatedByCString: "\n"];
count = [allLines count];
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];
}
}
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);
}
@ -707,18 +704,18 @@ static int currentPartVersion = 2;
//
- (id) parameterForKey: (NSString *) theKey
{
return [_parameters objectForKey: theKey];
return [_parameters objectForKey: theKey];
}
- (void) setParameter: (NSString *) theParameter forKey: (NSString *) theKey
{
if (theParameter)
if (theParameter)
{
[_parameters setObject: theParameter forKey: theKey];
[_parameters setObject: theParameter forKey: theKey];
}
else
else
{
[_parameters removeObjectForKey: theKey];
[_parameters removeObjectForKey: theKey];
}
}
@ -727,7 +724,7 @@ static int currentPartVersion = 2;
//
- (NSDictionary *) allHeaders
{
return _headers;
return _headers;
}
//
@ -735,21 +732,21 @@ static int currentPartVersion = 2;
//
- (id) headerValueForName: (NSString *) theName
{
NSArray *allKeys;
NSUInteger count;
NSArray *allKeys;
NSUInteger count;
allKeys = [_headers allKeys];
count = [allKeys count];
allKeys = [_headers allKeys];
count = [allKeys count];
while (count--)
while (count--)
{
if ([[allKeys objectAtIndex: count] caseInsensitiveCompare: theName] == NSOrderedSame)
{
return [_headers objectForKey: [allKeys objectAtIndex: count]];
}
if ([[allKeys objectAtIndex: count] caseInsensitiveCompare: theName] == NSOrderedSame)
{
return [_headers objectForKey: [allKeys objectAtIndex: count]];
}
}
return nil;
return nil;
}
//
@ -757,13 +754,13 @@ static int currentPartVersion = 2;
//
- (void) setHeaders: (NSDictionary *) theHeaders
{
if (theHeaders)
if (theHeaders)
{
[_headers addEntriesFromDictionary: theHeaders];
[_headers addEntriesFromDictionary: theHeaders];
}
else
else
{
[_headers removeAllObjects];
[_headers removeAllObjects];
}
}


Loading…
Cancel
Save