|
1 /* |
|
2 * Copyright (c) 2006 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 * Fetch message(s) operation, using client MTM Get Mail API |
|
16 * |
|
17 */ |
|
18 |
|
19 #include <eikenv.h> |
|
20 #include <StringLoader.h> |
|
21 #include <MsvPrgReporter.h> |
|
22 #include <ImumUtils.rsg> |
|
23 #include "ImumPanic.h" |
|
24 #include "MsvPop3FetchOperation.h" |
|
25 #include "MsvPop3ConnectOp.h" |
|
26 #include "MsvConnectionValidation.h" |
|
27 #include "MsvEmailConnectionProgressProvider.h" |
|
28 #include "EmailUtils.H" |
|
29 #include "ImumDisconnectOperation.h" |
|
30 |
|
31 // Constants and defines |
|
32 const TInt KFetchOpPriority = CActive::EPriorityStandard; |
|
33 |
|
34 |
|
35 // ---------------------------------------------------------------------------- |
|
36 // NewL |
|
37 // ---------------------------------------------------------------------------- |
|
38 CMsvPop3FetchOperation* CMsvPop3FetchOperation::NewL( |
|
39 CImumInternalApi& aMailboxApi, |
|
40 TRequestStatus& aObserverRequestStatus, |
|
41 MMsvProgressReporter& aReporter, |
|
42 TInt aFunctionId, |
|
43 TMsvId aService, |
|
44 const TImPop3GetMailInfo& aGetMailInfo, |
|
45 const CMsvEntrySelection& aSel) |
|
46 { |
|
47 IMUM_STATIC_CONTEXT( CMsvPop3FetchOperation::NewL, 0, mtm, KImumMtmLog ); |
|
48 IMUM_IN(); |
|
49 |
|
50 CMsvPop3FetchOperation* op = new(ELeave) CMsvPop3FetchOperation( |
|
51 aMailboxApi, |
|
52 aObserverRequestStatus, |
|
53 aReporter, |
|
54 aFunctionId, |
|
55 aService, |
|
56 aGetMailInfo); |
|
57 CleanupStack::PushL(op); |
|
58 op->ConstructL(aSel); |
|
59 CleanupStack::Pop(); // op |
|
60 IMUM_OUT(); |
|
61 return op; |
|
62 } |
|
63 |
|
64 // ---------------------------------------------------------------------------- |
|
65 //Overloaded NewL for partial fetch operation |
|
66 // ---------------------------------------------------------------------------- |
|
67 CMsvPop3FetchOperation* CMsvPop3FetchOperation::NewL( |
|
68 CImumInternalApi& aMailboxApi, |
|
69 TRequestStatus& aObserverRequestStatus, |
|
70 MMsvProgressReporter& aReporter, |
|
71 TInt aFunctionId, |
|
72 TMsvId aService, |
|
73 const TImPop3GetMailInfo& aGetMailInfo, |
|
74 const CMsvEntrySelection& aSel, |
|
75 TInt aLimit) |
|
76 { |
|
77 IMUM_STATIC_CONTEXT( CMsvPop3FetchOperation::NewL, 0, mtm, KImumMtmLog ); |
|
78 IMUM_IN(); |
|
79 |
|
80 CMsvPop3FetchOperation* op = new(ELeave) CMsvPop3FetchOperation( |
|
81 aMailboxApi, |
|
82 aObserverRequestStatus, |
|
83 aReporter, |
|
84 aFunctionId, |
|
85 aService, |
|
86 aGetMailInfo, |
|
87 aLimit); |
|
88 CleanupStack::PushL(op); |
|
89 op->ConstructL(aSel); |
|
90 CleanupStack::Pop(); // op |
|
91 IMUM_OUT(); |
|
92 return op; |
|
93 } |
|
94 |
|
95 |
|
96 // ---------------------------------------------------------------------------- |
|
97 // ~CMsvPop3FetchOperation |
|
98 // ---------------------------------------------------------------------------- |
|
99 CMsvPop3FetchOperation::~CMsvPop3FetchOperation() |
|
100 { |
|
101 IMUM_CONTEXT( CMsvPop3FetchOperation::~CMsvPop3FetchOperation, 0, KImumMtmLog ); |
|
102 IMUM_IN(); |
|
103 |
|
104 delete iFetchErrorProgress; |
|
105 delete iSelection; |
|
106 IMUM_OUT(); |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // ProgressL |
|
111 // ---------------------------------------------------------------------------- |
|
112 const TDesC8& CMsvPop3FetchOperation::ProgressL() |
|
113 { |
|
114 IMUM_CONTEXT( CMsvPop3FetchOperation::ProgressL, 0, KImumMtmLog ); |
|
115 IMUM_IN(); |
|
116 |
|
117 if(iFetchErrorProgress && (iState == EStateIdle)) |
|
118 { |
|
119 IMUM_OUT(); |
|
120 // Completed, but with an error during fetch. |
|
121 return *iFetchErrorProgress; |
|
122 } |
|
123 IMUM_OUT(); |
|
124 return CImumOnlineOperation::ProgressL(); |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------------------------------- |
|
128 // ConstructL |
|
129 // ---------------------------------------------------------------------------- |
|
130 void CMsvPop3FetchOperation::ConstructL(const CMsvEntrySelection& aSel) |
|
131 { |
|
132 IMUM_CONTEXT( CMsvPop3FetchOperation::ConstructL, 0, KImumMtmLog ); |
|
133 IMUM_IN(); |
|
134 |
|
135 BaseConstructL(KUidMsgTypePOP3); |
|
136 iSelection = aSel.CopyL(); |
|
137 iSelection->InsertL(0, iService); |
|
138 // For Get Mail API, first selection element must be service. |
|
139 DoConnectL(); |
|
140 IMUM_OUT(); |
|
141 } |
|
142 |
|
143 // ---------------------------------------------------------------------------- |
|
144 // DoConnectL |
|
145 // ---------------------------------------------------------------------------- |
|
146 void CMsvPop3FetchOperation::DoConnectL() |
|
147 { |
|
148 IMUM_CONTEXT( CMsvPop3FetchOperation::DoConnectL, 0, KImumMtmLog ); |
|
149 IMUM_IN(); |
|
150 |
|
151 iState = EStateConnecting; |
|
152 iStatus = KRequestPending; |
|
153 CMsvPop3ConnectOp* connOp = CMsvPop3ConnectOp::NewL( |
|
154 iStatus, |
|
155 iReporter, |
|
156 iService, |
|
157 0 ); |
|
158 // when connecting for the fetch operation, don't let connect operation to do fetch, |
|
159 // because we do it by ourself. That's why give 0 to connect operation. |
|
160 delete iOperation; |
|
161 iOperation = connOp; |
|
162 |
|
163 //We always leave connection on after fetching. |
|
164 //If fetching from off line state and want to disconnect afterwards, |
|
165 //checks are needed here. |
|
166 iDisconnect = EFalse; |
|
167 |
|
168 TMsvEntry serviceEntry; |
|
169 TMsvId serviceId; |
|
170 |
|
171 if ( iMsvSession.GetEntry( Service(), serviceId, serviceEntry ) == KErrNone ) |
|
172 { |
|
173 |
|
174 if ( !serviceEntry.Connected() ) |
|
175 { |
|
176 HBufC* text = StringLoader::LoadLC( |
|
177 R_EMAIL_CONNECTING_SERVER, serviceEntry.iDetails, iEikEnv ); |
|
178 iReporter.SetTitleL( *text ); |
|
179 CleanupStack::PopAndDestroy( text ); |
|
180 } |
|
181 } |
|
182 // Go active ourselves. |
|
183 SetActive(); |
|
184 IMUM_OUT(); |
|
185 } |
|
186 |
|
187 // ---------------------------------------------------------------------------- |
|
188 // DoFetchL |
|
189 // ---------------------------------------------------------------------------- |
|
190 void CMsvPop3FetchOperation::DoFetchL() |
|
191 { |
|
192 IMUM_CONTEXT( CMsvPop3FetchOperation::DoFetchL, 0, KImumMtmLog ); |
|
193 IMUM_IN(); |
|
194 |
|
195 iState = EStateFetching; |
|
196 |
|
197 // Switch operations. |
|
198 delete iOperation; |
|
199 iOperation = NULL; |
|
200 iStatus = KRequestPending; |
|
201 |
|
202 // Filters are not used when performing 'fetch' operation, use normal getmail info instead |
|
203 TPckg<TImPop3GetMailInfo> param(iGetMailInfo); |
|
204 InvokeClientMtmAsyncFunctionL(iFunctionId, *iSelection, iService, param ); |
|
205 SetActive(); |
|
206 IMUM_OUT(); |
|
207 } |
|
208 |
|
209 // ---------------------------------------------------------------------------- |
|
210 // DoDisconnectL |
|
211 // ---------------------------------------------------------------------------- |
|
212 void CMsvPop3FetchOperation::DoDisconnectL() |
|
213 { |
|
214 IMUM_CONTEXT( CMsvPop3FetchOperation::DoDisconnectL, 0, KImumMtmLog ); |
|
215 IMUM_IN(); |
|
216 |
|
217 iState = EStateDisconnecting; |
|
218 TMsvId temp; |
|
219 TMsvEntry entry; |
|
220 const TInt err = iMsvSession.GetEntry(iService, temp, entry); |
|
221 if( (iDisconnect) && (err==KErrNone) && (entry.Connected()) ) |
|
222 { |
|
223 delete iOperation; |
|
224 iOperation = NULL; |
|
225 iStatus = KRequestPending; |
|
226 iOperation = CImumDisconnectOperation::NewL( |
|
227 iMailboxApi, |
|
228 iStatus, |
|
229 iReporter, |
|
230 iService, |
|
231 KPOP3MTMDisconnect, |
|
232 KUidMsgTypePOP3); |
|
233 } |
|
234 else |
|
235 { |
|
236 CompleteThis(); |
|
237 } |
|
238 SetActive(); |
|
239 IMUM_OUT(); |
|
240 } |
|
241 |
|
242 // ---------------------------------------------------------------------------- |
|
243 // CMsvPop3FetchOperation |
|
244 // ---------------------------------------------------------------------------- |
|
245 CMsvPop3FetchOperation::CMsvPop3FetchOperation( |
|
246 CImumInternalApi& aMailboxApi, |
|
247 TRequestStatus& aObserverRequestStatus, |
|
248 MMsvProgressReporter& aReporter, |
|
249 TInt aFunctionId, |
|
250 TMsvId aService, |
|
251 const TImPop3GetMailInfo& aGetMailInfo) |
|
252 : |
|
253 CImumDiskSpaceObserverOperation( |
|
254 aMailboxApi, |
|
255 KFetchOpPriority, |
|
256 aObserverRequestStatus, |
|
257 aReporter), |
|
258 iFunctionId(aFunctionId), |
|
259 iGetMailInfo(aGetMailInfo) |
|
260 { |
|
261 IMUM_CONTEXT( CMsvPop3FetchOperation::CMsvPop3FetchOperation, 0, KImumMtmLog ); |
|
262 IMUM_IN(); |
|
263 |
|
264 iService = aService; |
|
265 IMUM_OUT(); |
|
266 } |
|
267 |
|
268 // ---------------------------------------------------------------------------- |
|
269 // CMsvPop3FetchOperation. Overloaded constructor for |
|
270 // partial fetch operation |
|
271 // ---------------------------------------------------------------------------- |
|
272 CMsvPop3FetchOperation::CMsvPop3FetchOperation( |
|
273 CImumInternalApi& aMailboxApi, |
|
274 TRequestStatus& aObserverRequestStatus, |
|
275 MMsvProgressReporter& aReporter, |
|
276 TInt aFunctionId, |
|
277 TMsvId aService, |
|
278 const TImPop3GetMailInfo& aGetMailInfo, |
|
279 TInt aLimit) |
|
280 : |
|
281 CImumDiskSpaceObserverOperation( |
|
282 aMailboxApi, |
|
283 KFetchOpPriority, |
|
284 aObserverRequestStatus, |
|
285 aReporter), |
|
286 iFunctionId(aFunctionId), |
|
287 iGetMailInfo(aGetMailInfo), |
|
288 iPopulateLimit( aLimit ) |
|
289 { |
|
290 IMUM_CONTEXT( CMsvPop3FetchOperation::CMsvPop3FetchOperation, 0, KImumMtmLog ); |
|
291 IMUM_IN(); |
|
292 |
|
293 iService = aService; |
|
294 IMUM_OUT(); |
|
295 } |
|
296 |
|
297 // ---------------------------------------------------------------------------- |
|
298 // RunL |
|
299 // ---------------------------------------------------------------------------- |
|
300 void CMsvPop3FetchOperation::RunL() |
|
301 { |
|
302 IMUM_CONTEXT( CMsvPop3FetchOperation::RunL, 0, KImumMtmLog ); |
|
303 IMUM_IN(); |
|
304 |
|
305 TRAP(iError, DoRunL()); // CSI: 86 # Needed here to properly handle error situations |
|
306 if(iError != KErrNone) |
|
307 { |
|
308 // Need to ensure we disconnect if we have connected. |
|
309 if( (iError == KErrNoMemory) || (iState == EStateDisconnecting) ) |
|
310 { |
|
311 // OOM and/or failed to create disconnect operation. Call StopService() |
|
312 iMsvSession.StopService(iService); |
|
313 // Ignore return, nothing we can do. |
|
314 } |
|
315 else if( (iState == EStateFetching) && (iDisconnect) ) |
|
316 { |
|
317 // Failed to start fetch operation. Need to disconnect. |
|
318 __ASSERT_DEBUG(!iFetchErrorProgress, |
|
319 User::Panic(KImumMtmUiPanic,EPop3MtmUiOpAlreadyHaveProgErr)); |
|
320 TPckgBuf<TPop3Progress>* progPkg = new TPckgBuf<TPop3Progress>; // CSI: 62 # We want to avoid leaves. |
|
321 iFetchErrorProgress = progPkg; |
|
322 if(iFetchErrorProgress) |
|
323 { |
|
324 TPop3Progress& errProg = (*progPkg)(); |
|
325 errProg.iPop3Progress = TPop3Progress::EPopPopulating; |
|
326 errProg.iTotalMsgs = 0; |
|
327 errProg.iMsgsToProcess = 0; |
|
328 errProg.iBytesDone = 0; |
|
329 errProg.iTotalBytes = 0; |
|
330 errProg.iErrorCode = iError; |
|
331 errProg.iPop3SubStateProgress = TPop3Progress::EPopPopulating; |
|
332 errProg.iServiceId = iService; |
|
333 } |
|
334 SetActive(); |
|
335 CompleteThis(); // Next DoRunL() will attempt to disconnect. |
|
336 IMUM_OUT(); |
|
337 return; |
|
338 } |
|
339 // Notify observer we have finished. |
|
340 CompleteObserver(); |
|
341 } |
|
342 IMUM_OUT(); |
|
343 } |
|
344 |
|
345 // ---------------------------------------------------------------------------- |
|
346 // DoCancel |
|
347 // ---------------------------------------------------------------------------- |
|
348 void CMsvPop3FetchOperation::DoCancel() |
|
349 { |
|
350 IMUM_CONTEXT( CMsvPop3FetchOperation::DoCancel, 0, KImumMtmLog ); |
|
351 IMUM_IN(); |
|
352 |
|
353 CImumOnlineOperation::DoCancel(); |
|
354 if(iState == EStateFetching) |
|
355 { |
|
356 // Cancelled while fetching. Need to disconnect. |
|
357 iMsvSession.StopService(iService); |
|
358 // Ignore return, nothing we can do. |
|
359 } |
|
360 IMUM_OUT(); |
|
361 } |
|
362 |
|
363 // ---------------------------------------------------------------------------- |
|
364 // DoRunL |
|
365 // ---------------------------------------------------------------------------- |
|
366 void CMsvPop3FetchOperation::DoRunL() |
|
367 { |
|
368 IMUM_CONTEXT( CMsvPop3FetchOperation::DoRunL, 0, KImumMtmLog ); |
|
369 IMUM_IN(); |
|
370 |
|
371 switch(iState) |
|
372 { |
|
373 case EStateConnecting: |
|
374 { |
|
375 // Connect complete. |
|
376 TBool connected = STATIC_CAST(CMsvPop3ConnectOp*,iOperation)->Connected(); |
|
377 if(!connected) |
|
378 { |
|
379 // Connect failed. |
|
380 CompleteObserver( KErrCouldNotConnect ); |
|
381 IMUM_OUT(); |
|
382 return; |
|
383 } |
|
384 DoFetchL(); |
|
385 } |
|
386 break; |
|
387 case EStateFetching: |
|
388 // Fetch complete. |
|
389 { |
|
390 TInt err = GetOperationCompletionCodeL(); |
|
391 if(err != KErrNone) |
|
392 { |
|
393 __ASSERT_DEBUG(!iFetchErrorProgress, |
|
394 User::Panic(KImumMtmUiPanic,EPop3MtmUiOpAlreadyHaveProgErr)); |
|
395 TPckgBuf<TPop3Progress> paramPack; |
|
396 paramPack.Copy( iOperation->ProgressL() ); |
|
397 TPop3Progress& progress = paramPack(); |
|
398 progress.iErrorCode = err; |
|
399 iFetchErrorProgress = paramPack.AllocL(); |
|
400 } |
|
401 DoDisconnectL(); |
|
402 } |
|
403 break; |
|
404 case EStateDisconnecting: |
|
405 // Disconnect complete. |
|
406 iState = EStateIdle; |
|
407 CompleteObserver(); |
|
408 break; |
|
409 default: |
|
410 User::Panic(KImumMtmUiPanic,EPop3MtmUiOpUnknownState); |
|
411 break; |
|
412 } |
|
413 if(iOperation) |
|
414 iMtm = iOperation->Mtm(); |
|
415 else |
|
416 iMtm = KUidMsgTypePOP3; |
|
417 IMUM_OUT(); |
|
418 } |
|
419 |
|
420 // ---------------------------------------------------------------------------- |
|
421 // GetErrorProgressL |
|
422 // ---------------------------------------------------------------------------- |
|
423 const TDesC8& CMsvPop3FetchOperation::GetErrorProgressL(TInt aError) |
|
424 // Called when DoRunL() leaves. |
|
425 { |
|
426 IMUM_CONTEXT( CMsvPop3FetchOperation::GetErrorProgressL, 0, KImumMtmLog ); |
|
427 IMUM_IN(); |
|
428 |
|
429 iError = aError; |
|
430 if(iFetchErrorProgress) |
|
431 { |
|
432 delete iFetchErrorProgress; |
|
433 iFetchErrorProgress = NULL; |
|
434 } |
|
435 TPckgBuf<TPop3Progress> paramPack; |
|
436 TPop3Progress& progress = paramPack(); |
|
437 progress.iPop3Progress = TPop3Progress::EPopConnecting; |
|
438 progress.iTotalMsgs = 0; |
|
439 progress.iMsgsToProcess = 0; |
|
440 progress.iBytesDone = 0; |
|
441 progress.iTotalBytes = 0; |
|
442 progress.iErrorCode = iError; |
|
443 switch(iState) |
|
444 { |
|
445 case EStateConnecting: // Should never get this, so treat as next state. |
|
446 case EStateFetching: |
|
447 if(iOperation) |
|
448 { |
|
449 paramPack.Copy( iOperation->ProgressL() ); |
|
450 } |
|
451 else |
|
452 { |
|
453 progress.iPop3Progress = TPop3Progress::EPopPopulating; |
|
454 } |
|
455 break; |
|
456 case EStateDisconnecting: |
|
457 progress.iPop3Progress = TPop3Progress::EPopDisconnecting; |
|
458 break; |
|
459 default: |
|
460 break; |
|
461 } |
|
462 iFetchErrorProgress = paramPack.AllocL(); |
|
463 IMUM_OUT(); |
|
464 return *iFetchErrorProgress; |
|
465 } |
|
466 |
|
467 // End of File |