|
1 /* |
|
2 * Copyright (c) 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: |
|
15 * Main plugin class |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 #include "emailtrace.h" |
|
21 #include <AlwaysOnlineManagerClient.h> |
|
22 #include <SendUiConsts.h> |
|
23 #include <msvids.h> |
|
24 #include <msvuids.h> |
|
25 |
|
26 // becuase of RD_IPS_AO_PLUGIN flag, can be removed |
|
27 // when flag is removed |
|
28 #include "ipsplgsosbaseplugin.hrh" |
|
29 |
|
30 #include "IpsSosAOImapPopLogic.h" |
|
31 #include "IpsSosAOMboxLogic.h" |
|
32 #include "IpsSosAOEMNResolver.h" |
|
33 #include "ipssetdataapi.h" |
|
34 |
|
35 |
|
36 |
|
37 #include "ipsplgcommon.h" |
|
38 |
|
39 //const TInt KAOSmtpStartDelaySeconds = 310; |
|
40 const TInt KIpsSosAOImapPopLogicDefGra = 1; |
|
41 //const TInt KIpsSosAoImapPopLogicEventGra = 2; |
|
42 |
|
43 // ---------------------------------------------------------------------------- |
|
44 // class CIpsSosAOImapPopLogic |
|
45 // ---------------------------------------------------------------------------- |
|
46 // |
|
47 CIpsSosAOImapPopLogic::CIpsSosAOImapPopLogic( CMsvSession& aSession ) |
|
48 : iSession( aSession ), iMailboxLogics( KIpsSosAOImapPopLogicDefGra ), |
|
49 iNoNWOpsAllowed( EFalse ) |
|
50 { |
|
51 FUNC_LOG; |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------------------------- |
|
55 // ---------------------------------------------------------------------------- |
|
56 // |
|
57 CIpsSosAOImapPopLogic::~CIpsSosAOImapPopLogic() |
|
58 { |
|
59 FUNC_LOG; |
|
60 iMailboxLogics.ResetAndDestroy(); |
|
61 // iActiveEvents.ResetAndDestroy(); |
|
62 delete iEmnResolver; |
|
63 delete iDataApi; |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // ---------------------------------------------------------------------------- |
|
68 // |
|
69 CIpsSosAOImapPopLogic* CIpsSosAOImapPopLogic::NewL( CMsvSession& aSession ) |
|
70 { |
|
71 FUNC_LOG; |
|
72 CIpsSosAOImapPopLogic* self = new (ELeave) CIpsSosAOImapPopLogic( |
|
73 aSession ); |
|
74 CleanupStack::PushL( self ); |
|
75 self->ConstructL(); |
|
76 CleanupStack::Pop( self ); |
|
77 return self; |
|
78 } |
|
79 |
|
80 // ---------------------------------------------------------------------------- |
|
81 // ---------------------------------------------------------------------------- |
|
82 // |
|
83 void CIpsSosAOImapPopLogic::ConstructL() |
|
84 { |
|
85 FUNC_LOG; |
|
86 iEmnResolver = CIpsSosAOEMNResolver::NewL(); |
|
87 iDataApi = CIpsSetDataApi::NewL( iSession ); |
|
88 } |
|
89 |
|
90 // ---------------------------------------------------------------------------- |
|
91 // ---------------------------------------------------------------------------- |
|
92 // |
|
93 TInt CIpsSosAOImapPopLogic::HandleAOServerCommandL( |
|
94 TInt aCommand, TDesC8* aParameters ) |
|
95 |
|
96 { |
|
97 |
|
98 FUNC_LOG; |
|
99 TInt result = KErrNone; |
|
100 |
|
101 TInt mailboxId = KErrNotFound; |
|
102 |
|
103 // Make sure that the parameter length matches Id length |
|
104 if ( aParameters && aParameters->Length() == sizeof( TMsvId ) ) |
|
105 { |
|
106 TPckgBuf<TMsvId> paramPack; |
|
107 paramPack.Copy( *aParameters ); |
|
108 |
|
109 // Get the mailbox id from the packet |
|
110 mailboxId = paramPack(); |
|
111 } |
|
112 |
|
113 switch ( aCommand ) |
|
114 { |
|
115 case EAOManagerPluginStart: |
|
116 RefreshMailboxListL( ); |
|
117 if ( !iNoNWOpsAllowed ) |
|
118 { |
|
119 SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStart ); |
|
120 } |
|
121 break; |
|
122 |
|
123 case EAOManagerPluginStop: |
|
124 SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStop ); |
|
125 // Return value does not matter, plugin will be stopped anyway. |
|
126 break; |
|
127 |
|
128 case EAOManagerNWOpsNotAllowed: |
|
129 iNoNWOpsAllowed = ETrue; |
|
130 SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStop ); |
|
131 break; |
|
132 |
|
133 case EAOManagerNWOpsAllowed: |
|
134 iNoNWOpsAllowed = EFalse; |
|
135 SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStart ); |
|
136 break; |
|
137 |
|
138 case EAOManagerStartedRoaming: |
|
139 SendCommandToMailboxesL( |
|
140 CIpsSosAOMBoxLogic::ECommandStartedRoaming ); |
|
141 break; |
|
142 |
|
143 case EAOManagerStoppedRoaming: |
|
144 SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStoppedRoaming ); |
|
145 break; |
|
146 |
|
147 case EAOManagerDiskSpaceAboveCritical: |
|
148 if ( !iNoNWOpsAllowed ) |
|
149 { |
|
150 SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStart ); |
|
151 } |
|
152 break; |
|
153 |
|
154 case EAOManagerDiskSpaceBelowCritical: |
|
155 SendCommandToMailboxesL( CIpsSosAOMBoxLogic::ECommandStop ); |
|
156 break; |
|
157 case EAOManagerSuicideQuery: |
|
158 // Always tell to server, that we don't |
|
159 // want to make a suicide. |
|
160 result = EFalse; |
|
161 break; |
|
162 // Mailbox handling |
|
163 case EAOManagerMailboxAgentSuspend: |
|
164 SendCommandToSpecificMailboxL( mailboxId, |
|
165 CIpsSosAOMBoxLogic::ECommandStop ); |
|
166 break; |
|
167 case EAOManagerMailboxAgentResume: |
|
168 RefreshMailboxListL( ); |
|
169 if ( !iNoNWOpsAllowed ) |
|
170 { |
|
171 SendCommandToSpecificMailboxL( mailboxId, |
|
172 CIpsSosAOMBoxLogic::ECommandStart ); |
|
173 } |
|
174 break; |
|
175 case EAOManagerMailboxAgentRemove: |
|
176 StopAndRemoveMailboxL( mailboxId ); |
|
177 //cancel all |
|
178 break; |
|
179 case EAOManagerEMNReceived: |
|
180 if ( aParameters ) |
|
181 { |
|
182 HandleEMNMessageL( *aParameters ); |
|
183 } |
|
184 break; |
|
185 case EAOManagerMailboxAgentUpdateMailWhileConnected: |
|
186 // Not supported atm, was in old plugin Imap-idle |
|
187 break; |
|
188 case EAOManagerQueryState: |
|
189 result = QueryMailboxStatus( *aParameters ); |
|
190 break; |
|
191 case EAOManagerCancelAllAndDisconnect: |
|
192 SendCommandToSpecificMailboxL( mailboxId, |
|
193 CIpsSosAOMBoxLogic::ECommandCancelAndDisconnect ); |
|
194 break; |
|
195 case EAOManagerCancelAllAndDoNotDisconnect: |
|
196 SendCommandToSpecificMailboxL( mailboxId, |
|
197 CIpsSosAOMBoxLogic::ECommandCancelDoNotDiconnect ); |
|
198 break; |
|
199 case EAOManagerSuspend: |
|
200 SendCommandToSpecificMailboxL( mailboxId, |
|
201 CIpsSosAOMBoxLogic::ECommandSuspend ); |
|
202 break; |
|
203 case EAOManagerContinue: |
|
204 SendCommandToSpecificMailboxL( mailboxId, |
|
205 CIpsSosAOMBoxLogic::ECommandContinue ); |
|
206 break; |
|
207 case EAOManagerDoNotDisconnect: |
|
208 SendCommandToSpecificMailboxL( mailboxId, |
|
209 CIpsSosAOMBoxLogic::ECommandDoNotDisconnect ); |
|
210 break; |
|
211 // error in CActiveScheduler |
|
212 // EAOManagerAOSchdulerError not handled because |
|
213 // there's no badly behaving active objects |
|
214 case EAOManagerAOSchdulerError: |
|
215 default: |
|
216 result = KErrNotSupported; |
|
217 break; |
|
218 } |
|
219 |
|
220 |
|
221 // </cmail> |
|
222 return result; |
|
223 } |
|
224 |
|
225 // ---------------------------------------------------------------------------- |
|
226 // ---------------------------------------------------------------------------- |
|
227 // |
|
228 void CIpsSosAOImapPopLogic::HandleMsvSessionEventL( |
|
229 // <cmail> RD_IPS_AO_PLUGIN flag removed |
|
230 MMsvSessionObserver::TMsvSessionEvent aEvent, |
|
231 TAny* aArg1, TAny* aArg2, TAny* /*aArg3*/ ) |
|
232 { |
|
233 FUNC_LOG; |
|
234 switch( aEvent ) |
|
235 { |
|
236 case MMsvSessionObserver::EMsvEntriesCreated: |
|
237 break; |
|
238 case MMsvSessionObserver::EMsvEntriesChanged: |
|
239 { |
|
240 TMsvId parent = (*(TMsvId*) (aArg2)); |
|
241 //we check that parent is the root. if not, it cannot be a |
|
242 //event from service, thus can't be from connection change.. |
|
243 if ( parent == KMsvRootIndexEntryId ) |
|
244 { |
|
245 const CMsvEntrySelection* selection = |
|
246 static_cast<CMsvEntrySelection*>( aArg1 ); |
|
247 |
|
248 TMsvEntry tEntry; |
|
249 TMsvId service; |
|
250 if ( selection->Count() ) |
|
251 { |
|
252 iSession.GetEntry( selection->At(0), service, tEntry ); |
|
253 } |
|
254 |
|
255 if ( !tEntry.Connected() ) |
|
256 { |
|
257 SendCommandToSpecificMailboxL( |
|
258 tEntry.Id(), |
|
259 CIpsSosAOMBoxLogic::ECommandClearDoNotDisconnect ); |
|
260 } |
|
261 } |
|
262 } |
|
263 break; |
|
264 case MMsvSessionObserver::EMsvEntriesDeleted: |
|
265 // NOTE: if mailbox is deleted somewhere else than ips plugin |
|
266 // in here need to put logic for removing corresponding |
|
267 // mailboxlogic object |
|
268 case MMsvSessionObserver::EMsvEntriesMoved: |
|
269 default: |
|
270 break; |
|
271 }; |
|
272 // </cmail> |
|
273 } |
|
274 |
|
275 // ---------------------------------------------------------------------------- |
|
276 // ---------------------------------------------------------------------------- |
|
277 // |
|
278 void CIpsSosAOImapPopLogic::SendCommandToMailboxesL( |
|
279 TInt aCommand ) |
|
280 { |
|
281 FUNC_LOG; |
|
282 for ( TInt i = 0; i < iMailboxLogics.Count(); i++ ) |
|
283 { |
|
284 iMailboxLogics[i]->SendCommandL( aCommand ); |
|
285 } |
|
286 } |
|
287 |
|
288 // ---------------------------------------------------------------------------- |
|
289 // ---------------------------------------------------------------------------- |
|
290 // |
|
291 void CIpsSosAOImapPopLogic::StopAndRemoveMailboxL( TMsvId aMailboxId ) |
|
292 { |
|
293 FUNC_LOG; |
|
294 TInt index = GetMailboxLogicIndex( aMailboxId ); |
|
295 |
|
296 if ( index != KErrNotFound ) |
|
297 { |
|
298 SendCommandToSpecificMailboxL( aMailboxId, |
|
299 CIpsSosAOMBoxLogic::ECommandStop ); |
|
300 delete iMailboxLogics[index]; |
|
301 iMailboxLogics.Remove( index ); |
|
302 } |
|
303 } |
|
304 |
|
305 // ---------------------------------------------------------------------------- |
|
306 // ---------------------------------------------------------------------------- |
|
307 // |
|
308 void CIpsSosAOImapPopLogic::SendCommandToSpecificMailboxL( |
|
309 TMsvId aMailboxId, |
|
310 TInt aCommand ) |
|
311 { |
|
312 FUNC_LOG; |
|
313 TInt index = GetMailboxLogicIndex( aMailboxId ); |
|
314 |
|
315 if ( index != KErrNotFound ) |
|
316 { |
|
317 iMailboxLogics[index]->SendCommandL( aCommand ); // faulty CS warning |
|
318 } |
|
319 } |
|
320 |
|
321 // ---------------------------------------------------------------------------- |
|
322 // ---------------------------------------------------------------------------- |
|
323 // |
|
324 void CIpsSosAOImapPopLogic::HandleEMNMessageL( |
|
325 const TDesC8& aParameters ) |
|
326 { |
|
327 FUNC_LOG; |
|
328 TEMNElement elements; |
|
329 |
|
330 if ( iEmnResolver->ParameterDispatchTEMNElement( |
|
331 aParameters, elements ) == KErrNone ) |
|
332 { |
|
333 |
|
334 TInt index = iEmnResolver->FindEMNMailbox( |
|
335 elements.mailbox, iMailboxLogics ); |
|
336 |
|
337 if ( index != KErrNotFound ) |
|
338 { |
|
339 CIpsSosAOMBoxLogic* logic = iMailboxLogics[index]; |
|
340 //<cmail> |
|
341 if ( !logic->FirstEMNReceived() ) |
|
342 { |
|
343 logic->SetFirstEMNReceived(); |
|
344 } |
|
345 if ( !iNoNWOpsAllowed && |
|
346 !logic->IsMailboxRoamingStoppedL() ) |
|
347 //</cmail> |
|
348 { |
|
349 SendCommandToSpecificMailboxL( |
|
350 logic->GetMailboxId(), // faulty CS warning |
|
351 CIpsSosAOMBoxLogic::ECommandStartSync ); |
|
352 } |
|
353 else |
|
354 { |
|
355 //<cmail> |
|
356 logic->SetEmnReceivedFlagL( ETrue ); |
|
357 //</cmail> |
|
358 } |
|
359 logic = NULL; |
|
360 } |
|
361 /*<cmail> |
|
362 else |
|
363 { |
|
364 } |
|
365 </cmail>*/ |
|
366 } |
|
367 } |
|
368 |
|
369 // ---------------------------------------------------------------------------- |
|
370 // ---------------------------------------------------------------------------- |
|
371 // |
|
372 void CIpsSosAOImapPopLogic::RefreshMailboxListL( ) |
|
373 { |
|
374 FUNC_LOG; |
|
375 CMsvEntry* cEntry = iSession.GetEntryL( KMsvRootIndexEntryId ); |
|
376 CleanupStack::PushL( cEntry ); |
|
377 |
|
378 CMsvEntrySelection* childEntries = cEntry->ChildrenWithMtmL( KSenduiMtmPop3Uid ); |
|
379 CleanupStack::PushL( childEntries ); |
|
380 UpdateLogicArrayL( *childEntries ); |
|
381 CleanupStack::PopAndDestroy( childEntries ); |
|
382 |
|
383 childEntries = cEntry->ChildrenWithMtmL( KSenduiMtmImap4Uid ); |
|
384 CleanupStack::PushL( childEntries ); |
|
385 UpdateLogicArrayL( *childEntries ); |
|
386 CleanupStack::PopAndDestroy( childEntries ); |
|
387 CleanupStack::PopAndDestroy( cEntry ); |
|
388 } |
|
389 |
|
390 // ---------------------------------------------------------------------------- |
|
391 // ---------------------------------------------------------------------------- |
|
392 // |
|
393 void CIpsSosAOImapPopLogic::UpdateLogicArrayL( |
|
394 const CMsvEntrySelection& aChilds ) |
|
395 { |
|
396 FUNC_LOG; |
|
397 for ( TInt i = 0; i < aChilds.Count(); i++ ) |
|
398 { |
|
399 TBool found = EFalse; |
|
400 TMsvId mboxId = aChilds.At(i); |
|
401 for ( TInt j = 0; !found && j < iMailboxLogics.Count(); j++ ) |
|
402 { |
|
403 if ( iMailboxLogics[j]->GetMailboxId() == mboxId ) |
|
404 { |
|
405 found = ETrue; |
|
406 } |
|
407 } |
|
408 |
|
409 CIpsSetDataExtension* extSet = CIpsSetDataExtension::NewLC(); |
|
410 TRAPD( error, iDataApi->LoadExtendedSettingsL( |
|
411 mboxId, *extSet ) ); |
|
412 if ( error == KErrNone ) |
|
413 { |
|
414 if ( !found && ( extSet->AlwaysOnlineState() != EMailAoOff || |
|
415 extSet->EmailNotificationState() != EMailEmnOff || |
|
416 !extSet->FirstEmnReceived() ) |
|
417 ) |
|
418 { |
|
419 CIpsSosAOMBoxLogic* newLogic = CIpsSosAOMBoxLogic::NewL( |
|
420 iSession, mboxId ); |
|
421 CleanupStack::PushL( newLogic ); |
|
422 iMailboxLogics.AppendL( newLogic ); |
|
423 CleanupStack::Pop( newLogic ); |
|
424 } |
|
425 else if ( found && extSet->AlwaysOnlineState() == EMailAoOff && |
|
426 extSet->EmailNotificationState() == EMailEmnOff && |
|
427 extSet->FirstEmnReceived() ) |
|
428 { |
|
429 StopAndRemoveMailboxL( mboxId ); |
|
430 } |
|
431 } |
|
432 CleanupStack::PopAndDestroy( extSet ); |
|
433 } |
|
434 } |
|
435 |
|
436 // ---------------------------------------------------------------------------- |
|
437 // ---------------------------------------------------------------------------- |
|
438 // |
|
439 TInt CIpsSosAOImapPopLogic::QueryMailboxStatus( TDesC8& aParameter ) |
|
440 { |
|
441 FUNC_LOG; |
|
442 TPckgBuf<RMessage2> param; |
|
443 param.Copy( aParameter ); |
|
444 // get ipc message from param |
|
445 RMessage2 msg = param(); |
|
446 TPckgBuf<TMsvId> mboxBuf; |
|
447 msg.Read(0, mboxBuf); |
|
448 |
|
449 TMsvId mbox = mboxBuf(); |
|
450 |
|
451 TInt error = KErrNone; |
|
452 |
|
453 TInt index = GetMailboxLogicIndex( mbox ); |
|
454 |
|
455 |
|
456 if ( index != KErrNotFound ) |
|
457 { |
|
458 TInt state = iMailboxLogics[index]->GetCurrentState(); // faulty CS warning |
|
459 |
|
460 if ( state == CIpsSosAOMBoxLogic::EStateSyncOngoing |
|
461 || state == CIpsSosAOMBoxLogic::EStateFetchOngoing ) |
|
462 { |
|
463 TPckgBuf<TInt> event( EIpsAOPluginStatusSyncStarted ); |
|
464 msg.Write(1, event ); |
|
465 } |
|
466 else |
|
467 { |
|
468 TPckgBuf<TInt> event( EIpsAOPluginStatusSyncCompleted ); |
|
469 msg.Write(1, event ); |
|
470 } |
|
471 } |
|
472 else |
|
473 { |
|
474 error = KErrNotFound; |
|
475 } |
|
476 |
|
477 return error; |
|
478 } |
|
479 |
|
480 // ---------------------------------------------------------------------------- |
|
481 // ---------------------------------------------------------------------------- |
|
482 // |
|
483 TInt CIpsSosAOImapPopLogic::GetMailboxLogicIndex( TMsvId aMailboxId ) |
|
484 { |
|
485 FUNC_LOG; |
|
486 TInt index = KErrNotFound; |
|
487 for ( TInt i = 0; |
|
488 index == KErrNotFound && i < iMailboxLogics.Count(); i++ ) |
|
489 { |
|
490 if ( iMailboxLogics[i]->GetMailboxId() == aMailboxId ) |
|
491 { |
|
492 index = i; |
|
493 } |
|
494 } |
|
495 return index; |
|
496 } |
|
497 |
|
498 // End of file |
|
499 |