Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
remove some useless methods from message
Browse files Browse the repository at this point in the history
  • Loading branch information
mgax committed Apr 11, 2010
1 parent a7b783e commit 134225e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 78 deletions.
8 changes: 0 additions & 8 deletions letterbox/source/LBMIMEMessage.h
Expand Up @@ -65,14 +65,6 @@
// Returns boundary that separates subparts
- (NSString*)multipartBoundary;

- (NSArray*)types;
- (NSString *)availableTypeFromArray:(NSArray *)types;
- (LBMIMEMessage*)partForType:(NSString*)mimeType;
- (LBMIMEMessage*)availablePartForTypeFromArray:(NSArray*) types;

// the MIME spec says the alternative parts are ordered from least faithful to the most faithful. we can only presume the sender has done that correctly. consider this a guess rather than being definitive.
- (NSString*)mostFailthfulAlternativeType;

// Get a parameter from the "Content-Type" header.
- (NSString*)contentTypeAttribute:(NSString*)attribName;

Expand Down
56 changes: 0 additions & 56 deletions letterbox/source/LBMIMEMessage.m
Expand Up @@ -103,62 +103,6 @@ - (NSString*)multipartBoundary {
return [self contentTypeAttribute:@"boundary"];
}

- (NSArray*) types {
NSMutableArray *types = [NSMutableArray array];
for (LBMIMEMessage *part in self.subparts) {
if ([part contentType]) {
[types addObject: part.contentType];
}
}

return types;
}

- (NSString *)availableTypeFromArray:(NSArray *)types {
NSArray *availableTypes = [self types];
for (NSString *type in types) {
if ([availableTypes containsObject: type]) {
return type;
}
}

return nil;
}

- (LBMIMEMessage*)availablePartForTypeFromArray:(NSArray*)types {

for (NSString *type in types) {
LBMIMEMessage *part = [self partForType:type];
if (part) {
return part;
}
}

return nil;
}

- (LBMIMEMessage*)partForType:(NSString*)mimeType {

if ([[self contentType] hasPrefix:mimeType]) {
return self;
}

if ([self isMultipart]) {
for (LBMIMEMessage *part in self.subparts) {
if ([[part contentType] hasPrefix:mimeType]) {
return part;
}
}
}

return nil;
}

// the MIME spec says the alternative parts are ordered from least faithful to the most faithful. we can only presume the sender has done that correctly. consider this a guess rather than being definitive.
- (NSString*)mostFailthfulAlternativeType {
return [[self.subparts lastObject] contentType];
}

- (NSString*)contentTypeAttribute:(NSString*)attribName {
// TODO: this function needs a battery of unit tests
NSString *attribString = nil;
Expand Down
16 changes: 2 additions & 14 deletions letterbox/tests/LBMessageTests.m
Expand Up @@ -38,10 +38,7 @@ - (void) testSomeMultipartYo {
GHAssertTrue([[[[mm subparts] objectAtIndex:0] contentType] hasPrefix:@"multipart/alternative"], @"the type of the first subpart");
GHAssertTrue([[[[mm subparts] objectAtIndex:1] contentType] hasPrefix:@"text/plain"], @"the type of the second subpart");

LBMIMEMessage *nosuchpart = [mm partForType: @"image/jpeg"];
GHAssertNil(nosuchpart, @"no such part");

LBMIMEMessage *altpart = [mm partForType: @"multipart/alternative"];
LBMIMEMessage *altpart = [[mm subparts] objectAtIndex:0];
GHAssertNotNil(altpart, @"the alternative part");
GHAssertTrue([[altpart subparts] count] == 2, @"two sub-parts in altpart");

Expand All @@ -57,19 +54,10 @@ - (void) testSomeMultipartYo {
GHAssertTrue([html_content rangeOfString:@"<blockquote type=\"cite\">Also, let's learn some IMAP."].location != NSNotFound, @"subpart_html contains the right substring");
GHAssertTrue([html_content hasSuffix:@"<br>Boone</div></body></html>"], @"subpart_html ends with the right text");

LBMIMEMessage *textpart = [mm availablePartForTypeFromArray:[NSArray arrayWithObjects: @"text/plain", @"text/html", nil]];

LBMIMEMessage *textpart = [[mm subparts] objectAtIndex:1];
GHAssertNotNil(textpart, @"the part");


GHAssertEqualStrings([textpart content], @"Hello sir, this is the content, and honestly it isn't much. Sorry.\n\nLinebreak!", @"Checking the content");

textpart = [mm availablePartForTypeFromArray:[NSArray arrayWithObjects: @"multipart/alternative", nil]];


GHAssertNotNil(textpart, @"the multipart part");


}

- (void) testBoundaryWarts {
Expand Down

0 comments on commit 134225e

Please sign in to comment.