|
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: POP3 connect operation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "emailtrace.h" |
|
20 #include "ipsplgheaders.h" |
|
21 |
|
22 // Constants and defines |
|
23 const TInt KConnectOpPriority = CActive::EPriorityStandard; |
|
24 const TInt KIpsPlgPop3PopulateLimitInitValue = 50; |
|
25 |
|
26 _LIT( KIpsPlgPopConnectPanic, "PopConnectOp" ); |
|
27 |
|
28 // ---------------------------------------------------------------------------- |
|
29 // CIpsPlgPop3ConnectOp::NewL() |
|
30 // ---------------------------------------------------------------------------- |
|
31 // |
|
32 CIpsPlgPop3ConnectOp* CIpsPlgPop3ConnectOp::NewL( |
|
33 CMsvSession& aMsvSession, |
|
34 TRequestStatus& aObserverRequestStatus, |
|
35 TMsvId aService, |
|
36 TBool aForcePopulate, |
|
37 CIpsPlgTimerOperation& aActivityTimer, |
|
38 TFSMailMsgId aFSMailBoxId, |
|
39 MFSMailRequestObserver& aFSOperationObserver, |
|
40 TInt aFSRequestId, |
|
41 CIpsPlgEventHandler* aEventHandler, |
|
42 TBool aSignallingAllowed ) |
|
43 { |
|
44 FUNC_LOG; |
|
45 CIpsPlgPop3ConnectOp* op = |
|
46 new(ELeave) CIpsPlgPop3ConnectOp( aMsvSession, aObserverRequestStatus, |
|
47 aService, aForcePopulate, aActivityTimer, aFSMailBoxId, |
|
48 aFSOperationObserver, aFSRequestId, |
|
49 aEventHandler, aSignallingAllowed ); |
|
50 |
|
51 CleanupStack::PushL( op ); |
|
52 op->ConstructL(); |
|
53 CleanupStack::Pop( op ); |
|
54 return op; |
|
55 } |
|
56 |
|
57 // ---------------------------------------------------------------------------- |
|
58 // CIpsPlgPop3ConnectOp::~CIpsPlgPop3ConnectOp() |
|
59 // ---------------------------------------------------------------------------- |
|
60 // |
|
61 CIpsPlgPop3ConnectOp::~CIpsPlgPop3ConnectOp() |
|
62 { |
|
63 FUNC_LOG; |
|
64 delete iEntry; |
|
65 delete iSelection; |
|
66 |
|
67 iState = EIdle; |
|
68 } |
|
69 |
|
70 // ---------------------------------------------------------------------------- |
|
71 // CIpsPlgPop3ConnectOp::ProgressL() |
|
72 // ---------------------------------------------------------------------------- |
|
73 // |
|
74 const TDesC8& CIpsPlgPop3ConnectOp::ProgressL() |
|
75 { |
|
76 FUNC_LOG; |
|
77 if( iError != KErrNone ) |
|
78 { |
|
79 return GetErrorProgressL( iError ); |
|
80 } |
|
81 else if( iOperation ) |
|
82 { |
|
83 return iOperation->ProgressL(); |
|
84 } |
|
85 |
|
86 iProgress().iErrorCode = KErrNone; |
|
87 return iProgress; |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // ---------------------------------------------------------------------------- |
|
92 // |
|
93 void CIpsPlgPop3ConnectOp::DoCancel() |
|
94 { |
|
95 FUNC_LOG; |
|
96 if( iOperation ) |
|
97 { |
|
98 iOperation->Cancel(); |
|
99 } |
|
100 CompleteObserver( KErrCancel ); |
|
101 } |
|
102 |
|
103 // ---------------------------------------------------------------------------- |
|
104 // CIpsPlgPop3ConnectOp::DoRunL() |
|
105 // ---------------------------------------------------------------------------- |
|
106 // |
|
107 void CIpsPlgPop3ConnectOp::DoRunL() |
|
108 { |
|
109 FUNC_LOG; |
|
110 // handle these error situations properly, |
|
111 // and report somehow back to framework |
|
112 TInt err = KErrNone; |
|
113 |
|
114 if ( iState == EQueryingDetails ) |
|
115 { |
|
116 // Retry connect. |
|
117 DoConnectL(); |
|
118 iState = EConnected; |
|
119 } |
|
120 else if ( iState == EStartConnect ) |
|
121 { |
|
122 |
|
123 if ( iOperation ) |
|
124 { |
|
125 // operation exist and it means |
|
126 // disconnect operation was ongoing. |
|
127 // How handle errors |
|
128 delete iOperation; |
|
129 iOperation = NULL; |
|
130 } |
|
131 |
|
132 if ( ValidateL() ) |
|
133 { |
|
134 // Begin Connect. |
|
135 DoConnectL(); |
|
136 iState = EConnected; |
|
137 } |
|
138 else |
|
139 { |
|
140 User::Leave( KErrCancel ); // User cancelled. |
|
141 } |
|
142 } |
|
143 else if ( iState == EConnected ) |
|
144 { |
|
145 // Connect completed. |
|
146 err = GetOperationErrorCodeL( ); |
|
147 |
|
148 if ( ( err == KPop3InvalidUser ) || |
|
149 ( err == KPop3InvalidLogin ) || |
|
150 ( err == KPop3InvalidApopLogin ) ) |
|
151 { |
|
152 // Login details are wrong. |
|
153 |
|
154 iState = EQueryingDetails; |
|
155 |
|
156 QueryUsrPassL(); |
|
157 } |
|
158 else if ( err == KErrNone ) |
|
159 { |
|
160 if ( iForcePopulate && Connected() ) |
|
161 { |
|
162 iState = EPopulate; |
|
163 DoPopulateL(); |
|
164 } |
|
165 else |
|
166 { |
|
167 iState = EIdle; |
|
168 CompleteObserver( KErrNone ); |
|
169 } |
|
170 |
|
171 } |
|
172 else |
|
173 { |
|
174 // We can't do this before, because |
|
175 // we want to handle KPop3InvalidUser, |
|
176 // KPop3InvalidLogin and KPop3InvalidApopLogin separately. |
|
177 User::Leave( err ); |
|
178 } |
|
179 } |
|
180 else if ( iState == EPopulate ) |
|
181 { |
|
182 err = GetOperationErrorCodeL( ); |
|
183 if ( iEventHandler ) |
|
184 { |
|
185 iEventHandler->SetNewPropertyEvent( |
|
186 iService, KIpsSosEmailSyncCompleted, err ); |
|
187 } |
|
188 CIpsPlgSyncStateHandler::SaveSuccessfulSyncTimeL( |
|
189 iMsvSession, iService ); |
|
190 CompleteObserver( err ); |
|
191 } |
|
192 else if ( iState == EErrInvalidDetails ) |
|
193 { |
|
194 // proper error code; |
|
195 CompleteObserver( KErrGeneral ); |
|
196 } |
|
197 else |
|
198 { |
|
199 User::Panic( KIpsPlgPopConnectPanic ,KErrNotFound); |
|
200 } |
|
201 |
|
202 } |
|
203 |
|
204 // ---------------------------------------------------------------------------- |
|
205 // CIpsPlgPop3ConnectOp::GetErrorProgressL |
|
206 // ---------------------------------------------------------------------------- |
|
207 // |
|
208 const TDesC8& CIpsPlgPop3ConnectOp::GetErrorProgressL( TInt aError ) |
|
209 { |
|
210 FUNC_LOG; |
|
211 iError = aError; |
|
212 if ( iOperation && iError == KErrNone ) |
|
213 { |
|
214 return iOperation->ProgressL(); |
|
215 } |
|
216 TPop3Progress& progress = iProgress(); |
|
217 progress.iPop3Progress = TPop3Progress::EPopConnecting; |
|
218 progress.iTotalMsgs = 0; |
|
219 progress.iMsgsToProcess = 0; |
|
220 progress.iBytesDone = 0; |
|
221 progress.iTotalBytes = 0; |
|
222 progress.iErrorCode = iError; |
|
223 progress.iPop3SubStateProgress = TPop3Progress::EPopConnecting; |
|
224 progress.iServiceId = iService; |
|
225 return iProgress; |
|
226 } |
|
227 |
|
228 // ---------------------------------------------------------------------------- |
|
229 // CIpsPlgPop3ConnectOp::GetFSProgressL() |
|
230 // ---------------------------------------------------------------------------- |
|
231 // |
|
232 TFSProgress CIpsPlgPop3ConnectOp::GetFSProgressL() const |
|
233 { |
|
234 FUNC_LOG; |
|
235 // might not never called, but gives something reasonable if called |
|
236 TFSProgress result = { TFSProgress::EFSStatus_Waiting, 0, 0, KErrNone }; |
|
237 result.iError = KErrNone; |
|
238 switch( iState ) |
|
239 { |
|
240 case EQueryingDetails: |
|
241 result.iProgressStatus = TFSProgress::EFSStatus_Authenticating; |
|
242 break; |
|
243 case EStartConnect: |
|
244 case EConnected: |
|
245 result.iProgressStatus = TFSProgress::EFSStatus_Connecting; |
|
246 break; |
|
247 case EPopulate: |
|
248 // staus is used to inform fetching in base plugin |
|
249 result.iProgressStatus = TFSProgress::EFSStatus_Status; |
|
250 break; |
|
251 default: |
|
252 result.iProgressStatus = TFSProgress::EFSStatus_RequestComplete; |
|
253 break; |
|
254 } |
|
255 if ( iStatus.Int() == KErrCancel ) |
|
256 { |
|
257 result.iProgressStatus = TFSProgress::EFSStatus_RequestCancelled; |
|
258 result.iError = KErrCancel; |
|
259 } |
|
260 |
|
261 return result; |
|
262 } |
|
263 |
|
264 // ---------------------------------------------------------------------------- |
|
265 // CIpsPlgPop3ConnectOp::CIpsPlgPop3ConnectOp |
|
266 // ---------------------------------------------------------------------------- |
|
267 // |
|
268 CIpsPlgPop3ConnectOp::CIpsPlgPop3ConnectOp( |
|
269 CMsvSession& aMsvSession, |
|
270 TRequestStatus& aObserverRequestStatus, |
|
271 TMsvId aServiceId, |
|
272 TBool aForcePopulate, |
|
273 CIpsPlgTimerOperation& aActivityTimer, |
|
274 TFSMailMsgId aFSMailBoxId, |
|
275 MFSMailRequestObserver& aFSOperationObserver, |
|
276 TInt aFSRequestId, |
|
277 CIpsPlgEventHandler* aEventHandler, |
|
278 TBool aSignallingAllowed ) |
|
279 : |
|
280 CIpsPlgOnlineOperation( aMsvSession, KConnectOpPriority, |
|
281 aObserverRequestStatus, aActivityTimer, aFSMailBoxId, |
|
282 aFSOperationObserver, aFSRequestId, aSignallingAllowed ), |
|
283 iState( EIdle ), |
|
284 iEntry( NULL ), |
|
285 iPopulateLimit( KIpsPlgPop3PopulateLimitInitValue ), |
|
286 iForcePopulate( aForcePopulate ), |
|
287 iSelection( NULL ), |
|
288 iEventHandler( aEventHandler ) |
|
289 { |
|
290 iService = aServiceId; |
|
291 } |
|
292 |
|
293 // ---------------------------------------------------------------------------- |
|
294 // CIpsPlgPop3ConnectOp::ConstructL() |
|
295 // ---------------------------------------------------------------------------- |
|
296 // |
|
297 void CIpsPlgPop3ConnectOp::ConstructL() |
|
298 { |
|
299 FUNC_LOG; |
|
300 BaseConstructL( KUidMsgTypePOP3 ); |
|
301 |
|
302 iEntry = iMsvSession.GetEntryL( iService ); |
|
303 if ( !iEntry ) |
|
304 { |
|
305 User::Leave( KErrGeneral ); |
|
306 } |
|
307 iSelection = new(ELeave) CMsvEntrySelection; |
|
308 const TMsvEntry& tentry = iEntry->Entry(); |
|
309 |
|
310 if ( tentry.iType.iUid != KUidMsvServiceEntryValue ) |
|
311 { |
|
312 // should we panic with own codes? |
|
313 User::Leave( KErrNotSupported ); |
|
314 } |
|
315 |
|
316 // get correct populate and sync limet values from settings |
|
317 CImPop3Settings* settings = new(ELeave) CImPop3Settings(); |
|
318 CleanupStack::PushL( settings ); |
|
319 TPopAccount popAccountId; |
|
320 CEmailAccounts* accounts = CEmailAccounts::NewLC(); |
|
321 accounts->GetPopAccountL( iService , popAccountId ); |
|
322 accounts->LoadPopSettingsL( popAccountId, *settings ); |
|
323 iPopulateLimit = settings->PopulationLimit(); |
|
324 if ( iPopulateLimit > 0 ) |
|
325 { |
|
326 iPopulateLimit = ( iPopulateLimit * 1024 ) / 75; |
|
327 } |
|
328 else if ( iPopulateLimit == KIpsSetDataHeadersOnly ) |
|
329 { |
|
330 iPopulateLimit = 0; |
|
331 } |
|
332 else |
|
333 { |
|
334 iPopulateLimit = KMaxTInt; |
|
335 } |
|
336 |
|
337 CleanupStack::PopAndDestroy( 2, settings ); |
|
338 |
|
339 if ( tentry.Connected() ) |
|
340 { |
|
341 iState = EConnected; |
|
342 SetActive(); |
|
343 CompleteThis(); |
|
344 } |
|
345 else |
|
346 { |
|
347 iState = EStartConnect; |
|
348 SetActive(); |
|
349 CompleteThis(); |
|
350 } |
|
351 } |
|
352 |
|
353 // ---------------------------------------------------------------------------- |
|
354 // CIpsPlgPop3ConnectOp::DoConnectL() |
|
355 // ---------------------------------------------------------------------------- |
|
356 // |
|
357 void CIpsPlgPop3ConnectOp::DoConnectL() |
|
358 { |
|
359 FUNC_LOG; |
|
360 iStatus = KRequestPending; |
|
361 InvokeClientMtmAsyncFunctionL( KPOP3MTMConnect, iService, iService ); |
|
362 SetActive(); |
|
363 } |
|
364 |
|
365 // ---------------------------------------------------------------------------- |
|
366 // CIpsPlgPop3ConnectOp::DoPopulateL() |
|
367 // ---------------------------------------------------------------------------- |
|
368 // |
|
369 void CIpsPlgPop3ConnectOp::DoPopulateL() |
|
370 { |
|
371 FUNC_LOG; |
|
372 iStatus = KRequestPending; |
|
373 |
|
374 // Prepare parameters and include filtering |
|
375 TImPop3PopulateOptions pop3GetMailInfo; |
|
376 pop3GetMailInfo.SetMaxEmailSize( KMaxTInt32 ); |
|
377 pop3GetMailInfo.SetPopulationLimit( iPopulateLimit ); |
|
378 TPckgBuf<TImPop3PopulateOptions> params( pop3GetMailInfo ); |
|
379 |
|
380 iSelection->InsertL(0, iService); |
|
381 iBaseMtm->SwitchCurrentEntryL( iService ); |
|
382 // Start the fetch operation |
|
383 InvokeClientMtmAsyncFunctionL( KPOP3MTMPopulateAll, *iSelection, |
|
384 iService, params); |
|
385 |
|
386 SetActive(); |
|
387 |
|
388 if ( iEventHandler ) |
|
389 { |
|
390 iEventHandler->SetNewPropertyEvent( |
|
391 iService, KIpsSosEmailSyncStarted, KErrNone ); |
|
392 } |
|
393 } |
|
394 // ---------------------------------------------------------------------------- |
|
395 // ---------------------------------------------------------------------------- |
|
396 // |
|
397 TBool CIpsPlgPop3ConnectOp::Connected() const |
|
398 { |
|
399 FUNC_LOG; |
|
400 TMsvEntry tentry; |
|
401 TMsvId service; |
|
402 iMsvSession.GetEntry(iService, service, tentry ); |
|
403 return tentry.Connected(); |
|
404 } |
|
405 |
|
406 // ---------------------------------------------------------------------------- |
|
407 // CIpsPlgImap4ConnectOp::IpsOpType() |
|
408 // ---------------------------------------------------------------------------- |
|
409 // |
|
410 TInt CIpsPlgPop3ConnectOp::IpsOpType() const |
|
411 { |
|
412 FUNC_LOG; |
|
413 return EIpsOpTypePop3SyncOp; |
|
414 } |
|
415 |
|
416 |
|
417 // ---------------------------------------------------------------------------- |
|
418 // CIpsPlgPop3ConnectOp::ValidateL() |
|
419 // ---------------------------------------------------------------------------- |
|
420 // |
|
421 TBool CIpsPlgPop3ConnectOp::ValidateL() |
|
422 { |
|
423 // do proper validation. OR: not needed? |
|
424 return ETrue; |
|
425 } |
|
426 |
|
427 // ---------------------------------------------------------------------------- |
|
428 // CIpsPlgPop3ConnectOp::QueryUsrPassL() |
|
429 // ---------------------------------------------------------------------------- |
|
430 // |
|
431 void CIpsPlgPop3ConnectOp::QueryUsrPassL() |
|
432 { |
|
433 FUNC_LOG; |
|
434 iEventHandler->QueryUsrPassL( iEntry->EntryId(), this ); |
|
435 } |
|
436 |
|
437 |
|
438 |
|
439 // ---------------------------------------------------------------------------- |
|
440 // CIpsPlgPop3ConnectOp::GetOperationErrorCodeL() |
|
441 // ---------------------------------------------------------------------------- |
|
442 // |
|
443 TInt CIpsPlgPop3ConnectOp::GetOperationErrorCodeL( ) |
|
444 { |
|
445 FUNC_LOG; |
|
446 if ( !iOperation ) |
|
447 { |
|
448 return KErrNotFound; |
|
449 } |
|
450 if ( !iOperation->IsActive() && iOperation->iStatus.Int() != KErrNone ) |
|
451 { |
|
452 return iOperation->iStatus.Int(); |
|
453 } |
|
454 |
|
455 TPckgBuf<TPop3Progress> paramPack; |
|
456 paramPack.Copy( iOperation->ProgressL() ); |
|
457 const TPop3Progress& progress = paramPack(); |
|
458 |
|
459 return progress.iErrorCode; |
|
460 } |
|
461 |
|
462 // ---------------------------------------------------------------------------- |
|
463 // ---------------------------------------------------------------------------- |
|
464 void CIpsPlgPop3ConnectOp::CredientialsSetL( TInt aEvent ) |
|
465 { |
|
466 FUNC_LOG; |
|
467 if ( aEvent == EIPSSosCredientialsCancelled ) |
|
468 { |
|
469 CompleteObserver( KErrCancel ); |
|
470 } |
|
471 //password has been set, continue with operation |
|
472 |
|
473 SetActive(); |
|
474 CompleteThis(); |
|
475 } |
|
476 //EOF |
|
477 |
|
478 |