| 1 |
footashida |
1.1 |
#import "DUMMail.h" |
| 2 |
|
|
|
| 3 |
|
|
@implementation DUMMail |
| 4 |
footashida |
1.2 |
// Private Method |
| 5 |
footashida |
1.1 |
-(void)parseMailData:(NSString *)mailData{ |
| 6 |
|
|
NSRange textRange; |
| 7 |
|
|
NSRange lineRange; |
| 8 |
|
|
NSString *line; |
| 9 |
|
|
|
| 10 |
|
|
textRange = NSMakeRange(0, [mailData length]); |
| 11 |
|
|
while(textRange.length > 0){ |
| 12 |
|
|
lineRange = [mailData lineRangeForRange: |
| 13 |
|
|
NSMakeRange(textRange.location, 0)]; |
| 14 |
|
|
line = [mailData substringWithRange:lineRange]; |
| 15 |
|
|
if([line hasPrefix:@"From: "]){ |
| 16 |
footashida |
1.2 |
from = [[DUMMailAddress alloc] |
| 17 |
|
|
initWithMailAddressString:[line substringFromIndex:[@"From: " length]]]; |
| 18 |
footashida |
1.1 |
[from retain]; |
| 19 |
|
|
}else if([line hasPrefix:@"To: "]){ |
| 20 |
footashida |
1.2 |
to = [[DUMMailAddress alloc] |
| 21 |
|
|
initWithMailAddressString:[line substringFromIndex:[@"To: " length]]]; |
| 22 |
footashida |
1.1 |
}else if([line hasPrefix:@"Subject: "]){ |
| 23 |
|
|
subject = [line substringFromIndex:[@"Subject: " length]]; |
| 24 |
|
|
[subject retain]; |
| 25 |
footashida |
1.2 |
}else if([line hasPrefix:@"Date: "]){ |
| 26 |
|
|
NSString *dateString = [line substringFromIndex:[@"Date: " length]]; |
| 27 |
|
|
date = [NSCalendarDate dateWithString:dateString |
| 28 |
|
|
calendarFormat:@"%a, %d %b %Y %H:%M:%S %z"]; |
| 29 |
|
|
[date retain]; |
| 30 |
footashida |
1.1 |
}else if([line isEqual:@"\r\n"]){ |
| 31 |
|
|
content = [mailData substringFromIndex:textRange.location]; |
| 32 |
|
|
[content retain]; |
| 33 |
|
|
return; |
| 34 |
|
|
}else{ |
| 35 |
|
|
//������ |
| 36 |
|
|
} |
| 37 |
|
|
|
| 38 |
|
|
textRange.location = NSMaxRange(lineRange); |
| 39 |
|
|
textRange.length -= lineRange.length; |
| 40 |
|
|
} |
| 41 |
|
|
} |
| 42 |
footashida |
1.2 |
// Public Method |
| 43 |
footashida |
1.1 |
-(id)initWithMailData:(NSString *)mailData{ |
| 44 |
|
|
self = [super init]; |
| 45 |
|
|
subject = nil; |
| 46 |
|
|
date = nil; |
| 47 |
|
|
content = nil; |
| 48 |
|
|
isUnread = YES; |
| 49 |
|
|
[self parseMailData:mailData]; |
| 50 |
|
|
return self; |
| 51 |
|
|
} |
| 52 |
|
|
-(void)dealloc{ |
| 53 |
|
|
[from release]; |
| 54 |
|
|
[to release]; |
| 55 |
|
|
[subject release]; |
| 56 |
|
|
[date release]; |
| 57 |
|
|
[content release]; |
| 58 |
|
|
[super dealloc]; |
| 59 |
|
|
} |
| 60 |
footashida |
1.2 |
-(DUMMailAddress *)from{ |
| 61 |
footashida |
1.1 |
return from; |
| 62 |
|
|
} |
| 63 |
footashida |
1.2 |
-(DUMMailAddress *)to{ |
| 64 |
footashida |
1.1 |
return to; |
| 65 |
|
|
} |
| 66 |
|
|
-(NSString *)subject{ |
| 67 |
|
|
return subject; |
| 68 |
|
|
} |
| 69 |
footashida |
1.2 |
-(NSCalendarDate *)date{ |
| 70 |
footashida |
1.1 |
return date; |
| 71 |
|
|
} |
| 72 |
|
|
-(NSString *)content{ |
| 73 |
|
|
return content; |
| 74 |
|
|
} |
| 75 |
|
|
-(BOOL)isUnread{ |
| 76 |
|
|
return isUnread; |
| 77 |
|
|
} |
| 78 |
|
|
-(void)setIsUnread:(BOOL)flag{ |
| 79 |
|
|
isUnread = flag; |
| 80 |
|
|
} |
| 81 |
|
|
- (NSString *)description{ |
| 82 |
|
|
return [NSString stringWithFormat:@"From:%@\nTo:%@\nSubject:%@\n%@" |
| 83 |
|
|
,from, to, subject, content]; |
| 84 |
|
|
} |
| 85 |
|
|
@end |