|
1 /* |
|
2 * Copyright (c) 2007-2008 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: IMAP4 connect operation |
|
15 * |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "emailtrace.h" |
|
21 #include "ipsplgheaders.h" |
|
22 |
|
23 |
|
24 _LIT( KIpsPlgIpsConnPanic, "IpsConn" ); |
|
25 |
|
26 // ---------------------------------------------------------------------------- |
|
27 // CIpsPlgImap4ConnectOp::NewL() |
|
28 // ---------------------------------------------------------------------------- |
|
29 // |
|
30 CIpsPlgImap4ConnectOp* CIpsPlgImap4ConnectOp::NewL( |
|
31 CMsvSession& aMsvSession, |
|
32 TInt aPriority, |
|
33 TRequestStatus& aObserverRequestStatus, |
|
34 TMsvId aService, |
|
35 CIpsPlgTimerOperation& aActivityTimer, |
|
36 TFSMailMsgId aFSMailBoxId, |
|
37 MFSMailRequestObserver& aFSOperationObserver, |
|
38 TInt aFSRequestId, |
|
39 CIpsPlgEventHandler* aEventHandler, |
|
40 TBool aDoPlainConnect, |
|
41 TBool aSignallingAllowed ) |
|
42 { |
|
43 FUNC_LOG; |
|
44 CIpsPlgImap4ConnectOp* self = new (ELeave) CIpsPlgImap4ConnectOp( |
|
45 aMsvSession, |
|
46 aPriority, |
|
47 aObserverRequestStatus, |
|
48 aService, |
|
49 aActivityTimer, |
|
50 aFSMailBoxId, |
|
51 aFSOperationObserver, |
|
52 aFSRequestId, |
|
53 aDoPlainConnect, |
|
54 aSignallingAllowed, |
|
55 aEventHandler ); |
|
56 |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop( self ); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // ---------------------------------------------------------------------------- |
|
64 // CIpsPlgImap4ConnectOp::CIpsPlgImap4ConnectOp() |
|
65 // ---------------------------------------------------------------------------- |
|
66 // |
|
67 CIpsPlgImap4ConnectOp::CIpsPlgImap4ConnectOp( |
|
68 CMsvSession& aMsvSession, |
|
69 TInt aPriority, |
|
70 TRequestStatus& aObserverRequestStatus, |
|
71 TMsvId aService, |
|
72 CIpsPlgTimerOperation& aActivityTimer, |
|
73 TFSMailMsgId aFSMailBoxId, |
|
74 MFSMailRequestObserver& aFSOperationObserver, |
|
75 TInt aFSRequestId, |
|
76 TBool aDoPlainConnect, |
|
77 TBool aSignallingAllowed, |
|
78 CIpsPlgEventHandler* aEventHandler) |
|
79 : |
|
80 CIpsPlgOnlineOperation( |
|
81 aMsvSession, |
|
82 aPriority, |
|
83 aObserverRequestStatus, |
|
84 aActivityTimer, |
|
85 aFSMailBoxId, |
|
86 aFSOperationObserver, |
|
87 aFSRequestId, |
|
88 aSignallingAllowed ), |
|
89 iDoPlainConnect( aDoPlainConnect ), |
|
90 iEventHandler( aEventHandler ), |
|
91 iIsSyncStartedSignaled( EFalse ) |
|
92 { |
|
93 FUNC_LOG; |
|
94 iService = aService; |
|
95 } |
|
96 |
|
97 // ---------------------------------------------------------------------------- |
|
98 // CIpsPlgImap4ConnectOp::~CIpsPlgImap4ConnectOp() |
|
99 // ---------------------------------------------------------------------------- |
|
100 // |
|
101 CIpsPlgImap4ConnectOp::~CIpsPlgImap4ConnectOp() |
|
102 { |
|
103 FUNC_LOG; |
|
104 Cancel(); |
|
105 delete iSelection; |
|
106 iState = EStateIdle; |
|
107 } |
|
108 |
|
109 // ---------------------------------------------------------------------------- |
|
110 // CIpsPlgImap4ConnectOp::ConstructL() |
|
111 // ---------------------------------------------------------------------------- |
|
112 // |
|
113 void CIpsPlgImap4ConnectOp::ConstructL() |
|
114 { |
|
115 FUNC_LOG; |
|
116 BaseConstructL( KUidMsgTypeIMAP4 ); |
|
117 iSelection = new(ELeave) CMsvEntrySelection; |
|
118 |
|
119 TMsvEntry tentry; |
|
120 TMsvId service; |
|
121 iMsvSession.GetEntry( iService, service, tentry ); |
|
122 |
|
123 if ( tentry.iType.iUid != KUidMsvServiceEntryValue ) |
|
124 { |
|
125 User::Panic( KIpsPlgIpsConnPanic, KErrNotSupported ); |
|
126 } |
|
127 |
|
128 iState = EStateStartConnect; |
|
129 iStatus = KRequestPending; |
|
130 SetActive(); |
|
131 CompleteThis(); |
|
132 } |
|
133 |
|
134 // ---------------------------------------------------------------------------- |
|
135 // CIpsPlgImap4ConnectOp::ProgressL() |
|
136 // ---------------------------------------------------------------------------- |
|
137 // |
|
138 const TDesC8& CIpsPlgImap4ConnectOp::ProgressL() |
|
139 { |
|
140 FUNC_LOG; |
|
141 if( iError != KErrNone ) |
|
142 { |
|
143 return GetErrorProgressL( iError ); |
|
144 } |
|
145 else if(iOperation) |
|
146 { |
|
147 return iOperation->ProgressL(); |
|
148 } |
|
149 |
|
150 TImap4CompoundProgress& prog = iProgressBuf(); |
|
151 prog.iGenericProgress.iErrorCode = KErrNone; |
|
152 return iProgressBuf; |
|
153 } |
|
154 |
|
155 // ---------------------------------------------------------------------------- |
|
156 // CIpsPlgImap4ConnectOp::GetErrorProgressL() |
|
157 // ---------------------------------------------------------------------------- |
|
158 // |
|
159 const TDesC8& CIpsPlgImap4ConnectOp::GetErrorProgressL(TInt aError) |
|
160 { |
|
161 FUNC_LOG; |
|
162 TImap4CompoundProgress& prog = iProgressBuf(); |
|
163 prog.iGenericProgress.iErrorCode = aError; |
|
164 return iProgressBuf; |
|
165 } |
|
166 |
|
167 // ---------------------------------------------------------------------------- |
|
168 // CIpsPlgImap4ConnectOp::GetFSProgressL() |
|
169 // ---------------------------------------------------------------------------- |
|
170 // |
|
171 TFSProgress CIpsPlgImap4ConnectOp::GetFSProgressL() const |
|
172 { |
|
173 FUNC_LOG; |
|
174 // might not never called, but gives something reasonable if called |
|
175 TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone }; |
|
176 result.iError = KErrNone; |
|
177 switch( iState ) |
|
178 { |
|
179 case EStateQueryingDetails: |
|
180 result.iProgressStatus = TFSProgress::EFSStatus_Authenticating; |
|
181 break; |
|
182 case EStateStartConnect: |
|
183 result.iProgressStatus = TFSProgress::EFSStatus_Started; |
|
184 break; |
|
185 case EStateConnectAndSync: |
|
186 result.iProgressStatus = TFSProgress::EFSStatus_Connecting; |
|
187 break; |
|
188 case EStateCompleted: |
|
189 default: |
|
190 result.iProgressStatus = TFSProgress::EFSStatus_RequestComplete; |
|
191 break; |
|
192 } |
|
193 if ( iStatus.Int() == KErrCancel ) |
|
194 { |
|
195 result.iProgressStatus = TFSProgress::EFSStatus_RequestCancelled; |
|
196 result.iError = KErrCancel; |
|
197 } |
|
198 return result; |
|
199 } |
|
200 |
|
201 // ---------------------------------------------------------------------------- |
|
202 // CIpsPlgImap4ConnectOp::IpsOpType() |
|
203 // ---------------------------------------------------------------------------- |
|
204 // |
|
205 TInt CIpsPlgImap4ConnectOp::IpsOpType() const |
|
206 { |
|
207 FUNC_LOG; |
|
208 return EIpsOpTypeImap4SyncOp; |
|
209 } |
|
210 |
|
211 // ---------------------------------------------------------------------------- |
|
212 // CIpsPlgImap4ConnectOp::Connected() |
|
213 // ---------------------------------------------------------------------------- |
|
214 // |
|
215 TBool CIpsPlgImap4ConnectOp::Connected() const |
|
216 { |
|
217 FUNC_LOG; |
|
218 TMsvEntry tentry; |
|
219 TMsvId service; |
|
220 iMsvSession.GetEntry(iService, service, tentry ); |
|
221 return tentry.Connected(); |
|
222 } |
|
223 |
|
224 |
|
225 // ---------------------------------------------------------------------------- |
|
226 // CIpsPlgImap4ConnectOp::DoCancel() |
|
227 // ---------------------------------------------------------------------------- |
|
228 // |
|
229 void CIpsPlgImap4ConnectOp::DoCancel() |
|
230 { |
|
231 FUNC_LOG; |
|
232 if( iOperation ) |
|
233 { |
|
234 iOperation->Cancel(); |
|
235 } |
|
236 SignalSyncCompleted( KErrCancel ); |
|
237 CompleteObserver( KErrCancel ); |
|
238 } |
|
239 |
|
240 // ---------------------------------------------------------------------------- |
|
241 // CIpsPlgImap4ConnectOp::DoRunL() |
|
242 // ---------------------------------------------------------------------------- |
|
243 // |
|
244 void CIpsPlgImap4ConnectOp::DoRunL() |
|
245 { |
|
246 FUNC_LOG; |
|
247 TInt err = KErrNone; |
|
248 __ASSERT_DEBUG( !(iOperation && iOperation->IsActive()), |
|
249 User::Panic( KIpsPlgPanicCategory, KErrGeneral ) ); |
|
250 if ( iOperation ) |
|
251 { |
|
252 err = iOperation->iStatus.Int(); |
|
253 delete iOperation; |
|
254 iOperation = NULL; |
|
255 } |
|
256 |
|
257 switch( iState ) |
|
258 { |
|
259 case EStateQueryingDetails: |
|
260 |
|
261 if ( KErrNone != err ) |
|
262 { |
|
263 // user might be cancelled query |
|
264 // or it IS EMPTY |
|
265 iError = err; |
|
266 iState = EStateIdle; |
|
267 } |
|
268 else |
|
269 { |
|
270 // Retry connect. |
|
271 DoConnectOpL(); |
|
272 } |
|
273 break; |
|
274 case EStateStartConnect: |
|
275 StartL(); |
|
276 break; |
|
277 case EStateConnectAndSync: |
|
278 // Connection completed |
|
279 |
|
280 if( err == KErrImapBadLogon ) |
|
281 { |
|
282 // Login details are wrong. |
|
283 QueryUserPwdL(); |
|
284 iState = EStateQueryingDetails; |
|
285 |
|
286 err = KErrNone; |
|
287 } |
|
288 else if ( err == KErrNone ) |
|
289 { |
|
290 // no errors in connection |
|
291 if( !iDoPlainConnect ) |
|
292 { |
|
293 DoPopulateAllL(); |
|
294 } |
|
295 else |
|
296 { |
|
297 // Get on with others using this class for connection only |
|
298 iState = EStateIdle; |
|
299 SetActive(); |
|
300 CompleteThis(); |
|
301 } |
|
302 } |
|
303 break; |
|
304 case EStatePopulateAllCompleted: |
|
305 CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL( |
|
306 iMsvSession, iService ); |
|
307 // break command is intentially left out |
|
308 case EStateCompleted: |
|
309 if ( err == KErrNone ) |
|
310 { |
|
311 iState = EStateIdle; |
|
312 SetActive(); |
|
313 CompleteThis(); |
|
314 } |
|
315 break; |
|
316 case EStateIdle: |
|
317 default: |
|
318 if ( iOperation ) |
|
319 { |
|
320 delete iOperation; |
|
321 iOperation = NULL; |
|
322 } |
|
323 CompleteObserver(); |
|
324 break; |
|
325 } |
|
326 |
|
327 // if iError < 0, observer is completed in base class |
|
328 iError = err; |
|
329 if ( err != KErrNone ) |
|
330 { |
|
331 SignalSyncCompleted( err ); |
|
332 } |
|
333 } |
|
334 |
|
335 // ---------------------------------------------------------------------------- |
|
336 // CIpsPlgImap4ConnectOp::HandleImapConnectionEvent() |
|
337 // ---------------------------------------------------------------------------- |
|
338 // |
|
339 void CIpsPlgImap4ConnectOp::HandleImapConnectionEvent( |
|
340 TImapConnectionEvent aConnectionEvent ) |
|
341 { |
|
342 FUNC_LOG; |
|
343 switch ( aConnectionEvent ) |
|
344 { |
|
345 case EConnectingToServer: |
|
346 break; |
|
347 case ESynchronisingFolderList: |
|
348 case ESynchronisingInbox: |
|
349 case ESynchronisingFolders: |
|
350 // send sync started event in any of these sync events |
|
351 SignalSyncStarted(); |
|
352 break; |
|
353 case ESynchronisationComplete: |
|
354 break; |
|
355 case EDisconnecting: |
|
356 break; |
|
357 case EConnectionCompleted: |
|
358 default: |
|
359 break; |
|
360 } |
|
361 } |
|
362 |
|
363 // ---------------------------------------------------------------------------- |
|
364 // CIpsPlgImap4ConnectOp::RequestResponseL() |
|
365 // ---------------------------------------------------------------------------- |
|
366 // |
|
367 void CIpsPlgImap4ConnectOp::RequestResponseL( |
|
368 TFSProgress /*aEvent*/, TInt /*aRequestId*/ ) |
|
369 { |
|
370 FUNC_LOG; |
|
371 } |
|
372 |
|
373 // ---------------------------------------------------------------------------- |
|
374 // CIpsPlgImap4ConnectOp::DoConnectOpL() |
|
375 // ---------------------------------------------------------------------------- |
|
376 // |
|
377 void CIpsPlgImap4ConnectOp::DoConnectOpL() |
|
378 { |
|
379 FUNC_LOG; |
|
380 iBaseMtm->SwitchCurrentEntryL( iService ); |
|
381 |
|
382 iSelection->ResizeL(0); |
|
383 iSelection->AppendL(iService); |
|
384 |
|
385 if ( iDoPlainConnect && !Connected() ) |
|
386 { |
|
387 TBuf8<1> parameter; |
|
388 iStatus = KRequestPending; |
|
389 // connect and synchronise starts background sync or idle |
|
390 iOperation = iBaseMtm->InvokeAsyncFunctionL( |
|
391 KIMAP4MTMConnect, *iSelection, parameter, iStatus); |
|
392 iState = EStateConnectAndSync; |
|
393 SetActive(); |
|
394 } |
|
395 else if ( Connected() ) |
|
396 { |
|
397 // in this point cant use "connect and do something" commands, |
|
398 // use regular sync, when new mails is populated elsewhere. |
|
399 TBuf8<1> parameter; |
|
400 iStatus = KRequestPending; |
|
401 iOperation = iBaseMtm->InvokeAsyncFunctionL( |
|
402 KIMAP4MTMFullSync, *iSelection, parameter, iStatus); |
|
403 // also set sync started |
|
404 SignalSyncStarted(); |
|
405 iState = EStateConnectAndSync; |
|
406 SetActive(); |
|
407 } |
|
408 else |
|
409 { |
|
410 TPckg<MMsvImapConnectionObserver*> parameter(this); |
|
411 // connect and synchronise starts background sync or idle |
|
412 iStatus = KRequestPending; |
|
413 iOperation = iBaseMtm->InvokeAsyncFunctionL( |
|
414 KIMAP4MTMConnectAndSyncCompleteAfterFullSync, |
|
415 *iSelection, parameter, iStatus); |
|
416 iState = EStateConnectAndSync; |
|
417 SetActive(); |
|
418 } |
|
419 } |
|
420 |
|
421 // ---------------------------------------------------------------------------- |
|
422 // CIpsPlgImap4ConnectOp::DoPopulateAll() |
|
423 // ---------------------------------------------------------------------------- |
|
424 void CIpsPlgImap4ConnectOp::DoPopulateAllL() |
|
425 { |
|
426 FUNC_LOG; |
|
427 |
|
428 // construct partial fetch info according to imap settings |
|
429 CImImap4Settings* settings = new ( ELeave ) CImImap4Settings(); |
|
430 CleanupStack::PushL( settings ); |
|
431 CEmailAccounts* accounts = CEmailAccounts::NewLC(); |
|
432 TImapAccount imapAcc; |
|
433 accounts->GetImapAccountL(iService, imapAcc ); |
|
434 accounts->LoadImapSettingsL( imapAcc, *settings ); |
|
435 TImImap4GetPartialMailInfo info; |
|
436 CIpsSetDataApi::ConstructImapPartialFetchInfo( info, *settings ); |
|
437 TPckgBuf<TImImap4GetPartialMailInfo> package(info); |
|
438 CleanupStack::PopAndDestroy( 2, settings ); |
|
439 |
|
440 if ( info.iTotalSizeLimit != KIpsSetDataHeadersOnly ) |
|
441 { |
|
442 SignalSyncStarted(); |
|
443 CMsvEntry* cEntry = iMsvSession.GetEntryL( iService ); |
|
444 CleanupStack::PushL( cEntry ); |
|
445 CMsvEntrySelection* childrenSelection = cEntry->ChildrenL(); |
|
446 CleanupStack::PushL( childrenSelection ); |
|
447 if ( childrenSelection->Count() ) |
|
448 { |
|
449 // only inbox is set, do we have to populate other folders also |
|
450 TMsvId id = (*childrenSelection)[0]; |
|
451 CMsvEntry* cEntry2 = iMsvSession.GetEntryL( id ); |
|
452 CleanupStack::PushL( cEntry2 ); |
|
453 delete iSelection; |
|
454 iSelection = NULL; |
|
455 iSelection = cEntry2->ChildrenWithTypeL( KUidMsvMessageEntry ); |
|
456 CleanupStack::PopAndDestroy( cEntry2 ); |
|
457 |
|
458 } |
|
459 CleanupStack::PopAndDestroy( childrenSelection ); |
|
460 |
|
461 iStatus = KRequestPending; |
|
462 CIpsPlgTimerOperation* dummy = NULL; |
|
463 iBaseMtm->SwitchCurrentEntryL( iService ); |
|
464 iOperation = CIpsPlgImap4PopulateOp::NewL( |
|
465 iMsvSession, |
|
466 this->iStatus, |
|
467 CActive::EPriorityLow, |
|
468 iService, |
|
469 *dummy, |
|
470 info, |
|
471 *iSelection, |
|
472 iFSMailboxId, |
|
473 *this, |
|
474 0, |
|
475 iEventHandler ); |
|
476 |
|
477 SetActive(); |
|
478 CleanupStack::PopAndDestroy( cEntry ); |
|
479 } |
|
480 else |
|
481 { |
|
482 SetActive(); |
|
483 CompleteThis(); |
|
484 } |
|
485 iState = EStatePopulateAllCompleted; |
|
486 } |
|
487 |
|
488 // ---------------------------------------------------------------------------- |
|
489 // CIpsPlgImap4ConnectOp::StartL() |
|
490 // ---------------------------------------------------------------------------- |
|
491 // |
|
492 void CIpsPlgImap4ConnectOp::StartL() |
|
493 { |
|
494 FUNC_LOG; |
|
495 if ( Connected() && iDoPlainConnect ) |
|
496 { |
|
497 // sync is done background, no explicit supported |
|
498 iState = EStateIdle; |
|
499 SetActive(); |
|
500 CompleteThis(); |
|
501 } |
|
502 else |
|
503 { |
|
504 DoConnectOpL(); |
|
505 } |
|
506 } |
|
507 |
|
508 // ---------------------------------------------------------------------------- |
|
509 // CIpsPlgImap4ConnectOp::QueryUserPwdL() |
|
510 // ---------------------------------------------------------------------------- |
|
511 // |
|
512 void CIpsPlgImap4ConnectOp::QueryUserPwdL() |
|
513 { |
|
514 iEventHandler->QueryUsrPassL( iService, this ); |
|
515 } |
|
516 |
|
517 |
|
518 // ---------------------------------------------------------------------------- |
|
519 // CIpsPlgImap4ConnectOp::GetOperationErrorCodeL() |
|
520 // ---------------------------------------------------------------------------- |
|
521 // |
|
522 /*TInt CIpsPlgImap4ConnectOp::GetOperationErrorCodeL( ) |
|
523 { |
|
524 if ( !iOperation ) |
|
525 { |
|
526 return KErrNotFound; |
|
527 } |
|
528 if ( !iOperation->IsActive() && iOperation->iStatus.Int() != KErrNone ) |
|
529 { |
|
530 return iOperation->iStatus.Int(); |
|
531 } |
|
532 |
|
533 TPckgBuf<TImap4CompoundProgress> paramPack; |
|
534 paramPack.Copy( iOperation->ProgressL() ); |
|
535 const TImap4CompoundProgress& comProgg = paramPack(); |
|
536 |
|
537 return comProgg.iGenericProgress.iErrorCode; |
|
538 }*/ |
|
539 |
|
540 // ---------------------------------------------------------------------------- |
|
541 // ---------------------------------------------------------------------------- |
|
542 void CIpsPlgImap4ConnectOp::SignalSyncStarted() |
|
543 { |
|
544 FUNC_LOG; |
|
545 if ( iEventHandler && !iIsSyncStartedSignaled ) |
|
546 { |
|
547 // mark that sync is signaled to prevent |
|
548 // sending necessary event |
|
549 iIsSyncStartedSignaled = ETrue; |
|
550 iEventHandler->SetNewPropertyEvent( |
|
551 iService, KIpsSosEmailSyncStarted, KErrNone ); |
|
552 } |
|
553 } |
|
554 |
|
555 // ---------------------------------------------------------------------------- |
|
556 // ---------------------------------------------------------------------------- |
|
557 void CIpsPlgImap4ConnectOp::SignalSyncCompleted( TInt aError ) |
|
558 { |
|
559 FUNC_LOG; |
|
560 if ( iEventHandler && aError == KErrImapBadLogon ) |
|
561 { |
|
562 iEventHandler->SetNewPropertyEvent( |
|
563 iService, KIpsSosEmailSyncCompleted, aError ); |
|
564 iIsSyncStartedSignaled = EFalse; |
|
565 } |
|
566 } |
|
567 |
|
568 |
|
569 // ---------------------------------------------------------------------------- |
|
570 // ---------------------------------------------------------------------------- |
|
571 void CIpsPlgImap4ConnectOp::CredientialsSetL( TInt aEvent ) |
|
572 { |
|
573 FUNC_LOG; |
|
574 if ( aEvent == EIPSSosCredientialsCancelled ) |
|
575 { |
|
576 CompleteObserver( KErrCancel ); |
|
577 } |
|
578 //password has been set, continue with operation |
|
579 |
|
580 SetActive(); |
|
581 CompleteThis(); |
|
582 } |
|
583 // End of File |
|
584 |