|
1 /* |
|
2 * Copyright (c) 2007 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 * Encapsulates saving and removing email accounts |
|
16 * Version : %version: 12.1.2 % |
|
17 * |
|
18 */ |
|
19 |
|
20 #include "emailtrace.h" |
|
21 #include <cemailaccounts.h> // CEmailAccounts |
|
22 #include <imapset.h> // CImImap4Settings |
|
23 #include <SendUiConsts.h> |
|
24 #include <e32property.h> |
|
25 |
|
26 #include "ipssetdatamanager.h" |
|
27 #include "ipssetdata.h" |
|
28 // <cmail> |
|
29 #include "ipssetutilsconsts.h" |
|
30 // </cmail> |
|
31 #include "ipssetdatastorer.h" |
|
32 #include "ipssetutils.h" |
|
33 #include "ipssetdatasignature.h" |
|
34 #include "ipssetdataapi.h" |
|
35 #include "ipsplgpropertywatcher.h" |
|
36 #include "ipsplgcommon.h" |
|
37 #include "CFSMailCommon.h" |
|
38 |
|
39 |
|
40 const TInt KIpsSetManagerMaxCreTry = 10; |
|
41 |
|
42 /* #ifdef _DEBUG <cmail> |
|
43 _LIT( KMailboxCreationFailed, "IpsSettings - mbox creation failed"); |
|
44 #endif </cmail>*/ |
|
45 |
|
46 // <cmail> |
|
47 const TInt KMaxBodyFetchSize = 999; |
|
48 // </cmail> |
|
49 |
|
50 // ============================ MEMBER FUNCTIONS =============================== |
|
51 |
|
52 // ---------------------------------------------------------------------------- |
|
53 // CIpsSetDataManager::CIpsSetDataManager() |
|
54 // ---------------------------------------------------------------------------- |
|
55 // |
|
56 CIpsSetDataManager::CIpsSetDataManager( |
|
57 CMsvSession& aSession ) |
|
58 : |
|
59 iSession( aSession ), |
|
60 iStorer( NULL ), |
|
61 iAccounts( NULL ) |
|
62 { |
|
63 FUNC_LOG; |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------------------------- |
|
67 // CIpsSetDataManager::ConstructL() |
|
68 // ---------------------------------------------------------------------------- |
|
69 // |
|
70 void CIpsSetDataManager::ConstructL() |
|
71 { |
|
72 FUNC_LOG; |
|
73 iAccounts = CEmailAccounts::NewL(); |
|
74 iStorer = CIpsSetDataStorer::NewL(); |
|
75 } |
|
76 |
|
77 // ---------------------------------------------------------------------------- |
|
78 // CIpsSetDataManager::~CIpsSetDataManager() |
|
79 // ---------------------------------------------------------------------------- |
|
80 // |
|
81 CIpsSetDataManager::~CIpsSetDataManager() |
|
82 { |
|
83 FUNC_LOG; |
|
84 delete iStorer; |
|
85 delete iAccounts; |
|
86 } |
|
87 |
|
88 // ---------------------------------------------------------------------------- |
|
89 // CIpsSetDataManager::NewL() |
|
90 // ---------------------------------------------------------------------------- |
|
91 // |
|
92 CIpsSetDataManager* CIpsSetDataManager::NewL( |
|
93 CMsvSession& aSession ) |
|
94 { |
|
95 FUNC_LOG; |
|
96 CIpsSetDataManager* self = NewLC( aSession ); |
|
97 CleanupStack::Pop( self ); |
|
98 return self; |
|
99 } |
|
100 |
|
101 // ---------------------------------------------------------------------------- |
|
102 // CIpsSetDataManager::NewLC() |
|
103 // ---------------------------------------------------------------------------- |
|
104 // |
|
105 CIpsSetDataManager* CIpsSetDataManager::NewLC( |
|
106 CMsvSession& aSession ) |
|
107 { |
|
108 FUNC_LOG; |
|
109 CIpsSetDataManager* self = |
|
110 new ( ELeave ) CIpsSetDataManager( aSession ); |
|
111 CleanupStack::PushL( self ); |
|
112 self->ConstructL(); |
|
113 return self; |
|
114 } |
|
115 |
|
116 /****************************************************************************** |
|
117 |
|
118 Manager tools |
|
119 |
|
120 ******************************************************************************/ |
|
121 |
|
122 |
|
123 // ---------------------------------------------------------------------------- |
|
124 // CIpsSetDataManager::RemoveAccountL() |
|
125 // ---------------------------------------------------------------------------- |
|
126 // |
|
127 void CIpsSetDataManager::RemoveAccountL( |
|
128 const TMsvEntry& aMailbox ) |
|
129 { |
|
130 FUNC_LOG; |
|
131 // First remove the extended settings, as this cannot leave |
|
132 TInt error = iStorer->DeleteExtendedSettingsL( aMailbox ); |
|
133 |
|
134 // Cleanup all global folders that might have entries belonging to the |
|
135 CleanGlobalFoldersL( aMailbox ); |
|
136 |
|
137 // Determine the account type |
|
138 if ( aMailbox.iMtm == KSenduiMtmImap4Uid ) |
|
139 { |
|
140 // Remove the Imap4 account |
|
141 TImapAccount imap; |
|
142 iAccounts->GetImapAccountL( aMailbox.iServiceId, imap); |
|
143 iAccounts->DeleteImapAccountL( imap ); |
|
144 } |
|
145 else |
|
146 { |
|
147 // Remove the Pop3 account |
|
148 TPopAccount pop; |
|
149 iAccounts->GetPopAccountL( aMailbox.iServiceId, pop); |
|
150 iAccounts->DeletePopAccountL( pop ); |
|
151 } |
|
152 TSmtpAccount smtp; |
|
153 iAccounts->GetSmtpAccountL( aMailbox.iRelatedId, smtp); |
|
154 iAccounts->DeleteSmtpAccountL( smtp ); |
|
155 } |
|
156 |
|
157 // ---------------------------------------------------------------------------- |
|
158 // CIpsSetDataManager::CleanGlobalFoldersL() |
|
159 // ---------------------------------------------------------------------------- |
|
160 // |
|
161 void CIpsSetDataManager::CleanGlobalFoldersL( const TMsvEntry& aMailbox ) |
|
162 { |
|
163 FUNC_LOG; |
|
164 CleanGlobalFolderL( KMsvGlobalOutBoxIndexEntryId, aMailbox ); |
|
165 CleanGlobalFolderL( KMsvDraftEntryId, aMailbox ); |
|
166 CleanGlobalFolderL( KMsvSentEntryId, aMailbox ); |
|
167 } |
|
168 |
|
169 // ---------------------------------------------------------------------------- |
|
170 // CIpsSetDataManager::CleanGlobalFolderL() |
|
171 // ---------------------------------------------------------------------------- |
|
172 // |
|
173 void CIpsSetDataManager::CleanGlobalFolderL( const TMsvId& aFolderId, const TMsvEntry& aMailbox ) |
|
174 { |
|
175 FUNC_LOG; |
|
176 // delete possible entries from this folder that are related to the given mailbox |
|
177 CMsvEntry* cEntry = iSession.GetEntryL( aFolderId ); |
|
178 CleanupStack::PushL( cEntry ); |
|
179 CMsvEntrySelection* selection = cEntry->ChildrenL(); |
|
180 CleanupStack::PushL( selection ); |
|
181 for ( TInt ii = 0; ii < selection->Count(); ii++ ) |
|
182 { |
|
183 TMsvEntry tEntry; |
|
184 TMsvId service; |
|
185 User::LeaveIfError( iSession.GetEntry( selection->At(ii), service, tEntry ) ); |
|
186 if( tEntry.iServiceId == aMailbox.iRelatedId ) |
|
187 { |
|
188 iSession.RemoveEntry( selection->At(ii) ); |
|
189 } |
|
190 } |
|
191 CleanupStack::PopAndDestroy( selection ); |
|
192 CleanupStack::PopAndDestroy( cEntry ); |
|
193 } |
|
194 |
|
195 /****************************************************************************** |
|
196 |
|
197 Account creation |
|
198 |
|
199 ******************************************************************************/ |
|
200 |
|
201 // ---------------------------------------------------------------------------- |
|
202 // CIpsSetDataManager::CreateEmailAccount() |
|
203 // ---------------------------------------------------------------------------- |
|
204 // |
|
205 TInt CIpsSetDataManager::CreateEmailAccount( |
|
206 CIpsSetData& aSettings , |
|
207 const TBool aPopulateDefaults ) |
|
208 { |
|
209 FUNC_LOG; |
|
210 TInt error = KErrNone; |
|
211 // If settings not ready, don't try to create |
|
212 if ( aSettings.IsOk() ) |
|
213 { |
|
214 TBool creReady = EFalse; |
|
215 for ( TInt i = 0; i < KIpsSetManagerMaxCreTry && !creReady; i++ ) |
|
216 { |
|
217 // Attempt to create the mailaccount |
|
218 error = KErrNone; |
|
219 TRAP( error, DoCreateEmailAccountL( |
|
220 aSettings, aPopulateDefaults ) ); |
|
221 |
|
222 if ( error == KErrNone ) |
|
223 { |
|
224 creReady = VerifyMailboxCreation( aSettings ); |
|
225 } |
|
226 else |
|
227 { |
|
228 CleanInvalidMailbox( aSettings ); |
|
229 } |
|
230 } |
|
231 if ( error == KErrNone && !creReady ) |
|
232 { |
|
233 // mailbox not good, set return error; |
|
234 error = KErrGeneral; |
|
235 } |
|
236 // Creating mailbox has failed, delete entries and cenrep settings |
|
237 if ( error != KErrNone ) |
|
238 { |
|
239 CleanInvalidMailbox( aSettings ); |
|
240 } |
|
241 } |
|
242 return error; |
|
243 } |
|
244 |
|
245 // ---------------------------------------------------------------------------- |
|
246 // CIpsSetDataManager::CleanInvalidMailbox() |
|
247 // ---------------------------------------------------------------------------- |
|
248 // |
|
249 TBool CIpsSetDataManager::VerifyMailboxCreation( const CIpsSetData& aSettings ) |
|
250 { |
|
251 FUNC_LOG; |
|
252 TInt error = KErrNotFound; |
|
253 |
|
254 TMsvId mboxId = 0; |
|
255 TMsvId smtpId = 0; |
|
256 TUid mtmId = aSettings.Protocol(); |
|
257 if ( mtmId == KSenduiMtmImap4Uid ) |
|
258 { |
|
259 mboxId = aSettings.ImapAccount().iImapService; |
|
260 smtpId = aSettings.ImapAccount().iSmtpService; |
|
261 } |
|
262 else |
|
263 { |
|
264 mboxId = aSettings.PopAccount().iPopService; |
|
265 smtpId = aSettings.PopAccount().iSmtpService; |
|
266 } |
|
267 |
|
268 |
|
269 TMsvEntry mboxEntry; |
|
270 TMsvEntry smtpEntry; |
|
271 TMsvId dummy; |
|
272 |
|
273 error = iSession.GetEntry( mboxId, dummy, mboxEntry ); |
|
274 |
|
275 if ( error == KErrNone ) |
|
276 { |
|
277 error = iSession.GetEntry( smtpId, dummy, smtpEntry ); |
|
278 } |
|
279 |
|
280 if ( error == KErrNone ) |
|
281 { |
|
282 // check that related id is set |
|
283 if ( mboxEntry.iRelatedId != smtpEntry.Id() ) |
|
284 { |
|
285 TRAP( error, SetRelatedIdL( mboxEntry.Id(), smtpEntry.Id() ) ); |
|
286 } |
|
287 if ( error == KErrNone && |
|
288 smtpEntry.iRelatedId != mboxEntry.Id() ) |
|
289 { |
|
290 TRAP( error, SetRelatedIdL( smtpEntry.Id(), mboxEntry.Id() ) ); |
|
291 } |
|
292 } |
|
293 |
|
294 TBool ret = EFalse; |
|
295 if ( error == KErrNone ) |
|
296 { |
|
297 ret = ETrue; |
|
298 } |
|
299 else |
|
300 { |
|
301 CleanInvalidMailbox( aSettings ); |
|
302 ret = EFalse; |
|
303 } |
|
304 return ret; |
|
305 } |
|
306 |
|
307 // ---------------------------------------------------------------------------- |
|
308 // CIpsSetDataManager::SetRelatedIdL() |
|
309 // ---------------------------------------------------------------------------- |
|
310 // |
|
311 void CIpsSetDataManager::SetRelatedIdL( TMsvId aEntryId, TMsvId aRelatedId ) |
|
312 { |
|
313 FUNC_LOG; |
|
314 CMsvEntry* centry = iSession.GetEntryL( aEntryId ); |
|
315 CleanupStack::PushL( centry ); |
|
316 |
|
317 TMsvEntry tentry = centry->Entry(); |
|
318 tentry.iRelatedId = aRelatedId; |
|
319 centry->ChangeL( tentry ); |
|
320 |
|
321 CleanupStack::PopAndDestroy( centry ); |
|
322 centry = NULL; |
|
323 |
|
324 // make sure that id is really changed |
|
325 TMsvId dummy; |
|
326 TInt error = iSession.GetEntry( aEntryId, dummy, tentry ); |
|
327 if ( error != KErrNone || tentry.iRelatedId != aRelatedId ) |
|
328 { |
|
329 User::Leave( KErrNotFound ); |
|
330 } |
|
331 } |
|
332 |
|
333 // ---------------------------------------------------------------------------- |
|
334 // CIpsSetDataManager::CleanInvalidMailbox() |
|
335 // ---------------------------------------------------------------------------- |
|
336 // |
|
337 void CIpsSetDataManager::CleanInvalidMailbox( const CIpsSetData& aSettings ) |
|
338 { |
|
339 FUNC_LOG; |
|
340 // Determine the account type |
|
341 TMsvId mboxId = 0; |
|
342 TUid mtmId = aSettings.Protocol(); |
|
343 // <cmail>TUint32 accountId = 0;</cmail> |
|
344 if ( mtmId == KSenduiMtmImap4Uid ) |
|
345 { |
|
346 // Remove the Imap4 account |
|
347 TImapAccount imap = aSettings.ImapAccount(); |
|
348 mboxId = imap.iImapService; |
|
349 // <cmail>accountId = imap.iImapAccountId;</cmail> |
|
350 TRAP_IGNORE( iAccounts->DeleteImapAccountL( imap ) ); |
|
351 } |
|
352 else |
|
353 { |
|
354 // Remove the Pop3 account |
|
355 TPopAccount pop = aSettings.PopAccount(); |
|
356 mboxId = pop.iPopService; |
|
357 // <cmail>accountId = pop.iPopAccountId;</cmail> |
|
358 TRAP_IGNORE( iAccounts->DeletePopAccountL( pop ) ); |
|
359 } |
|
360 TRAP_IGNORE( TInt error = iStorer->DeleteExtendedSettingsL( |
|
361 mboxId, mtmId ) ); |
|
362 |
|
363 TRAP_IGNORE( iAccounts->DeleteSmtpAccountL( aSettings.SmtpAccount() ) ); |
|
364 } |
|
365 |
|
366 // ---------------------------------------------------------------------------- |
|
367 // CIpsSetDataManager::DoCreateEmailAccountL() |
|
368 // ---------------------------------------------------------------------------- |
|
369 // |
|
370 void CIpsSetDataManager::DoCreateEmailAccountL( |
|
371 CIpsSetData& aSettings, |
|
372 const TBool aPopulateDefaults ) |
|
373 { |
|
374 FUNC_LOG; |
|
375 TUint32 id = 0; |
|
376 TUid mtmId; |
|
377 TMsvId mailboxId; |
|
378 |
|
379 // Check for imap4 |
|
380 if ( aSettings.Protocol() == KSenduiMtmImap4Uid ) |
|
381 { |
|
382 // Catch all the problems with account creation |
|
383 id = CreateImap4AccountL( aSettings, aPopulateDefaults ); |
|
384 mtmId = KSenduiMtmImap4Uid; |
|
385 mailboxId = aSettings.ImapAccount().iImapService; |
|
386 } |
|
387 else |
|
388 { |
|
389 id = CreatePop3AccountL( aSettings, aPopulateDefaults ); |
|
390 mtmId = KSenduiMtmPop3Uid; |
|
391 mailboxId = aSettings.PopAccount().iPopService; |
|
392 } |
|
393 CreateExtendedSettingsL( mailboxId, id, mtmId, aSettings ); |
|
394 |
|
395 TRAPD( signerr, StoreSignatureL( aSettings ) ); |
|
396 if ( signerr != KErrNone ) |
|
397 { |
|
398 } |
|
399 StoreIMEIToMailbox( mailboxId ); |
|
400 |
|
401 } |
|
402 |
|
403 // ---------------------------------------------------------------------------- |
|
404 // CIpsSetDataManager::CreateImap4AccountL() |
|
405 // ---------------------------------------------------------------------------- |
|
406 // |
|
407 TUint32 CIpsSetDataManager::CreateImap4AccountL( |
|
408 CIpsSetData& aSettings, |
|
409 const TBool aPopulateDefaults, |
|
410 const TBool aReadOnly ) |
|
411 { |
|
412 FUNC_LOG; |
|
413 // Populate defaults |
|
414 if ( aPopulateDefaults ) |
|
415 { |
|
416 iAccounts->PopulateDefaultImapSettingsL( |
|
417 *aSettings.Imap4Settings(), *aSettings.IncomingIapPref() ); |
|
418 iAccounts->PopulateDefaultSmtpSettingsL( |
|
419 *aSettings.SmtpSettings(), *aSettings.OutgoingIapPref() ); |
|
420 } |
|
421 |
|
422 aSettings.Imap4Settings()->SetPathSeparator( '/' ); |
|
423 aSettings.Imap4Settings()->SetUpdatingSeenFlags(ETrue); |
|
424 |
|
425 // Create the account |
|
426 aSettings.ImapAccount() = iAccounts->CreateImapAccountL( |
|
427 aSettings.MailboxName(), |
|
428 *aSettings.Imap4Settings(), *aSettings.IncomingIapPref(), aReadOnly ); |
|
429 aSettings.SmtpAccount() = iAccounts->CreateSmtpAccountL( |
|
430 aSettings.ImapAccount(), |
|
431 *aSettings.SmtpSettings(), *aSettings.OutgoingIapPref(), aReadOnly ); |
|
432 |
|
433 return aSettings.ImapAccount().iImapAccountId; |
|
434 } |
|
435 |
|
436 // ---------------------------------------------------------------------------- |
|
437 // CIpsSetDataManager::CreatePop3AccountL() |
|
438 // ---------------------------------------------------------------------------- |
|
439 // |
|
440 TUint32 CIpsSetDataManager::CreatePop3AccountL( |
|
441 CIpsSetData& aSettings, |
|
442 const TBool aPopulateDefaults, |
|
443 const TBool aReadOnly ) |
|
444 { |
|
445 FUNC_LOG; |
|
446 // Populate defaults |
|
447 if ( aPopulateDefaults ) |
|
448 { |
|
449 iAccounts->PopulateDefaultPopSettingsL( |
|
450 *aSettings.Pop3Settings(), *aSettings.IncomingIapPref() ); |
|
451 iAccounts->PopulateDefaultSmtpSettingsL( |
|
452 *aSettings.SmtpSettings(), *aSettings.OutgoingIapPref() ); |
|
453 } |
|
454 |
|
455 // Create the account |
|
456 aSettings.PopAccount() = iAccounts->CreatePopAccountL( |
|
457 aSettings.MailboxName(), |
|
458 *aSettings.Pop3Settings(), *aSettings.IncomingIapPref(), aReadOnly ); |
|
459 aSettings.SmtpAccount() = iAccounts->CreateSmtpAccountL( |
|
460 aSettings.PopAccount(), |
|
461 *aSettings.SmtpSettings(), *aSettings.OutgoingIapPref(), aReadOnly ); |
|
462 return aSettings.PopAccount().iPopAccountId; |
|
463 } |
|
464 |
|
465 // ---------------------------------------------------------------------------- |
|
466 // CIpsSetDataManager::CreateExtendedSettingsL() |
|
467 // ---------------------------------------------------------------------------- |
|
468 // |
|
469 void CIpsSetDataManager::CreateExtendedSettingsL( |
|
470 const TMsvId aMailboxId, |
|
471 const TUint32 aAccountId, |
|
472 const TUid& aProtocol, |
|
473 CIpsSetData& aSettings, |
|
474 const TBool aPopulateDefaults ) |
|
475 { |
|
476 FUNC_LOG; |
|
477 // If populating has been successful |
|
478 User::LeaveIfError( iStorer->CreateExtendedSettings( |
|
479 aMailboxId, aAccountId, aProtocol, |
|
480 *aSettings.ExtendedSettings(), aPopulateDefaults ) ); |
|
481 } |
|
482 |
|
483 // ---------------------------------------------------------------------------- |
|
484 // CIpsSetDataManager::StoreIMEIToMailbox() |
|
485 // ---------------------------------------------------------------------------- |
|
486 // |
|
487 TInt CIpsSetDataManager::StoreIMEIToMailbox( |
|
488 const TMsvId aMailboxId ) const |
|
489 { |
|
490 FUNC_LOG; |
|
491 // Get available mailbox entries |
|
492 TMsvEntry entry; |
|
493 TInt result = IpsSetUtils::GetMailboxEntry( iSession, aMailboxId, entry ); |
|
494 |
|
495 // Imap4 & Pop3 & Smtp protocols contain two entries |
|
496 if ( result == KErrNone ) |
|
497 { |
|
498 // Attempt to store the IMEI code to the entry |
|
499 result = StoreIMEIToEntry( entry.Id() ); |
|
500 } |
|
501 |
|
502 // Imap4 / Pop3 protocols have two different entries |
|
503 if ( IpsSetUtils::IsMailMtm( entry.iMtm ) ) |
|
504 { |
|
505 TMsvEntry secondaryEntry; |
|
506 result = IpsSetUtils::GetMailboxEntry( iSession, entry.iRelatedId, entry ); |
|
507 |
|
508 if ( result == KErrNone ) |
|
509 { |
|
510 // Attempt to store the IMEI code to the entry |
|
511 result = StoreIMEIToEntry( entry.Id() ); |
|
512 } |
|
513 } |
|
514 |
|
515 return result; |
|
516 } |
|
517 |
|
518 // ---------------------------------------------------------------------------- |
|
519 // CIpsSetDataManager::StoreIMEIToEntry() |
|
520 // ---------------------------------------------------------------------------- |
|
521 // |
|
522 TInt CIpsSetDataManager::StoreIMEIToEntry( const TMsvId aMailboxId ) const |
|
523 { |
|
524 FUNC_LOG; |
|
525 TRAPD( error, GetAndStoreIMEIToEntryL( aMailboxId ) ); |
|
526 return ( error == KErrNone ) ? KErrNone : KErrGeneral; |
|
527 } |
|
528 |
|
529 // ---------------------------------------------------------------------------- |
|
530 // CIpsSetDataManager::GetAndStoreIMEIToEntryL() |
|
531 // ---------------------------------------------------------------------------- |
|
532 // |
|
533 void CIpsSetDataManager::GetAndStoreIMEIToEntryL( |
|
534 const TMsvId aMailboxId ) const |
|
535 { |
|
536 FUNC_LOG; |
|
537 TBuf<KIMAMaxPhoneIdLength> imei; |
|
538 |
|
539 CIpsSetDataApi* setApi = CIpsSetDataApi::NewL( iSession ); |
|
540 CleanupStack::PushL( setApi ); |
|
541 |
|
542 setApi->GetIMEIFromThePhoneL( imei ); |
|
543 |
|
544 CMsvEntry* centry = iSession.GetEntryL( aMailboxId ); |
|
545 CleanupStack::PushL( centry ); |
|
546 |
|
547 TMsvEntry tentry = centry->Entry(); |
|
548 tentry.iDescription.Set( imei ); |
|
549 centry->ChangeL( tentry ); |
|
550 |
|
551 CleanupStack::PopAndDestroy( 2, setApi ); |
|
552 centry = NULL; |
|
553 } |
|
554 |
|
555 /****************************************************************************** |
|
556 |
|
557 Account Saving |
|
558 |
|
559 ******************************************************************************/ |
|
560 |
|
561 // ---------------------------------------------------------------------------- |
|
562 // CIpsSetDataManager::SaveEmailSettingsL() |
|
563 // ---------------------------------------------------------------------------- |
|
564 // |
|
565 TInt CIpsSetDataManager::SaveEmailSettingsL( |
|
566 CIpsSetData& aSettings ) |
|
567 { |
|
568 FUNC_LOG; |
|
569 // If settings not ready, don't try to create |
|
570 if ( !aSettings.IsOk() ) |
|
571 { |
|
572 return KErrNotFound; |
|
573 } |
|
574 |
|
575 TInt error = KErrNone; |
|
576 TBool isImap = ( aSettings.Protocol() == KSenduiMtmImap4Uid ); |
|
577 // Check for imap4 |
|
578 if ( isImap ) |
|
579 { |
|
580 // Catch all the problems with account creation |
|
581 TRAP( error, SaveImap4SettingsL( aSettings ) ); |
|
582 } |
|
583 // It's a pop |
|
584 else |
|
585 { |
|
586 // Catch all the problems with account creation |
|
587 TRAP( error, SavePop3SettingsL( aSettings ) ); |
|
588 } |
|
589 |
|
590 // Attempt to save the extended settings, even if other settings have |
|
591 // failed to save |
|
592 error = iStorer->SaveExtendedSettings( *aSettings.ExtendedSettings() ); |
|
593 TRAP_IGNORE( StoreSignatureL( aSettings ) ); |
|
594 |
|
595 //settings have been saved, signal email plugins |
|
596 SendPropertyEventL( (isImap ? |
|
597 aSettings.ImapAccount().iImapService : |
|
598 aSettings.PopAccount().iPopService), isImap ); |
|
599 return error; |
|
600 } |
|
601 |
|
602 // ---------------------------------------------------------------------------- |
|
603 // CIpsSetDataManager::SavePop3SettingsL() |
|
604 // ---------------------------------------------------------------------------- |
|
605 // |
|
606 void CIpsSetDataManager::SavePop3SettingsL( |
|
607 CIpsSetData& aSettings ) |
|
608 { |
|
609 FUNC_LOG; |
|
610 // Store the mailbox name |
|
611 aSettings.PopAccount().iPopAccountName.Copy( |
|
612 aSettings.MailboxName() ); |
|
613 aSettings.SmtpAccount().iSmtpAccountName.Copy( |
|
614 aSettings.MailboxName() ); |
|
615 |
|
616 // Load mailbox settings |
|
617 iAccounts->SavePopSettingsL( |
|
618 aSettings.PopAccount(), *aSettings.Pop3Settings() ); |
|
619 iAccounts->SavePopIapSettingsL( |
|
620 aSettings.PopAccount(), *aSettings.IncomingIapPref() ); |
|
621 iAccounts->SaveSmtpSettingsL( |
|
622 aSettings.SmtpAccount(), *aSettings.SmtpSettings() ); |
|
623 iAccounts->SaveSmtpIapSettingsL( |
|
624 aSettings.SmtpAccount(), *aSettings.OutgoingIapPref() ); |
|
625 } |
|
626 |
|
627 // ---------------------------------------------------------------------------- |
|
628 // CIpsSetDataManager::SaveImap4SettingsL() |
|
629 // ---------------------------------------------------------------------------- |
|
630 // |
|
631 void CIpsSetDataManager::SaveImap4SettingsL( |
|
632 CIpsSetData& aSettings ) |
|
633 { |
|
634 FUNC_LOG; |
|
635 // Store the mailbox name |
|
636 aSettings.ImapAccount().iImapAccountName.Copy( |
|
637 aSettings.MailboxName() ); |
|
638 aSettings.SmtpAccount().iSmtpAccountName.Copy( |
|
639 aSettings.MailboxName() ); |
|
640 |
|
641 // Load mailbox settings |
|
642 iAccounts->SaveImapSettingsL( |
|
643 aSettings.ImapAccount(), *aSettings.Imap4Settings() ); |
|
644 iAccounts->SaveImapIapSettingsL( |
|
645 aSettings.ImapAccount(), *aSettings.IncomingIapPref() ); |
|
646 iAccounts->SaveSmtpSettingsL( |
|
647 aSettings.SmtpAccount(), *aSettings.SmtpSettings() ); |
|
648 iAccounts->SaveSmtpIapSettingsL( |
|
649 aSettings.SmtpAccount(), *aSettings.OutgoingIapPref() ); |
|
650 } |
|
651 |
|
652 /****************************************************************************** |
|
653 |
|
654 Account Loading |
|
655 |
|
656 ******************************************************************************/ |
|
657 |
|
658 // ---------------------------------------------------------------------------- |
|
659 // CIpsSetDataManager::LoadEmailSettingsL() |
|
660 // ---------------------------------------------------------------------------- |
|
661 // |
|
662 void CIpsSetDataManager::LoadEmailSettingsL( |
|
663 const TMsvEntry& aEntry, |
|
664 CIpsSetData& aSettings ) |
|
665 { |
|
666 FUNC_LOG; |
|
667 // Get both of the entries |
|
668 TMsvEntry smtpEntry; |
|
669 TMsvEntry relatedEntry; |
|
670 TUid mtmId = IpsSetUtils::GetMailboxEntriesL( |
|
671 aEntry, iSession, smtpEntry, relatedEntry ); |
|
672 |
|
673 // Store the id and protocol |
|
674 aSettings.SetProtocol( mtmId ); |
|
675 |
|
676 // Load settings based on the protocol |
|
677 if ( aSettings.Protocol() == KSenduiMtmImap4Uid ) |
|
678 { |
|
679 iAccounts->GetImapAccountL( |
|
680 relatedEntry.Id(), aSettings.ImapAccount() ); |
|
681 LoadImap4SettingsL( aSettings ); |
|
682 |
|
683 // Load extended settings |
|
684 TUint32 accountId = aSettings.ImapAccount().iImapAccountId; |
|
685 TInt error = iStorer->LoadExtendedSettings( |
|
686 TIpsSetDataStorerParams( accountId, mtmId ), |
|
687 *aSettings.ExtendedSettings() ); |
|
688 } |
|
689 else |
|
690 { |
|
691 iAccounts->GetPopAccountL( |
|
692 relatedEntry.Id(), aSettings.PopAccount() ); |
|
693 LoadPop3SettingsL( aSettings ); |
|
694 |
|
695 // Load extended settings |
|
696 TUint32 accountId = aSettings.PopAccount().iPopAccountId; |
|
697 TInt error = iStorer->LoadExtendedSettings( |
|
698 TIpsSetDataStorerParams( accountId, mtmId ), |
|
699 *aSettings.ExtendedSettings() ); |
|
700 } |
|
701 |
|
702 // Attempt to read the signature |
|
703 TRAP_IGNORE( RestoreSignatureL( aSettings ) ); |
|
704 } |
|
705 |
|
706 // ---------------------------------------------------------------------------- |
|
707 // CIpsSetDataManager::LoadPop3SettingsL() |
|
708 // ---------------------------------------------------------------------------- |
|
709 // |
|
710 void CIpsSetDataManager::LoadPop3SettingsL( |
|
711 CIpsSetData& aSettings ) |
|
712 { |
|
713 FUNC_LOG; |
|
714 iAccounts->GetSmtpAccountL( |
|
715 aSettings.PopAccount().iSmtpService, aSettings.SmtpAccount() ); |
|
716 |
|
717 // Load mailbox settings |
|
718 iAccounts->LoadPopSettingsL( |
|
719 aSettings.PopAccount(), *aSettings.Pop3Settings() ); |
|
720 iAccounts->LoadPopIapSettingsL( |
|
721 aSettings.PopAccount(), *aSettings.IncomingIapPref() ); |
|
722 iAccounts->LoadSmtpSettingsL( |
|
723 aSettings.SmtpAccount(), *aSettings.SmtpSettings() ); |
|
724 iAccounts->LoadSmtpIapSettingsL( |
|
725 aSettings.SmtpAccount(), *aSettings.OutgoingIapPref() ); |
|
726 |
|
727 aSettings.SetMailboxName( aSettings.PopAccount().iPopAccountName ); |
|
728 } |
|
729 |
|
730 // ---------------------------------------------------------------------------- |
|
731 // CIpsSetDataManager::LoadImap4SettingsL() |
|
732 // ---------------------------------------------------------------------------- |
|
733 // |
|
734 void CIpsSetDataManager::LoadImap4SettingsL( |
|
735 CIpsSetData& aSettings ) |
|
736 { |
|
737 FUNC_LOG; |
|
738 iAccounts->GetSmtpAccountL( |
|
739 aSettings.ImapAccount().iSmtpService, aSettings.SmtpAccount() ); |
|
740 |
|
741 // Load mailbox settings |
|
742 iAccounts->LoadImapSettingsL( |
|
743 aSettings.ImapAccount(), *aSettings.Imap4Settings() ); |
|
744 |
|
745 // <cmail> |
|
746 TInt szLimit = aSettings.Imap4Settings()->BodyTextSizeLimit(); |
|
747 |
|
748 if( szLimit < KIpsSetDataFullBodyOnly || |
|
749 szLimit > KMaxBodyFetchSize ) |
|
750 { |
|
751 //body size limit value not set properly, so setting a default value. |
|
752 aSettings.Imap4Settings()->SetBodyTextSizeLimitL( |
|
753 KIpsSetDataDefaultDownloadSizeKb ); |
|
754 |
|
755 iAccounts->SaveImapSettingsL( |
|
756 aSettings.ImapAccount(), *aSettings.Imap4Settings() ); |
|
757 } |
|
758 // </cmail> |
|
759 |
|
760 iAccounts->LoadImapIapSettingsL( |
|
761 aSettings.ImapAccount(), *aSettings.IncomingIapPref() ); |
|
762 iAccounts->LoadSmtpSettingsL( |
|
763 aSettings.SmtpAccount(), *aSettings.SmtpSettings() ); |
|
764 iAccounts->LoadSmtpIapSettingsL( |
|
765 aSettings.SmtpAccount(), *aSettings.OutgoingIapPref() ); |
|
766 |
|
767 aSettings.SetMailboxName( aSettings.ImapAccount().iImapAccountName ); |
|
768 } |
|
769 |
|
770 /****************************************************************************** |
|
771 |
|
772 MISC TOOLS |
|
773 |
|
774 ******************************************************************************/ |
|
775 |
|
776 // ---------------------------------------------------------------------------- |
|
777 // CIpsSetDataManager::StoreSignatureL() |
|
778 // ---------------------------------------------------------------------------- |
|
779 // |
|
780 void CIpsSetDataManager::StoreSignatureL( |
|
781 const CIpsSetData& aSettings ) |
|
782 { |
|
783 FUNC_LOG; |
|
784 // Get Signature |
|
785 CMsvEntry* entry = |
|
786 iSession.GetEntryL( aSettings.SmtpAccount().iSmtpService ); |
|
787 CleanupStack::PushL( entry ); |
|
788 CMsvStore* msvStore = entry->EditStoreL(); |
|
789 CleanupStack::PushL( msvStore ); |
|
790 |
|
791 msvStore->StoreBodyTextL( *( aSettings.Signature().iRichText ) ); |
|
792 msvStore->CommitL(); |
|
793 |
|
794 CleanupStack::PopAndDestroy( msvStore ); |
|
795 msvStore = NULL; |
|
796 CleanupStack::PopAndDestroy( entry ); |
|
797 entry = NULL; |
|
798 } |
|
799 |
|
800 // ---------------------------------------------------------------------------- |
|
801 // CIpsSetDataManager::RestoreSignatureL() |
|
802 // ---------------------------------------------------------------------------- |
|
803 // |
|
804 void CIpsSetDataManager::RestoreSignatureL( |
|
805 CIpsSetData& aSettings ) |
|
806 { |
|
807 FUNC_LOG; |
|
808 // Get Signature |
|
809 CMsvEntry* entry = |
|
810 iSession.GetEntryL( aSettings.SmtpAccount().iSmtpService ); |
|
811 CleanupStack::PushL( entry ); |
|
812 CMsvStore* msvStore = entry->ReadStoreL(); |
|
813 CleanupStack::PushL( msvStore ); |
|
814 |
|
815 aSettings.Signature().CreateEmptyRichTextL(); |
|
816 msvStore->RestoreBodyTextL( *( aSettings.Signature().iRichText ) ); |
|
817 |
|
818 CleanupStack::PopAndDestroy( msvStore ); |
|
819 msvStore = NULL; |
|
820 CleanupStack::PopAndDestroy( entry ); |
|
821 entry = NULL; |
|
822 } |
|
823 |
|
824 // ---------------------------------------------------------------------------- |
|
825 // ---------------------------------------------------------------------------- |
|
826 TInt CIpsSetDataManager::SendPropertyEventL( TInt aMailbox, TBool aIsImap ) |
|
827 { |
|
828 FUNC_LOG; |
|
829 TInt error = RProperty::Define( |
|
830 KIpsPlgPropertyCatUid, |
|
831 KIPSSosEventPropertyKey, RProperty::EByteArray, |
|
832 KAllowAllPolicy, |
|
833 KAllowWriteDeviceDataPolicy ); |
|
834 |
|
835 TUid plugin = (aIsImap ? KIpsPlgImap4PluginUid : KIpsPlgPop3PluginUid); |
|
836 TIpsPlgPropertyEvent pEvent( |
|
837 EIPSSosSettingsChanged, |
|
838 aMailbox , |
|
839 plugin.iUid, |
|
840 KErrNone ); |
|
841 |
|
842 TPckgBuf<TIpsPlgPropertyEvent> propertyBuf = pEvent; |
|
843 |
|
844 // if definition was success |
|
845 if ( error == KErrNone || error == KErrAlreadyExists || |
|
846 error == KErrPermissionDenied ) |
|
847 { |
|
848 error = RProperty::Set( |
|
849 KIpsPlgPropertyCatUid, |
|
850 KIPSSosEventPropertyKey, propertyBuf ); |
|
851 |
|
852 } |
|
853 return error; |
|
854 } |
|
855 |
|
856 // End Of File |
|
857 |