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