|
1 /* |
|
2 * Copyright (c) 2002 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: Saves CWPEmailItems |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CWPEmailSaveItem.h" |
|
22 #include "CWPEmailItem.h" |
|
23 #include "EmailAdapter.pan" |
|
24 #include "WPEmail.hrh" |
|
25 |
|
26 #include <wpemailadapterresource.rsg> |
|
27 #include <WPAdapterUtil.h> // Adapter utils |
|
28 |
|
29 #include <ApUtils.h> |
|
30 #include <ApDataHandler.h> |
|
31 |
|
32 #include <CWPParameter.h> |
|
33 #include <txtrich.h> |
|
34 #include <iapprefs.h> |
|
35 #include <MuiuMsvUiServiceUtilities.h> |
|
36 |
|
37 #include <pop3set.h> |
|
38 |
|
39 #include <miutpars.h> // TImMessageField |
|
40 #include <cemailaccounts.h> |
|
41 #include <iapprefs.h> |
|
42 |
|
43 #include <ImumDaMailboxUtilities.h> |
|
44 #include <SendUiConsts.h> |
|
45 |
|
46 #include <ImumDaSettingsKeys.h> |
|
47 #include <ImumDaSettingsDataCollection.h> |
|
48 |
|
49 #include "../../../group/omacplogger.h" |
|
50 #include <PnpProvUtil.h> |
|
51 |
|
52 // ============================ MEMBER FUNCTIONS =============================== |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CWPEmailSaveItem::CWPEmailSaveItem |
|
56 // C++ default constructor can NOT contain any code, that |
|
57 // might leave. |
|
58 // ----------------------------------------------------------------------------- |
|
59 // |
|
60 CWPEmailSaveItem::CWPEmailSaveItem() |
|
61 { |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CWPEmailSaveItem::ConstructL |
|
66 // Symbian 2nd phase constructor can leave. |
|
67 // ----------------------------------------------------------------------------- |
|
68 // |
|
69 void CWPEmailSaveItem::ConstructL() |
|
70 { |
|
71 iExistingSettings = new (ELeave) CDesC16ArrayFlat(2); //1 or 2 settings |
|
72 |
|
73 TFileName fileName; |
|
74 Dll::FileName( fileName ); |
|
75 iDefaultName = WPAdapterUtil::ReadHBufCL( fileName, |
|
76 KAdapterName, |
|
77 R_QTN_SM_DEFAULT_EMAIL_NAME ); |
|
78 iDefaultMsvId = 0 ; |
|
79 iDomainApi = CreateDomainApiL(); |
|
80 iServices = &iDomainApi->MailboxServicesL(); |
|
81 } |
|
82 |
|
83 // ----------------------------------------------------------------------------- |
|
84 // Destructor |
|
85 // ----------------------------------------------------------------------------- |
|
86 CWPEmailSaveItem::~CWPEmailSaveItem() |
|
87 { |
|
88 delete iBufConvert; |
|
89 delete iExistingSettings; |
|
90 delete iDefaultName; |
|
91 delete iIapName; |
|
92 delete iDomainApi; |
|
93 } |
|
94 |
|
95 // ----------------------------------------------------------------------------- |
|
96 // CWPEmailSaveItem::SetAsDefaultL |
|
97 // ----------------------------------------------------------------------------- |
|
98 // |
|
99 void CWPEmailSaveItem::SetAsDefaultL() |
|
100 { |
|
101 iServices->SetDefaultMailboxL( iDefaultMsvId ); |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CWPEmailSaveItem::SummaryText |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 const TDesC& CWPEmailSaveItem::SummaryText() |
|
109 { |
|
110 return *iDefaultName; |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CWPEmailSaveItem::SetDefaultNameL |
|
115 // ----------------------------------------------------------------------------- |
|
116 // |
|
117 void CWPEmailSaveItem::SetDefaultNameL( const TDesC& aDefaultName ) |
|
118 { |
|
119 HBufC* temp = aDefaultName.AllocL(); |
|
120 delete iDefaultName; |
|
121 iDefaultName = temp; |
|
122 } |
|
123 |
|
124 // ----------------------------------------------------------------------------- |
|
125 // CWPEmailSaveItem::SetCommsDataBase |
|
126 // ----------------------------------------------------------------------------- |
|
127 // |
|
128 void CWPEmailSaveItem::SetCommsDataBase( CCommsDatabase& aCommsDataBase ) |
|
129 { |
|
130 iCommDb = &aCommsDataBase; |
|
131 } |
|
132 |
|
133 // ----------------------------------------------------------------------------- |
|
134 // CWPEmailSaveItem::SaveData |
|
135 // ----------------------------------------------------------------------------- |
|
136 // |
|
137 const TDesC8& CWPEmailSaveItem::SaveData() |
|
138 { |
|
139 iUid().iSmtpId = iSmtpTEntry.Id(); |
|
140 iUid().iPopImapId = iPopImapTEntry.Id(); |
|
141 return iUid; |
|
142 } |
|
143 |
|
144 // ----------------------------------------------------------------------------- |
|
145 // CWPEmailSaveItem::GetMailAccountNamesL |
|
146 // ----------------------------------------------------------------------------- |
|
147 // |
|
148 TInt CWPEmailSaveItem::GetMailAccountNamesL() |
|
149 { |
|
150 CMsvEntry* centry = iSession->GetEntryL(KMsvRootIndexEntryId); |
|
151 CleanupStack::PushL(centry); |
|
152 TInt count = centry->Count(); |
|
153 |
|
154 for ( TInt j = 0; j < count; j++ ) |
|
155 { |
|
156 if( (*centry)[j].iType == KUidMsvServiceEntry && |
|
157 ((*centry)[j].iMtm == KUidMsgTypePOP3 || |
|
158 (*centry)[j].iMtm == KUidMsgTypeIMAP4)) |
|
159 { |
|
160 iExistingSettings->AppendL( (*centry)[j].iDetails ); |
|
161 } |
|
162 } |
|
163 CleanupStack::PopAndDestroy( centry ); |
|
164 return iExistingSettings->Count(); |
|
165 } |
|
166 |
|
167 // ----------------------------------------------------------------------------- |
|
168 // CWPEmailSaveItem::SettingNameAlreadyExistsL |
|
169 // ----------------------------------------------------------------------------- |
|
170 // |
|
171 TBool CWPEmailSaveItem::SettingNameAlreadyExistsL( const TDesC& aName, |
|
172 TBool aReload ) |
|
173 { |
|
174 if ( aReload ) |
|
175 { |
|
176 GetMailAccountNamesL(); |
|
177 } |
|
178 TInt count = iExistingSettings->Count(); |
|
179 |
|
180 for ( TInt n(0); n < count; n++ ) |
|
181 { |
|
182 if (aName.CompareF( (*iExistingSettings)[n]) == 0 ) |
|
183 { |
|
184 // found match |
|
185 return ETrue; |
|
186 } |
|
187 } |
|
188 return EFalse; |
|
189 } |
|
190 |
|
191 // ----------------------------------------------------------------------------- |
|
192 // CWPEmailSaveItem::SaveMailSettingsToMessageServerL |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CWPEmailSaveItem::SaveMailSettingsToMessageServerL( CWPEmailItem& aSmtp, |
|
196 CWPEmailItem& aPopImap, |
|
197 TBool aIsPopNotImap, |
|
198 CMsvSession* aSession ) |
|
199 { |
|
200 __ASSERT_ALWAYS( aSession, Panic( EMailAdapterNullPointer ) ); |
|
201 |
|
202 iSession = aSession; |
|
203 iPopMail = aIsPopNotImap; |
|
204 |
|
205 ValidateSettingsNameL(); |
|
206 |
|
207 delete iIapName; |
|
208 iIapName = NULL; |
|
209 iIapName = aSmtp.AssociatedIapNameL(); |
|
210 if ( !iIapName ) |
|
211 { |
|
212 iIapName = iDefaultName->Des().AllocL(); |
|
213 } |
|
214 |
|
215 CreateMailboxEntryL( aPopImap,aSmtp ); |
|
216 } |
|
217 |
|
218 // ----------------------------------------------------------------------------- |
|
219 // CWPEmailSaveItem::IsValidEmailAddressL |
|
220 // ----------------------------------------------------------------------------- |
|
221 // |
|
222 TBool CWPEmailSaveItem::IsValidEmailAddressL( const TDesC& aAddress ) |
|
223 { |
|
224 TPtrC string = GetValidEmailAddressL( aAddress ); |
|
225 TImMessageField address; |
|
226 return address.ValidInternetEmailAddress( string ); |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CWPEmailSaveItem::GetValidEmailAddressL |
|
231 // ----------------------------------------------------------------------------- |
|
232 // |
|
233 TPtrC CWPEmailSaveItem::GetValidEmailAddressL( const TDesC& aAddress ) |
|
234 { |
|
235 TImMessageField address; |
|
236 return address.GetValidInternetEmailAddressFromString( aAddress ); |
|
237 } |
|
238 |
|
239 // ----------------------------------------------------------------------------- |
|
240 // CWPEmailSaveItem::FillTEntryWithSmtpData |
|
241 // ----------------------------------------------------------------------------- |
|
242 // |
|
243 void CWPEmailSaveItem::FillTEntryWithSmtpData( TMsvEntry& aTEntry, |
|
244 const TDesC& aIapName, |
|
245 const TDesC& aMailboxName ) |
|
246 { |
|
247 aTEntry.iMtm = KUidMsgTypeSMTP; |
|
248 aTEntry.iType= KUidMsvServiceEntry; |
|
249 aTEntry.iDate.HomeTime(); |
|
250 aTEntry.iDescription.Set( aIapName ); |
|
251 aTEntry.iDetails.Set( aMailboxName ); |
|
252 aTEntry.SetVisible( EFalse ); |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CWPEmailSaveItem::FillTEntryWithPopImapData |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CWPEmailSaveItem::FillTEntryWithPopImapData( TMsvEntry& aTEntry, |
|
260 const TMsvEntry& aSmtpEntry, |
|
261 const TDesC& aMailboxName, |
|
262 TBool aIsPop ) |
|
263 { |
|
264 aTEntry = aSmtpEntry; |
|
265 aTEntry.iRelatedId = aSmtpEntry.Id(); |
|
266 aTEntry.SetVisible( ETrue ); |
|
267 aTEntry.iType = KUidMsvServiceEntry; |
|
268 aTEntry.iDate.HomeTime(); |
|
269 aTEntry.iDetails.Set( aMailboxName ); |
|
270 if ( aIsPop ) |
|
271 { |
|
272 aTEntry.iMtm = KUidMsgTypePOP3; |
|
273 } |
|
274 else |
|
275 { |
|
276 aTEntry.iMtm = KUidMsgTypeIMAP4; |
|
277 } |
|
278 } |
|
279 |
|
280 // ----------------------------------------------------------------------------- |
|
281 // CWPEmailSaveItem::Des16To8L |
|
282 // ----------------------------------------------------------------------------- |
|
283 // |
|
284 const TDesC8& CWPEmailSaveItem::Des16To8L( const TDesC& aDes16 ) |
|
285 { |
|
286 HBufC8* text = HBufC8::NewL(aDes16.Length()); |
|
287 delete iBufConvert; |
|
288 iBufConvert = text; |
|
289 iBufConvert->Des().Copy(aDes16); |
|
290 return *iBufConvert; |
|
291 } |
|
292 |
|
293 // ----------------------------------------------------------------------------- |
|
294 // CWPEmailSaveItem::IapIdFromWapIdL |
|
295 // ----------------------------------------------------------------------------- |
|
296 // |
|
297 TUint32 CWPEmailSaveItem::IapIdFromWapIdL( TUint32 aWapId ) const |
|
298 { |
|
299 CApUtils* apUtils = CApUtils::NewLC( *iCommDb ); |
|
300 TUint32 iapId = NULL; |
|
301 iapId = apUtils->IapIdFromWapIdL( aWapId ); |
|
302 __ASSERT_ALWAYS( iapId, Panic( EMailAdapterInvalidId ) ); |
|
303 CleanupStack::PopAndDestroy( apUtils ); |
|
304 return iapId; |
|
305 } |
|
306 |
|
307 // ----------------------------------------------------------------------------- |
|
308 // CWPEmailSaveItem::ValidateSettingsNameL |
|
309 // ----------------------------------------------------------------------------- |
|
310 // |
|
311 void CWPEmailSaveItem::ValidateSettingsNameL( ) |
|
312 { |
|
313 LOGSTRING( "CWPEmailSaveItem::ValidateSettingsNameL : Enter" ); |
|
314 if ( SettingNameAlreadyExistsL( *iDefaultName, ETrue ) ) |
|
315 { |
|
316 |
|
317 //before appending (XX) to name if >26, make sure length is not equal |
|
318 //to KSettingsNameMaxLength |
|
319 |
|
320 |
|
321 if(iDefaultName->Length() > 26) |
|
322 { |
|
323 TBuf<30> temp_Name (*iDefaultName); |
|
324 |
|
325 TInt count = iExistingSettings->Count(); |
|
326 |
|
327 for ( TInt n(0); n < count; n++ ) |
|
328 { |
|
329 if (temp_Name.CompareF( (*iExistingSettings)[n]) == 0 ) |
|
330 { |
|
331 // found match |
|
332 User::Leave(KErrAlreadyExists); |
|
333 } |
|
334 } |
|
335 |
|
336 } |
|
337 |
|
338 HBufC* newName = HBufC::NewLC( KSettingsNameMaxLength ); |
|
339 *newName = *iDefaultName; |
|
340 |
|
341 TPtr namePtr = newName->Des(); |
|
342 IncrementNameL( namePtr ); |
|
343 |
|
344 while ( SettingNameAlreadyExistsL( namePtr, EFalse ) ) |
|
345 { |
|
346 IncrementNameL( namePtr ); |
|
347 } |
|
348 |
|
349 delete iDefaultName; |
|
350 iDefaultName = NULL; |
|
351 iDefaultName = namePtr.AllocL(); |
|
352 CleanupStack::PopAndDestroy( newName ); |
|
353 } |
|
354 LOGSTRING( "CWPEmailSaveItem::ValidateSettingsNameL : Exit" ); |
|
355 } |
|
356 |
|
357 // ----------------------------------------------------------------------------- |
|
358 // CWPEmailSaveItem::CreateMailboxEntryL |
|
359 // ----------------------------------------------------------------------------- |
|
360 // |
|
361 TInt CWPEmailSaveItem::CreateMailboxEntryL( CWPEmailItem& aPopImapItem, |
|
362 CWPEmailItem& aSmtpItem ) |
|
363 { |
|
364 LOGSTRING( "CWPEmailSaveItem::CreateMailboxEntryL : Entry" ); |
|
365 |
|
366 TInt err = KErrNone; |
|
367 TBuf<10> appIdValue; |
|
368 |
|
369 CImumDaSettingsData* eMailSettingsData(NULL); |
|
370 eMailSettingsData = iServices->CreateSettingsDataL(KNullUid); |
|
371 CleanupStack::PushL(eMailSettingsData); //1 |
|
372 |
|
373 CImIAPPreferences* apSet = CImIAPPreferences::NewLC(); //2 |
|
374 CImIAPPreferences* popImapIapSet = CImIAPPreferences::NewLC(); //3 |
|
375 |
|
376 TPtrC emailAddress = GetValidEmailAddressL(aSmtpItem.ParameterValue( |
|
377 EWPParameterFrom)); |
|
378 TImumDaSettings::TTextEmailAddress emailAddressText; |
|
379 emailAddressText.Append(emailAddress); |
|
380 |
|
381 err = eMailSettingsData->SetAttr(TImumDaSettings::EKeyEmailAddress, |
|
382 emailAddressText); |
|
383 User::LeaveIfError(err); |
|
384 |
|
385 TImumDaSettings::TTextMailboxName mailBoxName(*iDefaultName); |
|
386 err = eMailSettingsData->SetAttr(TImumDaSettings::EKeyMailboxName, |
|
387 mailBoxName); |
|
388 |
|
389 // set IMAP/POP specific settings, create the account and set as default |
|
390 if ( iPopMail ) // POP3 |
|
391 { |
|
392 // Add Pop set |
|
393 MImumDaSettingsDataCollection& pop3Set = eMailSettingsData->AddSetL( |
|
394 KSenduiMtmPop3Uid); |
|
395 |
|
396 |
|
397 // set access point preferences |
|
398 TImIAPChoice popIapChoice; |
|
399 popIapChoice.iDialogPref = ECommDbDialogPrefDoNotPrompt; |
|
400 popIapChoice.iIAP = 0; |
|
401 // We get Wap AP Uid from AP adapter, so it needs to be converted here. |
|
402 // If correct IAP is not found try to use default IAP from CommsDB |
|
403 TRAPD( error, popIapChoice.iIAP = IapIdFromWapIdL( aPopImapItem.AssociatedIapId() ) ); |
|
404 if ( error == KErrNone ) |
|
405 { |
|
406 popImapIapSet->AddIAPL(popIapChoice); |
|
407 } |
|
408 else if ( error == KErrNotFound ) |
|
409 { |
|
410 popIapChoice.iIAP = 0; |
|
411 popIapChoice.iDialogPref = ECommDbDialogPrefPrompt; |
|
412 popImapIapSet->AddIAPL( popIapChoice ); |
|
413 } |
|
414 else |
|
415 { |
|
416 User::Leave( error ); |
|
417 } |
|
418 |
|
419 //Set Access Point |
|
420 err = pop3Set.SetAttr(TImumDaSettings::EKeyAccessPoint, TInt( |
|
421 popImapIapSet->IAPPreference(0).iIAP)); |
|
422 User::LeaveIfError(err); |
|
423 |
|
424 TImumDaSettings::TTextServerAddress serverAddress; |
|
425 serverAddress.Append(aPopImapItem.ParameterValue(EWPParameterAddr)); |
|
426 |
|
427 err = pop3Set.SetAttr(TImumDaSettings::EKeyServer, serverAddress); |
|
428 User::LeaveIfError(err); |
|
429 |
|
430 TImumDaSettings::TTextUserName userName(Des16To8L( |
|
431 aPopImapItem.ParameterValue(EWPParameterAAuthName))); |
|
432 TImumDaSettings::TTextPassword passWord(Des16To8L( |
|
433 aPopImapItem.ParameterValue(EWPParameterAAuthSecret))); |
|
434 |
|
435 //set application ID |
|
436 const TDesC& appID = aPopImapItem.ParameterValue(EWPParameterAppID); |
|
437 appIdValue.Copy(appID); |
|
438 |
|
439 if (userName.Length() > 0) |
|
440 { |
|
441 err = pop3Set.SetAttr(TImumDaSettings::EKeyUsername, userName); |
|
442 } |
|
443 if (passWord.Length() > 0) |
|
444 { |
|
445 err = pop3Set.SetAttr(TImumDaSettings::EKeyPassword, passWord); |
|
446 } |
|
447 |
|
448 //Set Port Value |
|
449 TInt portVal; |
|
450 if (GetParamValue(aPopImapItem, EWPParameterPortNbr, portVal) |
|
451 == KErrNone) |
|
452 { |
|
453 err = pop3Set.SetAttr(TImumDaSettings::EKeyPort, portVal); |
|
454 } |
|
455 |
|
456 // Set Service parameter values [StartTLS, SSL/TLS, Normal] |
|
457 const TDesC& popSecure = aPopImapItem.ParameterValue( |
|
458 EWPParameterService); |
|
459 |
|
460 if (popSecure.Compare(KSecureString) == 0) |
|
461 { |
|
462 err = pop3Set.SetAttr(TImumDaSettings::EKeySecurity, |
|
463 TImumDaSettings::EValueSecurityTls); |
|
464 } |
|
465 else if (popSecure.Compare(KEmailSettingSecurePortPOP) == 0) |
|
466 { |
|
467 err = pop3Set.SetAttr(TImumDaSettings::EKeySecurity, |
|
468 TImumDaSettings::EValueSecuritySsl); |
|
469 if (!err) |
|
470 { |
|
471 err = pop3Set.SetAttr(TImumDaSettings::EKeyPort, |
|
472 KEmailSslWrappedPop3Port); |
|
473 } |
|
474 } |
|
475 else |
|
476 { |
|
477 err = pop3Set.SetAttr(TImumDaSettings::EKeySecurity, |
|
478 TImumDaSettings::EValueSecurityOff); |
|
479 } |
|
480 |
|
481 err = SetEmailNotificationRetrievalParamsL(*eMailSettingsData, |
|
482 aPopImapItem, pop3Set); |
|
483 |
|
484 } |
|
485 else // IMAP4 |
|
486 { |
|
487 // Add Imap set |
|
488 MImumDaSettingsDataCollection& imap4Set = eMailSettingsData->AddSetL( |
|
489 KSenduiMtmImap4Uid); |
|
490 // set access point preferences |
|
491 TImIAPChoice imapIapChoice; |
|
492 imapIapChoice.iDialogPref = ECommDbDialogPrefDoNotPrompt; |
|
493 imapIapChoice.iIAP = 0; |
|
494 // We get Wap AP Uid from AP adapter, so it needs to be converted here. |
|
495 // If correct IAP is not found try to use default IAP from CommsDB |
|
496 TRAPD( error, imapIapChoice.iIAP = IapIdFromWapIdL( aPopImapItem.AssociatedIapId() ) ); |
|
497 if ( error == KErrNone ) |
|
498 { |
|
499 popImapIapSet->AddIAPL(imapIapChoice); |
|
500 } |
|
501 else if ( error == KErrNotFound ) |
|
502 { |
|
503 imapIapChoice.iIAP = 0; |
|
504 imapIapChoice.iDialogPref = ECommDbDialogPrefPrompt; |
|
505 popImapIapSet->AddIAPL( imapIapChoice ); |
|
506 } |
|
507 else |
|
508 { |
|
509 User::Leave( error ); |
|
510 } |
|
511 |
|
512 //Set Access Point |
|
513 err = imap4Set.SetAttr(TImumDaSettings::EKeyAccessPoint, TInt( |
|
514 popImapIapSet->IAPPreference(0).iIAP)); |
|
515 User::LeaveIfError(err); |
|
516 |
|
517 // Set incoming mail server |
|
518 TImumDaSettings::TTextServerAddress serverAddress; |
|
519 serverAddress.Append(aPopImapItem.ParameterValue(EWPParameterAddr)); |
|
520 err = imap4Set.SetAttr(TImumDaSettings::EKeyServer, serverAddress); |
|
521 User::LeaveIfError(err); |
|
522 |
|
523 TImumDaSettings::TTextUserName userName(Des16To8L( |
|
524 aPopImapItem.ParameterValue(EWPParameterAAuthName))); |
|
525 TImumDaSettings::TTextPassword passWord(Des16To8L( |
|
526 aPopImapItem.ParameterValue(EWPParameterAAuthSecret))); |
|
527 |
|
528 //set application ID |
|
529 const TDesC& appID = aPopImapItem.ParameterValue( EWPParameterAppID ); |
|
530 appIdValue.Copy(appID); |
|
531 |
|
532 if (userName.Length() > 0) |
|
533 { |
|
534 err = imap4Set.SetAttr(TImumDaSettings::EKeyUsername, userName); |
|
535 } |
|
536 if (passWord.Length() > 0) |
|
537 { |
|
538 err = imap4Set.SetAttr(TImumDaSettings::EKeyPassword, passWord); |
|
539 } |
|
540 |
|
541 //Set Port Value |
|
542 TInt portVal; |
|
543 if (GetParamValue(aPopImapItem, EWPParameterPortNbr, portVal) |
|
544 == KErrNone) |
|
545 { |
|
546 err = imap4Set.SetAttr(TImumDaSettings::EKeyPort, portVal); |
|
547 } |
|
548 |
|
549 // Set Service parameter values [StartTLS, SSL/TLS, Normal] |
|
550 const TDesC& imapSecure = aPopImapItem.ParameterValue( |
|
551 EWPParameterService); |
|
552 if (imapSecure.Compare(KSecureString) == 0) |
|
553 { |
|
554 err = imap4Set.SetAttr(TImumDaSettings::EKeySecurity, |
|
555 TImumDaSettings::EValueSecurityTls); |
|
556 } |
|
557 else if (imapSecure.Compare(KEmailSettingSecurePortIMAP) == 0) |
|
558 { |
|
559 err = imap4Set.SetAttr(TImumDaSettings::EKeySecurity, |
|
560 TImumDaSettings::EValueSecuritySsl); |
|
561 if (!err) |
|
562 { |
|
563 err = imap4Set.SetAttr(TImumDaSettings::EKeyPort, |
|
564 KEmailSslWrappedImap4Port); |
|
565 } |
|
566 } |
|
567 else |
|
568 { |
|
569 err = imap4Set.SetAttr(TImumDaSettings::EKeySecurity, |
|
570 TImumDaSettings::EValueSecurityOff); |
|
571 } |
|
572 |
|
573 err = SetEmailNotificationRetrievalParamsL(*eMailSettingsData, |
|
574 aPopImapItem, imap4Set); |
|
575 |
|
576 } |
|
577 |
|
578 // Add smtp set |
|
579 MImumDaSettingsDataCollection& smtpSet = eMailSettingsData->AddSetL( |
|
580 KSenduiMtmSmtpUid); |
|
581 |
|
582 // set access point preferences |
|
583 TImIAPChoice smtpIapChoice; |
|
584 smtpIapChoice.iDialogPref = ECommDbDialogPrefDoNotPrompt; |
|
585 smtpIapChoice.iIAP = 0; |
|
586 // We get Wap AP Uid from AP adapter, so it needs to be converted here. |
|
587 // If correct IAP is not found try to use default IAP from CommsDB |
|
588 LOGSTRING( "CWPEmailSaveItem::IapIdFromWapIdL : Entry" ); |
|
589 TRAPD( error, smtpIapChoice.iIAP = IapIdFromWapIdL( aSmtpItem.AssociatedIapId() ) ); |
|
590 if (error == KErrNone) |
|
591 { |
|
592 apSet->AddIAPL(smtpIapChoice); |
|
593 } |
|
594 else if (error == KErrNotFound) |
|
595 { |
|
596 smtpIapChoice.iIAP = 0; |
|
597 smtpIapChoice.iDialogPref = ECommDbDialogPrefPrompt; |
|
598 apSet->AddIAPL(smtpIapChoice); |
|
599 } |
|
600 else |
|
601 { |
|
602 User::Leave(error); |
|
603 } |
|
604 LOGSTRING( "CWPEmailSaveItem::IapIdFromWapIdL : Exit" ); |
|
605 |
|
606 //Set Access Point |
|
607 err = smtpSet.SetAttr(TImumDaSettings::EKeyAccessPoint, TInt( |
|
608 apSet->IAPPreference(0).iIAP)); |
|
609 User::LeaveIfError(err); |
|
610 |
|
611 // Set outgoing server address |
|
612 TImumDaSettings::TTextServerAddress serverAddress; |
|
613 serverAddress.Append(aSmtpItem.ParameterValue(EWPParameterAddr)); |
|
614 err = smtpSet.SetAttr(TImumDaSettings::EKeyServer, serverAddress); |
|
615 User::LeaveIfError(err); |
|
616 |
|
617 TInt val; |
|
618 // set port number |
|
619 if (GetParamValue(aSmtpItem, EWPParameterPortNbr, val) == KErrNone) |
|
620 { |
|
621 err = smtpSet.SetAttr(TImumDaSettings::EKeyPort, val); |
|
622 } |
|
623 |
|
624 // Set Service parameter values [StartTLS, SSL/TLS, Normal] |
|
625 const TDesC& secure = aSmtpItem.ParameterValue(EWPParameterService); |
|
626 |
|
627 if (secure.Compare(KSecureString) == 0) |
|
628 { |
|
629 err = smtpSet.SetAttr(TImumDaSettings::EKeySecurity, |
|
630 TImumDaSettings::EValueSecurityTls); |
|
631 } |
|
632 else if (secure.Compare(KEmailSettingSecurePortSMTP) == 0) |
|
633 { |
|
634 err = smtpSet.SetAttr(TImumDaSettings::EKeySecurity, |
|
635 TImumDaSettings::EValueSecuritySsl); |
|
636 if (!err) |
|
637 { |
|
638 smtpSet.SetAttr(TImumDaSettings::EKeyPort, |
|
639 KEmailSslWrappedSmtpPort); |
|
640 } |
|
641 } |
|
642 else |
|
643 { |
|
644 err = smtpSet.SetAttr(TImumDaSettings::EKeySecurity, |
|
645 TImumDaSettings::EValueSecurityOff); |
|
646 } |
|
647 |
|
648 LOGSTRING( "Des16To8L : Entry" ); |
|
649 TImumDaSettings::TTextUserName smtpUserName(Des16To8L( |
|
650 aSmtpItem.ParameterValue(EWPParameterAAuthName))); |
|
651 LOGSTRING( "Des16To8L : Exit" ); |
|
652 LOGSTRING( "Des16To8L : Entry" ); |
|
653 TImumDaSettings::TTextPassword smtpPassWord(Des16To8L( |
|
654 aSmtpItem.ParameterValue(EWPParameterAAuthSecret))); |
|
655 LOGSTRING( "Des16To8L : Exit" ); |
|
656 |
|
657 if (smtpUserName.Length() > 0) |
|
658 { |
|
659 err = smtpSet.SetAttr(TImumDaSettings::EKeyUsername, smtpUserName); |
|
660 } |
|
661 if (smtpPassWord.Length() > 0) |
|
662 { |
|
663 err = smtpSet.SetAttr(TImumDaSettings::EKeyPassword, smtpPassWord); |
|
664 } |
|
665 |
|
666 //Set User Preferences |
|
667 err = smtpSet.SetAttr(TImumDaSettings::EKeyReplyToAddress, |
|
668 emailAddressText); |
|
669 |
|
670 LOGSTRING( "Emailservices::CreateMailboxL : Entry" ); |
|
671 iDefaultMsvId = iServices->CreateMailboxL(*eMailSettingsData); |
|
672 LOGSTRING( "Emailservices::CreateMailboxL : Exit" ); |
|
673 |
|
674 SetEmailAppIdForPnpServiceL(appIdValue); |
|
675 |
|
676 |
|
677 CleanupStack::PopAndDestroy(3); |
|
678 LOGSTRING( "CWPEmailSaveItem::CreateMailboxEntryL : Exit" ); |
|
679 |
|
680 return err; |
|
681 } |
|
682 void CWPEmailSaveItem::SetEmailAppIdForPnpServiceL(TDesC& appIDValue) |
|
683 { |
|
684 |
|
685 |
|
686 |
|
687 //if PnPMS service launched by Email client for email settings download |
|
688 //then set application ID of mail box into Cenrep. |
|
689 CPnpProvUtil* prov = CPnpProvUtil::NewLC(); |
|
690 // use contant value |
|
691 const TUint32 uidVal = 0x100058C5; |
|
692 TUint32 uidValCenrep = prov->GetApplicationUidL(); |
|
693 |
|
694 if(uidVal == uidValCenrep) |
|
695 prov->SetProvAdapterAppIdL(appIDValue); |
|
696 |
|
697 CleanupStack::PopAndDestroy(); |
|
698 |
|
699 |
|
700 } |
|
701 |
|
702 |
|
703 void CWPEmailSaveItem::IncrementNameL(TDes& aName) |
|
704 { |
|
705 LOGSTRING( "CWPEmailSaveItem::IncrementNameL: Enter" ); |
|
706 |
|
707 TInt length = aName.Length(); |
|
708 |
|
709 // If this fails it means that at least default name should have been assigned |
|
710 // to item. |
|
711 //__ASSERT_ALWAYS(length > 0, Panic(EMEUNameEmpty)); |
|
712 |
|
713 |
|
714 TInt newOrdinal = 0; |
|
715 TInt index = length-1; |
|
716 TInt charValue = aName[index]; |
|
717 |
|
718 // Check if name ends with ')' |
|
719 if (charValue == ')') |
|
720 { |
|
721 TBool cutBetweenIndexes = EFalse; |
|
722 index--; |
|
723 TInt multi = 1; |
|
724 while ( index >= 0) |
|
725 { |
|
726 charValue = aName[index]; |
|
727 TChar ch(charValue); |
|
728 |
|
729 if (!ch.IsDigit()) |
|
730 { |
|
731 // There was non-digits inside the brackets. |
|
732 if ( charValue == '(') |
|
733 { |
|
734 // We found the start |
|
735 cutBetweenIndexes = ETrue; |
|
736 index--; |
|
737 break; |
|
738 } |
|
739 else |
|
740 { |
|
741 // There was a non-digit inside the '(' and ')' |
|
742 // We just append after the original name. |
|
743 break; |
|
744 } |
|
745 } // if |
|
746 else |
|
747 { |
|
748 TInt newNum = ch.GetNumericValue(); |
|
749 if (multi <= 100000000) |
|
750 { |
|
751 // If there's a pattern (007) then this makes it to be (007)(01) |
|
752 if (newNum == 0 && newOrdinal != 0 && multi > 10) |
|
753 { |
|
754 break; |
|
755 } |
|
756 newOrdinal += newNum * multi; |
|
757 multi*=10; |
|
758 }//0010 |
|
759 else |
|
760 { |
|
761 newOrdinal = 0; |
|
762 break; |
|
763 } |
|
764 } |
|
765 index--; |
|
766 } // while |
|
767 |
|
768 // There was correct pattern of (0000) so now we delete it. |
|
769 if (cutBetweenIndexes) |
|
770 { |
|
771 aName.Delete(index+1, length-index); |
|
772 } |
|
773 else |
|
774 { |
|
775 // This case is for example 12345) so we get 12345)(01) |
|
776 newOrdinal = 0; |
|
777 } |
|
778 } // if |
|
779 |
|
780 // Add one to the ordinal read from the old name |
|
781 newOrdinal++; |
|
782 |
|
783 // Check that there's enough space to add the ordinal |
|
784 TInt maxLength = aName.MaxLength(); |
|
785 TInt ordinalSpace(4); // Ordinal space comes from (00) so it's 4 |
|
786 length = aName.Length(); |
|
787 if (length + ordinalSpace > maxLength) |
|
788 { |
|
789 aName.Delete(maxLength-ordinalSpace, ordinalSpace); |
|
790 } |
|
791 |
|
792 // Append the ordinal at the end of the name |
|
793 HBufC* old = aName.AllocLC(); |
|
794 |
|
795 _LIT(KFormatSpecLessTen, "%S(0%d)"); |
|
796 _LIT(KFormatSpecOverTen, "%S(%d)"); |
|
797 if (newOrdinal < 10) |
|
798 { |
|
799 aName.Format(KFormatSpecLessTen, old, newOrdinal); |
|
800 } |
|
801 else |
|
802 { |
|
803 aName.Format(KFormatSpecOverTen, old, newOrdinal); |
|
804 } |
|
805 CleanupStack::PopAndDestroy(old); // old |
|
806 |
|
807 LOGSTRING( "CWPEmailSaveItem::IncrementNameL: Exit" ); |
|
808 } |
|
809 |
|
810 |
|
811 // ----------------------------------------------------------------------------- |
|
812 // CWPEmailSaveItem::IncrementNameL |
|
813 // ----------------------------------------------------------------------------- |
|
814 // |
|
815 void CWPEmailSaveItem::IncrementNameL(TDes& aName, TInt aMaxLength) |
|
816 { |
|
817 LOGSTRING( "CWPEmailSaveItem::IncrementNameL: Enter" ); |
|
818 |
|
819 TInt length = aName.Length(); |
|
820 |
|
821 // If this fails it means that at least default name should have been assigned |
|
822 // to item. |
|
823 //__ASSERT_ALWAYS(length > 0, Panic(EMEUNameEmpty)); |
|
824 |
|
825 TInt newOrdinal = 0; |
|
826 TInt index = length-1; |
|
827 TInt charValue = aName[index]; |
|
828 |
|
829 // Check if name ends with ')' |
|
830 if (charValue == ')') |
|
831 { |
|
832 TBool cutBetweenIndexes = EFalse; |
|
833 index--; |
|
834 TInt multi = 1; |
|
835 while ( index >= 0) |
|
836 { |
|
837 charValue = aName[index]; |
|
838 TChar ch(charValue); |
|
839 |
|
840 if (!ch.IsDigit()) |
|
841 { |
|
842 // There was non-digits inside the brackets. |
|
843 if ( charValue == '(') |
|
844 { |
|
845 // We found the start |
|
846 cutBetweenIndexes = ETrue; |
|
847 index--; |
|
848 break; |
|
849 } |
|
850 else |
|
851 { |
|
852 // There was a non-digit inside the '(' and ')' |
|
853 // We just append after the original name. |
|
854 break; |
|
855 } |
|
856 } // if |
|
857 else |
|
858 { |
|
859 TInt newNum = ch.GetNumericValue(); |
|
860 if (multi <= 100000000) |
|
861 { |
|
862 // If there's a pattern (007) then this makes it to be (007)(01) |
|
863 if (newNum == 0 && newOrdinal != 0 && multi > 10) |
|
864 { |
|
865 break; |
|
866 } |
|
867 newOrdinal += newNum * multi; |
|
868 multi*=10; |
|
869 }//0010 |
|
870 else |
|
871 { |
|
872 newOrdinal = 0; |
|
873 break; |
|
874 } |
|
875 } |
|
876 index--; |
|
877 } // while |
|
878 |
|
879 // There was correct pattern of (0000) so now we delete it. |
|
880 if (cutBetweenIndexes) |
|
881 { |
|
882 aName.Delete(index+1, length-index); |
|
883 } |
|
884 else |
|
885 { |
|
886 // This case is for example 12345) so we get 12345)(01) |
|
887 newOrdinal = 0; |
|
888 } |
|
889 } // if |
|
890 |
|
891 // Add one to the ordinal read from the old name |
|
892 newOrdinal++; |
|
893 |
|
894 // Check that there's enough space to add the ordinal |
|
895 TInt maxLength = aMaxLength; |
|
896 TInt ordinalSpace(4); // Ordinal space comes from (00) so it's 4 |
|
897 length = aName.Length(); |
|
898 if (length + ordinalSpace > maxLength) |
|
899 { |
|
900 aName.Delete(maxLength-ordinalSpace, ordinalSpace); |
|
901 } |
|
902 |
|
903 // Append the ordinal at the end of the name |
|
904 HBufC* old = aName.AllocLC(); |
|
905 |
|
906 _LIT(KFormatSpecLessTen, "%S(0%d)"); |
|
907 _LIT(KFormatSpecOverTen, "%S(%d)"); |
|
908 if (newOrdinal < 10) |
|
909 { |
|
910 aName.Format(KFormatSpecLessTen, old, newOrdinal); |
|
911 } |
|
912 else |
|
913 { |
|
914 aName.Format(KFormatSpecOverTen, old, newOrdinal); |
|
915 } |
|
916 CleanupStack::PopAndDestroy(old); // old |
|
917 |
|
918 LOGSTRING( "CWPEmailSaveItem::IncrementNameL: Exit" ); |
|
919 } |
|
920 |
|
921 // ----------------------------------------------------------------------------- |
|
922 // CWPEmailSaveItem::ValidateText |
|
923 // ----------------------------------------------------------------------------- |
|
924 // |
|
925 TInt CWPEmailSaveItem::ValidateText(const TDesC& serverAddress) |
|
926 { |
|
927 |
|
928 // Check if the name of the mailbox contains only |
|
929 // white space characters. |
|
930 TInt length = serverAddress.Length(); |
|
931 |
|
932 |
|
933 for( TInt i = 0 ; i < length ; i++ ) |
|
934 { |
|
935 TChar tempChar(serverAddress[i]); |
|
936 if( !tempChar.IsSpace() ) |
|
937 { |
|
938 // If the character isn't a white space character |
|
939 // then KErrNone is returned. |
|
940 return KErrNone; |
|
941 } |
|
942 } |
|
943 return KErrGeneral; |
|
944 |
|
945 } |
|
946 |
|
947 |
|
948 // ----------------------------------------------------------------------------- |
|
949 // CWPEmailSaveItem::ValidateServerAddress |
|
950 // ----------------------------------------------------------------------------- |
|
951 // |
|
952 TInt CWPEmailSaveItem::ValidateServerAddress(const TDesC& serverAddress) |
|
953 { |
|
954 |
|
955 TInt result = ValidateText(serverAddress); |
|
956 |
|
957 // Check for valid server address |
|
958 if ( result == KErrNone ) |
|
959 { |
|
960 TBool ok = EFalse; |
|
961 TRAPD( error, ok = MsvUiServiceUtilities::IsValidDomainL(serverAddress) ); |
|
962 |
|
963 result = ( error == KErrNone ) && ok ? KErrNone : KErrGeneral; |
|
964 } |
|
965 |
|
966 return result; |
|
967 |
|
968 } |
|
969 |
|
970 // ----------------------------------------------------------------------------- |
|
971 // CWPEmailSaveItem::ValidatePortNo |
|
972 // ----------------------------------------------------------------------------- |
|
973 // |
|
974 TInt CWPEmailSaveItem::ValidatePortNo(const TUint& portVal) |
|
975 { |
|
976 TInt result = (portVal >= KEmailPortMinValue) && (portVal <= KEmailPortMaxValue) ? KErrNone : KErrArgument; |
|
977 return result; |
|
978 } |
|
979 |
|
980 // ----------------------------------------------------------------------------- |
|
981 // CWPEmailSaveItem::SetEmailNotificationRetrievalParamsL |
|
982 // ----------------------------------------------------------------------------- |
|
983 // |
|
984 TInt CWPEmailSaveItem::SetEmailNotificationRetrievalParamsL( |
|
985 CImumDaSettingsData& aEmailSettingsData, CWPEmailItem& aPopImapItem, |
|
986 MImumDaSettingsDataCollection& aPopImapSet) |
|
987 { |
|
988 LOGSTRING( "CWPEmailSaveItem::SetEmailNotificationRetrievalParamsL : Entry" ); |
|
989 TInt err = KErrGeneral; |
|
990 |
|
991 //Set EMN |
|
992 /* |
|
993 Characteristic/name: APPLICATION/EMN |
|
994 Status: Optional. |
|
995 Occurs: 0/1. |
|
996 Default value: 0. |
|
997 Used values: 0, 1, 2. |
|
998 OFF = 0. |
|
999 ON = 1. |
|
1000 VALID = 2. |
|
1001 Interpretation: |
|
1002 Specifies the usage of OMA EMN. If the value is OFF (0), OMA EMN |
|
1003 is disabled. If the value is ON (1) OMA EMN is enabled. If the value |
|
1004 is VALID (2) OMA EMN is enabled with proxy whitelist validation. |
|
1005 This means that OMA EMN messages are accepted only from |
|
1006 trusted push proxy gateways. Whitelist validation is made |
|
1007 based on Push Validation document available in Forum Nokia. |
|
1008 */ |
|
1009 |
|
1010 const TDesC& emnParamName(KParamEMN); |
|
1011 |
|
1012 TBool validUserPass = EFalse; |
|
1013 // Check whether Username and Password are there in the incoming settings |
|
1014 |
|
1015 err = ValidateUserNamePassword(aPopImapSet, validUserPass); |
|
1016 if (!err && validUserPass) |
|
1017 { |
|
1018 err = SetIntParam(aEmailSettingsData, aPopImapItem, emnParamName); |
|
1019 } |
|
1020 |
|
1021 TInt emnValSet; |
|
1022 TInt err1; |
|
1023 err1 = aEmailSettingsData.GetAttr(TImumDaSettings::EKeyAutoNotifications, |
|
1024 emnValSet); |
|
1025 |
|
1026 if (((!err && !err1 && !emnValSet) || err) && validUserPass) |
|
1027 { |
|
1028 const TDesC& onlineParamName(KParamONLINE); |
|
1029 // Check whether Username and Password are there in the incoming settings |
|
1030 |
|
1031 TInt onlineValRec; |
|
1032 err = GetParamValue(aPopImapItem, onlineParamName, onlineValRec); |
|
1033 if (emnValSet && !err && onlineValRec) |
|
1034 { |
|
1035 //Set EMN to Off before setting Online |
|
1036 err = aEmailSettingsData.SetAttr( |
|
1037 TImumDaSettings::EKeyAutoNotifications, |
|
1038 TImumDaSettings::EValueNotificationsOff); |
|
1039 } |
|
1040 //Set Online |
|
1041 /* |
|
1042 Characteristic/name: APPLICATION/ONLINE |
|
1043 Status: Optional. |
|
1044 Occurs: 0/1. |
|
1045 Default value: 0. |
|
1046 Used values: 0 or 1. |
|
1047 OFF = 0. |
|
1048 ON = 1. |
|
1049 Interpretation: |
|
1050 Specifies the online mode. Online mode works with APPLICATION/POLL and |
|
1051 APPLICATION/CS parameters in following way: |
|
1052 Connection shedule parameter specifies time windows when always online mode |
|
1053 is used. Polling can be used to shorter polling interval of IMAP IDLE. This |
|
1054 is useful option when network/NAT drops connection after short inactivity |
|
1055 */ |
|
1056 if (!err) |
|
1057 { |
|
1058 err = SetIntParam(aEmailSettingsData, aPopImapItem, |
|
1059 onlineParamName); |
|
1060 } |
|
1061 |
|
1062 } |
|
1063 |
|
1064 const TDesC& csParamName(KParamCS); |
|
1065 const TDesC& csParamVal(aPopImapItem.ParameterValue(csParamName)); |
|
1066 |
|
1067 if (csParamVal.Length()) |
|
1068 { |
|
1069 LOGSTRING2( "[Provisioning] CWPEmailSaveItem::SetEmailNotificationRetrievalParamsL: csParamVal value %i", csParamVal ); |
|
1070 |
|
1071 TLex csParamValue(csParamVal); |
|
1072 TInt64 retStartHourMinValue = KImumMboxDefaultAutoRetrievalStartHour; |
|
1073 TInt64 retEndHourMinValue = KImumMboxDefaultAutoRetrievalEndHour; |
|
1074 |
|
1075 //Get the Retrieval Start and End Hours, first |
|
1076 err = GetRetHoursValueL(csParamValue, '-', retStartHourMinValue); |
|
1077 |
|
1078 if (!err) |
|
1079 { |
|
1080 err = GetRetHoursValueL(csParamValue, '<', retEndHourMinValue); |
|
1081 } |
|
1082 |
|
1083 //Set Retrieval Days |
|
1084 /* |
|
1085 Characteristic/name: APPLICATION/CS |
|
1086 Status: Optional. |
|
1087 Occurs: 0/1. |
|
1088 Default value: empty. |
|
1089 Used values: empty or time<days>; 00:00-23:59<0,1,2,3,4,5,6> |
|
1090 Sunday = 0. |
|
1091 Monday = 1. |
|
1092 Tuesday = 2. |
|
1093 Wednesday = 3. |
|
1094 Thursday = 4. |
|
1095 Friday = 5. |
|
1096 Saturday = 6. |
|
1097 Interpretation: |
|
1098 Specifies the connection schedule when always online or polling is |
|
1099 active. When value is empty, connection schedule is disabled. If |
|
1100 connection shedule is inactivated, polling is still enabled. |
|
1101 */ |
|
1102 //Setting Retrieval Days, first, parse the CS parm, till the end |
|
1103 if (!err) |
|
1104 { |
|
1105 err = SetRetDaysL(csParamValue, aEmailSettingsData); |
|
1106 } |
|
1107 |
|
1108 // If there no error in parsing the CS parameter, then set the Retrieval Start and End Hours |
|
1109 if (!err && retStartHourMinValue |
|
1110 > KImumMboxDefaultAutoRetrievalStartHour) |
|
1111 { |
|
1112 //Set Retrieval Start Hour |
|
1113 err = aEmailSettingsData.SetAttr( |
|
1114 TImumDaSettings::EKeyAutoRetrievalStartHour, |
|
1115 retStartHourMinValue); |
|
1116 } |
|
1117 |
|
1118 if (!err && retEndHourMinValue > KImumMboxDefaultAutoRetrievalEndHour) |
|
1119 { |
|
1120 //Set Retrieval End Hour |
|
1121 err = aEmailSettingsData.SetAttr( |
|
1122 TImumDaSettings::EKeyAutoRetrievalEndHour, |
|
1123 retEndHourMinValue); |
|
1124 } |
|
1125 |
|
1126 } |
|
1127 |
|
1128 const TDesC& pollParamName(KParamPOLL); |
|
1129 //Set Poll |
|
1130 /* |
|
1131 Characteristic/name: APPLICATION/POLL |
|
1132 Status: Optional. |
|
1133 Occurs: 0/1. |
|
1134 Default value: 0. |
|
1135 Used values: 0 (off), or 16-bit unsigned integer. |
|
1136 Interpretation: |
|
1137 Specifies the polling period in minutes. Zero indicates that |
|
1138 polling is disabled. |
|
1139 */ |
|
1140 err = SetIntParam(aEmailSettingsData, aPopImapItem, pollParamName); |
|
1141 |
|
1142 const TDesC& lmsParamName(KParamLMS); |
|
1143 TInt onlineParamVal; |
|
1144 err = aEmailSettingsData.GetAttr(TImumDaSettings::EKeyAutoRetrieval, |
|
1145 onlineParamVal); |
|
1146 |
|
1147 if ((!err && onlineParamVal == KImumMboxDefaultAutoRetrieval) || err) |
|
1148 { |
|
1149 //Automatic Retrieval is off, then set Mailbox Update Limit to the value received |
|
1150 /* |
|
1151 Characteristic/name: APPLICATION/LMS |
|
1152 Status: Optional. |
|
1153 Occurs: 0/1. |
|
1154 Default value: 0. |
|
1155 Used values: 0 (all mails) or 32-bit unsigned integer. |
|
1156 Interpretation: |
|
1157 Specifies the local mailbox size. This defines the amount of mails kept in |
|
1158 local mailbox. If this value has been defined to zero (all), then all mails |
|
1159 are fetched to the mobile (local mailbox). If this value is define for |
|
1160 example 10, then only 10 newest mails are kept in local mailbox. |
|
1161 */ |
|
1162 err = SetIntParam(aEmailSettingsData, aPopImapItem, lmsParamName); |
|
1163 } |
|
1164 |
|
1165 LOGSTRING( "CWPEmailSaveItem::SetEmailNotificationRetrievalParamsL : Exit" ); |
|
1166 |
|
1167 return err; |
|
1168 |
|
1169 } |
|
1170 |
|
1171 // ----------------------------------------------------------------------------- |
|
1172 // CWPEmailSaveItem::SetIntParam |
|
1173 // ----------------------------------------------------------------------------- |
|
1174 // |
|
1175 TInt CWPEmailSaveItem::SetIntParam(CImumDaSettingsData& aEmailSettingsData, |
|
1176 CWPEmailItem& aPopImapItem, const TDesC& aParamName) |
|
1177 { |
|
1178 TInt err = KErrGeneral; |
|
1179 TInt paramMinValue; |
|
1180 TInt paramMaxValue; |
|
1181 TInt paramKey = 0x0000000; |
|
1182 |
|
1183 if (aParamName.CompareF(KParamEMN) == 0) |
|
1184 { |
|
1185 paramMinValue = TImumDaSettings::EValueNotificationsOff; |
|
1186 paramMaxValue = TImumDaSettings::EValueNotificationsHome; |
|
1187 paramKey = TImumDaSettings::EKeyAutoNotifications; |
|
1188 } |
|
1189 else if (aParamName.CompareF(KParamONLINE) == 0) |
|
1190 { |
|
1191 paramMinValue = TImumDaSettings::EValueAutoOff; |
|
1192 paramMaxValue = TImumDaSettings::EValueAutoHomeNetwork; |
|
1193 paramKey = TImumDaSettings::EKeyAutoRetrieval; |
|
1194 } |
|
1195 else if (aParamName.CompareF(KParamPOLL) == 0) |
|
1196 { |
|
1197 paramMinValue = KImumPollMinUpdateLimit; |
|
1198 paramMaxValue = KImumPollMaxUpdateLimit; |
|
1199 } |
|
1200 |
|
1201 else if (aParamName.CompareF(KParamLMS) == 0) |
|
1202 { |
|
1203 paramMinValue = KImumMboxInboxMinUpdateLimit; |
|
1204 paramMaxValue = KImumMboxInboxMaxUpdateLimit; |
|
1205 paramKey = TImumDaSettings::EKeyInboxUpdateLimit; |
|
1206 } |
|
1207 |
|
1208 else |
|
1209 { |
|
1210 return err; |
|
1211 } |
|
1212 |
|
1213 TInt val; |
|
1214 err = GetParamValue(aPopImapItem, aParamName, val); |
|
1215 if (!err) |
|
1216 { |
|
1217 if (val >= paramMinValue && val <= paramMaxValue) |
|
1218 { |
|
1219 if (aParamName.CompareF(KParamPOLL) != 0) |
|
1220 { |
|
1221 //Set the value for the Parm |
|
1222 err = aEmailSettingsData.SetAttr(paramKey, val); |
|
1223 } |
|
1224 else |
|
1225 { |
|
1226 //Set the value for Poll |
|
1227 err = SetPollValue(aEmailSettingsData, val); |
|
1228 } |
|
1229 } |
|
1230 else |
|
1231 { |
|
1232 return KErrOverflow; |
|
1233 } |
|
1234 } |
|
1235 return err; |
|
1236 } |
|
1237 // ----------------------------------------------------------------------------- |
|
1238 // CWPEmailSaveItem::GetParamValue |
|
1239 // ----------------------------------------------------------------------------- |
|
1240 // |
|
1241 TInt CWPEmailSaveItem::GetParamValue(CWPEmailItem& aEmailItem, |
|
1242 const TInt aParamID, TInt& aVal) |
|
1243 { |
|
1244 TLex paramValue(aEmailItem.ParameterValue(aParamID)); |
|
1245 return (paramValue.Val(aVal)); |
|
1246 } |
|
1247 |
|
1248 // ----------------------------------------------------------------------------- |
|
1249 // CWPEmailSaveItem::GetParamValue |
|
1250 // ----------------------------------------------------------------------------- |
|
1251 // |
|
1252 TInt CWPEmailSaveItem::GetParamValue(CWPEmailItem& aEmailItem, |
|
1253 const TDesC& aParamName, TInt& aVal) |
|
1254 { |
|
1255 TLex paramValue(aEmailItem.ParameterValue(aParamName)); |
|
1256 return (paramValue.Val(aVal)); |
|
1257 } |
|
1258 |
|
1259 // ----------------------------------------------------------------------------- |
|
1260 // CWPEmailSaveItem::GetRetParamValuesFromCS |
|
1261 // ----------------------------------------------------------------------------- |
|
1262 // |
|
1263 TBool CWPEmailSaveItem::GetRetParamValuesFromCS(TLex& aCSParamValue, |
|
1264 const TInt aTokenMark, TPtrC& aParm) |
|
1265 { |
|
1266 aCSParamValue.Mark(); |
|
1267 TInt next = aCSParamValue.Peek(); |
|
1268 TChar cnext = aCSParamValue.Peek(); |
|
1269 TInt count = 0; |
|
1270 |
|
1271 while (!cnext.Eos()) |
|
1272 { |
|
1273 if (next == aTokenMark) |
|
1274 { |
|
1275 aParm.Set(aCSParamValue.MarkedToken()); |
|
1276 aCSParamValue.Inc(); |
|
1277 return ETrue; |
|
1278 } |
|
1279 aCSParamValue.Inc(); |
|
1280 next = aCSParamValue.Peek(); |
|
1281 cnext = aCSParamValue.Peek(); |
|
1282 count++; |
|
1283 } |
|
1284 |
|
1285 while (count--) |
|
1286 { |
|
1287 aCSParamValue.UnGet(); |
|
1288 } |
|
1289 return EFalse; |
|
1290 } |
|
1291 |
|
1292 // ----------------------------------------------------------------------------- |
|
1293 // CWPEmailSaveItem::GetRetHoursValueL |
|
1294 // ----------------------------------------------------------------------------- |
|
1295 // |
|
1296 TInt CWPEmailSaveItem::GetRetHoursValueL(TLex& aCSParamValue, |
|
1297 TInt aTokenMark, TInt64& aRetHourMinValue) |
|
1298 { |
|
1299 TInt err = KErrGeneral; |
|
1300 TPtrC retHour(KNullDesC); |
|
1301 TPtrC retMin(KNullDesC); |
|
1302 |
|
1303 if (GetRetParamValuesFromCS(aCSParamValue, KColonChar, retHour) |
|
1304 && GetRetParamValuesFromCS(aCSParamValue, aTokenMark, retMin)) |
|
1305 { |
|
1306 if (retHour.Length() != KRetHourStandardLength || retMin.Length() |
|
1307 != KRetMinStandardLength) |
|
1308 { |
|
1309 return KErrOverflow; |
|
1310 } |
|
1311 TLex lexRetHour(retHour); |
|
1312 TLex lexRetMin(retMin); |
|
1313 TInt64 valRetHour; |
|
1314 TInt64 valRetMin; |
|
1315 |
|
1316 err = ValidateRetHourorMin(lexRetHour); |
|
1317 |
|
1318 if (!err) |
|
1319 { |
|
1320 err = ValidateRetHourorMin(lexRetMin); |
|
1321 } |
|
1322 |
|
1323 if (!err) |
|
1324 { |
|
1325 err = lexRetHour.Val(valRetHour); |
|
1326 } |
|
1327 |
|
1328 if (!err) |
|
1329 { |
|
1330 err = lexRetMin.Val(valRetMin); |
|
1331 } |
|
1332 |
|
1333 if (!err) |
|
1334 { |
|
1335 //Check for the boundary values |
|
1336 if (valRetHour >= KRetHourLowerBound && valRetHour |
|
1337 <= KRetHourUpperBound && valRetMin >= KRetMinLowerBound |
|
1338 && valRetMin <= KRetMinUpperBound) |
|
1339 { |
|
1340 const TDesC& retSecMilliSec(KRetSecMilliSec); |
|
1341 TInt retHourMinMaxSize = retHour.Size() + retMin.Size() |
|
1342 + retSecMilliSec.Size(); |
|
1343 TInt retHourMaxSize = retHour.Size(); |
|
1344 TInt retMinMaxSize = retMin.Size(); |
|
1345 HBufC* bufRetHour = HBufC::NewL(retHourMaxSize); |
|
1346 HBufC* bufRetMin = HBufC::NewL(retMinMaxSize); |
|
1347 HBufC* bufRetHourMin = HBufC::NewL(retHourMinMaxSize); |
|
1348 |
|
1349 TPtr ptrRetHour(bufRetHour->Des()); |
|
1350 //Change the Absolute Integer Hour value to a string |
|
1351 GetRetHourorMinfromIntValue(retHour, valRetHour, ptrRetHour); |
|
1352 |
|
1353 TPtr ptrRetMin(bufRetMin->Des()); |
|
1354 //Change the Absolute Integer Min value to a string |
|
1355 GetRetHourorMinfromIntValue(retMin, valRetMin, ptrRetMin); |
|
1356 |
|
1357 TPtr retHourMin(bufRetHourMin->Des()); |
|
1358 retHourMin.Append(ptrRetHour); |
|
1359 retHourMin.Append(ptrRetMin); |
|
1360 //Make the string to be in proper Time format |
|
1361 retHourMin.Append(retSecMilliSec); |
|
1362 |
|
1363 LOGSTRING2( "[Provisioning] CWPEmailSaveItem::GetRetHoursValueL: retHourMin value %i", retHourMin ); |
|
1364 |
|
1365 TTime timeretHour(retHourMin); |
|
1366 aRetHourMinValue = timeretHour.Int64(); |
|
1367 delete bufRetHourMin; |
|
1368 delete bufRetMin; |
|
1369 delete bufRetHour; |
|
1370 |
|
1371 } |
|
1372 else |
|
1373 { |
|
1374 return KErrOverflow; |
|
1375 } |
|
1376 } |
|
1377 |
|
1378 } |
|
1379 |
|
1380 return err; |
|
1381 |
|
1382 } |
|
1383 |
|
1384 // ----------------------------------------------------------------------------- |
|
1385 // CWPEmailSaveItem::SetRetDaysL |
|
1386 // ----------------------------------------------------------------------------- |
|
1387 // |
|
1388 TInt CWPEmailSaveItem::SetRetDaysL(TLex& aCSParamValue, |
|
1389 CImumDaSettingsData& aEmailSettingsData) |
|
1390 { |
|
1391 TInt err = KErrGeneral; |
|
1392 TPtrC retDays(KNullDesC); |
|
1393 |
|
1394 if (GetRetParamValuesFromCS(aCSParamValue, KGTChar, retDays)) |
|
1395 { |
|
1396 LOGSTRING2( "[Provisioning] CWPEmailSaveItem::SetRetDaysL: retDays value, %i", retDays ); |
|
1397 |
|
1398 const TDesC& comma(KComma); |
|
1399 const TInt retDaysMaxSize = retDays.Size() + comma.Size(); |
|
1400 HBufC* bufRetDays = HBufC::NewL(retDaysMaxSize); |
|
1401 *bufRetDays = retDays; |
|
1402 |
|
1403 TPtr ptrRetDays(bufRetDays->Des()); |
|
1404 //Append comma to demarcate the last day |
|
1405 ptrRetDays.Append(comma); |
|
1406 |
|
1407 if (ptrRetDays.Length() > KRetDaysStandardMaxLength) |
|
1408 { |
|
1409 delete bufRetDays; |
|
1410 return KErrOverflow; |
|
1411 } |
|
1412 |
|
1413 TLex lexRetDays(ptrRetDays); |
|
1414 TChar next = lexRetDays.Peek(); |
|
1415 TInt retDaysFlag = 0x0000000; |
|
1416 |
|
1417 while (!next.Eos()) |
|
1418 { |
|
1419 TPtrC retDay(KNullDesC); |
|
1420 |
|
1421 if (GetRetParamValuesFromCS(lexRetDays, KCommaChar, retDay)) |
|
1422 { |
|
1423 if (retDay.Length() != KRetDayStandardLength) |
|
1424 { |
|
1425 delete bufRetDays; |
|
1426 return KErrOverflow; |
|
1427 } |
|
1428 TLex lexRetDay(retDay); |
|
1429 TInt retDayVal; |
|
1430 LOGSTRING2( "[Provisioning] CWPEmailSaveItem::SetRetDaysL: retDay value, %i", retDay ); |
|
1431 |
|
1432 err = lexRetDay.Val(retDayVal); |
|
1433 if (!err) |
|
1434 { |
|
1435 switch (retDayVal) |
|
1436 { |
|
1437 case KRetSunday: |
|
1438 { |
|
1439 retDaysFlag |= TImumDaSettings::EFlagSunday; |
|
1440 break; |
|
1441 } |
|
1442 case KRetMonday: |
|
1443 { |
|
1444 retDaysFlag |= TImumDaSettings::EFlagMonday; |
|
1445 break; |
|
1446 } |
|
1447 case KRetTuesday: |
|
1448 { |
|
1449 retDaysFlag |= TImumDaSettings::EFlagTuesday; |
|
1450 break; |
|
1451 } |
|
1452 case KRetWednesday: |
|
1453 { |
|
1454 retDaysFlag |= TImumDaSettings::EFlagWednesday; |
|
1455 break; |
|
1456 } |
|
1457 case KRetThursday: |
|
1458 { |
|
1459 retDaysFlag |= TImumDaSettings::EFlagThursday; |
|
1460 break; |
|
1461 } |
|
1462 case KRetFriday: |
|
1463 { |
|
1464 retDaysFlag |= TImumDaSettings::EFlagFriday; |
|
1465 break; |
|
1466 } |
|
1467 case KRetSaturday: |
|
1468 { |
|
1469 retDaysFlag |= TImumDaSettings::EFlagSaturday; |
|
1470 break; |
|
1471 } |
|
1472 default: |
|
1473 { |
|
1474 delete bufRetDays; |
|
1475 return KErrOverflow; |
|
1476 } |
|
1477 } |
|
1478 } |
|
1479 else |
|
1480 { |
|
1481 break; |
|
1482 } |
|
1483 |
|
1484 } |
|
1485 |
|
1486 next = lexRetDays.Peek(); |
|
1487 } |
|
1488 |
|
1489 if (!err && retDaysFlag) |
|
1490 { |
|
1491 //If the flag is set, set the value to Retrieval Days |
|
1492 err = aEmailSettingsData.SetAttr( |
|
1493 TImumDaSettings::EKeyAutoRetrievalDays, retDaysFlag); |
|
1494 } |
|
1495 |
|
1496 delete bufRetDays; |
|
1497 } |
|
1498 |
|
1499 return err; |
|
1500 |
|
1501 } |
|
1502 |
|
1503 // ----------------------------------------------------------------------------- |
|
1504 // CWPEmailSaveItem::SetPollValue |
|
1505 // ----------------------------------------------------------------------------- |
|
1506 // |
|
1507 TInt CWPEmailSaveItem::SetPollValue(CImumDaSettingsData& aEmailSettingsData, |
|
1508 TInt aPollValue) |
|
1509 { |
|
1510 TInt err = KErrGeneral; |
|
1511 TInt pollhour = aPollValue / 60; |
|
1512 TInt pollmin = aPollValue % 60; |
|
1513 TInt pollval = pollhour; |
|
1514 |
|
1515 if (!pollhour) |
|
1516 { |
|
1517 pollval = pollmin; |
|
1518 } |
|
1519 |
|
1520 //Consider only the absolute minutes and absolute hours |
|
1521 if ((pollhour && !pollmin) || (!pollhour && pollmin)) |
|
1522 { |
|
1523 TInt val = 0; |
|
1524 switch (pollval) |
|
1525 { |
|
1526 case KPoll5minutes: |
|
1527 { |
|
1528 val = TImumDaSettings::EValue5Minutes; |
|
1529 break; |
|
1530 } |
|
1531 case KPoll15minutes: |
|
1532 { |
|
1533 val = TImumDaSettings::EValue15Minutes; |
|
1534 break; |
|
1535 } |
|
1536 case KPoll30minutes: |
|
1537 { |
|
1538 val = TImumDaSettings::EValue30Minutes; |
|
1539 break; |
|
1540 } |
|
1541 case KPoll1Hour: |
|
1542 { |
|
1543 val = TImumDaSettings::EValue1Hour; |
|
1544 break; |
|
1545 } |
|
1546 case KPoll2Hours: |
|
1547 { |
|
1548 val = TImumDaSettings::EValue2Hours; |
|
1549 break; |
|
1550 } |
|
1551 case KPoll4Hours: |
|
1552 { |
|
1553 val = TImumDaSettings::EValue4Hours; |
|
1554 break; |
|
1555 } |
|
1556 case KPoll6Hours: |
|
1557 { |
|
1558 val = TImumDaSettings::EValue6Hours; |
|
1559 break; |
|
1560 } |
|
1561 } |
|
1562 if (val) |
|
1563 { |
|
1564 //If val is set, set it to Poll |
|
1565 err = aEmailSettingsData.SetAttr( |
|
1566 TImumDaSettings::EKeyAutoRetrievalInterval, val); |
|
1567 } |
|
1568 } |
|
1569 return err; |
|
1570 } |
|
1571 |
|
1572 // ----------------------------------------------------------------------------- |
|
1573 // CWPEmailSaveItem::ValidateUserNamePassword |
|
1574 // ----------------------------------------------------------------------------- |
|
1575 // |
|
1576 TInt CWPEmailSaveItem::ValidateUserNamePassword( |
|
1577 MImumDaSettingsDataCollection& aPopImapSet, TBool& aValidUserPass ) |
|
1578 { |
|
1579 TInt err = KErrGeneral; |
|
1580 TImumDaSettings::TTextUserName userName(KNullDesC8); |
|
1581 TImumDaSettings::TTextPassword passWord(KNullDesC8); |
|
1582 |
|
1583 err = aPopImapSet.GetAttr(TImumDaSettings::EKeyUsername, userName); |
|
1584 |
|
1585 if (!err) |
|
1586 { |
|
1587 err = aPopImapSet.GetAttr(TImumDaSettings::EKeyPassword, passWord); |
|
1588 } |
|
1589 |
|
1590 if (!err && userName.Length() > 0 && passWord.Length() > 0) |
|
1591 { |
|
1592 aValidUserPass = ETrue; |
|
1593 } |
|
1594 |
|
1595 return err; |
|
1596 } |
|
1597 |
|
1598 // ----------------------------------------------------------------------------- |
|
1599 // CWPEmailSaveItem::GetRetHourorMinfromIntValue |
|
1600 // ----------------------------------------------------------------------------- |
|
1601 // |
|
1602 void CWPEmailSaveItem::GetRetHourorMinfromIntValue(TPtrC& aRetHourMin, |
|
1603 TInt64 aValRetHourMin, TPtr& aPtrRetHourMin) |
|
1604 { |
|
1605 const TDesC& retLeadingZero(KRetLeadingZero); |
|
1606 TInt retHourMaxSize = aRetHourMin.Size(); |
|
1607 HBufC* bufRetHourMin = HBufC::NewL(retHourMaxSize); |
|
1608 HBufC* TempBufRetHourMin = HBufC::NewL(retHourMaxSize); |
|
1609 |
|
1610 TPtr ptrTempRetHourMin(TempBufRetHourMin->Des()); |
|
1611 ptrTempRetHourMin.Num(aValRetHourMin); |
|
1612 LOGSTRING2( "[Provisioning] CWPEmailSaveItem::GetRetHoursValueL: ptrTempRetHourMin value, %i ", ptrTempRetHourMin ); |
|
1613 |
|
1614 if (aValRetHourMin < KRetHourMinLeadLimit) |
|
1615 { |
|
1616 aPtrRetHourMin.Append(retLeadingZero); |
|
1617 } |
|
1618 |
|
1619 aPtrRetHourMin.Append(ptrTempRetHourMin); |
|
1620 LOGSTRING2( "[Provisioning] CWPEmailSaveItem::GetRetHoursValueL: aPtrRetHourMin value %i", aPtrRetHourMin ); |
|
1621 |
|
1622 delete TempBufRetHourMin; |
|
1623 delete bufRetHourMin; |
|
1624 } |
|
1625 |
|
1626 // ----------------------------------------------------------------------------- |
|
1627 // CWPEmailSaveItem::ValidateRetHourorMin |
|
1628 // ----------------------------------------------------------------------------- |
|
1629 // |
|
1630 TInt CWPEmailSaveItem::ValidateRetHourorMin(TLex& aRetHourMin) |
|
1631 { |
|
1632 TChar cnext = aRetHourMin.Peek(); |
|
1633 TInt count = 0; |
|
1634 |
|
1635 while (!cnext.Eos()) |
|
1636 { |
|
1637 if (!(cnext.IsDigit())) |
|
1638 { |
|
1639 return KErrGeneral; |
|
1640 } |
|
1641 aRetHourMin.Inc(); |
|
1642 cnext = aRetHourMin.Peek(); |
|
1643 count++; |
|
1644 } |
|
1645 |
|
1646 while (count--) |
|
1647 { |
|
1648 aRetHourMin.UnGet(); |
|
1649 } |
|
1650 |
|
1651 return KErrNone; |
|
1652 } |
|
1653 // End of File |