-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathATFieldBody.m
More file actions
145 lines (116 loc) · 4.09 KB
/
ATFieldBody.m
File metadata and controls
145 lines (116 loc) · 4.09 KB
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
//
// ATFieldBody.m
// ATMail
//
// Created by 高田 明史 on 06/03/11.
// Copyright 2006 __MyCompanyName__. All rights reserved.
//
#import "ATFieldBody.h"
#import "ATTokenScanner.h"
#import "ATUnstructuredFieldBody.h"
#import "ATMailboxListFieldBody.h"
#import "ATAddressListFieldBody.h"
#import "ATKeywordsFieldBody.h"
#import "ATMailboxFieldBody.h"
#import "ATBccFieldBody.h"
#import "ATMsgIDFieldBody.h"
#import "ATPathFieldBody.h"
#import "ATReceivedFieldBody.h"
#import "ATMIMEVersionFieldBody.h"
#import "ATContentTypeFieldBody.h"
#import "ATContentTransferEncodingFieldBody.h"
#import "ATContentIDFieldBody.h"
#import "ATContentDescriptionFieldBody.h"
#import "ATMIMETokenScanner.h"
#import "ATDateTimeFieldBody.h"
#import "ATContentDispositionFieldBody.h"
static NSMutableDictionary *fieldBodyClassDictionary;
@implementation ATFieldBody
+ (void)initialize
{
fieldBodyClassDictionary = [NSMutableDictionary new];
[self setFieldBody:[ATDateTimeFieldBody class] forName:@"date"];
[self setFieldBody:[ATMailboxListFieldBody class] forName:@"from"];
[self setFieldBody:[ATAddressListFieldBody class] forName:@"to"];
[self setFieldBody:[ATKeywordsFieldBody class] forName:@"keywords"];
[self setFieldBody:[ATMailboxFieldBody class] forName:@"sender"];
[self setFieldBody:[ATAddressListFieldBody class] forName:@"reply-to"];
[self setFieldBody:[ATAddressListFieldBody class] forName:@"cc"];
[self setFieldBody:[ATBccFieldBody class] forName:@"bcc"];
[self setFieldBody:[ATMsgIDFieldBody class] forName:@"message-id"];
[self setFieldBody:[ATMsgIDFieldBody class] forName:@"in-reply-to"];
[self setFieldBody:[ATMsgIDFieldBody class] forName:@"references"];
[self setFieldBody:[ATDateTimeFieldBody class] forName:@"resent-date"];
[self setFieldBody:[ATMailboxListFieldBody class] forName:@"resent-from"];
[self setFieldBody:[ATMailboxFieldBody class] forName:@"resent-sender"];
[self setFieldBody:[ATAddressListFieldBody class] forName:@"resent-to"];
[self setFieldBody:[ATBccFieldBody class] forName:@"resent-bcc"];
[self setFieldBody:[ATMsgIDFieldBody class] forName:@"resent-msg-id"];
[self setFieldBody:[ATPathFieldBody class] forName:@"return-path"];
[self setFieldBody:[ATReceivedFieldBody class] forName:@"received"];
[self setFieldBody:[ATMIMEVersionFieldBody class] forName:@"MIME-Version"];
[self setFieldBody:[ATContentTypeFieldBody class] forName:@"Content-Type"];
[self setFieldBody:[ATContentTransferEncodingFieldBody class] forName:@"Content-Transfer-Encoding"];
[self setFieldBody:[ATContentIDFieldBody class] forName:@"Content-ID"];
[self setFieldBody:[ATContentDescriptionFieldBody class] forName:@"Content-Description"];
[self setFieldBody:[ATContentDispositionFieldBody class] forName:@"Content-Disposition"];
}
+ (void)setFieldBody:(Class)aFieldBodyClass forName:(NSString *)aName
{
[fieldBodyClassDictionary setObject:aFieldBodyClass forKey:[aName lowercaseString]];
}
+ (Class)fieldBodyForName:(NSString *)aName
{
if (aName)
{
Class aFieldBodyClass = [fieldBodyClassDictionary objectForKey:[aName lowercaseString]];
return aFieldBodyClass ? aFieldBodyClass : [ATUnstructuredFieldBody class];
}
else
return [ATFieldBody class];
}
@end
@implementation ATFieldBody (Initializing)
- (id)init
{
return [self initWithFoldedLine:[NSMutableString string]];;
}
- (id)initWith:(NSString *)aString
{
return [self initWithFoldedLine:aString];
}
- (id)initWithFoldedLine:(NSString *)aString
{
[super init];
[self setValue:[[aString mutableCopy] autorelease]];
return self;
}
- (void)dealloc
{
[self setValue:nil];
[super dealloc];
}
@end
@implementation ATFieldBody (Accessing)
- (void)setValue:(NSMutableString *)aString
{
[value release];
value = [aString retain];
}
- (NSMutableString *)value
{
return value;
}
- (NSString *)stringValue
{
return [self value];
}
- (NSAttributedString *)attributedString
{
return [[[NSAttributedString alloc] initWithString:[self stringValue] attributes:[NSDictionary dictionaryWithObject:[NSColor redColor] forKey:NSForegroundColorAttributeName]] autorelease];
}
- (void)addLine:(NSString *)aLine
{
[[self value] appendString:aLine];
}
@end