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