|
1 /* |
|
2 * Copyright (c) 2007-2009 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: ESMR mrinfo calendar entry retriever implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include "cesmrimapicalretriever.h" |
|
21 #include "cesmrimapmailfetcher.h" |
|
22 #include "cesmrattachmentinfo.h" |
|
23 #include "tesmrinputparams.h" |
|
24 #include "esmricalviewerutils.h" |
|
25 #include "esmrconfig.hrh" |
|
26 |
|
27 //<cmail> |
|
28 #include "CFSMailClient.h" |
|
29 #include "CFSMailBox.h" |
|
30 #include "CFSMailMessage.h" |
|
31 #include "CFSMailMessagePart.h" |
|
32 #include "CFSMailCommon.h" |
|
33 #include "cesmragnexternalinterface.h" |
|
34 #include "esmricalvieweropcodes.hrh" |
|
35 //</cmail> |
|
36 |
|
37 //<cmail> hardcoded paths removal |
|
38 #include "esmrhelper.h" |
|
39 //</cmail> |
|
40 #include <calentry.h> |
|
41 #include <caluser.h> |
|
42 #include <calalarm.h> |
|
43 #include <CalenInterimUtils2.h> |
|
44 #include <s32file.h> |
|
45 #include <eikenv.h> |
|
46 |
|
47 // Unnamed namespace for local definitions |
|
48 namespace { |
|
49 |
|
50 // Mime type literal for text/calendar |
|
51 _LIT8( KTextCalendar8, "text/calendar" ); |
|
52 |
|
53 // Literal for received ics filename |
|
54 //<cmail> hard coded path removal, store goes to process's own private directory |
|
55 //_LIT( KTempReceivedIcsFile, |
|
56 // "c:\\temp\\tempreceived.ics" ); //codescanner::driveletters |
|
57 _LIT( KTempReceivedIcsFileName, "temp\\tempreceived.ics" ); |
|
58 //</cmail> |
|
59 |
|
60 // Definition for temporary folder |
|
61 //<cmail> hard coded path removal, store goes to process's own private directory |
|
62 //_LIT( KTempFolder, "c:\\temp\\" ); //codescanner::driveletters |
|
63 //</cmail> |
|
64 |
|
65 // Definition for first position |
|
66 const TInt KFirstPos(0); |
|
67 |
|
68 /** |
|
69 * Cleanup operations for RPointerArray. |
|
70 * |
|
71 * @param aArray Pointer to RPointerArray. |
|
72 */ |
|
73 void MessagePartPointerArrayCleanup( TAny* aArray ) |
|
74 { |
|
75 RPointerArray<CFSMailMessagePart>* messagePartArray = |
|
76 static_cast<RPointerArray<CFSMailMessagePart>*>( aArray ); |
|
77 |
|
78 messagePartArray->ResetAndDestroy(); |
|
79 messagePartArray->Close(); |
|
80 } |
|
81 |
|
82 /** |
|
83 * Cleanup operations for RPointerArray. |
|
84 * |
|
85 * @param aArray Pointer to RPointerArray. |
|
86 */ |
|
87 void CalEntryPointerArrayCleanup( TAny* aArray ) |
|
88 { |
|
89 RPointerArray<CCalEntry>* entryArray = |
|
90 static_cast<RPointerArray<CCalEntry>*>( aArray ); |
|
91 |
|
92 entryArray->ResetAndDestroy(); |
|
93 entryArray->Close(); |
|
94 } |
|
95 |
|
96 }//namespace |
|
97 |
|
98 // ======== MEMBER FUNCTIONS ======== |
|
99 |
|
100 // --------------------------------------------------------------------------- |
|
101 // CESMRImapIcalRetriever::CESMRImapIcalRetrieverCmd |
|
102 // --------------------------------------------------------------------------- |
|
103 // |
|
104 CESMRImapIcalRetrieverCmd::CESMRImapIcalRetrieverCmd( |
|
105 CCalSession& aCalSession, |
|
106 CFSMailClient& aMailClient, |
|
107 TESMRInputParams& aInputParameters ) |
|
108 : CESMRIcalViewerAsyncCommand( EESMRLoadMRIcalData, aCalSession ), |
|
109 iMailClient( aMailClient ), |
|
110 iInputParameters( aInputParameters ) |
|
111 { |
|
112 FUNC_LOG; |
|
113 iResult.iResultCode = KErrNone; |
|
114 iResult.iOpType = OperationType(); |
|
115 } |
|
116 |
|
117 // --------------------------------------------------------------------------- |
|
118 // CESMRImapIcalRetriever::~CESMRImapIcalRetrieverCmd |
|
119 // --------------------------------------------------------------------------- |
|
120 // |
|
121 CESMRImapIcalRetrieverCmd::~CESMRImapIcalRetrieverCmd() |
|
122 { |
|
123 FUNC_LOG; |
|
124 CancelCommand(); |
|
125 delete iCalImporter; |
|
126 delete iMailFetcher; |
|
127 delete iConvertedEntry; |
|
128 delete iIcsFilename; |
|
129 delete iAttachmentInfo; |
|
130 } |
|
131 |
|
132 // --------------------------------------------------------------------------- |
|
133 // CESMRImapIcalRetriever::NewL |
|
134 // --------------------------------------------------------------------------- |
|
135 // |
|
136 CESMRImapIcalRetrieverCmd* CESMRImapIcalRetrieverCmd::NewL( |
|
137 CCalSession& aCalSession, |
|
138 CFSMailClient& aMailClient, |
|
139 TESMRInputParams& aInputParameters ) |
|
140 { |
|
141 FUNC_LOG; |
|
142 CESMRImapIcalRetrieverCmd* self = |
|
143 new (ELeave) CESMRImapIcalRetrieverCmd( |
|
144 aCalSession, |
|
145 aMailClient, |
|
146 aInputParameters ); |
|
147 |
|
148 CleanupStack::PushL( self ); |
|
149 self->ConstructL(); |
|
150 CleanupStack::Pop( self ); |
|
151 return self; |
|
152 } |
|
153 |
|
154 // --------------------------------------------------------------------------- |
|
155 // CESMRImapIcalRetriever::ConstructL |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 void CESMRImapIcalRetrieverCmd::ConstructL() |
|
159 { |
|
160 FUNC_LOG; |
|
161 BaseConstructL(); |
|
162 |
|
163 TFileName fileName(KTempReceivedIcsFileName); |
|
164 User::LeaveIfError(ESMRHelper::CreateAndAppendPrivateDirToFileName(fileName)); |
|
165 iIcsFilename = fileName.AllocL(); |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // CESMRImapIcalRetriever::ExecuteAsyncCommandL |
|
170 // --------------------------------------------------------------------------- |
|
171 // |
|
172 void CESMRImapIcalRetrieverCmd::ExecuteAsyncCommandL() |
|
173 { |
|
174 FUNC_LOG; |
|
175 delete iCalImporter; iCalImporter = NULL; |
|
176 delete iMailFetcher; iMailFetcher = NULL; |
|
177 |
|
178 iCalImporter = CESMRAgnExternalInterface::NewL( KTextCalendar8 ); |
|
179 iMailFetcher = CESMRImapMailFetcherCmd::NewL( |
|
180 iMailClient , |
|
181 CalSession() ); |
|
182 |
|
183 // Ensure mesasge is fetched to device |
|
184 // Completion is noticed via observer |
|
185 iMailFetcher->ExecuteCommandL( |
|
186 *Message(), |
|
187 *this ); |
|
188 } |
|
189 |
|
190 // --------------------------------------------------------------------------- |
|
191 // CESMRImapIcalRetriever::CancelAsyncCommand |
|
192 // --------------------------------------------------------------------------- |
|
193 // |
|
194 void CESMRImapIcalRetrieverCmd::CancelAsyncCommand() |
|
195 { |
|
196 FUNC_LOG; |
|
197 if ( iMailFetcher ) |
|
198 { |
|
199 iMailFetcher->CancelCommand(); |
|
200 } |
|
201 } |
|
202 |
|
203 // --------------------------------------------------------------------------- |
|
204 // CESMRImapIcalRetriever::AgnImportErrorL |
|
205 // --------------------------------------------------------------------------- |
|
206 // |
|
207 MESMRAgnImportObserver::TImpResponse CESMRImapIcalRetrieverCmd::AgnImportErrorL( |
|
208 MESMRAgnImportObserver::TImpError /*aType*/, |
|
209 const TDesC8& /*aUid*/, |
|
210 const TDesC& /*aContext*/) |
|
211 { |
|
212 FUNC_LOG; |
|
213 // Ignore error and continue processing |
|
214 return MESMRAgnImportObserver::EImpResponseContinue; |
|
215 } |
|
216 |
|
217 // --------------------------------------------------------------------------- |
|
218 // CESMRImapIcalRetrieverCmd::OperationCompleted |
|
219 // --------------------------------------------------------------------------- |
|
220 // |
|
221 void CESMRImapIcalRetrieverCmd::OperationCompleted( |
|
222 MESMRIcalViewerObserver::TIcalViewerOperationResult aResult ) |
|
223 { |
|
224 FUNC_LOG; |
|
225 if ( aResult.iOpType == EESMRFetchMailContent ) |
|
226 { |
|
227 TRAPD( error, HandleMailContentL() ); |
|
228 |
|
229 if ( error != KErrNone || |
|
230 !iInputParameters.iCalEntry ) |
|
231 { |
|
232 aResult.iOpType = OperationType(); |
|
233 aResult.iResultCode = KErrNotSupported; |
|
234 Observer()->OperationError( aResult ); |
|
235 } |
|
236 else |
|
237 { |
|
238 aResult.iOpType = OperationType(); |
|
239 Observer()->OperationCompleted( aResult ); |
|
240 } |
|
241 } |
|
242 else |
|
243 { |
|
244 aResult.iOpType = OperationType(); |
|
245 aResult.iResultCode = KErrNotSupported; |
|
246 |
|
247 Observer()->OperationError( aResult ); |
|
248 } |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------------------------- |
|
252 // CESMRImapIcalRetrieverCmd::HandleMailContentL |
|
253 // --------------------------------------------------------------------------- |
|
254 // |
|
255 void CESMRImapIcalRetrieverCmd::HandleMailContentL() |
|
256 { |
|
257 FUNC_LOG; |
|
258 CFSMailMessage* msg = Message(); |
|
259 |
|
260 // Fetch own pointer email message, because message structure is |
|
261 // not necessarily up to date |
|
262 CFSMailMessage* message = |
|
263 iMailClient.GetMessageByUidL( |
|
264 msg->GetMailBoxId(), |
|
265 msg->GetFolderId(), |
|
266 msg->GetMessageId(), |
|
267 EFSMsgDataStructure ); |
|
268 CleanupStack::PushL( message ); |
|
269 |
|
270 CFSMailMessagePart* calendarPart = ESMRIcalViewerUtils::LocateCalendarPartL( *message ); |
|
271 if ( !calendarPart ) |
|
272 { |
|
273 // message does not contain calendar part at all |
|
274 iResult.iResultCode = KErrNotFound; |
|
275 User::Leave( KErrNotFound ); |
|
276 } |
|
277 CleanupStack::PushL( calendarPart ); |
|
278 |
|
279 CreateEntryL( *calendarPart, *msg ); |
|
280 iInputParameters.iCalEntry = iConvertedEntry; |
|
281 iCalendarPartId = calendarPart->GetPartId(); |
|
282 |
|
283 CheckAttachmentDataL( *message ); |
|
284 |
|
285 CleanupStack::PopAndDestroy( calendarPart ); |
|
286 CleanupStack::PopAndDestroy( message ); |
|
287 } |
|
288 |
|
289 // --------------------------------------------------------------------------- |
|
290 // CESMRImapIcalRetrieverCmd::OperationError |
|
291 // --------------------------------------------------------------------------- |
|
292 // |
|
293 void CESMRImapIcalRetrieverCmd::OperationError( |
|
294 MESMRIcalViewerObserver::TIcalViewerOperationResult aResult ) |
|
295 { |
|
296 FUNC_LOG; |
|
297 iResult.iResultCode = aResult.iResultCode; |
|
298 Observer()->OperationError( iResult ); |
|
299 } |
|
300 |
|
301 // --------------------------------------------------------------------------- |
|
302 // CESMRImapIcalRetriever::CreateEntryL |
|
303 // --------------------------------------------------------------------------- |
|
304 // |
|
305 void CESMRImapIcalRetrieverCmd::CreateEntryL( |
|
306 CFSMailMessagePart& aMessagePart, |
|
307 CFSMailMessage& aMsg) |
|
308 { |
|
309 FUNC_LOG; |
|
310 delete iConvertedEntry; iConvertedEntry = NULL; |
|
311 |
|
312 aMessagePart.CopyContentFileL( *iIcsFilename ); |
|
313 |
|
314 //set up calendar session; just creating and deleting these leads to memory |
|
315 //and handle leaks. |
|
316 RFs& rfs( CEikonEnv::Static()->FsSession() );// codescanner::eikonenvstatic |
|
317 |
|
318 RFileReadStream fileStream; |
|
319 fileStream.PushL(); |
|
320 User::LeaveIfError( fileStream.Open( rfs, *iIcsFilename, EFileRead)); //<cmail> |
|
321 |
|
322 RPointerArray<CCalEntry> entries; |
|
323 CleanupStack::PushL( |
|
324 TCleanupItem( |
|
325 CalEntryPointerArrayCleanup, |
|
326 &entries ) ); |
|
327 |
|
328 // Replaced with internal ical module |
|
329 TRAPD( err, iCalImporter->ImportL( |
|
330 entries, |
|
331 fileStream, |
|
332 0, |
|
333 *this ) ); |
|
334 |
|
335 User::LeaveIfError( err ); |
|
336 |
|
337 TInt entryCount( entries.Count() ); |
|
338 if ( !entryCount ) |
|
339 { |
|
340 // There are no entries to be processed |
|
341 User::Leave( KErrNotSupported ); |
|
342 } |
|
343 |
|
344 // Only the first entry is processed --> Others are discarded. |
|
345 iConvertedEntry = entries[ KFirstPos ]; |
|
346 entries.Remove( KFirstPos ); |
|
347 |
|
348 CleanupStack::PopAndDestroy( &entries ); |
|
349 CleanupStack::PopAndDestroy( &fileStream ); |
|
350 |
|
351 //If there is no organizer (special case for some Exchange servers) |
|
352 //we need to add mail sender as organizer |
|
353 if(!iConvertedEntry->OrganizerL()) |
|
354 { |
|
355 CFSMailAddress* sender = aMsg.GetSender(); |
|
356 |
|
357 if(sender) |
|
358 { |
|
359 CCalUser* organizer = CCalUser::NewL( sender->GetEmailAddress() ); |
|
360 CleanupStack::PushL(organizer); |
|
361 |
|
362 organizer->SetCommonNameL( sender->GetDisplayName() ); |
|
363 iConvertedEntry->SetOrganizerL(organizer); |
|
364 |
|
365 CleanupStack::Pop( organizer ); // Ownership trasferred |
|
366 } |
|
367 } |
|
368 } |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 // CESMRImapIcalRetriever::CheckAttachmentDataL |
|
372 // --------------------------------------------------------------------------- |
|
373 // |
|
374 void CESMRImapIcalRetrieverCmd::CheckAttachmentDataL( |
|
375 CFSMailMessage& aMessage ) |
|
376 { |
|
377 FUNC_LOG; |
|
378 if ( aMessage.IsFlagSet( EFSMsgFlag_Attachments ) ) |
|
379 { |
|
380 RPointerArray<CFSMailMessagePart> attachmentParts; |
|
381 CleanupStack::PushL( |
|
382 TCleanupItem( |
|
383 MessagePartPointerArrayCleanup, |
|
384 &attachmentParts ) ); |
|
385 |
|
386 aMessage.AttachmentListL( attachmentParts ); |
|
387 |
|
388 TInt attachmentCount( attachmentParts.Count() ); |
|
389 if ( attachmentCount > 0 ) |
|
390 { |
|
391 delete iAttachmentInfo; |
|
392 iAttachmentInfo = NULL; |
|
393 |
|
394 iInputParameters.iAttachmentInfo = NULL; |
|
395 |
|
396 CESMRAttachmentInfo* attachmentInfo = CESMRAttachmentInfo::NewL(); |
|
397 CleanupStack::PushL( attachmentInfo ); |
|
398 |
|
399 for( TInt i(0); i < attachmentCount; ++i ) |
|
400 { |
|
401 CESMRAttachment::TESMRAttachmentState state( |
|
402 CESMRAttachment::EAttachmentStateDownloaded ); |
|
403 |
|
404 if ( EFSFull != attachmentParts[i]->FetchLoadState() ) |
|
405 { |
|
406 state = CESMRAttachment::EAttachmentStateNotDownloaded; |
|
407 } |
|
408 |
|
409 TInt contentSize( attachmentParts[i]->ContentSize() ); |
|
410 TPtrC attachmentName( attachmentParts[i]->AttachmentNameL() ); |
|
411 |
|
412 if ( contentSize >= 0 && attachmentName.Length() && |
|
413 iCalendarPartId != attachmentParts[i]->GetPartId() ) |
|
414 { |
|
415 attachmentInfo->AddAttachmentInfoL( |
|
416 attachmentName, |
|
417 contentSize, |
|
418 state ); |
|
419 } |
|
420 } |
|
421 |
|
422 if ( attachmentInfo->AttachmentCount() ) |
|
423 { |
|
424 iAttachmentInfo = attachmentInfo; |
|
425 CleanupStack::Pop( attachmentInfo ); |
|
426 // ownership does not change |
|
427 iInputParameters.iAttachmentInfo = iAttachmentInfo; |
|
428 } |
|
429 else |
|
430 { |
|
431 CleanupStack::PopAndDestroy( attachmentInfo ); |
|
432 } |
|
433 |
|
434 attachmentInfo = NULL; |
|
435 |
|
436 } |
|
437 CleanupStack::PopAndDestroy(); // attachmentparts |
|
438 } |
|
439 } |
|
440 |
|
441 // EOF |
|
442 |