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