|
1 /* |
|
2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "creator_mailboxelement.h" |
|
20 #include "creator_traces.h" |
|
21 #include "creator_mailbox.h" |
|
22 |
|
23 using namespace creatormailbox; |
|
24 |
|
25 /* |
|
26 * |
|
27 */ |
|
28 CCreatorMailboxElement* CCreatorMailboxElement::NewL(CCreatorEngine* aEngine, const TDesC& aName, const TDesC& aContext ) |
|
29 { |
|
30 CCreatorMailboxElement* self = new (ELeave) CCreatorMailboxElement(aEngine); |
|
31 CleanupStack::PushL(self); |
|
32 self->ConstructL(aName, aContext); |
|
33 CleanupStack::Pop(self); |
|
34 return self; |
|
35 } |
|
36 /* |
|
37 * |
|
38 */ |
|
39 CCreatorMailboxElement::CCreatorMailboxElement(CCreatorEngine* aEngine) |
|
40 : |
|
41 CCreatorScriptElement(aEngine) |
|
42 { |
|
43 iIsCommandElement = ETrue; |
|
44 } |
|
45 |
|
46 TBool CCreatorMailboxElement::SetIntegerParamL(const TDesC& aElemName, const TDesC& aElemContent, CMailboxesParameters* param, TBool aSetRandom ) |
|
47 { |
|
48 _LIT( KAll, "all"); |
|
49 |
|
50 if( aElemName == Kincomingport ) |
|
51 { |
|
52 if( aSetRandom ) |
|
53 param->iIncomingPort = iEngine->RandomNumber(25, 500); |
|
54 else |
|
55 param->iIncomingPort = ConvertStrToIntL(aElemContent); |
|
56 } |
|
57 else if( aElemName == Kattachmentsizelimit ) |
|
58 { |
|
59 if( aSetRandom ) |
|
60 param->iAttachmentSizeLimit = iEngine->RandomNumber(1, KMaxTInt); |
|
61 else |
|
62 param->iAttachmentSizeLimit = ConvertStrToIntL(aElemContent); |
|
63 } |
|
64 else if( aElemName == Kbodytextsizelimit ) |
|
65 { |
|
66 if( aSetRandom ) |
|
67 param->iBodyTextSizeLimit = iEngine->RandomNumber(1, KMaxTInt); |
|
68 else |
|
69 param->iBodyTextSizeLimit = ConvertStrToIntL(aElemContent); |
|
70 } |
|
71 else if( aElemName == Kattachmentfetchsize ) |
|
72 { |
|
73 if( aSetRandom ) |
|
74 param->iAttachmentFetchSize = iEngine->RandomNumber(1, 40960); |
|
75 else |
|
76 param->iAttachmentFetchSize = ConvertStrToIntL(aElemContent); |
|
77 } |
|
78 else if( aElemName == Kimapidletimeout ) |
|
79 { |
|
80 if( aSetRandom ) |
|
81 param->iImapIdleTimeout = iEngine->RandomNumber(10, 2000); |
|
82 else |
|
83 param->iImapIdleTimeout = ConvertStrToIntL(aElemContent); |
|
84 } |
|
85 else if( aElemName == Kmaxemailsize ) |
|
86 { |
|
87 if( aSetRandom ) |
|
88 param->iMaxEmailSize = iEngine->RandomNumber(1024, KMaxTInt); |
|
89 else |
|
90 param->iMaxEmailSize = ConvertStrToIntL(aElemContent); |
|
91 } |
|
92 else if( aElemName == Ksyncrate ) |
|
93 { |
|
94 if( aSetRandom ) |
|
95 param->iSyncRate = iEngine->RandomNumber(10, 500); |
|
96 else |
|
97 param->iSyncRate = ConvertStrToIntL(aElemContent); |
|
98 } |
|
99 else if( aElemName == Kinboxsynclimit ) |
|
100 { |
|
101 if( aSetRandom ) |
|
102 param->iInboxSyncLimit = iEngine->RandomNumber(-1, 256); |
|
103 else if( CompareIgnoreCase(aElemContent, KAll) == 0 ) |
|
104 param->iInboxSyncLimit = -1; |
|
105 else |
|
106 param->iInboxSyncLimit = ConvertStrToIntL(aElemContent); |
|
107 } |
|
108 else if( aElemName == Kmailboxsynclimit ) |
|
109 { |
|
110 if( aSetRandom ) |
|
111 param->iMailboxSyncLimit = iEngine->RandomNumber(-1, 256); |
|
112 else if( CompareIgnoreCase(aElemContent, KAll) == 0 ) |
|
113 param->iMailboxSyncLimit = -1; |
|
114 else |
|
115 param->iMailboxSyncLimit = ConvertStrToIntL(aElemContent); |
|
116 } |
|
117 else if( aElemName == Koutgoingport ) |
|
118 { |
|
119 if( aSetRandom ) |
|
120 param->iOutgoingPort = KDefaultSmtpPort; |
|
121 else |
|
122 param->iOutgoingPort = ConvertStrToIntL(aElemContent); |
|
123 } |
|
124 else if( aElemName == Ktoccincludelimit ) |
|
125 { |
|
126 if( aSetRandom ) |
|
127 param->iToCCIncludeLimit = iEngine->RandomNumber(0, 30); |
|
128 else |
|
129 param->iToCCIncludeLimit = ConvertStrToIntL(aElemContent); |
|
130 } |
|
131 else |
|
132 return EFalse; |
|
133 |
|
134 return ETrue; |
|
135 } |
|
136 |
|
137 TBool CCreatorMailboxElement::GetBooleanValueL(const TDesC& aElemContent, TBool aSetRandom) |
|
138 { |
|
139 if( aSetRandom ) |
|
140 return iEngine->RandomNumber(0,1) == 1; |
|
141 |
|
142 return ConvertStrToBooleanL(aElemContent); |
|
143 } |
|
144 |
|
145 TBool CCreatorMailboxElement::SetBooleanParamL(const TDesC& aElemName, const TDesC& aElemContent, CMailboxesParameters* param, TBool aSetRandom ) |
|
146 { |
|
147 TBool val = GetBooleanValueL(aElemContent, aSetRandom); |
|
148 if( aElemName == Kincomingsslwrapper ) |
|
149 param->iIncomingSSLWrapper = val; |
|
150 else if( aElemName == Kincomingsecuresockets ) |
|
151 param->iIncomingSecureSockets = val; |
|
152 else if( aElemName == Kacknowledgereceipts ) |
|
153 param->iAcknowledgeReceipts = val; |
|
154 else if( aElemName == Kautosendonconnect ) |
|
155 param->iAutoSendOnConnect = val; |
|
156 else if( aElemName == Kdeletemailsatdisconnect ) |
|
157 param->iDeleteEmailsAtDisconnect = val; |
|
158 else if( aElemName == Kimapidlecommand ) |
|
159 param->iImapIdleCommand = val; |
|
160 else if( aElemName == Kmarkseeninsync ) |
|
161 param->iMarkSeenInSync = val; |
|
162 else if( aElemName == Kenableexpungemode ) |
|
163 param->iEnableExpungeMode = val; |
|
164 else if( aElemName == Kuseapopsecurelogin ) |
|
165 param->iUseApop = val; |
|
166 else if( aElemName == Kdisconnectedusermode ) |
|
167 param->iDisconnectedUserMode = val; |
|
168 else if( aElemName == Koutgoingsslwrapper ) |
|
169 param->iOutgoingSSLWrapper = val; |
|
170 else if( aElemName == Koutgoingsecuresockets ) |
|
171 param->iOutgoingSecureSockets = val; |
|
172 else if( aElemName == Kincludesignature ) |
|
173 param->iIncludeSignature = val; |
|
174 else if( aElemName == Kaddvcard ) |
|
175 param->iAddVCard = val; |
|
176 else if( aElemName == Krequestreceipts ) |
|
177 param->iRequestReceipts = val; |
|
178 else if( aElemName == Ksmtpauth ) |
|
179 param->iSmtpAuth = val; |
|
180 else |
|
181 return EFalse; |
|
182 |
|
183 return ETrue; |
|
184 } |
|
185 |
|
186 TBool CCreatorMailboxElement::SetTextParamL(const TDesC& aElemName, const TDesC& aElemContent, CMailboxesParameters* param, TBool aSetRandom ) |
|
187 { |
|
188 _LIT(KIncomingSrvPrefix, "mail."); |
|
189 _LIT(KOutgoingSrvPrefix, "smtp."); |
|
190 _LIT(KSrvPostfix, ".com"); |
|
191 _LIT(KDefaultConnMethod, "internet"); |
|
192 |
|
193 if( aElemName == Kname ) |
|
194 { |
|
195 if( aSetRandom ) |
|
196 { |
|
197 TPtrC company(iEngine->RandomString(CCreatorEngine::ECompany)); |
|
198 SetContentToTextParamL(param->iMailboxName, company); |
|
199 } |
|
200 else |
|
201 SetContentToTextParamL(param->iMailboxName, aElemContent); |
|
202 } |
|
203 else if( aElemName == Kincomingloginname ) |
|
204 { |
|
205 if( aSetRandom ) |
|
206 { |
|
207 TPtrC random(iEngine->RandomString(CCreatorEngine::EFirstName)); |
|
208 SetContentToTextParamL(param->iIncomingLoginName, random); |
|
209 param->iIncomingLoginName->Des().LowerCase(); |
|
210 } |
|
211 else |
|
212 SetContentToTextParamL(param->iIncomingLoginName, aElemContent); |
|
213 } |
|
214 else if( aElemName == Kincomingpassword ) |
|
215 { |
|
216 if( aSetRandom ) |
|
217 { |
|
218 TPtrC random(iEngine->RandomString(CCreatorEngine::EFirstName)); |
|
219 SetContentToTextParamL(param->iIncomingPassword, random); |
|
220 param->iIncomingPassword->Des().LowerCase(); |
|
221 } |
|
222 else |
|
223 SetContentToTextParamL(param->iIncomingPassword, aElemContent); |
|
224 } |
|
225 else if( aElemName == Kincomingservername ) |
|
226 { |
|
227 if( aSetRandom ) |
|
228 { |
|
229 TPtrC random(iEngine->RandomString(CCreatorEngine::ECompany)); |
|
230 HBufC* srvName = HBufC::NewLC(KIncomingSrvPrefix().Length()+random.Length()+KSrvPostfix().Length()); |
|
231 srvName->Des().Copy(KIncomingSrvPrefix); |
|
232 srvName->Des().Append(random); |
|
233 srvName->Des().Append(KSrvPostfix); |
|
234 SetContentToTextParamL(param->iIncomingServerName, srvName->Des()); |
|
235 CleanupStack::PopAndDestroy(); // srvName |
|
236 } |
|
237 else |
|
238 SetContentToTextParamL(param->iIncomingServerName, aElemContent); |
|
239 } |
|
240 else if( aElemName == Kincomingconnectionmethod ) |
|
241 { |
|
242 if( aSetRandom ) |
|
243 SetContentToTextParamL(param->iIncomingConnectionMethod, KDefaultConnMethod); |
|
244 else |
|
245 SetContentToTextParamL(param->iIncomingConnectionMethod, aElemContent); |
|
246 } |
|
247 else if( aElemName == Kincomingfolderpath ) |
|
248 SetContentToTextParamL(param->iIncomingFolderPath, aElemContent); |
|
249 else if( aElemName == Kpathseparator ) |
|
250 SetContentToTextParamL(param->iPathSeparator, aElemContent); |
|
251 else if( aElemName == Koutgoingloginname ) |
|
252 { |
|
253 if( aSetRandom ) |
|
254 { |
|
255 TPtrC random(iEngine->RandomString(CCreatorEngine::EFirstName)); |
|
256 SetContentToTextParamL(param->iOutgoingLoginName, random); |
|
257 param->iOutgoingLoginName->Des().LowerCase(); |
|
258 } |
|
259 else |
|
260 SetContentToTextParamL(param->iOutgoingLoginName, aElemContent); |
|
261 } |
|
262 else if( aElemName == Koutgoingpassword ) |
|
263 { |
|
264 if( aSetRandom ) |
|
265 { |
|
266 TPtrC random(iEngine->RandomString(CCreatorEngine::EFirstName)); |
|
267 SetContentToTextParamL(param->iOutgoingPassword, random); |
|
268 param->iOutgoingPassword->Des().LowerCase(); |
|
269 } |
|
270 else |
|
271 SetContentToTextParamL(param->iOutgoingPassword, aElemContent); |
|
272 } |
|
273 else if( aElemName == Koutgoingservername ) |
|
274 { |
|
275 if( aSetRandom ) |
|
276 { |
|
277 TPtrC random(iEngine->RandomString(CCreatorEngine::ECompany)); |
|
278 HBufC* srvName = HBufC::NewLC(KOutgoingSrvPrefix().Length()+random.Length()+KSrvPostfix().Length()); |
|
279 srvName->Des().Copy(KOutgoingSrvPrefix); |
|
280 srvName->Des().Append(random); |
|
281 srvName->Des().Append(KSrvPostfix); |
|
282 SetContentToTextParamL(param->iOutgoingServerName, srvName->Des()); |
|
283 CleanupStack::PopAndDestroy(); // srvName |
|
284 } |
|
285 else |
|
286 SetContentToTextParamL(param->iOutgoingServerName, aElemContent); |
|
287 } |
|
288 else if( aElemName == Koutgoingconnectionmethod ) |
|
289 { |
|
290 if( aSetRandom ) |
|
291 SetContentToTextParamL(param->iOutgoingConnectionMethod, KDefaultConnMethod); |
|
292 else |
|
293 SetContentToTextParamL(param->iOutgoingConnectionMethod, aElemContent); |
|
294 } |
|
295 else if( aElemName == Kownemail ) |
|
296 { |
|
297 if( aSetRandom ) |
|
298 { |
|
299 TDesC* email = iEngine->CreateEmailAddressLC(); |
|
300 SetContentToTextParamL(param->iOwnEmailAddress, *email); |
|
301 CleanupStack::PopAndDestroy(); // email |
|
302 } |
|
303 else |
|
304 SetContentToTextParamL(param->iOwnEmailAddress, aElemContent); |
|
305 } |
|
306 else if( aElemName == Kemailalias ) |
|
307 { |
|
308 if( aSetRandom ) |
|
309 { |
|
310 _LIT(KSpace, " "); |
|
311 TPtrC firstName(iEngine->RandomString(CCreatorEngine::EFirstName)); |
|
312 TPtrC lastName(iEngine->RandomString(CCreatorEngine::ESurname)); |
|
313 HBufC* alias = HBufC::NewLC(firstName.Length() + lastName.Length() + KSpace().Length()); |
|
314 alias->Des().Copy(firstName); |
|
315 alias->Des().Append(KSpace); |
|
316 alias->Des().Append(lastName); |
|
317 SetContentToTextParamL(param->iOwnEmailAlias, alias->Des()); |
|
318 CleanupStack::PopAndDestroy(); // alias |
|
319 } |
|
320 else |
|
321 SetContentToTextParamL(param->iOwnEmailAlias, aElemContent); |
|
322 } |
|
323 else if( aElemName == Kreceiptaddress ) |
|
324 { |
|
325 if( aSetRandom ) |
|
326 { |
|
327 TDesC* email = iEngine->CreateEmailAddressLC(); |
|
328 SetContentToTextParamL(param->iReceiptAddress, *email); |
|
329 CleanupStack::PopAndDestroy(); // email |
|
330 } |
|
331 else |
|
332 SetContentToTextParamL(param->iReceiptAddress, aElemContent); |
|
333 } |
|
334 else if( aElemName == Kreplytoaddress ) |
|
335 { |
|
336 if( aSetRandom ) |
|
337 { |
|
338 TDesC* email = iEngine->CreateEmailAddressLC(); |
|
339 SetContentToTextParamL(param->iReceiptAddress, *email); |
|
340 CleanupStack::PopAndDestroy(); // email |
|
341 } |
|
342 else |
|
343 SetContentToTextParamL(param->iReplyToAddress, aElemContent); |
|
344 } |
|
345 else |
|
346 return EFalse; |
|
347 |
|
348 return ETrue; |
|
349 } |
|
350 |
|
351 TBool CCreatorMailboxElement::SetEnumParamL(const TDesC& aElemName, const TDesC& aElemContent, CMailboxesParameters* param, TBool aSetRandom ) |
|
352 { |
|
353 // Get email options: |
|
354 if( aElemName == Kgetemailoptions ) |
|
355 { |
|
356 if( aSetRandom ) |
|
357 param->iGetEmailOptions = (CMailboxesParameters::TGetEmailOption) iEngine->RandomNumber( |
|
358 CMailboxesParameters::EGetHeaders, |
|
359 CMailboxesParameters::EGetEmailOptionLast-1); |
|
360 else if( CompareIgnoreCase(aElemContent, Kgetheaders ) == 0 ) |
|
361 param->iGetEmailOptions = CMailboxesParameters::EGetHeaders; |
|
362 else if( CompareIgnoreCase(aElemContent, Kgetbodytext) == 0 ) |
|
363 param->iGetEmailOptions = CMailboxesParameters::EGetBodyText; |
|
364 else if( CompareIgnoreCase(aElemContent, Kgetbodytextandattachments) == 0 ) |
|
365 param->iGetEmailOptions = CMailboxesParameters::EGetBodyTextAndAttachments; |
|
366 else if( CompareIgnoreCase(aElemContent, Kgetattachments) == 0 ) |
|
367 param->iGetEmailOptions = CMailboxesParameters::EGetAttachments; |
|
368 else if( CompareIgnoreCase(aElemContent, Kgetbodyalternativetext) == 0 ) |
|
369 param->iGetEmailOptions = CMailboxesParameters::EGetBodyAlternativeText; |
|
370 else |
|
371 param->iGetEmailOptions = CMailboxesParameters::EUndef; |
|
372 } |
|
373 |
|
374 // Subscribe type: |
|
375 else if( aElemName == Ksubscribetype ) |
|
376 { |
|
377 if( aSetRandom ) |
|
378 param->iSubscribeType = (TFolderSubscribeType) iEngine->RandomNumber( EUpdateNeither, EUpdateBoth ); |
|
379 else if( CompareIgnoreCase( aElemContent, Kupdatelocal) == 0 ) |
|
380 param->iSubscribeType = EUpdateLocal; |
|
381 else if( CompareIgnoreCase( aElemContent, Kupdateremote) == 0 ) |
|
382 param->iSubscribeType = EUpdateRemote; |
|
383 else if( CompareIgnoreCase( aElemContent, Kupdateboth) == 0 ) |
|
384 param->iSubscribeType = EUpdateBoth; |
|
385 else |
|
386 param->iSubscribeType = EUpdateNeither; |
|
387 } |
|
388 |
|
389 // Folder synchronization type: |
|
390 else if( aElemName == Kfoldersynctype) |
|
391 { |
|
392 if( aSetRandom ) |
|
393 param->iSyncType = (TFolderSyncType) iEngine->RandomNumber(EUseCombination, EUseRemote); |
|
394 else if( CompareIgnoreCase( aElemContent, Kuselocal) == 0 ) |
|
395 param->iSyncType = EUseLocal; |
|
396 else if( CompareIgnoreCase( aElemContent, Kuseremote) == 0 ) |
|
397 param->iSyncType = EUseRemote; |
|
398 else |
|
399 param->iSyncType = EUseCombination; |
|
400 } |
|
401 |
|
402 // Send copy to self option: |
|
403 else if( aElemName == Kcopytoself ) |
|
404 { |
|
405 if( aSetRandom ) |
|
406 param->iSendCopyToSelf = (TImSMTPSendCopyToSelf) iEngine->RandomNumber(ESendNoCopy, ESendCopyAsBccRecipient); |
|
407 else if( CompareIgnoreCase( aElemContent, Kto) == 0 ) |
|
408 param->iSendCopyToSelf = ESendCopyAsToRecipient; |
|
409 else if( CompareIgnoreCase( aElemContent, Kcc) == 0 ) |
|
410 param->iSendCopyToSelf = ESendCopyAsCcRecipient; |
|
411 else if( CompareIgnoreCase( aElemContent, Kbcc) == 0 ) |
|
412 param->iSendCopyToSelf = ESendCopyAsBccRecipient; |
|
413 else |
|
414 param->iSendCopyToSelf = ESendNoCopy; |
|
415 } |
|
416 |
|
417 // Send option: |
|
418 else if( aElemName == Ksendoption ) |
|
419 { |
|
420 if( aSetRandom ) |
|
421 param->iSendOption = (TImSMTPSendMessageOption) iEngine->RandomNumber(ESendMessageImmediately, ESendMessageOnRequest); |
|
422 else if( CompareIgnoreCase( aElemContent, Konnextconnection) == 0 ) |
|
423 param->iSendOption = ESendMessageOnNextConnection; |
|
424 else if( CompareIgnoreCase( aElemContent, Konrequest) == 0 ) |
|
425 param->iSendOption = ESendMessageOnRequest; |
|
426 else |
|
427 param->iSendOption = ESendMessageImmediately; |
|
428 } |
|
429 else |
|
430 { |
|
431 return EFalse; |
|
432 } |
|
433 return ETrue; |
|
434 } |
|
435 |
|
436 void CCreatorMailboxElement::ExecuteCommandL() |
|
437 { |
|
438 const CCreatorScriptAttribute* amountAttr = FindAttributeByName(KAmount); |
|
439 const CCreatorScriptAttribute* typeAttr = FindAttributeByName(KMailboxType); |
|
440 TInt amount = 1; |
|
441 if( amountAttr ) |
|
442 { |
|
443 amount = ConvertStrToIntL(amountAttr->Value()); |
|
444 } |
|
445 |
|
446 TMailboxType mailboxType = EMailboxPOP3; |
|
447 |
|
448 if( typeAttr && CompareIgnoreCase(typeAttr->Value(), Kimap4) == 0 ) |
|
449 { |
|
450 mailboxType = EMailboxIMAP4; |
|
451 } |
|
452 |
|
453 // Get 'fields' element |
|
454 CCreatorScriptElement* fieldsElement = FindSubElement(KFields); |
|
455 if( fieldsElement && fieldsElement->SubElements().Count() > 0) |
|
456 { |
|
457 // Get sub-elements |
|
458 const RPointerArray<CCreatorScriptElement>& fields = fieldsElement->SubElements(); |
|
459 // Create mailbox entries, the amount of entries is defined by amount: |
|
460 for( TInt cI = 0; cI < amount; ++cI ) |
|
461 { |
|
462 CMailboxesParameters* param = new (ELeave) CMailboxesParameters; |
|
463 CleanupStack::PushL(param); |
|
464 |
|
465 param->iMailboxType = mailboxType; |
|
466 |
|
467 for( TInt i = 0; i < fields.Count(); ++i ) |
|
468 { |
|
469 CCreatorScriptElement* field = fields[i]; |
|
470 TPtrC elemName = field->Name(); |
|
471 TPtrC elemContent = field->Content(); |
|
472 const CCreatorScriptAttribute* randomAttr = fields[i]->FindAttributeByName(KRandomLength); |
|
473 TBool useRandom = EFalse; |
|
474 if( randomAttr || elemContent.Length() == 0 ) |
|
475 { |
|
476 useRandom = ETrue; |
|
477 } |
|
478 |
|
479 if( SetTextParamL(elemName, elemContent, param, useRandom ) == EFalse && |
|
480 SetBooleanParamL(elemName, elemContent, param, useRandom ) == EFalse && |
|
481 SetIntegerParamL(elemName, elemContent, param, useRandom ) == EFalse && |
|
482 SetEnumParamL(elemName, elemContent, param, useRandom ) ) |
|
483 { |
|
484 LOGSTRING2("CCreatorMailboxElement::ExecuteCommandL: Unknown mailbox field: %S", &elemName); |
|
485 } |
|
486 } |
|
487 iEngine->AppendToCommandArrayL(ECmdCreateMessagingEntryMailboxes, param); |
|
488 CleanupStack::Pop(); // param |
|
489 } |
|
490 } |
|
491 else |
|
492 { |
|
493 iEngine->AppendToCommandArrayL(ECmdCreateMessagingEntryMailboxes, 0, amount); |
|
494 } |
|
495 } |