ipsservices/tsrc/profiletester/src/popimapprofiletesterBlocks.cpp
branchRCL_3
changeset 26 968773a0b6ef
equal deleted inserted replaced
25:3533d4323edc 26:968773a0b6ef
       
     1 /* ============================================================================
       
     2  *  Name        :  popimapprofiletesterBlocks.cpp
       
     3  *  Part of     :  ipsservices / profiletester 
       
     4  *  Description :: STIF test cases
       
     5  *  Version     : %version: 1 % << Don't touch! Updated by Synergy at check-out.
       
     6  *
       
     7  *  Copyright © 2010-2010 Nokia and/or its subsidiary(-ies).  All rights reserved.
       
     8  *  This material, including documentation and any related computer
       
     9  *  programs, is protected by copyright controlled by Nokia.  All
       
    10  *  rights are reserved.  Copying, including reproducing, storing,
       
    11  *  adapting or translating, any or all of this material requires the
       
    12  *  prior written consent of Nokia.  This material also contains
       
    13  *  confidential information which may not be disclosed to others
       
    14  *  without the prior written consent of Nokia.
       
    15  * ============================================================================
       
    16  */
       
    17 
       
    18 //--INCLUDE FILES-- 
       
    19 #include <e32svr.h>
       
    20 #include <StifParser.h>
       
    21 #include <StifTestInterface.h>
       
    22 #include <e32math.h>
       
    23 #include <msvids.h>
       
    24 #include "popimapprofiletester.h"
       
    25 _LIT( KPopImapProfileTester, "c:\\TestFramework\\TestFramework_ips.ini" );
       
    26 _LIT( KStifEmailSubject, "STIF Basic Operations test" );
       
    27 _LIT( KStifEmailSubjectDes,"STIF_");
       
    28 _LIT( KStifEmailBodyText, "This is a temporary STIF test message");
       
    29 _LIT( KStifEmailSubjectAttHandling, "STIF Attachment Handling Test" );
       
    30 _LIT( KStifEmailToRec1, "dummyTo1@empty.com" );
       
    31 _LIT( KStifEmailCcRec1, "dummyCc1@empty.com" );
       
    32 _LIT( KStifEmailCcRec2, "dummyCc2@empty.com" );
       
    33 _LIT( KStifEmailBccRec1, "dummyBcc1@empty.com" );
       
    34 
       
    35 // ============================ MEMBER FUNCTIONS ===============================
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CPopImapProfileTester::Delete
       
    39 // Delete here all resources allocated and opened from test methods. 
       
    40 // Called from destructor. 
       
    41 // -----------------------------------------------------------------------------
       
    42 //
       
    43 void CPopImapProfileTester::Delete()
       
    44     {
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CPopImapProfileTester::RunMethodL
       
    49 // Run specified method. Contains also table of test mothods and their names.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 TInt CPopImapProfileTester::RunMethodL(CStifItemParser& aItem)
       
    53     {
       
    54     static TStifFunctionInfo const
       
    55             KFunctions[] =
       
    56                 {
       
    57                         // Copy this line for every implemented function.
       
    58                         // First string is the function name used in TestScripter script file.
       
    59                         // Second is the actual implementation member function. 
       
    60                         ENTRY( "SetupAccount", CPopImapProfileTester::SetupAccountL ),
       
    61                         ENTRY( "GoOnline", CPopImapProfileTester::GoOnlineL ),
       
    62                         ENTRY( "GoOffline", CPopImapProfileTester::GoOfflineL ),
       
    63                         ENTRY( "RefreshNow", CPopImapProfileTester::RefreshNowL ),
       
    64                         ENTRY( "CancelSync", CPopImapProfileTester::CancelSyncL ),
       
    65                         ENTRY( "ListStandardFolders", CPopImapProfileTester::ListStandardFoldersL ),
       
    66                         ENTRY( "ListFolders", CPopImapProfileTester::ListFoldersL ),
       
    67                         ENTRY( "ListMessages", CPopImapProfileTester::ListMessagesL ),
       
    68                         ENTRY( "FetchMessages", CPopImapProfileTester::FetchMessagesL ),
       
    69                         ENTRY( "SendMessage", CPopImapProfileTester::SendMessageL ),
       
    70                         ENTRY( "BasicMsgOperations", CPopImapProfileTester::BasicMsgOperationsL ),
       
    71                         ENTRY( "CopyMoveMsgs", CPopImapProfileTester::CopyMoveMsgsL ),
       
    72                         ENTRY( "Search", CPopImapProfileTester::SearchL ),
       
    73                         ENTRY( "AttachmentHandling", CPopImapProfileTester::AttachmentHandlingL ),
       
    74                         ENTRY( "Branding", CPopImapProfileTester::BrandingL ),
       
    75                         ENTRY( "DeleteMsgs", CPopImapProfileTester::DeleteMsgsL ),
       
    76                         ENTRY( "RemoveAccount", CPopImapProfileTester::RemoveAccountL ),
       
    77                 };
       
    78 
       
    79     const TInt count = sizeof(KFunctions) / sizeof(TStifFunctionInfo);
       
    80 
       
    81     InitMailboxL();
       
    82     return RunInternalL(KFunctions, count, aItem);
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CPopImapProfileTester:: SetupAccountL
       
    87 // Method used to create an imap or pop account, depends on .cfg file
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 TInt CPopImapProfileTester::SetupAccountL(CStifItemParser& /* aItem */)
       
    91     {
       
    92     //I.Check if mail client exists
       
    93     if (NULL == iMailClient)
       
    94         {
       
    95         iLog->Log(_L( "Error: Failed to create test instance(No Memory)." ));
       
    96         return KErrNoMemory;
       
    97         }
       
    98     TInt err(KErrNone);
       
    99 
       
   100     // II. Check if imap/pop profile already exists
       
   101 
       
   102     if (NULL != iIPSMailbox)
       
   103         {
       
   104         iLog->Log(_L("Error: There is IMAP/POP profile alredy existed"));
       
   105         return KErrAlreadyExists;
       
   106         }
       
   107 
       
   108     iLog->Log(_L( "== SetupAccount Begins ==" ));
       
   109     TAccountSetting settings;
       
   110     // III. Read settings and write to CR
       
   111     ReadAccountSettings(settings);
       
   112     err = WriteToWizardCRL(settings);
       
   113     iLog->Log(_L( "== WriteToWizardCR Ends err=%d" ), err);
       
   114     iLog->Log(_L( "== End a transaction in SetupAccount ==" ));
       
   115 
       
   116     // IV. Create mailbox through WizardDataAvailableL()
       
   117     err = iMailClient->WizardDataAvailableL();
       
   118     if (KErrNone == err)
       
   119         WaitForEvent(TFSEventNewMailbox, NULL, NULL, KTenSecondsTime);
       
   120     err = InitMailboxL();
       
   121     if ((KErrNone == err) && NULL != iIPSMailbox)
       
   122         err = KErrNone;
       
   123     else
       
   124         err = KErrGeneral;
       
   125 
       
   126     iLog->Log(_L( "== SetupAccount Ends err=%d" ), err);
       
   127     return err;
       
   128     }
       
   129 // -----------------------------------------------------------------------------
       
   130 // CPopImapProfileTester:: GoOnlineL
       
   131 // Method used to let phone online
       
   132 // -----------------------------------------------------------------------------
       
   133 //
       
   134 TInt CPopImapProfileTester::GoOnlineL(CStifItemParser& /* aItem */)
       
   135     {
       
   136     TInt err(KErrNone);
       
   137     if (NULL == iIPSMailbox)
       
   138         {
       
   139         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   140         return KErrGeneral;
       
   141         }
       
   142 
       
   143     iLog->Log(_L( "== GoOnline Begins ==" ));
       
   144 
       
   145     // check current mailbox status
       
   146     TBuf<10> statusDes;
       
   147     TFSMailBoxStatus status = iIPSMailbox->GetMailBoxStatus();
       
   148     if (status == EFSMailBoxOffline)
       
   149         {
       
   150         statusDes.Copy(_L("offline"));
       
   151         }
       
   152     else if (status == EFSMailBoxOnline)
       
   153         {
       
   154         statusDes.Copy(_L("online"));
       
   155         iLog->Log(_L("Mailbox has been Online, go offline firstly"));
       
   156         iLog->Log(_L( "== GoOnline ends err=%d" ), err);
       
   157         return KErrGeneral;
       
   158         }
       
   159     else
       
   160         {
       
   161         statusDes.Copy(_L("unknown"));
       
   162         }
       
   163 
       
   164     iLog->Log(_L("Going online (from %S)..."), &statusDes);
       
   165     TSSMailSyncState syncstatus = iIPSMailbox->CurrentSyncState();
       
   166     // call function to go online
       
   167     iEventSynchronousCall = ETrue;
       
   168     iIPSMailbox->GoOnlineL();
       
   169     syncstatus = iIPSMailbox->CurrentSyncState();
       
   170     // we should likely base on TFSEventMailboxOnline, but this does not come always (?)
       
   171     err = WaitForEvent(TFSEventMailboxOnline, NULL, NULL, KOneMinuteTime);
       
   172 
       
   173     syncstatus = iIPSMailbox->CurrentSyncState();
       
   174 
       
   175     //check status of current mailbox again
       
   176     status = iIPSMailbox->GetMailBoxStatus();
       
   177 
       
   178     if (status == EFSMailBoxOnline)
       
   179         {
       
   180         err = KErrNone;
       
   181         iLog->Log(_L("Success: mailbox online"));
       
   182         }
       
   183     else
       
   184         {
       
   185         err = KErrGeneral;
       
   186         iLog->Log(_L("Failed: mailbox status- %S"), &statusDes);
       
   187         }
       
   188 
       
   189     iLog->Log(_L( "== GoOnline ends err=%d" ), err);
       
   190     return err;
       
   191     }
       
   192 // -----------------------------------------------------------------------------
       
   193 // CPopImapProfileTester:: GoOfflineL
       
   194 // Method used to let phone offline
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 TInt CPopImapProfileTester::GoOfflineL(CStifItemParser& /* aItem */)
       
   198     {
       
   199     TInt err(KErrNone);
       
   200     if (NULL == iIPSMailbox)
       
   201         {
       
   202         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   203         return KErrGeneral;
       
   204         }
       
   205 
       
   206     iLog->Log(_L( "== GoOffline Begins ==" ));
       
   207     TBuf<10> statusDes;
       
   208     TFSMailBoxStatus status = iIPSMailbox->GetMailBoxStatus();
       
   209     if (status == EFSMailBoxOffline)
       
   210         {
       
   211         statusDes.Copy(_L("offline"));
       
   212         iLog->Log(_L("Mailbox has been Offline, go online firstly"));
       
   213         iLog->Log(_L( "== GoOffline ends err=%d" ), err);
       
   214         return KErrGeneral;
       
   215         }
       
   216     else if (status == EFSMailBoxOnline)
       
   217         {
       
   218         statusDes.Copy(_L("online"));
       
   219         }
       
   220     else
       
   221         {
       
   222         statusDes.Copy(_L("unknown"));
       
   223         }
       
   224 
       
   225     iLog->Log(_L("Going offline (from %S)..."), &statusDes);
       
   226 
       
   227     // call function to go offline
       
   228     iEventSynchronousCall = ETrue;
       
   229     TSSMailSyncState syncstatus = iIPSMailbox->CurrentSyncState();
       
   230     iIPSMailbox->GoOfflineL();
       
   231     syncstatus = iIPSMailbox->CurrentSyncState();
       
   232     err = WaitForEvent(TFSEventMailboxOffline, NULL, NULL, KOneMinuteTime);
       
   233     syncstatus = iIPSMailbox->CurrentSyncState();
       
   234     //check status of current mailbox again
       
   235     status = iIPSMailbox->GetMailBoxStatus();
       
   236 
       
   237     if (status == EFSMailBoxOffline)
       
   238         {
       
   239         iLog->Log(_L("Success: mailbox offline"));
       
   240         }
       
   241     else
       
   242         {
       
   243         err = KErrGeneral;
       
   244         iLog->Log(_L("Failed: mailbox status- %S"), &statusDes);
       
   245         }
       
   246 
       
   247     iLog->Log(_L( "GoOffline ends err=%d" ), err);
       
   248     return err;
       
   249     }
       
   250 // -----------------------------------------------------------------------------
       
   251 // CPopImapProfileTester:: RefreshNowL
       
   252 // Method used to let phone refresh
       
   253 // -----------------------------------------------------------------------------
       
   254 //
       
   255 TInt CPopImapProfileTester::RefreshNowL(CStifItemParser& /* aItem */)
       
   256     {
       
   257     TInt err(KErrNone);
       
   258     if (NULL == iIPSMailbox)
       
   259         {
       
   260         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   261         return KErrGeneral;
       
   262         }
       
   263     iLog->Log(_L( "RefreshNow begins" ));
       
   264     TInt reqId = iIPSMailbox->RefreshNowL(*this);
       
   265     iLog->Log(_L("Request Id -> %d"), reqId);
       
   266     TSSMailSyncState syncstatus = iIPSMailbox->CurrentSyncState();
       
   267     if ((StartingSync == syncstatus) || (EmailSyncing == syncstatus))
       
   268         err = WaitForEvent(TFSEventMailboxOnline);
       
   269     else
       
   270         err = KErrGeneral;
       
   271     if (err == KErrNone)
       
   272         {
       
   273         WaitForResponse(TFSProgress::EFSStatus_RequestComplete, KOneMinuteTime*3);
       
   274         syncstatus = iIPSMailbox->CurrentSyncState();
       
   275         }
       
   276     iLog->Log(_L( "RefreshNow ends err=%d" ), err);
       
   277     return err;
       
   278     }
       
   279 // -----------------------------------------------------------------------------
       
   280 // CPopImapProfileTester:: CancelSyncL
       
   281 // Method used to cancle action of Sync.
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 TInt CPopImapProfileTester::CancelSyncL(CStifItemParser& /* aItem */)
       
   285     {
       
   286     TInt err(KErrNone);
       
   287     if (NULL == iIPSMailbox)
       
   288         {
       
   289         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   290         return KErrGeneral;
       
   291         }
       
   292     iLog->Log(_L( "CancelSync begins" ));
       
   293     iIPSMailbox->RefreshNowL(*this);
       
   294     err = WaitForEvent(TFSEventMailboxOnline);
       
   295     if (KErrNone == err)
       
   296         {
       
   297         iIPSMailbox->CancelSyncL();
       
   298         err = WaitForEvent(TFSEventMailboxOffline);
       
   299         TSSMailSyncState syncstatus = iIPSMailbox->CurrentSyncState();
       
   300         if ((err != KErrNone) || (Idle != syncstatus))
       
   301         	{
       
   302             err = KErrGeneral;
       
   303         	}
       
   304         }
       
   305     iLog->Log(_L( "CancelSync ends err=%d" ), err);
       
   306     return err;
       
   307     }
       
   308 // -----------------------------------------------------------------------------
       
   309 // CPopImapProfileTester::ListStandardFoldersL
       
   310 // Method used to list standard folders
       
   311 // -----------------------------------------------------------------------------
       
   312 //
       
   313 TInt CPopImapProfileTester::ListStandardFoldersL(CStifItemParser& /* aItem */)
       
   314     {
       
   315     if (NULL == iIPSMailbox)
       
   316         {
       
   317         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   318         return KErrGeneral;
       
   319         }
       
   320 
       
   321     TInt err(KErrNone);
       
   322     iLog->Log(_L( "ListStandardFolders begins" ));
       
   323 
       
   324     // list all root folders
       
   325     RPointerArray<CFSMailFolder> rootFolders;
       
   326     iIPSMailbox->ListFolders(TFSMailMsgId(), rootFolders);
       
   327 
       
   328     // how many root folders we have
       
   329     TInt rootFolderCount = rootFolders.Count();
       
   330 
       
   331     /* Standard folders are:
       
   332      * EFSInbox, EFSOutbox, EFSDraftsFolder, EFSSentFolder, EFSDeleted
       
   333      * IMAP/POP may not have 'EFSDeleted'? Four only?
       
   334      */
       
   335 
       
   336     // check if all standard folders are present among root folders
       
   337     TFSMailMsgId folderId = TFSMailMsgId();
       
   338     iLog->Log(_L("== List of Standard Folders == "));
       
   339     for (TInt i = 1; i < EFSDeleted; ++i)
       
   340         {
       
   341         folderId = iIPSMailbox->GetStandardFolderId((TFSFolderType) i);
       
   342         TBool folderPresent = EFalse;
       
   343         for (TInt ii = 0; ii < rootFolderCount; ++ii)
       
   344             {
       
   345             if (rootFolders[ii]->GetFolderId() == folderId)
       
   346                 {
       
   347                 iLog->Log(_L("   %S"), &rootFolders[ii]->GetFolderName());
       
   348                 folderPresent = ETrue;
       
   349                 break;
       
   350                 }
       
   351             }
       
   352         if (NULL == folderPresent)
       
   353             {
       
   354             iLog->Log(_L("  Error: folder of id %d is missing"), i);
       
   355             err = KErrNotFound;
       
   356             }
       
   357         }
       
   358     rootFolders.ResetAndDestroy();
       
   359 
       
   360     iLog->Log(_L( "ListStandardFolders ends err=%d" ), err);
       
   361     return err;
       
   362     }
       
   363 // -----------------------------------------------------------------------------
       
   364 // CPopImapProfileTester::ListFoldersL
       
   365 // Method used to list all folders
       
   366 // -----------------------------------------------------------------------------
       
   367 //
       
   368 TInt CPopImapProfileTester::ListFoldersL(CStifItemParser& aItem)
       
   369     {
       
   370     if (NULL == iIPSMailbox)
       
   371         {
       
   372         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   373         return KErrGeneral;
       
   374         }
       
   375     /**
       
   376      * 1. Check subfolders of given folder - use ListFolders(FSMailMsgId, RPointerArray<CFSMailFolder>&)
       
   377      * 2. List all folders and compare check cout of listed folders - use ListFolders()
       
   378      * 
       
   379      */
       
   380     TInt paramErr(KErrNone);
       
   381     TInt err(KErrNone);
       
   382     iLog->Log(_L( "ListFoldersL begins" ));
       
   383     iLog->Log(_L( "Mailbox's Id: %x"), iIPSMailbox->GetId().Id());
       
   384 
       
   385     RPointerArray<CFSMailFolder>& folders = iIPSMailbox->ListFolders();
       
   386     //.. 
       
   387     // 1. subfolders check
       
   388     TPtrC parentFolderS, subfolderSetS, subfolderS;
       
   389 
       
   390     //get parent folder name  
       
   391     paramErr = aItem.GetString(_L("_parentFolder:"), parentFolderS);
       
   392     TFSMailMsgId parentFolderId = GetFolderIdFromName(parentFolderS);
       
   393 
       
   394     if (!parentFolderId.IsNullId())
       
   395         {
       
   396         iLog->Log(_L("Testing folder hierachy"));
       
   397         iLog->Log(_L("Parent folder found; id: %x"), parentFolderId.Id());
       
   398 
       
   399         RPointerArray<CFSMailFolder> subfolders;
       
   400         iIPSMailbox->ListFolders(parentFolderId, subfolders);
       
   401 
       
   402         TInt subfolderErr(KErrNone);
       
   403         //there should be at least one subfolder defined  
       
   404         paramErr &= aItem.GetString(_L("_subfolders:"), subfolderSetS);
       
   405 
       
   406         TInt idx(0);
       
   407         do
       
   408             {
       
   409             idx = subfolderSetS.Locate(',');
       
   410             if (idx > 0)
       
   411                 {
       
   412                 // extract next subfolder
       
   413                 subfolderS.Set(subfolderSetS.Left(idx));
       
   414                 // skip current subfolder
       
   415                 subfolderSetS.Set(subfolderSetS.Mid(idx + 1));
       
   416                 }
       
   417             else
       
   418                 {
       
   419                 subfolderS.Set(subfolderSetS);
       
   420                 }
       
   421 
       
   422             // check subfolder 
       
   423             subfolderErr = KErrNotFound;
       
   424             for (TInt i = 0; (i < folders.Count() && !paramErr); i++)
       
   425                 {
       
   426                 if (folders[i]->GetFolderName().Compare(subfolderS) == 0)
       
   427                     {
       
   428                     subfolderErr = KErrNone;
       
   429                     iLog->Log(
       
   430                             _L("Subfolder %S of parent folder %S found; id: %x"),
       
   431                             &(folders[i]->GetFolderName()), &parentFolderS,
       
   432                             folders[i]->GetFolderId().Id());
       
   433                     break;
       
   434                     }
       
   435                 }
       
   436 
       
   437             }
       
   438         while (!subfolderErr && idx >= 0);
       
   439 
       
   440         //set global err value - zeroes err if OK 
       
   441         err &= subfolderErr;
       
   442         subfolders.ResetAndDestroy();
       
   443         }//end if '!parentFolderId.IsNullId()'
       
   444 
       
   445     //parse params - we have to know what actualy we are testing
       
   446     TInt foldersCount(0);
       
   447     paramErr &= aItem.GetInt(_L("_expectedFoldersCount:"), foldersCount);
       
   448     //.. 
       
   449     // 2. total number of folders
       
   450     if (foldersCount > 0)
       
   451         {
       
   452         (folders.Count() == foldersCount) ? err = KErrNone : err = KErrGeneral;
       
   453         iLog->Log(_L("Actual folders count: %d vs. %d expected"),
       
   454                 folders.Count(), foldersCount);
       
   455         }
       
   456     //..
       
   457 
       
   458     if (paramErr != 0)
       
   459         {
       
   460         iLog->Log(_L("  Error: Invalid test case parameters!"));
       
   461         }
       
   462 
       
   463     iLog->Log(_L( "ListFolders ends err=%d" ), err);
       
   464     return err;
       
   465     }
       
   466 // -----------------------------------------------------------------------------
       
   467 // CPopImapProfileTester::ListMessagesL
       
   468 // Method used to list messages in a specific folder
       
   469 // -----------------------------------------------------------------------------
       
   470 //
       
   471 TInt CPopImapProfileTester::ListMessagesL(CStifItemParser& aItem)
       
   472     {
       
   473     if (NULL == iIPSMailbox)
       
   474         {
       
   475         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   476         return KErrGeneral;
       
   477         }
       
   478 
       
   479     TInt err(KErrNone);
       
   480     iLog->Log(_L( "ListMessagesL begins" ));
       
   481 
       
   482     // I. get test case params
       
   483     TPtrC folderName;
       
   484     TInt msgCount(0);
       
   485 
       
   486     // since folder name might consists of more than one word
       
   487     // lets use quote parsing for param
       
   488     aItem.SetParsingType(CStifItemParser::EQuoteStyleParsing);
       
   489     if (aItem.GetString(_L("_folder:"), folderName))
       
   490         {
       
   491         iLog->Log(_L("Error: test case argument is missing"));
       
   492         err = KErrArgument;
       
   493         }
       
   494     else
       
   495         {
       
   496         // II. Get folder of given name and list its emails
       
   497         CFSMailFolder* folder = FindFolder(folderName);
       
   498         if (NULL != folder)
       
   499             {
       
   500             RPointerArray<CFSMailMessage> messages;
       
   501             TInt gotMsgs = GetMessagesFromFolderL(messages, folder,
       
   502                     EFSMsgDataSubject, EFSMailSortByDate, msgCount);
       
   503             if (gotMsgs > 0)
       
   504                 {
       
   505                 iLog->Log(_L("  Listing first %d emails:"), gotMsgs);
       
   506                 }
       
   507             for (TInt i = 0; i < messages.Count(); ++i)
       
   508                 {
       
   509                 iLog->Log(_L("    %d. %S"), i + 1, &messages[i]->GetSubject());
       
   510                 }
       
   511             if (gotMsgs != messages.Count())
       
   512                 { // warning, NextL() returned fewer entries than expected
       
   513                 TInt diff = gotMsgs > messages.Count() ? gotMsgs
       
   514                         - messages.Count() : messages.Count() - gotMsgs;
       
   515                 iLog->Log(_L("Warning: %d entries are still not be listed."),
       
   516                         diff);
       
   517                 err = KErrNotFound;
       
   518                 }
       
   519             messages.ResetAndDestroy();
       
   520             }//end if 'folder'
       
   521         else
       
   522             {
       
   523             iLog->Log(_L("Error: %S folder not found"), &folderName);
       
   524             err = KErrNotFound;
       
   525             }
       
   526         }//end if 'folderName'
       
   527 
       
   528     iLog->Log(_L( "ListMessages ends err=%d" ), err);
       
   529     return err;
       
   530     }
       
   531 // -----------------------------------------------------------------------------
       
   532 // CPopImapProfileTester::FetchMessagesL
       
   533 // Method used to fetch messages in a specific folder
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 TInt CPopImapProfileTester::FetchMessagesL(CStifItemParser& aItem)
       
   537     {
       
   538     TInt err(KErrNone);
       
   539     if (NULL == iIPSMailbox)
       
   540         {
       
   541         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   542         return KErrGeneral;
       
   543         }
       
   544     iLog->Log(_L( "FetchMessages begins" ));
       
   545 
       
   546     /**
       
   547      * Params:
       
   548      * - folder name; Inbox if not provided 
       
   549      */
       
   550     TFSMailMsgId msgFolderId;
       
   551     TPtrC folderS;
       
   552 
       
   553     //get folder name  
       
   554     if (aItem.GetString(_L("_messageFolder:"), folderS) == KErrNone)
       
   555         {
       
   556         RPointerArray<CFSMailFolder>& folders = iIPSMailbox->ListFolders();
       
   557         // find and get folder id
       
   558         for (TInt i = 0; i < folders.Count(); i++)
       
   559             {
       
   560             if (folders[i]->GetFolderName().Compare(folderS) == 0)
       
   561                 {
       
   562                 msgFolderId = folders[i]->GetFolderId();
       
   563                 iLog->Log(_L("Message will be fetched from %S folder"),
       
   564                         &folderS);
       
   565                 break;
       
   566                 }
       
   567             }
       
   568         }
       
   569     if (msgFolderId.IsNullId())
       
   570         {
       
   571         iLog->Log(
       
   572                 _L("Proper message folder not provided, Inbox folder will be used instead"));
       
   573         msgFolderId = iIPSMailbox->GetStandardFolderId(EFSInbox);
       
   574         }
       
   575     CFSMailFolder* folder = NULL;
       
   576     // get message folder
       
   577     TRAPD(trapErr, folder = iMailClient->GetFolderByUidL(iIPSMailbox->GetId(),msgFolderId));
       
   578     CleanupStack::PushL(folder);
       
   579 
       
   580     if (KErrNone == trapErr)
       
   581         {
       
   582         //to get messages from folder
       
   583         RPointerArray<CFSMailMessage> allMessages;
       
   584         GetMessagesFromFolderL(allMessages, folder, EFSMsgDataIdOnly,
       
   585                 EFSMailSortByDate, folder->GetMessageCount());
       
   586 
       
   587         if (allMessages.Count() > 0)
       
   588             {
       
   589             RArray<TFSMailMsgId> messages;
       
   590             CleanupClosePushL(messages);
       
   591             messages.Append(allMessages[0]->GetMessageId());
       
   592 
       
   593             // not used in function
       
   594             TFSMailDetails ruleToFetch = EFSMsgDataEnvelope;
       
   595 
       
   596             TRAP(err,folder->FetchMessagesL(messages,ruleToFetch,*this));
       
   597             WaitForResponse(TFSProgress::EFSStatus_RequestComplete,
       
   598                     KOneMinuteTime);
       
   599             if (KErrNone == err)
       
   600                 {
       
   601                 iLog->Log(_L("Messages fetched successfuly"));
       
   602                 }
       
   603             else
       
   604                 {
       
   605                 iLog->Log(_L("Messages fetching failed"));
       
   606                 }
       
   607             CleanupStack::PopAndDestroy(&messages);
       
   608             }//end if 'allMessages'
       
   609         else
       
   610             {
       
   611             iLog->Log(_L("No message in %S folder"), &folder->GetFolderName());
       
   612             err = KErrNotFound;
       
   613             }
       
   614         allMessages.ResetAndDestroy();
       
   615         }//end 'trapErr'
       
   616     else
       
   617         {
       
   618         iLog->Log(_L("Message folder could not be created"));
       
   619         }
       
   620     CleanupStack::PopAndDestroy(folder);
       
   621 
       
   622     iLog->Log(_L( "FetchMessages ends err=%d" ), err);
       
   623     return err;
       
   624     }
       
   625 // -----------------------------------------------------------------------------
       
   626 // CPopImapProfileTester::SendMessagesL
       
   627 // Method used to send messages
       
   628 // -----------------------------------------------------------------------------
       
   629 //
       
   630 TInt CPopImapProfileTester::SendMessageL(CStifItemParser& /* aItem*/)
       
   631     {
       
   632     TInt err(KErrNone);
       
   633     TBuf<20> buf;
       
   634     if (NULL == iIPSMailbox)
       
   635         {
       
   636         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   637         return KErrNotFound;
       
   638         }
       
   639     iLog->Log(_L( "SendMessageL begins" ));
       
   640 
       
   641     // Step01: Create a message subject
       
   642     buf.Append(KStifEmailSubjectDes);
       
   643     buf.AppendNum(Math::Random());
       
   644     TPtrC subject = buf.Mid(0);
       
   645     iLog->Log(_L("Message is to be sent(Subject:%S)"), &subject);
       
   646 
       
   647     // Step02: Create default msg
       
   648     CFSMailMessage* newMsg = CreatePlainTextMsgL(subject, KStifEmailBodyText());
       
   649 
       
   650     //Step03: To send message and check it
       
   651     if (NULL != newMsg)
       
   652         {
       
   653         iLog->Log(_L("Tested message with subject '%S' was created"), &subject);
       
   654         CleanupStack::PushL(newMsg);
       
   655         TFSMailMsgId newMsgId = TFSMailMsgId();
       
   656         iLog->Log(_L("Message is to be sent..."));
       
   657         err = SendMsgL(*newMsg, subject, newMsgId); //sending message..
       
   658 
       
   659         if (KErrNone == err)
       
   660             iLog->Log(_L("Message was sent successfully"));
       
   661         else
       
   662             iLog->Log(_L("Failed to send message with error (ID:%d)"), err);
       
   663 
       
   664         CleanupStack::PopAndDestroy(newMsg);
       
   665         }
       
   666     else
       
   667         {
       
   668         iLog->Log(_L("Error: Tested message was NOT created"));
       
   669         err = KErrNoMemory;
       
   670         }
       
   671     iLog->Log(_L( "SendMessageL ends: %d" ), err);
       
   672     return err;
       
   673     }
       
   674 // -----------------------------------------------------------------------------
       
   675 // CPopImapProfileTester::BasicMsgOperationsL
       
   676 // Method used to test basic operations of messages
       
   677 // -----------------------------------------------------------------------------
       
   678 //
       
   679 TInt CPopImapProfileTester::BasicMsgOperationsL(CStifItemParser& /* aItem */)
       
   680     {
       
   681     TInt err(KErrNone);
       
   682     if (NULL == iIPSMailbox)
       
   683         {
       
   684         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   685         return KErrNotFound;
       
   686         }
       
   687 
       
   688     iLog->Log(_L( "BasicMsgOperationsL begins" ));
       
   689     // I. Prepare test message to send, using basic operations to set msg details
       
   690     CFSMailMessage* newMsg = CreatePlainTextMsgL(KStifEmailSubject,
       
   691             KStifEmailBodyText);
       
   692     CleanupStack::PushL(newMsg);
       
   693 
       
   694     // update msg details, add one more recipient in 'To' field (first is own mail address)
       
   695     CFSMailAddress* rec = CFSMailAddress::NewL();
       
   696     rec->SetEmailAddress(KStifEmailToRec1);
       
   697     newMsg->AppendToRecipient(rec);
       
   698 
       
   699     // add some recipients to 'Cc' filed
       
   700     rec = CFSMailAddress::NewL();
       
   701     rec->SetEmailAddress(KStifEmailCcRec1);
       
   702     newMsg->AppendCCRecipient(rec);
       
   703 
       
   704     rec = CFSMailAddress::NewL();
       
   705     rec->SetEmailAddress(KStifEmailCcRec2);
       
   706     newMsg->AppendCCRecipient(rec);
       
   707 
       
   708     // add one recipient in 'Bcc' filed
       
   709     rec = CFSMailAddress::NewL();
       
   710     rec->SetEmailAddress(KStifEmailBccRec1);
       
   711     newMsg->AppendBCCRecipient(rec);
       
   712     rec = NULL;
       
   713 
       
   714     // set low priority flag
       
   715     newMsg->SetFlag(EFSMsgFlag_Low);
       
   716 
       
   717     // save all changes
       
   718     newMsg->SaveMessageL();
       
   719 
       
   720     // II. Send test message
       
   721     TFSMailMsgId newMsgId = TFSMailMsgId();
       
   722     err = SendMsgL(*newMsg, KStifEmailSubject, newMsgId);
       
   723     CleanupStack::PopAndDestroy(newMsg);
       
   724     newMsg = NULL;
       
   725     TFSMailMsgId msgFolderId = iIPSMailbox->GetStandardFolderId(EFSInbox);
       
   726     CFSMailFolder* pFolder = NULL;
       
   727     // get message folder
       
   728     TRAPD(trapErr, pFolder = iMailClient->GetFolderByUidL(iIPSMailbox->GetId(),msgFolderId));
       
   729     CleanupStack::PushL(pFolder);
       
   730 
       
   731     if (KErrNone == trapErr)
       
   732         {
       
   733         TFSMailDetails dymmy = EFSMsgDataEnvelope;
       
   734         RArray<TFSMailMsgId> messages;
       
   735         CleanupClosePushL(messages);
       
   736         messages.Append(newMsgId);
       
   737         TRAP(err,pFolder->FetchMessagesL(messages,dymmy,*this));
       
   738         err = WaitForResponse(TFSProgress::EFSStatus_RequestComplete,
       
   739                 KOneMinuteTime);
       
   740         if (KErrNone == err)
       
   741             {
       
   742             iLog->Log(_L("Messages fetched successfuly"));
       
   743             }
       
   744         else
       
   745             {
       
   746             iLog->Log(_L("Messages fetching failed"));
       
   747             }
       
   748         CleanupStack::PopAndDestroy(&messages);
       
   749         }
       
   750     CleanupStack::PopAndDestroy(pFolder);
       
   751 
       
   752     // III. Check message details, using basic operations to read msg details
       
   753     if (KErrNone == err)
       
   754         {
       
   755         // Test message successfully received
       
   756         // pass null id, not used by BasePlugin anyway
       
   757         newMsg = iMailClient->GetMessageByUidL(iIPSMailbox->GetId(),
       
   758                 TFSMailMsgId(), newMsgId, EFSMsgDataEnvelope);
       
   759         if (NULL != newMsg)
       
   760             {
       
   761             CleanupStack::PushL(newMsg);
       
   762             iLog->Log(_L("   Checking message details:"));
       
   763 
       
   764             // check sender
       
   765             CFSMailAddress* sender = newMsg->GetSender();
       
   766             TPtrC senderAddr = sender->GetEmailAddress();
       
   767             if (senderAddr.Compare(
       
   768                     iIPSMailbox->OwnMailAddress().GetEmailAddress()))
       
   769                 {
       
   770                 iLog->Log(_L("   Error: Sender '%S' does not match"),
       
   771                         &senderAddr);
       
   772                 err = KErrGeneral;
       
   773                 }
       
   774 
       
   775             // check subject
       
   776             TPtrC subject = newMsg->GetSubject();
       
   777             if (subject.Compare(KStifEmailSubject()))
       
   778                 {
       
   779                 iLog->Log(_L("   Error: Subject '%S' does not match"), &subject);
       
   780                 err = KErrGeneral;
       
   781                 }
       
   782 
       
   783             // check To recipients
       
   784             RPointerArray<CFSMailAddress>& toRecipients =
       
   785                     newMsg->GetToRecipients();
       
   786             TInt toRec = toRecipients.Count();
       
   787             if (toRec != 2)
       
   788                 {
       
   789                 iLog->Log(_L("   Error: Got %d 'To' recipients, expected 2"),
       
   790                         toRec);
       
   791                 err = KErrGeneral;
       
   792                 }
       
   793             else
       
   794                 {
       
   795                 TPtrC recMail = toRecipients[0]->GetEmailAddress();
       
   796                 if (recMail.Compare(
       
   797                         iIPSMailbox->OwnMailAddress().GetEmailAddress()))
       
   798                     {
       
   799                     iLog->Log(_L("   Error: 1. 'To' recipient does not match"));
       
   800                     err = KErrGeneral;
       
   801                     }
       
   802                 recMail.Set(toRecipients[1]->GetEmailAddress());
       
   803                 if (recMail.Compare(KStifEmailToRec1))
       
   804                     {
       
   805                     iLog->Log(_L("   Error: 2. 'To' recipient does not match"));
       
   806                     err = KErrGeneral;
       
   807                     }
       
   808                 }
       
   809             toRecipients.ResetAndDestroy();
       
   810             // check Cc recipients
       
   811             RPointerArray<CFSMailAddress>& ccRecipients =
       
   812                     newMsg->GetCCRecipients();
       
   813             TInt ccRec = ccRecipients.Count();
       
   814             if (ccRec != 2)
       
   815                 {
       
   816                 iLog->Log(_L("   Error: Got %d 'Cc' recipients, expected 2"),
       
   817                         ccRec);
       
   818                 err = KErrGeneral;
       
   819                 }
       
   820             else
       
   821                 {
       
   822                 TPtrC recMail = ccRecipients[0]->GetEmailAddress();
       
   823                 if (recMail.Compare(KStifEmailCcRec1))
       
   824                     {
       
   825                     iLog->Log(_L("   Error: 1. 'Cc' recipient does not match"));
       
   826                     err = KErrGeneral;
       
   827                     }
       
   828                 recMail.Set(ccRecipients[1]->GetEmailAddress());
       
   829                 if (recMail.Compare(KStifEmailCcRec2))
       
   830                     {
       
   831                     iLog->Log(_L("   Error: 2. 'Cc' recipient does not match"));
       
   832                     err = KErrGeneral;
       
   833                     }
       
   834                 }
       
   835             ccRecipients.ResetAndDestroy();
       
   836             // check Bcc recipients, should be 0
       
   837             RPointerArray<CFSMailAddress>& bccRecipients =
       
   838                     newMsg->GetBCCRecipients();
       
   839             TInt bccRec = bccRecipients.Count();
       
   840             if (bccRec != 0)
       
   841                 {
       
   842                 iLog->Log(_L("   Error: Got %d 'Bcc' recipients, expected 0"),
       
   843                         bccRec);
       
   844                 err = KErrGeneral;
       
   845                 }
       
   846 
       
   847             // check priority
       
   848             if (!(newMsg->GetFlags() & EFSMsgFlag_Low))
       
   849                 {
       
   850                 iLog->Log(_L("   Error: Priority not set to low" ));
       
   851                 err = KErrGeneral;
       
   852                 }
       
   853 
       
   854             // check msg's mailboxId
       
   855             if (newMsg->GetMailBoxId() != iIPSMailbox->GetId())
       
   856                 {
       
   857                 iLog->Log(_L("  Error: Msg's mailboxId not correct"));
       
   858                 err = KErrGeneral;
       
   859                 }
       
   860 
       
   861             // check test msg's folderId
       
   862             if (newMsg->GetFolderId() != iIPSMailbox->GetStandardFolderId(
       
   863                     EFSInbox))
       
   864                 {
       
   865                 iLog->Log(_L("  Error: Msg's folderId not correct"));
       
   866                 err = KErrGeneral;
       
   867                 }
       
   868             if (!err)
       
   869                 {
       
   870                 iLog->Log(_L("   Message details all ok"));
       
   871                 }
       
   872             bccRecipients.ResetAndDestroy();
       
   873             CleanupStack::PopAndDestroy(newMsg);
       
   874             }
       
   875         }
       
   876     else
       
   877         {
       
   878         // some problems with sending or receiving came up
       
   879         iLog->Log(_L("  Error: Sending/Receiving failed"));
       
   880         }
       
   881 
       
   882     iLog->Log(_L( "BasicMsgOperationsL ends: %d" ), err);
       
   883     return err;
       
   884     }
       
   885 // -----------------------------------------------------------------------------
       
   886 // CPopImapProfileTester::CopyMoveMsgsL
       
   887 // Method used to copy and move messages from 'Inbox' to a specific folder
       
   888 // -----------------------------------------------------------------------------
       
   889 //
       
   890 TInt CPopImapProfileTester::CopyMoveMsgsL(CStifItemParser& /* aItem */)
       
   891     {
       
   892     if (NULL == iIPSMailbox)
       
   893         {
       
   894         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   895         return KErrNotFound;
       
   896         }
       
   897     iLog->Log(_L( "CopyMoveMsgs begins" ));
       
   898     TInt err(KErrNone);
       
   899     TInt errMove(KErrNone);
       
   900 
       
   901     if (iPluginId.PluginId() == TUid::Uid(KIPSSosPop3PluginUid))
       
   902         {
       
   903         //POP plugin not support Move And Copy message functionality.
       
   904         iLog->Log(
       
   905                 _L( "POP plugin not support Move And Copy message functionality." ));
       
   906         iLog->Log(_L( "CopyMoveMsgs ends err=%d(Move)" ), errMove);
       
   907         return err;
       
   908         }
       
   909 
       
   910     TFSMailMsgId newMsgId = TFSMailMsgId();
       
   911     TFSMailMsgId inboxFolderId = iIPSMailbox->GetStandardFolderId(EFSInbox);
       
   912     TFSMailMsgId draftsFolderId = iIPSMailbox->GetStandardFolderId(
       
   913             EFSDraftsFolder);
       
   914     TFSMailMsgId sentFolderId = iIPSMailbox->GetStandardFolderId(EFSSentFolder);
       
   915 
       
   916     CFSMailFolder* folder = iMailClient->GetFolderByUidL(iIPSMailbox->GetId(),
       
   917             inboxFolderId);
       
   918 
       
   919     if (NULL != folder)
       
   920         {
       
   921         CleanupStack::PushL(folder);
       
   922         RPointerArray<CFSMailMessage> messages;
       
   923         TInt msgCount(0);
       
   924         TInt gotMsgs = GetMessagesFromFolderL(messages, folder,
       
   925                 EFSMsgDataSubject, EFSMailSortByDate, msgCount);
       
   926         RArray<TFSMailMsgId> originalArray;
       
   927         CleanupClosePushL(originalArray);
       
   928         /*
       
   929          * CIpsPlgSosBasePlugin::CopyMessagesL() is empty.
       
   930          * So, it can't test this function
       
   931          */
       
   932         //Moving tested messages from 'Inbox' to 'Sent Items'
       
   933         if (gotMsgs > 0)
       
   934             {
       
   935             iLog->Log(_L("  Listing %d messages:"), gotMsgs);
       
   936             for (TInt i = 0; i < messages.Count(); i++)
       
   937                 {
       
   938                 iLog->Log(_L("%d.ID:,Subject: %S"), i + 1,
       
   939                         &messages[i]->GetSubject());
       
   940                 originalArray.Append(messages[i]->GetMessageId());
       
   941                 }//end loop: 'for'
       
   942             // Note: Messages cannot be moved from Deleted Items, Drafts, Outbox folders
       
   943 
       
   944             //Different between 'IMAP' and  'POP'
       
   945             iLog->Log(_L("IMAP: Moving from 'Inbox' to 'Sent'..."));
       
   946             iIPSMailbox->MoveMessagesL(originalArray, inboxFolderId,
       
   947                     sentFolderId);
       
   948             originalArray.Reset();
       
   949 
       
   950             // there is no TFSEventMailMoved or TFSEventMailCopied event coming, just TFSEventMailDeleted?
       
   951             errMove = WaitForEvent(TFSEventMailDeleted);
       
   952             }// end of 'gotMsgs > 0'
       
   953         else
       
   954             {
       
   955             iLog->Log(_L("No message in %S folder"), &folder->GetFolderName());
       
   956             errMove = KErrNotFound;
       
   957             }
       
   958         if (KErrNone == errMove)
       
   959             {
       
   960             iLog->Log(_L("Successfully move messages."));
       
   961             }
       
   962         else
       
   963             {
       
   964             iLog->Log(_L("Failed to move with error(ID:%d)"), errMove);
       
   965             err = errMove;
       
   966             }
       
   967         CleanupStack::PopAndDestroy(&originalArray);
       
   968         messages.ResetAndDestroy();
       
   969         CleanupStack::PopAndDestroy(folder);
       
   970         }//end if: 'NULL!=Folder'
       
   971     else
       
   972         {
       
   973         iLog->Log(_L(" Folder is NOT found.(Error's ID:%d)"), err);
       
   974         }
       
   975     iLog->Log(_L( "CopyMoveMsgs ends err=%d(Move)" ), errMove);
       
   976     return err;
       
   977     }
       
   978 // -----------------------------------------------------------------------------
       
   979 // CPopImapProfileTester::SearchL
       
   980 // Method used to test searching functionality
       
   981 // -----------------------------------------------------------------------------
       
   982 //
       
   983 TInt CPopImapProfileTester::SearchL(CStifItemParser& /* aItem */)
       
   984     {
       
   985     if (NULL == iIPSMailbox)
       
   986         {
       
   987         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
   988         return KErrNotFound;
       
   989         }
       
   990 
       
   991     TInt err(KErrNone);
       
   992     iLog->Log(_L( "Search begins" ));
       
   993 
       
   994     // Step01: to prepare testing msg
       
   995     HBufC* bufSubject = HBufC::NewL(30);
       
   996     HBufC* bufBody = HBufC::NewL(128);
       
   997     TPtr subject = bufSubject->Des();
       
   998     TPtr body = bufBody->Des();
       
   999     subject.Append(KStifEmailSubjectDes);
       
  1000     body.Append(KStifEmailBodyText);
       
  1001 
       
  1002     TUint randomNum = Math::Random();
       
  1003     subject.AppendNum(randomNum);
       
  1004     body.Append(_L("-"));
       
  1005     body.AppendNum(randomNum);
       
  1006 
       
  1007     iLog->Log(_L("==Testing Email=="));
       
  1008     iLog->Log(_L("=Subject is:%S"), &subject);
       
  1009     iLog->Log(_L("=Body is:%S"), &body);
       
  1010 
       
  1011     // Step02: Send testing msg to own mail address
       
  1012     CFSMailMessage* newMsg = CreatePlainTextMsgL(subject, body);
       
  1013     if (NULL != newMsg)
       
  1014         {
       
  1015         CleanupStack::PushL(newMsg);
       
  1016         TFSMailMsgId newMsgId = TFSMailMsgId();
       
  1017         err = SendMsgL(*newMsg, subject, newMsgId);
       
  1018         if (KErrNone == err)
       
  1019             {
       
  1020             // Step03: to setup searchL params
       
  1021             TFSMailSortCriteria criteria;
       
  1022             criteria.iField = EFSMailSortByDate;
       
  1023             criteria.iOrder = EFSMailDescending;
       
  1024             RPointerArray<TDesC> searchStrings;
       
  1025             // Step04: to perform 'Subject' search
       
  1026             searchStrings.Append(bufSubject);
       
  1027             err = DoSearch(searchStrings, criteria, KOneMinuteTime);
       
  1028 
       
  1029             // Check results for subject Search
       
  1030             if (KErrNone == err && iSearchMatches > 0)
       
  1031                 {
       
  1032                 iLog->Log(_L("Success: Subject search passed"));
       
  1033                 }
       
  1034             else
       
  1035                 {
       
  1036                 iLog->Log(_L("Failed: 'Subject' search with error(%d)"), err);
       
  1037                 err = KErrNotFound;
       
  1038                 }
       
  1039 
       
  1040             // Step05: to perform 'Body' search
       
  1041             searchStrings.ResetAndDestroy();
       
  1042             searchStrings.Append(bufBody);
       
  1043 
       
  1044             //Check results for body Search
       
  1045             err = DoSearch(searchStrings, criteria, KOneMinuteTime);
       
  1046             if (KErrNone == err && iSearchMatches > 0)
       
  1047                 {
       
  1048                 iLog->Log(_L("Success:Body search passed"));
       
  1049                 }
       
  1050             else
       
  1051                 {
       
  1052                 iLog->Log(_L("Failed to 'Body' search with error(%d)"), err);
       
  1053                 err = KErrNotFound;
       
  1054                 }
       
  1055             searchStrings.ResetAndDestroy();
       
  1056             }//end if 'KErrNone == err'(sent 'msg' with KErrNone)
       
  1057         else
       
  1058             {
       
  1059             iLog->Log(_L(" Failed to sent message with error(ID:%d)"), err);
       
  1060             }
       
  1061         CleanupStack::PopAndDestroy(newMsg);
       
  1062         }//end if 'NULL != newMsg'
       
  1063     else
       
  1064         {
       
  1065         iLog->Log(_L("Error: tested message was NOT created"));
       
  1066         err = KErrGeneral;
       
  1067         }
       
  1068     iLog->Log(_L( "Search ends err=%d" ), err);
       
  1069     return err;
       
  1070     }
       
  1071 // -----------------------------------------------------------------------------
       
  1072 // CPopImapProfileTester::AttachmentHandlingL
       
  1073 // Method used to test functionality of hanlding attachments
       
  1074 // -----------------------------------------------------------------------------
       
  1075 //
       
  1076 TInt CPopImapProfileTester::AttachmentHandlingL(CStifItemParser& /* aItem */)
       
  1077     {
       
  1078     TInt err(KErrNone);
       
  1079     if (NULL == iIPSMailbox)
       
  1080         {
       
  1081         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
  1082         return KErrNotFound;
       
  1083         }
       
  1084 
       
  1085     iLog->Log(_L( "AttachmentHandlingL begins" ));
       
  1086 
       
  1087     // Create default msg in 'Drafts' folder
       
  1088     CFSMailMessage* newMsg = CreatePlainTextMsgL(KStifEmailSubjectAttHandling,
       
  1089             KStifEmailBodyText);
       
  1090 
       
  1091     if (NULL != newMsg)
       
  1092         {
       
  1093         CleanupStack::PushL(newMsg);
       
  1094         iLog->Log(_L("Test Email created"));
       
  1095         TFSMailMsgId dummyId = TFSMailMsgId();
       
  1096 
       
  1097         //add attachment
       
  1098         TFSMailMsgId aInsertBefore;
       
  1099         CFSMailMessagePart* msgPart = NULL;
       
  1100         TRAP(err,msgPart = newMsg->AddNewAttachmentL(KPopImapProfileTester,aInsertBefore));
       
  1101         CleanupStack::PushL(msgPart);
       
  1102 
       
  1103         if (KErrNone != err)
       
  1104             {
       
  1105             iLog->Log(_L("Adding attachment failed. Error: %d"), err);
       
  1106             }
       
  1107         else
       
  1108             {
       
  1109             iLog->Log(_L("New attachment added."));
       
  1110             newMsg->SaveMessageL();
       
  1111 
       
  1112             //check if attachment was added
       
  1113             RPointerArray<CFSMailMessagePart> attParts;
       
  1114             TRAP( err,newMsg->AttachmentListL(attParts) );
       
  1115 
       
  1116             if (KErrNone != err)
       
  1117                 {
       
  1118                 iLog->Log(_L("Unable to take attachment list. Error %d"), err);
       
  1119                 }
       
  1120             else
       
  1121                 {
       
  1122                 if (attParts.Count() > 0)
       
  1123                     {
       
  1124                     TPtrC filename(KPopImapProfileTester);
       
  1125                     filename.Set(filename.Mid(filename.LocateReverse('\\') + 1));
       
  1126                     err = attParts[0]->AttachmentNameL().Compare(filename);
       
  1127                     iLog->Log(
       
  1128                             _L("Attachment's names comparison: %S (attached file name) vs.  %S (expected). Result: %d"),
       
  1129                             &(attParts[0]->AttachmentNameL()), &filename, err);
       
  1130                     }
       
  1131                 }//end if 'KErrNone!=err'
       
  1132             attParts.ResetAndDestroy();
       
  1133             }//end if 'KErrNone!=err'
       
  1134         CleanupStack::PopAndDestroy(msgPart);
       
  1135         CleanupStack::PopAndDestroy(newMsg);
       
  1136         }//end if 'newMsg'
       
  1137     else
       
  1138         {
       
  1139         iLog->Log(_L("Error: Test Email not created"));
       
  1140         err = KErrNoMemory;
       
  1141         }
       
  1142 
       
  1143     iLog->Log(_L( "AttachmentHandlingL ends: %d" ), err);
       
  1144     return err;
       
  1145     }
       
  1146 // -----------------------------------------------------------------------------
       
  1147 // CPopImapProfileTester::BrandingL
       
  1148 // Method used to test functionality of branding
       
  1149 // -----------------------------------------------------------------------------
       
  1150 //
       
  1151 TInt CPopImapProfileTester::BrandingL(CStifItemParser& aItem)
       
  1152     {
       
  1153     TInt err(KErrNone);
       
  1154     if (NULL == iIPSMailbox)
       
  1155         {
       
  1156         iLog->Log(_L("Error: IMAP/POP profile does NOT exist"));
       
  1157         return KErrNotFound;
       
  1158         }
       
  1159 
       
  1160     iLog->Log(_L( "== Branding begins ==" ));
       
  1161 
       
  1162     // get brand manager
       
  1163     MFSMailBrandManager* brandManager = NULL;
       
  1164 
       
  1165     TRAP( err, brandManager = &iMailClient->GetBrandManagerL() );
       
  1166 
       
  1167     //to check brand manager
       
  1168     if (KErrNone != err)
       
  1169         {
       
  1170         iLog->Log(
       
  1171                 _L("Error: CFSMailClient::GetBrandManagerL() leaved with %d"),
       
  1172                 err);
       
  1173         }
       
  1174     else if (NULL == brandManager)
       
  1175         {
       
  1176         iLog->Log(_L("Error: CFSMailClient::GetBrandManagerL() returns NULL"));
       
  1177         err = KErrGeneral;
       
  1178         }
       
  1179     else
       
  1180         {
       
  1181         // test updating mailbox names with real mailbox id
       
  1182         TRAP( err, brandManager->UpdateMailboxNamesL( iIPSMailbox->GetId() ) );
       
  1183         if (KErrNone != err)
       
  1184             {
       
  1185             iLog->Log(
       
  1186                     _L("Error: MFSMailBrandManager::UpdateMailboxNamesL() leaved with %d"),
       
  1187                     err);
       
  1188             }
       
  1189         else
       
  1190             {
       
  1191             // get param regarding expected branding status 
       
  1192             TBool brand = EFalse;
       
  1193             TPtrC expectBrandS;
       
  1194             aItem.GetString(_L("_isBranded:"), expectBrandS);
       
  1195 
       
  1196             if (expectBrandS.Compare(_L("true")) == 0)
       
  1197                 {
       
  1198                 iLog->Log(_L("Branding expected..."));
       
  1199                 brand = ETrue;
       
  1200                 }
       
  1201             else
       
  1202                 {
       
  1203                 iLog->Log(_L("Branding not expected..."));
       
  1204                 }
       
  1205 
       
  1206             // check mailbox name branding
       
  1207             TPtrC textBrand;
       
  1208             TRAP( err, textBrand.Set( brandManager->GetTextL( EFSMailboxName, iIPSMailbox->GetId() ) ) );
       
  1209             if (KErrNone != err)
       
  1210                 {
       
  1211                 iLog->Log(
       
  1212                         _L("Error: MFSMailBrandManager::GetTextL() leaved with %d"),
       
  1213                         err);
       
  1214                 }
       
  1215             TBool textBranded = textBrand.Length() != 0 ? ETrue : EFalse;
       
  1216             if (textBranded)
       
  1217                 {
       
  1218                 iLog->Log(_L("Mailbox's name (%S) branded."), &textBrand);
       
  1219                 }
       
  1220             else
       
  1221                 {
       
  1222                 iLog->Log(_L("Mailbox's name (%S) was not branded."),
       
  1223                         &textBrand);
       
  1224                 }
       
  1225             //to check whether it is expected?
       
  1226             if (brand == textBranded)
       
  1227                 {
       
  1228                 iLog->Log(_L("Successfully test, it was a expected retult."));
       
  1229                 err = KErrNone;
       
  1230                 }
       
  1231             else
       
  1232                 {
       
  1233                 iLog->Log(_L("Failed to test, it was NOT a expected retult."));
       
  1234                 err = KErrGeneral;
       
  1235                 }
       
  1236             } // end if 'UpdateMailboxNames'
       
  1237         } //end if 'BrandManager'
       
  1238 
       
  1239     iLog->Log(_L( "Branding ends ret=%d" ), err);
       
  1240     return err;
       
  1241     }
       
  1242 // -----------------------------------------------------------------------------
       
  1243 // CPopImapProfileTester::DeleteMsgsL
       
  1244 // Method used to delete messages
       
  1245 // -----------------------------------------------------------------------------
       
  1246 //
       
  1247 TInt CPopImapProfileTester::DeleteMsgsL(CStifItemParser& aItem)
       
  1248     {
       
  1249     TInt err(KErrNone);
       
  1250     iLog->Log(_L( "DeleteMessagesL begins" ));
       
  1251 
       
  1252     // Step 01: To refresh mailbox
       
  1253     iLog->Log(_L(" Step 01: To synchronize mailbox"));
       
  1254     TInt reqId = iIPSMailbox->RefreshNowL(*this);
       
  1255     err = WaitForEvent(TFSEventMailboxOnline);
       
  1256     WaitForResponse(TFSProgress::EFSStatus_RequestComplete, KOneMinuteTime);
       
  1257     if (KErrNone == err)
       
  1258         {
       
  1259         // Step 02: To delete tested messages
       
  1260         iLog->Log(_L(" Step 02: To delete tested messages"));
       
  1261         TPtrC folderName;
       
  1262         // We intended to delete messages in a folder only. Here, it is 'Inbox' folder. 
       
  1263         aItem.SetParsingType(CStifItemParser::EQuoteStyleParsing);
       
  1264         if (aItem.GetString(_L("_folder:"), folderName))
       
  1265             {
       
  1266             iLog->Log(_L("Error: test case argument is missing"));
       
  1267             err = KErrArgument;
       
  1268             }
       
  1269         else
       
  1270             err = DeleteTestMsgL(folderName);
       
  1271 
       
  1272         if (KErrNone == err)
       
  1273             {
       
  1274             //Step 03: To check whether tested messages were sucessfully deleted
       
  1275             iLog->Log(_L(" Step 03: To tested if messages really deleted"));
       
  1276             err = DeleteTestMsgL(folderName);
       
  1277 
       
  1278             if (err == KErrNotFound)
       
  1279                 {
       
  1280                 iLog->Log(_L("Succesfully deleted tested messages"));
       
  1281                 err = KErrNone;
       
  1282                 }
       
  1283             else
       
  1284                 {
       
  1285                 iLog->Log(_L("Failed to delete tested messages"));
       
  1286                 err = KErrGeneral;
       
  1287                 }
       
  1288             }//end if 'KErrNone == err'
       
  1289         else
       
  1290             {
       
  1291             iLog->Log(_L(" Warning: No tested messages to delete"));
       
  1292             }
       
  1293         }//end outer if
       
  1294     else
       
  1295         {
       
  1296         iLog->Log(_L(" Warning: synchronize mailbox failed!"));
       
  1297         err = KErrGeneral;
       
  1298         }
       
  1299     iLog->Log(_L( "DeleteMessagesL ends: %d" ), err);
       
  1300     return err;
       
  1301     }
       
  1302 // -----------------------------------------------------------------------------
       
  1303 // CPopImapProfileTester::RemoveAccountL
       
  1304 // Method used to remove an imap or pop account
       
  1305 // -----------------------------------------------------------------------------
       
  1306 //
       
  1307 TInt CPopImapProfileTester::RemoveAccountL(CStifItemParser& /* aItem */)
       
  1308     {
       
  1309     iLog->Log(_L( "RemoveAccount begins" ));
       
  1310     TInt err(KErrNone);
       
  1311     if (NULL == iIPSMailbox)
       
  1312         {
       
  1313         iLog->Log(_L( " Error: IMAP/POP profile does NOT exist" ));
       
  1314         err = KErrNotFound;
       
  1315         }
       
  1316     else
       
  1317         {
       
  1318         iLog->Log(_L( "Mailbox Id: %x"), iIPSMailbox->GetId().Id());
       
  1319         // start test case
       
  1320         TInt reqId = iMailClient->DeleteMailBoxByUidL(iIPSMailbox->GetId(),
       
  1321                 *this);
       
  1322         // end test case
       
  1323         iLog->Log(_L("-->ReqResp: %d"), reqId);
       
  1324 
       
  1325         // Check if mailbox is really deleted
       
  1326         RPointerArray<CFSMailBox> mailboxes;
       
  1327         iMailClient->ListMailBoxes(iIPSMailbox->GetId(), mailboxes);
       
  1328         if (mailboxes.Count() > 0)
       
  1329             {
       
  1330             iLog->Log(_L( " Failed: Mailbox was not deleted" ));
       
  1331             err = KErrGeneral;
       
  1332             }
       
  1333         else
       
  1334             {
       
  1335             iLog->Log(_L( " Success: Mailbox was deleted" ));
       
  1336             iMailClient->UnsubscribeMailboxEvents(iIPSMailbox->GetId(), *this);
       
  1337             DELANDNULL(iIPSMailbox);
       
  1338             err = KErrNone;
       
  1339             }
       
  1340         mailboxes.ResetAndDestroy();
       
  1341         }//end if 'count'
       
  1342 
       
  1343     iLog->Log(_L( "RemoveAccount ends err=%d" ), err);
       
  1344     return err;
       
  1345     }
       
  1346 
       
  1347 //  End of File