|
1 /* |
|
2 * Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * CUniMimeInfo, Storage for objects mime headers. |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // ========== INCLUDE FILES ================================ |
|
22 |
|
23 #include <e32def.h> // for basic types |
|
24 #include <eikenv.h> // for CBase |
|
25 #include <msvstd.h> // for TMsvId |
|
26 #include <msvids.h> // for KMsvTempIndexEntryId |
|
27 |
|
28 #include <mmsvattachmentmanager.h> |
|
29 #include <cmsvattachment.h> |
|
30 #include <cmsvmimeheaders.h> |
|
31 |
|
32 #include "msgtextutils.h" |
|
33 #include "UniModelConst.h" |
|
34 #include "UniDataUtils.h" |
|
35 #include "UniMimeInfo.h" |
|
36 |
|
37 // ========== EXTERNAL DATA STRUCTURES ===================== |
|
38 |
|
39 // ========== EXTERNAL FUNCTION PROTOTYPES ================= |
|
40 |
|
41 // ========== CONSTANTS ==================================== |
|
42 |
|
43 // Maximum num of characters for descriptors stored in HBufC members |
|
44 const TInt KMaxMimeFieldLength = 260; |
|
45 const TInt KMaxContentLocation = 100; // Max byte size for content location |
|
46 |
|
47 // From RFC2183. Content-Disposition filename max length. |
|
48 // Does not need special handling. |
|
49 //const TInt KMaxMimeFieldParamLength = 78; |
|
50 |
|
51 // ========== MACROS ======================================= |
|
52 |
|
53 // ========== LOCAL CONSTANTS AND MACROS =================== |
|
54 |
|
55 // ========== MODULE DATA STRUCTURES ======================= |
|
56 |
|
57 |
|
58 // ========== LOCAL FUNCTION PROTOTYPES ==================== |
|
59 |
|
60 // ========== LOCAL FUNCTIONS ============================== |
|
61 |
|
62 // ========== MEMBER FUNCTIONS ============================= |
|
63 |
|
64 |
|
65 // --------------------------------------------------------- |
|
66 // CUniMimeInfo |
|
67 // |
|
68 // Constructor |
|
69 // --------------------------------------------------------- |
|
70 // |
|
71 CUniMimeInfo::CUniMimeInfo() : iContentTypeCharset(0) |
|
72 { |
|
73 } |
|
74 |
|
75 // --------------------------------------------------------- |
|
76 // CUniMimeInfo |
|
77 // |
|
78 // Destructor. |
|
79 // --------------------------------------------------------- |
|
80 // |
|
81 CUniMimeInfo::~CUniMimeInfo() |
|
82 { |
|
83 delete iContentDescription; |
|
84 delete iContentBase; |
|
85 delete iContentLocation; |
|
86 delete iContentId; |
|
87 delete iContentType; |
|
88 delete iContentDisposition; |
|
89 } |
|
90 |
|
91 |
|
92 // --------------------------------------------------------- |
|
93 // Accessors/Mutators |
|
94 // --------------------------------------------------------- |
|
95 |
|
96 // --------------------------------------------------------- |
|
97 // SetContentTypeL |
|
98 // NOTE: 8 bit. |
|
99 // --------------------------------------------------------- |
|
100 void CUniMimeInfo::SetContentTypeL( const TDesC8& aSourceDesc ) |
|
101 { |
|
102 if ( aSourceDesc.Length() > KMaxMimeFieldLength ) |
|
103 User::Leave( KErrArgument ); |
|
104 |
|
105 HBufC8* buf = aSourceDesc.AllocL(); |
|
106 delete iContentType; |
|
107 iContentType = buf; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------- |
|
111 // SetContentLocationL |
|
112 // NOTE: 16 bit. |
|
113 // --------------------------------------------------------- |
|
114 void CUniMimeInfo::SetContentLocationL( const TDesC& aSourceDesc ) |
|
115 { |
|
116 TInt copyLen = aSourceDesc.Length(); |
|
117 if ( copyLen > KMaxContentLocation ) |
|
118 { |
|
119 copyLen = KMaxContentLocation; |
|
120 } |
|
121 |
|
122 HBufC* buf = HBufC::NewL( copyLen ); |
|
123 *buf = aSourceDesc.Left( copyLen ); |
|
124 delete iContentLocation; |
|
125 iContentLocation = buf; |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // SetContentIdL |
|
130 // NOTE: 8 bit. |
|
131 // --------------------------------------------------------- |
|
132 void CUniMimeInfo::SetContentIdL( const TDesC8& aSourceDesc ) |
|
133 { |
|
134 if ( aSourceDesc.Length() > KMaxMimeFieldLength ) |
|
135 User::Leave( KErrArgument ); |
|
136 |
|
137 HBufC8* buf = aSourceDesc.AllocL(); |
|
138 delete iContentId; |
|
139 iContentId = buf; |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------- |
|
143 // SetContentBaseL |
|
144 // NOTE: 8 bit. |
|
145 // --------------------------------------------------------- |
|
146 void CUniMimeInfo::SetContentBaseL( const TDesC8& aSourceDesc ) |
|
147 { |
|
148 if ( aSourceDesc.Length() > KMaxMimeFieldLength ) |
|
149 User::Leave( KErrArgument ); |
|
150 |
|
151 HBufC8* buf = aSourceDesc.AllocL(); |
|
152 delete iContentBase; |
|
153 iContentBase = buf; |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------- |
|
157 // SetContentDescriptionL |
|
158 // NOTE: 8 bit. |
|
159 // --------------------------------------------------------- |
|
160 void CUniMimeInfo::SetContentDescriptionL( const TDesC8& aSourceDesc ) |
|
161 { |
|
162 if ( aSourceDesc.Length() > KMaxMimeFieldLength ) |
|
163 User::Leave( KErrArgument ); |
|
164 |
|
165 HBufC8* buf = aSourceDesc.AllocL(); |
|
166 delete iContentDescription; |
|
167 iContentDescription = buf; |
|
168 } |
|
169 |
|
170 // --------------------------------------------------------- |
|
171 // SetContentDispositionL |
|
172 // NOTE: 8 bit. |
|
173 // --------------------------------------------------------- |
|
174 void CUniMimeInfo::SetContentDispositionL( const TDesC8& aSourceDesc ) |
|
175 { |
|
176 if ( aSourceDesc.Length() > KMaxMimeFieldLength ) |
|
177 User::Leave( KErrArgument ); |
|
178 |
|
179 HBufC8* buf = aSourceDesc.AllocL(); |
|
180 delete iContentDisposition; |
|
181 iContentDisposition = buf; |
|
182 } |
|
183 |
|
184 // --------------------------------------------------------- |
|
185 // Size |
|
186 // --------------------------------------------------------- |
|
187 TInt CUniMimeInfo::Size() const |
|
188 { |
|
189 // TODO: Check that MIME info size matches to the actual |
|
190 // MIME header size |
|
191 //TInt size = sizeof( iContentTypeCharset ); |
|
192 TInt size = sizeof( TUint32 ); // mmsengine uses this |
|
193 |
|
194 if ( iContentDescription ) size += iContentDescription->Size(); |
|
195 |
|
196 if ( iContentBase ) size += iContentBase->Size(); |
|
197 |
|
198 if ( iContentLocation ) size += iContentLocation->Size(); |
|
199 |
|
200 if ( iContentId ) size += iContentId->Size(); |
|
201 |
|
202 if ( iContentType ) size += iContentType->Size(); |
|
203 |
|
204 if ( iContentDisposition ) size += iContentDisposition->Size(); |
|
205 |
|
206 return size; |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------- |
|
210 // CUniMimeInfo::SaveMimeInfoL |
|
211 // |
|
212 // Save MIME info |
|
213 // --------------------------------------------------------- |
|
214 // |
|
215 void CUniMimeInfo::SaveMimeInfoL( MMsvAttachmentManager& aManager, CMsvAttachment& aAttachment ) |
|
216 { |
|
217 // Content-Location. |
|
218 HBufC* safeContentLocation = CMsgTextUtils::GetSafeAttachmentNameLC( |
|
219 aManager, |
|
220 ContentLocation(), |
|
221 aAttachment.Id(), |
|
222 ETrue ); |
|
223 SetContentLocationL( *safeContentLocation ); |
|
224 CleanupStack::PopAndDestroy( safeContentLocation ); |
|
225 |
|
226 CMsvMimeHeaders* msvMime = CMsvMimeHeaders::NewLC(); |
|
227 msvMime->RestoreL( aAttachment ); |
|
228 |
|
229 msvMime->SetContentLocationL( *iContentLocation ); |
|
230 |
|
231 // Content-type |
|
232 if ( iContentType ) |
|
233 { |
|
234 TInt slash = iContentType->Locate( '/' ); |
|
235 if ( slash != KErrNotFound ) |
|
236 { |
|
237 msvMime->SetContentTypeL( iContentType->Left( slash ) ); |
|
238 msvMime->SetContentSubTypeL( iContentType->Mid( slash + 1 ) ); |
|
239 } |
|
240 } |
|
241 |
|
242 // Character set |
|
243 if ( iContentTypeCharset ) |
|
244 { |
|
245 msvMime->SetMimeCharset( iContentTypeCharset ); |
|
246 } |
|
247 // Content-Id |
|
248 if ( iContentId && iContentId->Length() ) |
|
249 { |
|
250 msvMime->SetContentIdL( *iContentId ); |
|
251 } |
|
252 // Content-Description |
|
253 if ( iContentDescription && iContentDescription->Length() ) |
|
254 { |
|
255 msvMime->SetContentDescriptionL( *iContentDescription ); |
|
256 } |
|
257 // Content-Base |
|
258 if ( iContentBase && iContentBase->Length() ) |
|
259 { |
|
260 msvMime->SetContentBaseL( *iContentBase ); |
|
261 } |
|
262 // Content-Disposition |
|
263 if ( iContentDisposition && iContentDisposition->Length() ) |
|
264 { |
|
265 msvMime->SetContentDispositionL( *iContentDisposition ); |
|
266 } |
|
267 msvMime->StoreL( aAttachment ); |
|
268 CleanupStack::PopAndDestroy( msvMime ); |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------- |
|
272 // CUniMimeInfo::DoReadMimeInfoL |
|
273 // |
|
274 // Reads mime info from clientMtm to aMimeInfo. |
|
275 // If function leaves whole MimeInfo object should be considered |
|
276 // invalid. |
|
277 // --------------------------------------------------------- |
|
278 // |
|
279 |
|
280 void CUniMimeInfo::ReadMimeInfoL( CMsvAttachment& aAttachment ) |
|
281 { |
|
282 CMsvMimeHeaders* msvMime = CMsvMimeHeaders::NewLC(); |
|
283 msvMime->RestoreL( aAttachment ); |
|
284 |
|
285 // Content-Location |
|
286 SetContentLocationL( msvMime->ContentLocation() ); |
|
287 |
|
288 // Content-ID |
|
289 SetContentIdL( msvMime->ContentId() ); |
|
290 |
|
291 TBuf8<KMaxDataTypeLength> contentType; |
|
292 contentType.Copy( msvMime->ContentType() ); |
|
293 contentType.Append( _L8("/") ); |
|
294 contentType.Append( msvMime->ContentSubType() ); |
|
295 // Content-type |
|
296 SetContentTypeL( contentType ); |
|
297 |
|
298 // Character set |
|
299 SetCharset( msvMime->MimeCharset() ); |
|
300 |
|
301 // Content-Description |
|
302 SetContentDescriptionL( msvMime->ContentDescription() ); |
|
303 |
|
304 // Content-Base |
|
305 SetContentBaseL( msvMime->ContentBase() ); |
|
306 |
|
307 // Content-Disposition |
|
308 SetContentDispositionL( msvMime->ContentDisposition() ); |
|
309 |
|
310 CleanupStack::PopAndDestroy( msvMime ); |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------- |
|
314 // EnsureContentLocationL |
|
315 // --------------------------------------------------------- |
|
316 void CUniMimeInfo::EnsureContentLocationL( |
|
317 MMsvAttachmentManager& aManager, |
|
318 CMsvAttachment& aAttachment, |
|
319 TDesC& aPlainFileName ) |
|
320 { |
|
321 if ( !ContentLocation().Length() && aPlainFileName.Length() ) |
|
322 { |
|
323 // Generate safe content location from file name |
|
324 HBufC* contLoc = CMsgTextUtils::GetSafeAttachmentNameLC( |
|
325 aManager, |
|
326 aPlainFileName, |
|
327 aAttachment.Id(), |
|
328 ETrue ); |
|
329 SetContentLocationL( *contLoc ); |
|
330 |
|
331 CleanupStack::PopAndDestroy( contLoc ); |
|
332 |
|
333 // Save ContentLocation. |
|
334 SaveMimeInfoL( aManager, aAttachment ); |
|
335 } |
|
336 } |
|
337 |
|
338 // EOF |