|
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 // |
|
15 |
|
16 #include "cimapmimeheaderfields.h" |
|
17 #include "cimapsessionconsts.h" |
|
18 |
|
19 CImapMimeHeaderFields* CImapMimeHeaderFields::NewL() |
|
20 { |
|
21 CImapMimeHeaderFields* self = new (ELeave) CImapMimeHeaderFields(); |
|
22 CleanupStack::PushL(self); |
|
23 self->ConstructL(); |
|
24 CleanupStack::Pop(); |
|
25 return self; |
|
26 } |
|
27 |
|
28 CImapMimeHeaderFields::CImapMimeHeaderFields() |
|
29 { |
|
30 } |
|
31 |
|
32 void CImapMimeHeaderFields::ConstructL() |
|
33 { |
|
34 CImapHeaderFields::ConstructL(EImapCountFields); |
|
35 } |
|
36 |
|
37 CImapMimeHeaderFields::~CImapMimeHeaderFields() |
|
38 { |
|
39 iImapUnmatchedNameArray.ResetAndDestroy(); |
|
40 iImapUnmatchedValueArray.ResetAndDestroy(); |
|
41 } |
|
42 |
|
43 /** |
|
44 Returns the value of the field identified by the supplied field index. |
|
45 If the field has not been populated, a null descriptor is returned. |
|
46 @param aFieldId index of the field value to return. |
|
47 @return The value of the filed or a null descriptor. |
|
48 */ |
|
49 EXPORT_C const TDesC8& CImapMimeHeaderFields::FieldValue(THeaderFields aFieldId) |
|
50 { |
|
51 return CImapHeaderFields::FieldValue(aFieldId); |
|
52 } |
|
53 |
|
54 /** |
|
55 Returns whether the field identified by the supplied field index has been populated. |
|
56 This indicates whether the field value was supplied by the server. |
|
57 @param aFieldId index of the field value to return. |
|
58 @return Whether field has been populated. |
|
59 */ |
|
60 EXPORT_C TBool CImapMimeHeaderFields::FieldExists(THeaderFields aFieldId) |
|
61 { |
|
62 return CImapHeaderFields::FieldExists(aFieldId); |
|
63 } |
|
64 |
|
65 TBool CImapMimeHeaderFields::SetFieldL(const TDesC8& aFieldName, HBufC8* aValue) |
|
66 { |
|
67 // Take a copy of the value, as CImapHeaderFields::SetFieldL takes |
|
68 // ownership of it and may destroy it. |
|
69 HBufC8* valueCopy = (*aValue).AllocLC(); |
|
70 |
|
71 if (CImapHeaderFields::SetFieldL(aFieldName, aValue)) |
|
72 { |
|
73 CleanupStack::PopAndDestroy(valueCopy); |
|
74 return ETrue; |
|
75 } |
|
76 |
|
77 // Try to find the name in the unmatched name list |
|
78 for (TInt pos(0); pos < iImapUnmatchedNameArray.Count(); ++pos) |
|
79 { |
|
80 if (iImapUnmatchedNameArray[pos]->CompareF(aFieldName) == 0) |
|
81 { |
|
82 // The name has been found. Replace the corresponding value |
|
83 // with the new one. Ownership is passed to the array. |
|
84 delete iImapUnmatchedValueArray[pos]; |
|
85 iImapUnmatchedValueArray[pos] = valueCopy; |
|
86 CleanupStack::Pop(valueCopy); |
|
87 return ETrue; |
|
88 } |
|
89 } |
|
90 |
|
91 // The name has not been found. We need to add a new entry to the |
|
92 // unmatched lists. |
|
93 HBufC8* name = aFieldName.AllocLC(); |
|
94 |
|
95 // Append name to field name array. We pass ownership to the array. |
|
96 iImapUnmatchedNameArray.AppendL(name); |
|
97 CleanupStack::Pop(name); |
|
98 |
|
99 // Append value to field value array. We pass ownership to the array. |
|
100 iImapUnmatchedValueArray.AppendL(valueCopy); |
|
101 CleanupStack::Pop(valueCopy); |
|
102 |
|
103 return ETrue; |
|
104 } |
|
105 |
|
106 void CImapMimeHeaderFields::RestartGetNextField() |
|
107 { |
|
108 iGetNextFieldPos = 0; |
|
109 } |
|
110 |
|
111 TBool CImapMimeHeaderFields::GetNextField(TPtrC8& aFieldName, TPtrC8& aValue) |
|
112 { |
|
113 TBool found(EFalse); |
|
114 |
|
115 while (!found && (iGetNextFieldPos < EImapCountFields)) |
|
116 { |
|
117 if (CImapHeaderFields::FieldExists(iGetNextFieldPos)) |
|
118 { |
|
119 aFieldName.Set(FieldNameFromId(static_cast<THeaderFields>(iGetNextFieldPos))); |
|
120 aValue.Set(CImapHeaderFields::FieldValue(iGetNextFieldPos)); |
|
121 found = ETrue; |
|
122 } |
|
123 |
|
124 ++iGetNextFieldPos; |
|
125 } |
|
126 |
|
127 if (!found) |
|
128 { |
|
129 TInt offset(iGetNextFieldPos - EImapCountFields); |
|
130 |
|
131 if (offset < iImapUnmatchedNameArray.Count()) |
|
132 { |
|
133 aFieldName.Set(*iImapUnmatchedNameArray[offset]); |
|
134 aValue.Set(*iImapUnmatchedValueArray[offset]); |
|
135 found = ETrue; |
|
136 } |
|
137 } |
|
138 |
|
139 ++iGetNextFieldPos; |
|
140 |
|
141 return found; |
|
142 } |
|
143 |
|
144 TInt CImapMimeHeaderFields::Match(const TDesC8& aFieldName, TBool& aNeedToStripSpaces) |
|
145 { |
|
146 THeaderFields fieldId; |
|
147 |
|
148 if (aFieldName.CompareF(KImapTxtContentBase) == 0) |
|
149 { |
|
150 fieldId = EImapContentBase; |
|
151 aNeedToStripSpaces = ETrue; |
|
152 } |
|
153 else if (aFieldName.CompareF(KImapTxtContentLocation) == 0) |
|
154 { |
|
155 fieldId = EImapContentLocation; |
|
156 aNeedToStripSpaces = ETrue; |
|
157 } |
|
158 else |
|
159 { |
|
160 return KErrNotFound; |
|
161 } |
|
162 |
|
163 return fieldId; |
|
164 } |
|
165 |
|
166 const TDesC8& CImapMimeHeaderFields::FieldNameFromId(THeaderFields aFieldId) |
|
167 { |
|
168 switch (aFieldId) |
|
169 { |
|
170 case EImapContentBase: |
|
171 { |
|
172 return KImapTxtContentBase(); |
|
173 } |
|
174 |
|
175 case EImapContentLocation: |
|
176 { |
|
177 return KImapTxtContentLocation(); |
|
178 } |
|
179 |
|
180 default: |
|
181 { |
|
182 break; |
|
183 } |
|
184 } |
|
185 |
|
186 return KNullDesC8(); |
|
187 } |