email/email/pop/src/t_verifyheaders.cpp
branchSymbian3
changeset 18 147b85a37c23
equal deleted inserted replaced
17:e3e31170f643 18:147b85a37c23
       
     1 // Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description: Verify email header
       
    14 
       
    15 // @file
       
    16 
       
    17 //
       
    18 //
       
    19 // [TestStep Name]
       
    20 // VerifyHeaders
       
    21 //
       
    22 // [Paramaters]
       
    23 // PopAccountName			:		Name of the Pop account
       
    24 // ToAddress%d%d			: 		Name of To Address with
       
    25 //									First %d for multiple message entries
       
    26 //									Seconde %d for multiple email addresses
       
    27 // CcAddress%d%d			:		Name of Cc Address with
       
    28 //									First %d for multiple message entries
       
    29 //									Seconde %d for multiple email addresses
       
    30 // BccAddress%d%d			:		Name of Bcc Address with
       
    31 //									First %d for multiple message entries
       
    32 //									Seconde %d for multiple email addresses
       
    33 // FromAddress%d			:		Name of From Address with
       
    34 //									First %d for multiple message entries
       
    35 // Subject%d				:		Name of Subject with
       
    36 //									First %d for multiple message entries
       
    37 // ContentType%d			:		Name of ContentType with
       
    38 //									First %d for multiple message entries
       
    39 // ContentSubType%d			:		Name of ContentSubType with
       
    40 //									First %d for multiple message entries
       
    41 //
       
    42 // [Description]
       
    43 // Veriy the email messge header parts
       
    44 //
       
    45 // [APIs Used]
       
    46 // CMsvEntry::ReadStoreL
       
    47 // CImHeader::RestoreL
       
    48 //
       
    49 //
       
    50 
       
    51 // User includes
       
    52 #include "t_verifyheaders.h"
       
    53 
       
    54 // Epoc includes
       
    55 #include <t_utils.h>
       
    56 #include <t_utilscentralrepository.h>
       
    57 #include <miuthdr.h>
       
    58 
       
    59 // Literals used
       
    60 _LIT(KPopAccountName,"PopAccountName");
       
    61 _LIT(KToAddress,"ToAddress%d%d");
       
    62 _LIT(KCcAddress,"CcAddress%d%d");
       
    63 _LIT(KBccAddress,"BccAddress%d%d");
       
    64 _LIT(KFromAddress,"FromAddress%d");
       
    65 _LIT(KSubject,"Subject%d");
       
    66 
       
    67 _LIT(KContentType,"ContentType%d");
       
    68 _LIT(KContentSubType,"ContentSubType%d");
       
    69 
       
    70 /**
       
    71   Function 		: CT_MsgVerifyHeaders
       
    72   Description 	: Constructor
       
    73   @param 		:
       
    74   @return 		: N/A
       
    75 */
       
    76 CT_MsgVerifyHeaders::CT_MsgVerifyHeaders(CT_MsgSharedDataPop& aSharedDataPOP)
       
    77 :	CT_MsgSyncStepPOP(aSharedDataPOP)
       
    78 	{
       
    79 	SetTestStepName(KVerifyHeaders);
       
    80 	}
       
    81 
       
    82 /**
       
    83   Function    	: doTestStepL
       
    84   Description 	: Reads the POP account name and the expected header parts from the ini file.
       
    85 				  Obtains the header parts of the children entries under the given folder.
       
    86   @return     	: TVerdict - Test step result
       
    87 			      EPass, if the header part matches
       
    88 			      EFail, if the header part does not match
       
    89 */
       
    90 TVerdict CT_MsgVerifyHeaders::doTestStepL()
       
    91 	{
       
    92 	INFO_PRINTF1(_L("Test Step :VerifyHeaders for POP services "));
       
    93 	// Read the POP account name from the ini file
       
    94 	TPtrC	popAccountName;
       
    95 	if(!GetStringFromConfig(ConfigSection(), KPopAccountName, popAccountName))
       
    96 		{
       
    97 		ERR_PRINTF1(_L("POP account name is not specified"));
       
    98 		SetTestStepResult(EFail);
       
    99 		}
       
   100 	else
       
   101 		{
       
   102 		// Retrieving the POP service Id based on the account name read from ini
       
   103 		TMsvId popServiceId = CT_MsgUtilsCentralRepository::GetPopServiceIdL((TDes&) popAccountName);
       
   104 		if(popServiceId == KMsvNullIndexEntryId)
       
   105 			{
       
   106 			ERR_PRINTF1(_L("Invalid Pop account name specified"));
       
   107 			SetTestStepResult(EFail);
       
   108 			}
       
   109 		else
       
   110 			{
       
   111 			// Create a selection of the children entries under the given folder and verify the header parts
       
   112 			CMsvEntrySelection* selection = CT_MsgUtils::CreateChildrenSelectionL(iSharedDataPOP.iSession, popServiceId);
       
   113 			CleanupStack::PushL(selection);
       
   114 			// Verify the header parts
       
   115 			TBool status = VerifyImHeaderPartsL(selection);
       
   116 			if (status == EFail )
       
   117 				{
       
   118 				SetTestStepResult(EFail);
       
   119 				}
       
   120 			// Verify mime header parts
       
   121 			status = VerifyMimeHeaderPartsL(selection);
       
   122 			if (status == EFail )
       
   123 				{
       
   124 				SetTestStepResult(EFail);
       
   125 				}
       
   126 			CleanupStack::PopAndDestroy(selection);
       
   127 			}
       
   128 		}
       
   129 	return TestStepResult();
       
   130 	}
       
   131 TBool CT_MsgVerifyHeaders::VerifyImHeaderPartsL(CMsvEntrySelection* aEntrySelection)
       
   132 	{
       
   133 	TBool status = EPass;
       
   134 	for(int index = 0; index < aEntrySelection->Count(); ++index)
       
   135 		{
       
   136 		CMsvEntry* entry = iSharedDataPOP.iSession->GetEntryL(aEntrySelection->At(index));
       
   137 		CleanupStack::PushL(entry);
       
   138 		CMsvStore* store = entry->ReadStoreL();
       
   139 		CleanupStack::PushL(store);
       
   140 		CImHeader* header = CImHeader::NewLC();
       
   141 		// Retrieve the email message header part from the message store
       
   142 		header->RestoreL(*store);
       
   143 
       
   144 		// Validate the header fields
       
   145 		TBuf<256> param;
       
   146 
       
   147 		for(int indexTo = 0; indexTo < header->ToRecipients().Count(); ++indexTo)
       
   148 			{
       
   149 			TPtrC toAddress;
       
   150 			param.Format(KToAddress, index, indexTo);
       
   151 			if(GetStringFromConfig( ConfigSection(), param, toAddress))
       
   152 				{
       
   153 				TPtrC toAdd = header->ToRecipients()[indexTo];
       
   154 				if(toAddress.Compare(header->ToRecipients()[indexTo]))
       
   155 					{
       
   156 					ERR_PRINTF1(_L(" To Address is not matched"));
       
   157 					status = EFail;
       
   158 					}
       
   159 				}
       
   160 			}
       
   161 		for(int indexCc = 0; indexCc < header->CcRecipients().Count(); ++indexCc)
       
   162 			{
       
   163 			TPtrC ccAddress;
       
   164 			param.Format(KCcAddress, index, indexCc);
       
   165 			if(GetStringFromConfig( ConfigSection(), param, ccAddress))
       
   166 				{
       
   167 				TPtrC ccAdd = header->CcRecipients()[indexCc];
       
   168 				if(ccAddress.Compare(header->CcRecipients()[indexCc]))
       
   169 					{
       
   170 					ERR_PRINTF1(_L("CC Address is not matched"));
       
   171 					status = EFail;
       
   172 					}
       
   173 				}
       
   174 			}
       
   175 		for(int indexBcc = 0; indexBcc < header->BccRecipients().Count(); ++indexBcc)
       
   176 			{
       
   177 			TPtrC bccAddress;
       
   178 			param.Format(KBccAddress, index, indexBcc);
       
   179 			if(GetStringFromConfig( ConfigSection(), param, bccAddress))
       
   180 				{
       
   181 				TPtrC bccAdd = header->BccRecipients()[indexBcc];
       
   182 				if(bccAddress.Compare(header->BccRecipients()[indexBcc]))
       
   183 					{
       
   184 					ERR_PRINTF1(_L("BCC Address is not matched"));
       
   185 					status = EFail;
       
   186 					}
       
   187 				}
       
   188 			}
       
   189 		TPtrC fromAddress;
       
   190 		param.Format(KFromAddress, index);
       
   191 		if(GetStringFromConfig( ConfigSection(), param, fromAddress))
       
   192 			{
       
   193 			TPtrC fromAdd = header->From();
       
   194 			if(fromAddress.Compare(header->From()))
       
   195 				{
       
   196 				ERR_PRINTF1(_L("From Address is not matched"));
       
   197 				status = EFail;
       
   198 				}
       
   199 			}
       
   200 		TPtrC subject;
       
   201 		param.Format(KSubject, index);
       
   202 		if(GetStringFromConfig( ConfigSection(), param, subject))
       
   203 			{
       
   204 			TPtrC tsub = header->Subject();
       
   205 			if(subject.Compare(header->Subject()))
       
   206 				{
       
   207 				ERR_PRINTF1(_L("Subject is not matched"));
       
   208 				status = EFail;
       
   209 				}
       
   210 			}
       
   211 		CleanupStack::PopAndDestroy(header);
       
   212 		CleanupStack::PopAndDestroy(store);
       
   213 		CleanupStack::PopAndDestroy(entry);
       
   214 		}
       
   215 	return status;
       
   216 	}
       
   217 TBool CT_MsgVerifyHeaders::VerifyMimeHeaderPartsL(CMsvEntrySelection* aEntrySelection)
       
   218 	{
       
   219 	TBool status = EPass;
       
   220 	for(int index = 0; index < aEntrySelection->Count(); ++index)
       
   221 		{
       
   222 		CMsvEntry* entry = iSharedDataPOP.iSession->GetEntryL(aEntrySelection->At(index));
       
   223 		CleanupStack::PushL(entry);
       
   224 		CMsvStore* store = entry->ReadStoreL();
       
   225 		CleanupStack::PushL(store);
       
   226 		if (store->IsPresentL(KUidMsgFileMimeHeader))
       
   227 			{
       
   228 			CImMimeHeader* mimeHeader = CImMimeHeader::NewLC();
       
   229 			mimeHeader->RestoreL(*store);
       
   230 	
       
   231 			TBuf<256> param;
       
   232 			TPtrC contentType;
       
   233 			param.Format(KContentType, index);
       
   234 			if(GetStringFromConfig( ConfigSection(), param, contentType))
       
   235 				{
       
   236 				TPtrC8 content8 = mimeHeader->ContentType();
       
   237 				HBufC* content16 = HBufC::NewLC(content8.Length());
       
   238 				content16->Des().Copy(content8);
       
   239 				if(contentType.Compare(content16->Des()))
       
   240 					{
       
   241 					ERR_PRINTF1(_L("Content Type is not matched"));
       
   242 					status = EFail;
       
   243 					}
       
   244 				CleanupStack::PopAndDestroy(content16);
       
   245 				}
       
   246 			TPtrC contentSubType;
       
   247 			param.Format(KContentSubType, index);
       
   248 			if(GetStringFromConfig( ConfigSection(), param, contentSubType))
       
   249 				{
       
   250 				TPtrC8 content8 = mimeHeader->ContentSubType();
       
   251 				HBufC* content16 = HBufC::NewLC(content8.Length());
       
   252 				content16->Des().Copy(content8);
       
   253 				if(contentSubType.Compare(content16->Des()))
       
   254 					{
       
   255 					ERR_PRINTF1(_L("Content Sub Type is not matched"));
       
   256 					status = EFail;
       
   257 					}
       
   258 				CleanupStack::PopAndDestroy(content16);
       
   259 				}
       
   260 			CleanupStack::PopAndDestroy(mimeHeader);
       
   261 			}
       
   262 		CleanupStack::PopAndDestroy(store);
       
   263 		CleanupStack::PopAndDestroy(entry);
       
   264 		}
       
   265 	return status;
       
   266 	}