|
1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // cimaprfc822headerfields.cpp |
|
15 // |
|
16 |
|
17 #include "cimaprfc822headerfields.h" |
|
18 #include "cimapsessionconsts.h" |
|
19 |
|
20 class CDesC8Array; |
|
21 |
|
22 #include <imcvutil.h> |
|
23 #include <miuthdr.h> |
|
24 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
25 #include "timrfc822datefield.h" |
|
26 #endif |
|
27 |
|
28 CImapRfc822HeaderFields* CImapRfc822HeaderFields::NewL() |
|
29 { |
|
30 CImapRfc822HeaderFields* self = new (ELeave) CImapRfc822HeaderFields(); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(); |
|
33 CleanupStack::Pop(); |
|
34 return self; |
|
35 } |
|
36 |
|
37 CImapRfc822HeaderFields::CImapRfc822HeaderFields() |
|
38 { |
|
39 } |
|
40 |
|
41 void CImapRfc822HeaderFields::ConstructL() |
|
42 { |
|
43 CImapHeaderFields::ConstructL(EImapCountFields); |
|
44 } |
|
45 |
|
46 CImapRfc822HeaderFields::~CImapRfc822HeaderFields() |
|
47 { |
|
48 } |
|
49 |
|
50 /** |
|
51 Returns the value of the field identified by the supplied field index. |
|
52 If the field has not been populated, a null descriptor is returned. |
|
53 @param aFieldId index of the field value to return. |
|
54 @return The value of the filed or a null descriptor. |
|
55 */ |
|
56 EXPORT_C const TDesC8& CImapRfc822HeaderFields::FieldValue(THeaderFields aFieldId) |
|
57 { |
|
58 return CImapHeaderFields::FieldValue(aFieldId); |
|
59 } |
|
60 |
|
61 /** |
|
62 Returns whether the field identified by the supplied field index has been populated. |
|
63 This indicates whether the field value was supplied by the server. |
|
64 @param aFieldId index of the field value to return. |
|
65 @return Whether field has been populated. |
|
66 */ |
|
67 EXPORT_C TBool CImapRfc822HeaderFields::FieldExists(THeaderFields aFieldId) |
|
68 { |
|
69 return CImapHeaderFields::FieldExists(aFieldId); |
|
70 } |
|
71 |
|
72 /** |
|
73 Returns the numerical priority for an email based on the various priority fields that can |
|
74 be received in the header fields. |
|
75 If no priority is found, then the returned value will be set to medium priority. |
|
76 @return Extracted numerical priority. If no priority is found, then medium priority is returned. |
|
77 */ |
|
78 EXPORT_C TMsvPriority CImapRfc822HeaderFields::PriorityL() |
|
79 { |
|
80 CImcvUtils* imcvUtils = CImcvUtils::NewLC(); |
|
81 TMsvPriority priority(EMsvMediumPriority); |
|
82 |
|
83 if (FieldExists(EImapPriority)) |
|
84 { |
|
85 priority = imcvUtils->EvaluatePriorityText(FieldValue(EImapPriority)); |
|
86 } |
|
87 else if (FieldExists(EImapXPriority)) |
|
88 { |
|
89 priority = imcvUtils->EvaluatePriorityText(FieldValue(EImapXPriority)); |
|
90 } |
|
91 else if (FieldExists(EImapXMSMailPriority)) |
|
92 { |
|
93 priority = imcvUtils->EvaluatePriorityText(FieldValue(EImapXMSMailPriority)); |
|
94 } |
|
95 else if (FieldExists(EImapImportance)) |
|
96 { |
|
97 priority = imcvUtils->EvaluatePriorityText(FieldValue(EImapImportance)); |
|
98 } |
|
99 |
|
100 CleanupStack::PopAndDestroy(imcvUtils); |
|
101 |
|
102 return priority; |
|
103 } |
|
104 |
|
105 /** |
|
106 Returns a date for an email. If the 'date' header field exists, then this is used. If not, |
|
107 then a check is made to see if a 'received' header field exists containing a date. |
|
108 @return Date value. If no date found, then the date value will be set to 0. |
|
109 */ |
|
110 EXPORT_C TTime CImapRfc822HeaderFields::Date() |
|
111 { |
|
112 TTime date(0); |
|
113 TImRfc822DateField dateField; |
|
114 |
|
115 if (FieldExists(EImapDate)) |
|
116 { |
|
117 dateField.ParseDateField(FieldValue(EImapDate), date); |
|
118 } |
|
119 else if (FieldExists(EImapReceived)) |
|
120 { |
|
121 TPtrC8 ptr(FieldValue(EImapReceived)); |
|
122 |
|
123 _LIT8(KSemiColonSpace, "; "); |
|
124 TInt semicolonPos = ptr.Find(KSemiColonSpace); |
|
125 |
|
126 if (semicolonPos >= 0) |
|
127 { |
|
128 ptr.Set(ptr.Right(ptr.Length() - semicolonPos - 2)); |
|
129 |
|
130 if (ptr.Length() > 0) |
|
131 { |
|
132 dateField.ParseDateField(ptr, date); |
|
133 } |
|
134 } |
|
135 } |
|
136 |
|
137 return date; |
|
138 } |
|
139 |
|
140 /** |
|
141 Returns the return receipt value from the header fields based on the various 'return receipt' |
|
142 header fields that can be received. |
|
143 @return Return receipt field value. Null descriptor if no 'return receipt' fields exist. |
|
144 */ |
|
145 EXPORT_C const TDesC8& CImapRfc822HeaderFields::ReturnReceiptField() |
|
146 { |
|
147 if (FieldExists(EImapReturnReceiptTo)) |
|
148 { |
|
149 return FieldValue(EImapReturnReceiptTo); |
|
150 } |
|
151 |
|
152 if (FieldExists(EImapXReturnReceiptTo)) |
|
153 { |
|
154 return FieldValue(EImapXReturnReceiptTo); |
|
155 } |
|
156 |
|
157 if (FieldExists(EImapDispositionNotificationTo)) |
|
158 { |
|
159 return FieldValue(EImapDispositionNotificationTo); |
|
160 } |
|
161 |
|
162 return KNullDesC8(); |
|
163 } |
|
164 |
|
165 |
|
166 TInt CImapRfc822HeaderFields::Match(const TDesC8& aFieldName, TBool& /*aNeedToStripSpaces*/) |
|
167 { |
|
168 THeaderFields fieldId; |
|
169 |
|
170 if (aFieldName.CompareF(KImapTxtFrom) == 0) |
|
171 { |
|
172 fieldId = EImapFrom; |
|
173 } |
|
174 else if (aFieldName.CompareF(KImapTxtReplyTo) == 0) |
|
175 { |
|
176 fieldId = EImapReplyTo; |
|
177 } |
|
178 else if (aFieldName.CompareF(KImapTxtTo) == 0) |
|
179 { |
|
180 fieldId = EImapTo; |
|
181 } |
|
182 else if (aFieldName.CompareF(KImapTxtCc) == 0) |
|
183 { |
|
184 fieldId = EImapCc; |
|
185 } |
|
186 else if (aFieldName.CompareF(KImapTxtBcc) == 0) |
|
187 { |
|
188 fieldId = EImapBcc; |
|
189 } |
|
190 else if (aFieldName.CompareF(KImapTxtSubject) == 0) |
|
191 { |
|
192 fieldId = EImapSubject; |
|
193 } |
|
194 else if (aFieldName.CompareF(KImapTxtReceived) == 0) |
|
195 { |
|
196 fieldId = EImapReceived; |
|
197 } |
|
198 else if (aFieldName.CompareF(KImapTxtDate) == 0) |
|
199 { |
|
200 fieldId = EImapDate; |
|
201 } |
|
202 else if (aFieldName.CompareF(KImapTxtMessageId) == 0) |
|
203 { |
|
204 fieldId = EImapMessageId; |
|
205 } |
|
206 else if (aFieldName.CompareF(KImapTxtXMailer) == 0) |
|
207 { |
|
208 fieldId = EImapXMailer; |
|
209 } |
|
210 else if (aFieldName.CompareF(KImapTxtPriority) == 0) |
|
211 { |
|
212 fieldId = EImapPriority; |
|
213 } |
|
214 else if (aFieldName.CompareF(KImapTxtXPriority) == 0) |
|
215 { |
|
216 fieldId = EImapXPriority; |
|
217 } |
|
218 else if (aFieldName.CompareF(KImapTxtXMSMailPriority) == 0) |
|
219 { |
|
220 fieldId = EImapXMSMailPriority; |
|
221 } |
|
222 else if (aFieldName.CompareF(KImapTxtPrecedence) == 0) |
|
223 { |
|
224 fieldId = EImapPrecedence; |
|
225 } |
|
226 else if (aFieldName.CompareF(KImapTxtImportance) == 0) |
|
227 { |
|
228 fieldId = EImapImportance; |
|
229 } |
|
230 else if (aFieldName.CompareF(KImapTxtReturnReceiptTo) == 0) |
|
231 { |
|
232 fieldId = EImapReturnReceiptTo; |
|
233 } |
|
234 else if (aFieldName.CompareF(KImapTxtXReturnReceiptTo) == 0) |
|
235 { |
|
236 fieldId = EImapXReturnReceiptTo; |
|
237 } |
|
238 else if (aFieldName.CompareF(KImapTxtDispositionNotificationTo) == 0) |
|
239 { |
|
240 fieldId = EImapDispositionNotificationTo; |
|
241 } |
|
242 else if (aFieldName.CompareF(KImapTxtDispositionNotificationOptions) == 0) |
|
243 { |
|
244 fieldId = EImapDispositionNotificationOptions; |
|
245 } |
|
246 else |
|
247 { |
|
248 return KErrNotFound; |
|
249 } |
|
250 |
|
251 return fieldId; |
|
252 } |