|
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: ImumInHealthServicesImpl.cpp |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32base.h> |
|
21 #include <MuiuMsvUiServiceUtilities.h> // MsvUiServiceUtilities |
|
22 #include <cemailaccounts.h> // CEmailAccounts |
|
23 #include <etelmm.h> |
|
24 #include <SendUiConsts.h> |
|
25 |
|
26 #include "ImumInternalApiImpl.h" // CImumInternalApiImpl |
|
27 #include "ImumMboxManager.h" |
|
28 #include "EmailUtils.H" |
|
29 #include "ImumInHealthServicesImpl.h" |
|
30 #include "ImumInMailboxUtilitiesImpl.h" |
|
31 #include "ImumUtilsLogging.h" |
|
32 |
|
33 |
|
34 |
|
35 // EXTERNAL DATA STRUCTURES |
|
36 // EXTERNAL FUNCTION PROTOTYPES |
|
37 // CONSTANTS |
|
38 // MACROS |
|
39 #ifdef __WINS__ |
|
40 _LIT( KIMAEmulatorImei, "123456789012345" ); |
|
41 #endif // __WINS__ |
|
42 |
|
43 // LOCAL CONSTANTS AND MACROS |
|
44 // MODULE DATA STRUCTURES |
|
45 // LOCAL FUNCTION PROTOTYPES |
|
46 // FORWARD DECLARATIONS |
|
47 |
|
48 // ============================ MEMBER FUNCTIONS =============================== |
|
49 |
|
50 // ---------------------------------------------------------------------------- |
|
51 // CImumInHealthServicesImpl::CImumInHealthServicesImpl() |
|
52 // ---------------------------------------------------------------------------- |
|
53 // |
|
54 CImumInHealthServicesImpl::CImumInHealthServicesImpl( |
|
55 CImumInternalApiImpl& aMailboxApi ) |
|
56 : |
|
57 iInternalApi( aMailboxApi ), |
|
58 iExtendedSettings( NULL ), |
|
59 iRoot( NULL ), |
|
60 iUtils( NULL ) |
|
61 { |
|
62 IMUM_CONTEXT( CImumInHealthServicesImpl::CImumInHealthServicesImpl, 0, KLogInApi ); |
|
63 IMUM_IN(); |
|
64 IMUM_OUT(); |
|
65 } |
|
66 |
|
67 // ---------------------------------------------------------------------------- |
|
68 // CImumInHealthServicesImpl::~CImumInHealthServicesImpl() |
|
69 // ---------------------------------------------------------------------------- |
|
70 // |
|
71 CImumInHealthServicesImpl::~CImumInHealthServicesImpl() |
|
72 { |
|
73 IMUM_CONTEXT( CImumInHealthServicesImpl::~CImumInHealthServicesImpl, 0, KLogInApi ); |
|
74 IMUM_IN(); |
|
75 |
|
76 delete iExtendedSettings; |
|
77 iExtendedSettings = NULL; |
|
78 delete iRoot; |
|
79 iRoot = NULL; |
|
80 iUtils = NULL; |
|
81 |
|
82 IMUM_OUT(); |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------------------------- |
|
86 // CImumInHealthServicesImpl::ConstructL() |
|
87 // ---------------------------------------------------------------------------- |
|
88 // |
|
89 void CImumInHealthServicesImpl::ConstructL() |
|
90 { |
|
91 IMUM_CONTEXT( CImumInHealthServicesImpl::ConstructL, 0, KLogInApi ); |
|
92 IMUM_IN(); |
|
93 |
|
94 iExtendedSettings = CImumMboxDataExtension::NewL(); |
|
95 GetIMEIFromThePhoneL(); |
|
96 iRoot = iInternalApi.MsvSession().GetEntryL( KMsvRootIndexEntryIdValue ); |
|
97 iRoot->SetSortTypeL( TMsvSelectionOrdering( |
|
98 KMsvGroupByType | KMsvGroupByStandardFolders, |
|
99 EMsvSortByDetailsReverse, ETrue ) ); |
|
100 iUtils = const_cast<MImumInMailboxUtilities*>( |
|
101 &iInternalApi.MailboxUtilitiesL() ); |
|
102 |
|
103 IMUM_OUT(); |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------------------------- |
|
107 // CImumInHealthServicesImpl::NewL() |
|
108 // ---------------------------------------------------------------------------- |
|
109 // |
|
110 CImumInHealthServicesImpl* CImumInHealthServicesImpl::NewL( |
|
111 CImumInternalApiImpl& aMailboxApi ) |
|
112 { |
|
113 IMUM_STATIC_CONTEXT( CImumInHealthServicesImpl::NewL, 0, utils, KLogInApi ); |
|
114 IMUM_IN(); |
|
115 |
|
116 CImumInHealthServicesImpl* self = NewLC( aMailboxApi ); |
|
117 CleanupStack::Pop( self ); |
|
118 |
|
119 IMUM_OUT(); |
|
120 |
|
121 return self; |
|
122 } |
|
123 |
|
124 // ---------------------------------------------------------------------------- |
|
125 // CImumInHealthServicesImpl::NewLC() |
|
126 // ---------------------------------------------------------------------------- |
|
127 // |
|
128 CImumInHealthServicesImpl* CImumInHealthServicesImpl::NewLC( |
|
129 CImumInternalApiImpl& aMailboxApi ) |
|
130 { |
|
131 IMUM_STATIC_CONTEXT( CImumInHealthServicesImpl::NewLC, 0, utils, KLogInApi ); |
|
132 IMUM_IN(); |
|
133 |
|
134 CImumInHealthServicesImpl* self = new ( ELeave ) CImumInHealthServicesImpl( aMailboxApi ); |
|
135 |
|
136 CleanupStack::PushL( self ); |
|
137 self->ConstructL(); |
|
138 |
|
139 IMUM_OUT(); |
|
140 |
|
141 return self; |
|
142 } |
|
143 |
|
144 /****************************************************************************** |
|
145 |
|
146 Cleanup operations |
|
147 |
|
148 ******************************************************************************/ |
|
149 |
|
150 // ---------------------------------------------------------------------------- |
|
151 // CImumInHealthServicesImpl::GetIMEIFromTheEntry() |
|
152 // ---------------------------------------------------------------------------- |
|
153 // |
|
154 TIMDErrors CImumInHealthServicesImpl::GetIMEIFromTheEntry( |
|
155 const TMsvId aEntryId, |
|
156 TDes& aIMEI ) const |
|
157 { |
|
158 TMsvEntry mailbox; |
|
159 TIMDErrors result = GetMailboxEntry( aEntryId, mailbox ); |
|
160 |
|
161 if ( result == EIMDNoError ) |
|
162 { |
|
163 aIMEI.Copy( mailbox.iDescription.Left( KIMAMaxPhoneIdLength ) ); |
|
164 } |
|
165 |
|
166 return result; |
|
167 } |
|
168 |
|
169 // ---------------------------------------------------------------------------- |
|
170 // CImumInHealthServicesImpl::GetIMEIFromTheEntry() |
|
171 // ---------------------------------------------------------------------------- |
|
172 // |
|
173 TIMDErrors CImumInHealthServicesImpl::GetIMEIFromTheEntry( |
|
174 const TMsvEntry& aEntry, |
|
175 TDes& aIMEI ) const |
|
176 { |
|
177 // IMEI is stored into description field |
|
178 aIMEI.Copy( aEntry.iDescription.Left( KIMAMaxPhoneIdLength ) ); |
|
179 |
|
180 return EIMDNoError; |
|
181 } |
|
182 |
|
183 // ---------------------------------------------------------------------------- |
|
184 // CImumInHealthServicesImpl::GetIMEIFromThePhone() |
|
185 // ---------------------------------------------------------------------------- |
|
186 // |
|
187 void CImumInHealthServicesImpl::GetIMEIFromThePhoneL() |
|
188 { |
|
189 IMUM_CONTEXT( CImumInHealthServicesImpl::GetIMEIFromThePhoneL, 0, KLogInApi ); |
|
190 IMUM_IN(); |
|
191 |
|
192 // In Emulator version, the imei cannot be fetched, so the basic number |
|
193 // is used instead |
|
194 #ifndef __WINS__ |
|
195 |
|
196 RTelServer telServer; |
|
197 User::LeaveIfError( telServer.Connect() ); |
|
198 CleanupClosePushL(telServer); |
|
199 |
|
200 TInt numPhones = 0; |
|
201 User::LeaveIfError( telServer.EnumeratePhones( numPhones ) ); |
|
202 if ( numPhones < 1 ) |
|
203 { |
|
204 User::Leave( KErrNotFound ); |
|
205 } |
|
206 RTelServer::TPhoneInfo info; |
|
207 User::LeaveIfError( telServer.GetPhoneInfo( 0, info ) ); |
|
208 RMobilePhone mobilePhone; |
|
209 User::LeaveIfError( mobilePhone.Open( telServer, info.iName ) ); |
|
210 CleanupClosePushL( mobilePhone ); |
|
211 |
|
212 //mobilePhone.Initialise(); |
|
213 TUint32 identityCaps; |
|
214 User::LeaveIfError( mobilePhone.GetIdentityCaps( identityCaps ) ); |
|
215 |
|
216 if ( identityCaps & RMobilePhone::KCapsGetSerialNumber ) |
|
217 { |
|
218 TRequestStatus status; |
|
219 RMobilePhone::TMobilePhoneIdentityV1 mobilePhoneIdentity; |
|
220 |
|
221 mobilePhone.GetPhoneId( status, mobilePhoneIdentity ); |
|
222 |
|
223 User::WaitForRequest( status ); |
|
224 User::LeaveIfError( status.Int() ); |
|
225 |
|
226 iIMEI.Copy( mobilePhoneIdentity.iSerialNumber ); |
|
227 } |
|
228 else |
|
229 { |
|
230 User::Leave( KErrNotSupported ); |
|
231 } |
|
232 |
|
233 CleanupStack::PopAndDestroy( &mobilePhone ); |
|
234 CleanupStack::PopAndDestroy( &telServer ); |
|
235 #else |
|
236 iIMEI.Copy( KIMAEmulatorImei ); |
|
237 #endif // __WINS__ |
|
238 |
|
239 IMUM1(0, "Phones IMEI code: %S", &iIMEI); |
|
240 |
|
241 IMUM_OUT(); |
|
242 } |
|
243 |
|
244 // ---------------------------------------------------------------------------- |
|
245 // CImumInHealthServicesImpl::StoreIMEIToMailbox() |
|
246 // ---------------------------------------------------------------------------- |
|
247 // |
|
248 TIMDErrors CImumInHealthServicesImpl::StoreIMEIToMailbox( |
|
249 const TMsvId aMailboxId ) const |
|
250 { |
|
251 IMUM_CONTEXT( CImumInHealthServicesImpl::StoreIMEIToMailbox, 0, KLogInApi ); |
|
252 IMUM1_IN( "aMailboxId = 0x%x", aMailboxId ); |
|
253 |
|
254 // Get available mailbox entries |
|
255 TMsvEntry entry; |
|
256 TIMDErrors result = GetMailboxEntry( aMailboxId, entry ); |
|
257 |
|
258 // Imap4 & Pop3 & Smtp protocols contain two entries |
|
259 if ( result == EIMDNoError ) |
|
260 { |
|
261 // Attempt to store the IMEI code to the entry |
|
262 result = StoreIMEIToEntry( entry.Id() ); |
|
263 } |
|
264 |
|
265 // Imap4 / Pop3 protocols have two different entries |
|
266 if ( iUtils->IsMailMtm( entry.iMtm ) ) |
|
267 { |
|
268 TMsvEntry secondaryEntry; |
|
269 result = GetMailboxEntry( entry.iRelatedId, entry ); |
|
270 |
|
271 if ( result == EIMDNoError ) |
|
272 { |
|
273 // Attempt to store the IMEI code to the entry |
|
274 result = StoreIMEIToEntry( entry.Id() ); |
|
275 } |
|
276 } |
|
277 |
|
278 IMUM_OUT(); |
|
279 |
|
280 return result; |
|
281 } |
|
282 |
|
283 |
|
284 // ---------------------------------------------------------------------------- |
|
285 // CImumInHealthServicesImpl::StoreIMEIToEntry() |
|
286 // ---------------------------------------------------------------------------- |
|
287 // |
|
288 TIMDErrors CImumInHealthServicesImpl::StoreIMEIToEntry( |
|
289 const TMsvId aMailboxId ) const |
|
290 { |
|
291 IMUM_CONTEXT( CImumInHealthServicesImpl::StoreIMEIToEntry, 0, KLogInApi ); |
|
292 IMUM1_IN( "aMailboxId = 0x%x", aMailboxId ); |
|
293 |
|
294 TRAPD( error, StoreIMEIToEntryL( aMailboxId ) ); |
|
295 |
|
296 IMUM_OUT(); |
|
297 return ( error == KErrNone ) ? EIMDNoError : EIMDStoringFailureWithIMEI; |
|
298 } |
|
299 |
|
300 |
|
301 // ---------------------------------------------------------------------------- |
|
302 // CImumInHealthServicesImpl::StoreIMEIToEntryL() |
|
303 // ---------------------------------------------------------------------------- |
|
304 // |
|
305 void CImumInHealthServicesImpl::StoreIMEIToEntryL( |
|
306 const TMsvId aMailboxId ) const |
|
307 { |
|
308 IMUM_CONTEXT( CImumInHealthServicesImpl::StoreIMEIToEntryL, 0, KLogInApi ); |
|
309 IMUM1_IN( "aMailboxId = 0x%x", aMailboxId ); |
|
310 |
|
311 CMsvEntry* centry = iInternalApi.MsvSession().GetEntryL( aMailboxId ); |
|
312 CleanupStack::PushL( centry ); |
|
313 |
|
314 TMsvEntry tentry = centry->Entry(); |
|
315 tentry.iDescription.Set( iIMEI ); |
|
316 centry->ChangeL( tentry ); |
|
317 |
|
318 CleanupStack::PopAndDestroy( centry ); |
|
319 centry = NULL; |
|
320 |
|
321 IMUM_OUT(); |
|
322 } |
|
323 |
|
324 // ---------------------------------------------------------------------------- |
|
325 // CImumInHealthServicesImpl::GetMailboxEntry() |
|
326 // ---------------------------------------------------------------------------- |
|
327 // |
|
328 TIMDErrors CImumInHealthServicesImpl::GetMailboxEntry( |
|
329 const TMsvId aMailboxId, |
|
330 TMsvEntry& aMailboxEntry ) const |
|
331 { |
|
332 IMUM_CONTEXT( CImumInHealthServicesImpl::GetMailboxEntry, 0, KLogInApi ); |
|
333 IMUM1_IN( "aMailboxId = 0x%x", aMailboxId ); |
|
334 |
|
335 // Get both receiving and sending entries of the mailbox |
|
336 TIMDErrors result = EIMDNoError; |
|
337 |
|
338 TMsvId service; |
|
339 TInt error = iInternalApi.MsvSession().GetEntry( |
|
340 aMailboxId, service, aMailboxEntry ); |
|
341 |
|
342 // Make sure getting of the entry was ok |
|
343 if ( error == KErrNone ) |
|
344 { |
|
345 // Verify that the entry has mail mtm |
|
346 if ( !iUtils->IsMailMtm( aMailboxEntry.iMtm, ETrue ) ) |
|
347 { |
|
348 result = EIMDNotMailMtmId; |
|
349 } |
|
350 // Mailbox, log the details |
|
351 else |
|
352 { |
|
353 IMUM0( 0, "************ Entry Data START ******************" ); |
|
354 IMUM1( 0, "MailboxId = 0x%x", aMailboxEntry.Id() ); |
|
355 IMUM1( 0, "RelatedId = 0x%x", aMailboxEntry.iRelatedId ); |
|
356 IMUM1( 0, "MTM type = 0x%x", aMailboxEntry.iMtm.iUid ); |
|
357 IMUM1( 0, "Visible = %d", aMailboxEntry.Visible() ); |
|
358 IMUM1( 0, "iMtmData2 = 0x%x", aMailboxEntry.iMtmData2 ); |
|
359 IMUM1( 0, "iDescription = %S", &aMailboxEntry.iDescription ); |
|
360 IMUM1( 0, "iDetails = %S", &aMailboxEntry.iDetails ); |
|
361 IMUM0( 0, "************* Entry Data END *******************" ); |
|
362 |
|
363 //Make sure that all settings are ok |
|
364 if ( aMailboxEntry.iDetails.Length() > KIMASMaxMailboxNameLength ) |
|
365 { |
|
366 if ( aMailboxEntry.iMtm == KUidMsgTypeIMAP4 ) |
|
367 { |
|
368 result = EIMDGetEntryFailure; |
|
369 TRAP_IGNORE( result = iInternalApi.SettingsStorerL().CheckMailboxNameImap( aMailboxEntry ) ); |
|
370 // Should SettingsStorerL leave, result == EIMDGetEntryFailure |
|
371 } |
|
372 else if ( aMailboxEntry.iMtm == KUidMsgTypePOP3 ) |
|
373 { |
|
374 result = EIMDGetEntryFailure; |
|
375 TRAP_IGNORE( result = iInternalApi.SettingsStorerL().CheckMailboxNamePop( aMailboxEntry ) ); |
|
376 // Should SettingsStorerL leave, result == EIMDGetEntryFailure |
|
377 } |
|
378 else if ( aMailboxEntry.iMtm == KUidMsgTypeSMTP ) |
|
379 { |
|
380 result = EIMDGetEntryFailure; |
|
381 TRAP_IGNORE( result = iInternalApi.SettingsStorerL().CheckMailboxNameSmtp( aMailboxEntry ) ); |
|
382 // Should SettingsStorerL leave, result == EIMDGetEntryFailure |
|
383 } |
|
384 else |
|
385 { |
|
386 result = EIMDGetEntryFailure; |
|
387 } |
|
388 } |
|
389 } |
|
390 } |
|
391 else |
|
392 { |
|
393 result = EIMDGetEntryFailure; |
|
394 } |
|
395 |
|
396 IMUM1( 0, "Result of getting the entry: %d", result ); |
|
397 IMUM_OUT(); |
|
398 return result; |
|
399 } |
|
400 |
|
401 // ---------------------------------------------------------------------------- |
|
402 // CImumInHealthServicesImpl::VerifyMailboxHealth() |
|
403 // ---------------------------------------------------------------------------- |
|
404 // |
|
405 TIMDErrors CImumInHealthServicesImpl::VerifyMailboxHealth( |
|
406 const TMsvId aMailboxId ) const |
|
407 { |
|
408 IMUM_CONTEXT( CImumInHealthServicesImpl::VerifyMailboxHealth, 0, KLogInApi ); |
|
409 IMUM1_IN( "aMailboxId = 0x%x", aMailboxId ); |
|
410 |
|
411 TMsvEntry primaryEntry; |
|
412 TMsvEntry secondaryEntry; |
|
413 TMsvEntry* secondaryEntryPtr = NULL; |
|
414 TIMDErrors verification = GetMailboxEntry( aMailboxId, primaryEntry ); |
|
415 |
|
416 // Imap4 & Pop3 & Smtp protocols contain two entries |
|
417 if ( verification == EIMDNoError && |
|
418 iUtils->IsMailMtm( primaryEntry.iMtm ) ) |
|
419 { |
|
420 verification = GetMailboxEntry( |
|
421 primaryEntry.iRelatedId, secondaryEntry ); |
|
422 |
|
423 if ( verification == EIMDNoError ) |
|
424 { |
|
425 secondaryEntryPtr = &secondaryEntry; |
|
426 } |
|
427 } |
|
428 |
|
429 // Make sure |
|
430 if ( verification == EIMDNoError ) |
|
431 { |
|
432 verification = VerifyMailboxHealth( primaryEntry, secondaryEntryPtr ); |
|
433 } |
|
434 |
|
435 IMUM_OUT(); |
|
436 return verification; |
|
437 } |
|
438 |
|
439 // ---------------------------------------------------------------------------- |
|
440 // CImumInHealthServicesImpl::VerifyMailboxHealth() |
|
441 // ---------------------------------------------------------------------------- |
|
442 // |
|
443 TIMDErrors CImumInHealthServicesImpl::VerifyMailboxHealth( |
|
444 const TMsvEntry& aPrimaryEntry, |
|
445 const TMsvEntry* aSecondaryEntry ) const |
|
446 { |
|
447 IMUM_CONTEXT( CImumInHealthServicesImpl::VerifyMailboxHealth, 0, KLogInApi ); |
|
448 IMUM_IN(); |
|
449 |
|
450 // Verify that SMTP part of the mailbox has got the settings |
|
451 // Verify that SMTP account id's matches with the settings |
|
452 // Verify that SMTP mailbox id's matches with the settings |
|
453 TIMDErrors verification = MatchEntryWithSettings( aPrimaryEntry ); |
|
454 IMUM1( 0, "Mailbox primary entry IMEI settings matching result: %d", verification ); |
|
455 |
|
456 // Verify that related part of the mailbox has got the settings |
|
457 // Verify that related account id's matches with the settings |
|
458 // Verify that related mailbox id's matches with the settings |
|
459 if ( !verification && aSecondaryEntry ) |
|
460 { |
|
461 verification = MatchEntryWithSettings( *aSecondaryEntry ); |
|
462 IMUM1( 0, "Mailbox secondary entry IMEI settings matching result: %d", verification ); |
|
463 } |
|
464 |
|
465 // Verify that primary entry has IMEI code stored |
|
466 if ( !verification ) |
|
467 { |
|
468 verification = VerifyEntryIMEI( aPrimaryEntry ); |
|
469 IMUM1( 0, "Mailbox primary entry IMEI verification result: %d", verification ); |
|
470 if( verification == EIMDMissingIMEI ) |
|
471 { |
|
472 // Mailbox has no IMEI code stored. This Mailbox is most likely created |
|
473 // with CEmailAccounts. Lock the account to current Phone. |
|
474 verification = StoreIMEIToMailbox( aPrimaryEntry.Id() ); |
|
475 IMUM1( 0, "IMEI missing. Lock to current device: %d", verification ); |
|
476 } |
|
477 } |
|
478 |
|
479 // Verify that related entry has IMEI code stored |
|
480 if ( !verification && aSecondaryEntry ) |
|
481 { |
|
482 verification = VerifyEntryIMEI( *aSecondaryEntry ); |
|
483 IMUM1( 0, "Mailbox secondary entry IMEI verification result: %d", verification ); |
|
484 if( verification == EIMDMissingIMEI ) |
|
485 { |
|
486 // Mailbox has no IMEI code stored. This Mailbox is most likely created |
|
487 // with CEmailAccounts. Lock the account to current Phone. |
|
488 verification = StoreIMEIToMailbox( aSecondaryEntry->Id() ); |
|
489 IMUM1( 0, "IMEI missing. Lock to current device: %d", verification ); |
|
490 } |
|
491 } |
|
492 |
|
493 IMUM_OUT(); |
|
494 |
|
495 return verification; |
|
496 } |
|
497 |
|
498 // ---------------------------------------------------------------------------- |
|
499 // CImumInHealthServicesImpl::MatchEntryWithSettings() |
|
500 // ---------------------------------------------------------------------------- |
|
501 // |
|
502 TIMDErrors CImumInHealthServicesImpl::MatchEntryWithSettings( |
|
503 const TMsvEntry& aMailbox ) const |
|
504 { |
|
505 IMUM_CONTEXT( CImumInHealthServicesImpl::MatchEntryWithSettings, 0, KLogInApi ); |
|
506 IMUM1_IN( "aMailbox.Id = 0x%x", aMailbox.Id() ); |
|
507 IMUM_OUT(); |
|
508 |
|
509 switch ( aMailbox.iMtm.iUid ) |
|
510 { |
|
511 case KSenduiMtmImap4UidValue: |
|
512 return VerifyImap4EntryWithSettings( aMailbox ); |
|
513 |
|
514 case KSenduiMtmPop3UidValue: |
|
515 return VerifyPop3EntryWithSettings( aMailbox ); |
|
516 |
|
517 case KSenduiMtmSmtpUidValue: |
|
518 return VerifySmtpEntryWithSettings( aMailbox ); |
|
519 |
|
520 default: |
|
521 // 3rd party mailbox |
|
522 // MTM UID is unknown -> check technology type and return |
|
523 // EIMDNoError if it is mailbox |
|
524 if( iUtils->IsMailbox( aMailbox.Id() ) ) |
|
525 { |
|
526 return EIMDNoError; |
|
527 } |
|
528 break; |
|
529 } |
|
530 |
|
531 return EIMDUnknownMailbox; |
|
532 } |
|
533 |
|
534 // ---------------------------------------------------------------------------- |
|
535 // CImumInHealthServicesImpl::VerifyImap4EntryWithSettings() |
|
536 // ---------------------------------------------------------------------------- |
|
537 // |
|
538 TIMDErrors CImumInHealthServicesImpl::VerifyImap4EntryWithSettings( |
|
539 const TMsvEntry& aMailbox ) const |
|
540 { |
|
541 IMUM_CONTEXT( CImumInHealthServicesImpl::VerifyImap4EntryWithSettings, 0, KLogInApi ); |
|
542 IMUM1_IN( "aMailbox.Id = 0x%x", aMailbox.Id() ); |
|
543 |
|
544 // Get IMAP4 account information from the repository |
|
545 TIMDErrors verification = EIMDNoError; |
|
546 TImapAccount imapAccount; |
|
547 TRAPD( error, iInternalApi.EmailAccountsL().GetImapAccountL( |
|
548 aMailbox.Id(), imapAccount ) ); |
|
549 |
|
550 // Continue only, if successful |
|
551 if ( error == KErrNone ) |
|
552 { |
|
553 // Verify that the entry's account id matches with repository |
|
554 if ( aMailbox.iMtmData2 != imapAccount.iImapAccountId ) |
|
555 { |
|
556 verification = EIMDImap4AccountIdNotMatching; |
|
557 } |
|
558 |
|
559 // Verify that the related id matches with the one in the repository |
|
560 if ( verification == EIMDNoError && |
|
561 aMailbox.iRelatedId != imapAccount.iSmtpService ) |
|
562 { |
|
563 verification = EIMDImap4RelatedEntryIdNotMatching; |
|
564 } |
|
565 } |
|
566 else |
|
567 { |
|
568 verification = EIMDImap4AccountFailure; |
|
569 } |
|
570 |
|
571 IMUM_OUT(); |
|
572 return verification; |
|
573 } |
|
574 |
|
575 // ---------------------------------------------------------------------------- |
|
576 // CImumInHealthServicesImpl::VerifyPop3EntryWithSettings() |
|
577 // ---------------------------------------------------------------------------- |
|
578 // |
|
579 TIMDErrors CImumInHealthServicesImpl::VerifyPop3EntryWithSettings( |
|
580 const TMsvEntry& aMailbox ) const |
|
581 { |
|
582 IMUM_CONTEXT( CImumInHealthServicesImpl::VerifyPop3EntryWithSettings, 0, KLogInApi ); |
|
583 IMUM1_IN( "aMailbox.Id = 0x%x", aMailbox.Id() ); |
|
584 |
|
585 // Get POP3 account information from the repository |
|
586 TIMDErrors verification = EIMDNoError; |
|
587 TPopAccount popAccount; |
|
588 TRAPD( error, iInternalApi.EmailAccountsL().GetPopAccountL( |
|
589 aMailbox.Id(), popAccount ) ); |
|
590 |
|
591 // Continue only, if successful |
|
592 if ( error == KErrNone ) |
|
593 { |
|
594 // Verify that the entry's account id matches with repository |
|
595 if ( aMailbox.iMtmData2 != popAccount.iPopAccountId ) |
|
596 { |
|
597 verification = EIMDPop3AccountIdNotMatching; |
|
598 } |
|
599 |
|
600 // Verify that the related id matches with the one in the repository |
|
601 if ( verification == EIMDNoError && |
|
602 aMailbox.iRelatedId != popAccount.iSmtpService ) |
|
603 { |
|
604 verification = EIMDPop3RelatedEntryIdNotMatching; |
|
605 } |
|
606 } |
|
607 else |
|
608 { |
|
609 verification = EIMDPop3AccountFailure; |
|
610 } |
|
611 |
|
612 IMUM_OUT(); |
|
613 return verification; |
|
614 } |
|
615 |
|
616 // ---------------------------------------------------------------------------- |
|
617 // CImumInHealthServicesImpl::VerifySmtpEntryWithSettings() |
|
618 // ---------------------------------------------------------------------------- |
|
619 // |
|
620 TIMDErrors CImumInHealthServicesImpl::VerifySmtpEntryWithSettings( |
|
621 const TMsvEntry& aMailbox ) const |
|
622 { |
|
623 IMUM_CONTEXT( CImumInHealthServicesImpl::VerifySmtpEntryWithSettings, 0, KLogInApi ); |
|
624 IMUM1_IN( "aMailbox.Id = 0x%x", aMailbox.Id() ); |
|
625 |
|
626 // Get SMTP account information from the repository |
|
627 TIMDErrors verification = EIMDNoError; |
|
628 TSmtpAccount smtpAccount; |
|
629 TRAPD( error, iInternalApi.EmailAccountsL().GetSmtpAccountL( |
|
630 aMailbox.Id(), smtpAccount ) ); |
|
631 |
|
632 // Continue only, if successful |
|
633 if ( error == KErrNone ) |
|
634 { |
|
635 // Verify that the entry's account id matches with repository |
|
636 if ( aMailbox.iMtmData2 != smtpAccount.iSmtpAccountId ) |
|
637 { |
|
638 verification = EIMDSmtpAccountIdNotMatching; |
|
639 } |
|
640 |
|
641 // Verify that the related id matches with the one in the repository |
|
642 if ( verification == EIMDNoError && |
|
643 aMailbox.iRelatedId != smtpAccount.iRelatedService ) |
|
644 { |
|
645 verification = EIMDSmtpRelatedEntryIdNotMatching; |
|
646 } |
|
647 } |
|
648 else |
|
649 { |
|
650 verification = EIMDSmtpAccountFailure; |
|
651 } |
|
652 |
|
653 IMUM_OUT(); |
|
654 return verification; |
|
655 } |
|
656 |
|
657 // ---------------------------------------------------------------------------- |
|
658 // CImumInHealthServicesImpl::VerifyEntryIMEI() |
|
659 // ---------------------------------------------------------------------------- |
|
660 // |
|
661 TIMDErrors CImumInHealthServicesImpl::VerifyEntryIMEI( |
|
662 const TMsvEntry& aMailbox ) const |
|
663 { |
|
664 IMUM_CONTEXT( CImumInHealthServicesImpl::VerifyEntryIMEI, 0, KLogInApi ); |
|
665 IMUM1_IN( "aMailbox.Id = 0x%x", aMailbox.Id() ); |
|
666 |
|
667 TIMDErrors result = EIMDNoError; |
|
668 |
|
669 // In emulator, always return true for the IMEI verification, |
|
670 // so that mismatching IMEI codes doesn't prevent debugging |
|
671 |
|
672 // Make sure the field contains at least something |
|
673 if ( aMailbox.iDescription.Length() ) |
|
674 { |
|
675 if ( iIMEI.Match( aMailbox.iDescription ) ) |
|
676 { |
|
677 TDriveUnit driveUnit = EDriveC; |
|
678 TRAPD( err, driveUnit = |
|
679 iInternalApi.MsvSession().CurrentDriveL() ); |
|
680 |
|
681 // When memory card restored to another phone emailbox should be visible |
|
682 if ( err == KErrNone && driveUnit == EDriveC ) |
|
683 { |
|
684 result = StoreIMEIToMailbox( aMailbox.Id() ); |
|
685 } |
|
686 else |
|
687 { |
|
688 result = EIMDMismatchingIMEI; |
|
689 } |
|
690 } |
|
691 } |
|
692 else |
|
693 { |
|
694 result = EIMDMissingIMEI; |
|
695 } |
|
696 |
|
697 IMUM_OUT(); |
|
698 return result; |
|
699 } |
|
700 |
|
701 // ---------------------------------------------------------------------------- |
|
702 // CImumInHealthServicesImpl::IsRequiredMailbox() |
|
703 // ---------------------------------------------------------------------------- |
|
704 // |
|
705 TBool CImumInHealthServicesImpl::IsRequiredMailbox( |
|
706 const TMsvEntry& aEntry, |
|
707 const TMuiuFlags& aFlags ) const |
|
708 { |
|
709 IMUM_CONTEXT( CImumInHealthServicesImpl::IsRequiredMailbox, 0, KLogInApi ); |
|
710 IMUM1_IN( "aEntry.Id() = 0x%x", aEntry.Id() ); |
|
711 |
|
712 IMUM1( 0, "ServiceEntry: %d", aEntry.iType.iUid == KUidMsvServiceEntryValue ); |
|
713 IMUM1( 0, "Entry ID not Local: %d", aEntry.Id() != KMsvLocalServiceIndexEntryIdValue ); |
|
714 |
|
715 // Accept only services. |
|
716 TBool result = ( aEntry.iType.iUid == KUidMsvServiceEntryValue ) && |
|
717 ( aEntry.Id() != KMsvLocalServiceIndexEntryIdValue ); |
|
718 |
|
719 IMUM1( 0, "Result after service test: %d", result ); |
|
720 |
|
721 if ( result ) |
|
722 { |
|
723 IMUM1( 0, "Get healthy mailboxes: %d", !aFlags.Flag( EFlagHealthy ) ); |
|
724 IMUM1( 0, "Entry is visible: %d", aEntry.Visible() ); |
|
725 IMUM1( 0, "Entry is SMTP: %d", aEntry.iMtm == KSenduiMtmSmtpUid ); |
|
726 |
|
727 // For valid mailboxes, only visible entries are allowed. For cleanup, |
|
728 // all entries must be allowed. |
|
729 result = !aFlags.Flag( EFlagHealthy ) | aEntry.Visible(); |
|
730 |
|
731 // Smtp services are invisible, so the result must be acceptable |
|
732 // for them. |
|
733 result |= !aEntry.Visible() && aEntry.iMtm == KSenduiMtmSmtpUid; |
|
734 |
|
735 IMUM1( 0, "Result after entry test: %d", result ); |
|
736 } |
|
737 |
|
738 if ( result ) |
|
739 { |
|
740 // Entry is valid service entry. Now, check if the mailbox is... |
|
741 |
|
742 // ...Imap4 and it is required... |
|
743 IMUM2( 0, "IMAP4 required: %d AND entry is IMAP4 %d", |
|
744 aFlags.Flag( EFlagImap4 ), |
|
745 aEntry.iMtm == KSenduiMtmImap4Uid ); |
|
746 |
|
747 result = |
|
748 aFlags.Flag( EFlagImap4 ) && |
|
749 aEntry.iMtm == KSenduiMtmImap4Uid; |
|
750 |
|
751 // ...or Pop3 and it is required... |
|
752 IMUM2( 0, "POP3 required: %d AND entry is POP3 %d", |
|
753 aFlags.Flag( EFlagPop3 ), |
|
754 aEntry.iMtm == KSenduiMtmPop3Uid ); |
|
755 |
|
756 result |= |
|
757 aFlags.Flag( EFlagPop3 ) && |
|
758 aEntry.iMtm == KSenduiMtmPop3Uid; |
|
759 |
|
760 // ...or Smtp and it is required... |
|
761 IMUM2( 0, "SMTP required: %d AND entry is SMTP %d", |
|
762 aFlags.Flag( EFlagSmtp ), |
|
763 aEntry.iMtm == KSenduiMtmSmtpUid ); |
|
764 |
|
765 result |= |
|
766 aFlags.Flag( EFlagSmtp ) && |
|
767 aEntry.iMtm == KSenduiMtmSmtpUid; |
|
768 |
|
769 // ...or other MTM and it is required |
|
770 IMUM2( 0, "Other required: %d AND entry is other %d", |
|
771 aFlags.Flag( EFlagOtherService ), |
|
772 aEntry.iMtm != KSenduiMtmSmtpUid && |
|
773 aEntry.iMtm != KSenduiMtmPop3Uid && |
|
774 aEntry.iMtm != KSenduiMtmImap4Uid ); |
|
775 |
|
776 result |= |
|
777 aFlags.Flag( EFlagOtherService ) && |
|
778 aEntry.iMtm != KSenduiMtmSmtpUid && |
|
779 aEntry.iMtm != KSenduiMtmPop3Uid && |
|
780 aEntry.iMtm != KSenduiMtmImap4Uid; |
|
781 |
|
782 IMUM1( 0, "Result of service test: %d", result ); |
|
783 } |
|
784 |
|
785 IMUM_OUT(); |
|
786 return result; |
|
787 } |
|
788 |
|
789 // ---------------------------------------------------------------------------- |
|
790 // CImumInHealthServicesImpl::DoGetMailboxList() |
|
791 // ---------------------------------------------------------------------------- |
|
792 // |
|
793 void CImumInHealthServicesImpl::DoGetMailboxList( |
|
794 RMailboxIdArray& aMailboxArray, |
|
795 const TMuiuFlags& aFlags ) const |
|
796 { |
|
797 IMUM_CONTEXT( CImumInHealthServicesImpl::DoGetMailboxList, 0, KLogInApi ); |
|
798 IMUM_IN(); |
|
799 |
|
800 TBool getHealthy = aFlags.Flag( EFlagHealthy ); |
|
801 |
|
802 for ( TInt item = iRoot->Count(); --item >= 0; ) |
|
803 { |
|
804 // Check if the item is mailbox flagged to be retrieved |
|
805 const TMsvEntry& candidate = ( *iRoot )[item]; |
|
806 if ( IsRequiredMailbox( candidate, aFlags ) ) |
|
807 { |
|
808 // Append to array, if healthy and healthy required OR |
|
809 // unhealthy and unhealthy required |
|
810 if ( IsMailboxHealthy( candidate.Id() ) == getHealthy ) |
|
811 { |
|
812 IMUM1( 0, "Adding candidate 0x%x to list", candidate.Id() ); |
|
813 aMailboxArray.Append( candidate.Id() ); |
|
814 } |
|
815 } |
|
816 } |
|
817 |
|
818 IMUM_OUT(); |
|
819 } |
|
820 |
|
821 // ---------------------------------------------------------------------------- |
|
822 // CImumInHealthServicesImpl::DoCleanup() |
|
823 // ---------------------------------------------------------------------------- |
|
824 // |
|
825 void CImumInHealthServicesImpl::DoCleanup( |
|
826 const RMailboxIdArray& aMailboxArray ) const |
|
827 { |
|
828 IMUM_CONTEXT( CImumInHealthServicesImpl::DoCleanup, 0, KLogInApi ); |
|
829 IMUM_IN(); |
|
830 |
|
831 for ( TInt mailbox = aMailboxArray.Count(); --mailbox >= 0; ) |
|
832 { |
|
833 TMsvId serviceId; |
|
834 TMsvEntry entry; |
|
835 TInt error = iInternalApi.MsvSession().GetEntry( |
|
836 aMailboxArray[mailbox], serviceId, entry ); |
|
837 |
|
838 // We detect only missing settings, so remove the entries only if |
|
839 // created on this phone |
|
840 if ( error == KErrNone && VerifyEntryIMEI( entry ) == EIMDNoError ) |
|
841 { |
|
842 |
|
843 iInternalApi.MsvSession().RemoveEntry( entry.Id() ); |
|
844 iInternalApi.MsvSession().RemoveEntry( entry.iRelatedId ); |
|
845 } |
|
846 } |
|
847 |
|
848 IMUM_OUT(); |
|
849 } |
|
850 |
|
851 // ---------------------------------------------------------------------------- |
|
852 // CImumInHealthServicesImpl::PrepareFlags() |
|
853 // ---------------------------------------------------------------------------- |
|
854 // |
|
855 TMuiuFlags CImumInHealthServicesImpl::PrepareFlags( |
|
856 const TInt64 aFlags ) const |
|
857 { |
|
858 TMuiuFlags flags = aFlags; |
|
859 |
|
860 return flags; |
|
861 } |
|
862 |
|
863 /****************************************************************************** |
|
864 |
|
865 Functions from the base classes |
|
866 |
|
867 ******************************************************************************/ |
|
868 |
|
869 // ---------------------------------------------------------------------------- |
|
870 // CImumInHealthServicesImpl::GetMailboxList() |
|
871 // ---------------------------------------------------------------------------- |
|
872 // |
|
873 TInt CImumInHealthServicesImpl::GetMailboxList( |
|
874 RMailboxIdArray& aHealthyMailboxArray, |
|
875 const TInt64 aFlags, |
|
876 const TBool aClearArray ) const |
|
877 { |
|
878 IMUM_CONTEXT( CImumInHealthServicesImpl::GetMailboxList, 0, KLogInApi ); |
|
879 IMUM2_IN( "aFlags = 0x%x, aClearArray = %d", aFlags, aClearArray ); |
|
880 |
|
881 TInt error = KErrNone; |
|
882 |
|
883 if ( aClearArray ) |
|
884 { |
|
885 aHealthyMailboxArray.Reset(); |
|
886 } |
|
887 |
|
888 DoGetMailboxList( aHealthyMailboxArray, PrepareFlags( aFlags ) ); |
|
889 |
|
890 IMUM_OUT(); |
|
891 |
|
892 return error; |
|
893 } |
|
894 |
|
895 // ---------------------------------------------------------------------------- |
|
896 // CImumInHealthServicesImpl::GetHealthyMailboxList() |
|
897 // ---------------------------------------------------------------------------- |
|
898 // |
|
899 TInt CImumInHealthServicesImpl::GetHealthyMailboxList( |
|
900 RMailboxIdArray& aHealthyMailboxArray, |
|
901 const TInt64 aFlags, |
|
902 const TBool aClearArray ) const |
|
903 { |
|
904 IMUM_CONTEXT( CImumInHealthServicesImpl::GetHealthyMailboxList, 0, KLogInApi ); |
|
905 IMUM_IN(); |
|
906 |
|
907 IMUM_OUT(); |
|
908 return GetMailboxList( aHealthyMailboxArray, aFlags, aClearArray ); |
|
909 } |
|
910 |
|
911 // ---------------------------------------------------------------------------- |
|
912 // CImumInHealthServicesImpl::IsMailboxHealthy() |
|
913 // ---------------------------------------------------------------------------- |
|
914 // |
|
915 TBool CImumInHealthServicesImpl::IsMailboxHealthy( |
|
916 const TMsvId aMailboxId ) const |
|
917 { |
|
918 IMUM_CONTEXT( CImumInHealthServicesImpl::IsMailboxHealthy, 0, KLogInApi ); |
|
919 IMUM1_IN( "aMailboxId = 0x%x", aMailboxId ); |
|
920 |
|
921 TIMDErrors verification = VerifyMailboxHealth( aMailboxId ); |
|
922 |
|
923 IMUM_OUT(); |
|
924 return !verification; |
|
925 } |
|
926 |
|
927 // ---------------------------------------------------------------------------- |
|
928 // CImumInHealthServicesImpl::CleanupUnhealthyMailboxes() |
|
929 // ---------------------------------------------------------------------------- |
|
930 // |
|
931 void CImumInHealthServicesImpl::CleanupUnhealthyMailboxes() const |
|
932 { |
|
933 IMUM_CONTEXT( CImumInHealthServicesImpl::CleanupUnhealthyMailboxes, 0, KLogInApi ); |
|
934 IMUM_IN(); |
|
935 |
|
936 RMailboxIdArray unhealthyMailboxes; |
|
937 TMuiuFlags flags; |
|
938 |
|
939 flags.SetFlag( EFlagImap4 ); |
|
940 flags.SetFlag( EFlagPop3 ); |
|
941 |
|
942 DoGetMailboxList( unhealthyMailboxes, flags ); |
|
943 DoCleanup( unhealthyMailboxes ); |
|
944 |
|
945 unhealthyMailboxes.Reset(); |
|
946 |
|
947 IMUM_OUT(); |
|
948 } |
|
949 |
|
950 |
|
951 // End of File |
|
952 |