// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
TInt CIpsPlgPop3ConnectOp::GetPopulateLimitFromSettingsL()
    {
    FUNC_LOG;
    TInt limit( KDefaultPopulateLimit );
        
    CImPop3Settings* settings = new(ELeave) CImPop3Settings();
    CleanupStack::PushL( settings );
    TPopAccount popAccountId;
    CEmailAccounts* accounts = CEmailAccounts::NewLC();
    accounts->GetPopAccountL( iService , popAccountId );
    accounts->LoadPopSettingsL( popAccountId, *settings );
    limit = settings->PopulationLimit();
    if ( limit > 0 )
        {
        // basically doing a _very_rough_ conversion from kilobyte value to number-of-rows
        limit = ( limit * KPopulateAlgorithmBytesInKilo ) / KPopulateAlgorithmRowLength;
        }
    CleanupStack::PopAndDestroy( 2, settings );
    return limit;
    }
void CPopsTestHarness::SetUpPopServiceL()
	{
	// Create the POP3 service and set the settings for this test.
	iPop3Service = iTestUtils->CreatePopServiceL();

	CImPop3Settings* settings = new(ELeave) CImPop3Settings();
	CleanupStack::PushL(settings);

	settings->Reset();
	_LIT(KPopServer, "pop3.demon.co.uk");
	settings->SetServerAddressL(KPopServer);
	settings->SetLoginNameL(iTestUtils->MachineName());
	settings->SetPasswordL(iTestUtils->MachineName());
	settings->SetPort(110);
	settings->SetDisconnectedUserMode(ETrue); // eh xxxx, must test this when set to EFalse

	CEmailAccounts* accounts = CEmailAccounts::NewLC();
 	TPopAccount popAccount;
 	accounts->GetPopAccountL(iPop3Service, popAccount);						
 	accounts->SavePopSettingsL(popAccount, *settings);
	CleanupStack::PopAndDestroy(2, settings); // accounts/store, settings

	test.Printf(_L("\nPerforming Tests\n"));
	}
Exemple #3
0
//
// Get all email services
//
void CEmailNotificationParser::GetEmailServicesL()
	{

	CCnvCharacterSetConverter* charconv = CCnvCharacterSetConverter::NewL();
	CleanupStack::PushL(charconv);
	CArrayFix<CCnvCharacterSetConverter::SCharacterSet> *charsetsAvailable = charconv->CreateArrayOfCharacterSetsAvailableL(iFs);
	CleanupStack::PushL(charsetsAvailable);

	charconv->PrepareToConvertToOrFromL(KUidCharsetISO88591,*charsetsAvailable,iFs);
	
	const TMsvId current = iEntry.Entry().Id();
	iEntry.SetEntryL(KMsvRootIndexEntryId);
	// Get all POP3 and Imap services
	CMsvEntrySelection* rootChildren = iEntry.ChildrenL();
	CleanupStack::PushL(rootChildren);

	TMsvEntry entry;

	CEmailAccounts* accounts = CEmailAccounts::NewLC();

	const TInt count = rootChildren->Count(); 
	TInt j =0;
	while(j < count && iFoundServer ==EFalse)
		{
		// set context to service entry
		iEntry.SetEntryL((*rootChildren)[j]);
		entry = iEntry.Entry(); 
		if (entry.iType == KUidMsvServiceEntry && (entry.iMtm == KUidMsgTypePOP3 || entry.iMtm == KUidMsgTypeIMAP4))
			{
			TBuf8<8> port;

			if(entry.iMtm == KUidMsgTypePOP3)
				{
				// calculate hash value
				CImPop3Settings* settings = new(ELeave)CImPop3Settings;
				CleanupStack::PushL(settings);
 
 				TPopAccount id;
				accounts->GetPopAccountL(entry.Id(), id);
				accounts->LoadPopSettingsL(id, *settings);

				port.Num((TUint)KPOP3DefaultPortNumber);
				iFoundServer = CalcHashValueL( *charconv, settings->LoginName(), settings->ServerAddress(), port);
				}
			else // entry.iMtm == KUidMsgTypeIMAP4
				{
				CImImap4Settings* settings = new(ELeave)CImImap4Settings;
				CleanupStack::PushL(settings);
				
 				TImapAccount id;
				accounts->GetImapAccountL(entry.Id(), id);
				accounts->LoadImapSettingsL(id, *settings);

				port.Num((TUint)KIMAPDefaultPortNumber);
				iFoundServer = CalcHashValueL( *charconv, settings->LoginName(), settings->ServerAddress(), port);
				}
			CleanupStack::PopAndDestroy(); // settings
			}
		j++;
		}

	if(	iFoundServer )
		iServiceMsvId = entry.Id();

	CleanupStack::PopAndDestroy(4, charconv); // charconv, charsetsAvailable, rootChildren, accounts
	
	iEntry.SetEntryL(current);
	}
LOCAL_C void doMainL()
	{
	Init();
	testUtils->FileSession().SetSessionPath(_L("c:\\"));

//	smtpService = testUtils->CreateSmtpServiceL();
	
	// Create the POP3 service and set the settings for this test.
	pop3Service = testUtils->CreatePopServiceL();

	CImPop3Settings* settings = new(ELeave) CImPop3Settings();
	CleanupStack::PushL(settings);
	settings->Reset();
	_LIT(KPopServer, "internet-test.plc.psion.com");
	settings->SetServerAddressL(KPopServer);
	settings->SetLoginNameL(testUtils->MachineName());
	settings->SetPasswordL(testUtils->MachineName());
	settings->SetPort(110);
	
 	// Saving POP settings
	CEmailAccounts* accounts = CEmailAccounts::NewLC();
 	TPopAccount popAccount;
 	accounts->GetPopAccountL(pop3Service, popAccount);						
 	accounts->SavePopSettingsL(popAccount, *settings);
	CleanupStack::PopAndDestroy(2, settings); // accounts/store, settings

	// Set the IAP to Demon (even though we're not going to dial up as such.)
	User::LeaveIfError(testUtils->iServerEntry->SetEntry(pop3Service));
	TMsvEntry entry = testUtils->iServerEntry->Entry();
	entry.SetMtmData1(3);
	User::LeaveIfError(testUtils->iServerEntry->ChangeEntry(entry));

	test.Printf(_L("\nPerforming Tests\n"));

	CTestActive* activeObjectTester = new (ELeave) CTestActive;
	CleanupStack::PushL(activeObjectTester);
	
	// Get server MTM.
	testUtils->InstantiatePopServerMtmL();
	CBaseServerMtm* pop3ServerMtm = testUtils->iPopServerMtm;

	// Get the POP3 server MTM to connect.
	log->AppendComment(_L8("Connect to POP3 server"));
	CMsvEntrySelection* serviceId = new (ELeave) CMsvEntrySelection;
	CleanupStack::PushL(serviceId);
	serviceId->AppendL(pop3Service);
	TBuf8<1> parameters;
	activeObjectTester->StartL();
	User::LeaveIfError(testUtils->iServerEntry->SetEntry(pop3Service));

	pop3ServerMtm->StartCommandL(*serviceId, KPOP3MTMConnect, parameters, activeObjectTester->iStatus);
	CActiveScheduler::Start();

	// Get the progress
	TPop3Progress prog;	
	TPckgC<TPop3Progress> paramPack(prog);
	paramPack.Set(pop3ServerMtm->Progress());
	TPop3Progress progress=paramPack();

	// Check that the reported progress is EPopConnecting
	test(progress.iPop3Progress == TPop3Progress::EPopConnecting);

	CleanupStack::PopAndDestroy(); // serviceId

	// Cleanup
	CleanupStack::PopAndDestroy(); // activeObjectTester

	Closedown();
	}
/**
ReadPopSettingsFromConfigurationFileL()
Modifies the POP related default setting and IAP objects.

@param  aSettingsFile
Configuration/setting file path. 

@param  aPopSet
CImPop3Settings object.

@param  aPopIapPref
*/
EXPORT_C void CT_MsgUtilsReadEmailSettingsFromConfigFile::ReadPopSettingsFromConfigurationFileL(TDesC& aSettingsFile, 
											CImPop3Settings& aPopSet, CImIAPPreferences& aPopIapPref, const TDesC& /*aPtrEmailAdd*/)
	{
	// Parses the setting file
	CT_MsgUtilsConfigFileParserUtility* scriptFileParser = CT_MsgUtilsConfigFileParserUtility::NewL(aSettingsFile);
	CleanupStack::PushL(scriptFileParser);	
	
	TPtrC8 string8Ptr; 
	TPtrC stringPtr = KNone(); 
	TInt intValue;

	if(scriptFileParser->GetFieldAsString(KCfgPopServerAddress, stringPtr) == KErrNone)
		{	
		aPopSet.SetServerAddressL(stringPtr);
		}

	CT_MsgUtilsConfigFileMachineName* machineNameFile = CT_MsgUtilsConfigFileMachineName::NewLC(stringPtr);
	TPtrC8 machineName(machineNameFile->MachineName());

	
	if(scriptFileParser->GetFieldAsString8(KCfgPopLoginName, string8Ptr) == KErrNone)
		{
		aPopSet.SetLoginNameL(string8Ptr);
		}

	else
		{
		aPopSet.SetLoginNameL(machineName);
		}
	
	if(scriptFileParser->GetFieldAsString8(KCfgPopPassword, string8Ptr) == KErrNone)
		{
		aPopSet.SetPasswordL(string8Ptr);
		}

	else
		{
		aPopSet.SetPasswordL(machineName);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgPopMaxEmailSize, intValue) == KErrNone)
		{
		aPopSet.SetMaxEmailSize(intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgPopPort, intValue) == KErrNone)
		{
		aPopSet.SetPort(intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgPopInboxSynchronisationLimit, intValue) == KErrNone)
		{
		aPopSet.SetInboxSynchronisationLimit(intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgPopSecureSockets, intValue) == KErrNone)
		{
		aPopSet.SetSecureSockets((TBool)intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgPopSSLWrapper, intValue) == KErrNone)
		{
		aPopSet.SetSSLWrapper((TBool)intValue);
		}
	
	if(scriptFileParser->GetFieldAsString(KCfgPopGetMailOptions, stringPtr) == KErrNone)
		{
		TPop3GetMailOptions options = CT_MsgUtilsEnumConverter::ConvertDesToTPop3GetMailOptions(stringPtr);
		aPopSet.SetGetMailOptions(options);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgPopPopulationLimit, intValue) == KErrNone)
		{
		aPopSet.SetPopulationLimitL(intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgPopAutoSendOnConnect, intValue) == KErrNone)
		{	
		aPopSet.SetAutoSendOnConnect((TBool) intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgPopDeleteEmailsWhenDisconnecting, intValue) == KErrNone)
		{	
		aPopSet.SetDeleteEmailsWhenDisconnecting((TBool) intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgPopAcknowledgeReceipts, intValue) == KErrNone)
		{	
		aPopSet.SetAcknowledgeReceipts((TBool) intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgPopDisconnectedUserMode, intValue) == KErrNone)
		{	
		aPopSet.SetDisconnectedUserMode((TBool) intValue);
		}
	
	if(scriptFileParser->GetFieldAsInteger(KCfgPopAPOPEncryption, intValue) == KErrNone)
		{	
		aPopSet.SetApop((TBool) intValue);
		}
		
	if(scriptFileParser->GetFieldAsString(KCfgPopIapList, stringPtr) == KErrNone)
		{
		ReadPopIAPAndAddL(scriptFileParser, (TDesC&) KCfgPopIapList, aPopIapPref);
		}
		
	if(scriptFileParser->GetFieldAsInteger(KCfgPopSNAPId, intValue) == KErrNone)
		{		
		aPopIapPref.SetSNAPL(intValue);
		}
		
	if(scriptFileParser->GetFieldAsInteger(KCfgPopBearerMobility, intValue) == KErrNone)
		{	
		aPopSet.SetBearerMobility((TBool) intValue);
		}
		
	CleanupStack::PopAndDestroy(2,scriptFileParser);
	}
void CPopsTestHarness::SetUpPopServiceL()
	{
	// Handle command line arguments
	CCommandLineArguments* cmdLineArg=CCommandLineArguments::NewLC();
	TInt count = cmdLineArg->Count();
	TBool isCmdLine=FALSE;
	if (count>2)	// Command line arguments?
		{
		if ((!(cmdLineArg->Arg(EArgTestParams).Compare(KTestParams))) && count==EArgEnd)
			isCmdLine=TRUE;
		}	

	// Create the POP3 service and set the settings for this test.
	iPop3Service = iTestUtils.CreatePopServiceL();
	CImPop3Settings* settings = new(ELeave) CImPop3Settings();
	CleanupStack::PushL(settings);
	settings->Reset();

	TBuf<100> buf;
	if (isCmdLine)
		{
		TLex lex(cmdLineArg->Arg(EArgServerAddress));
		buf=lex.NextToken();
		test.Printf(_L("Server address: %S\n"),&buf);
		}
	else
		{
		readConsoleLineBuf(_L("Server address: "),buf);
		}
	settings->SetServerAddressL(buf);
	buf.Zero();
	if (isCmdLine)
		{
		TLex lex(cmdLineArg->Arg(EArgLogin));
		buf=lex.NextToken();
		test.Printf(_L("Login: %S\n"),&buf);
		}
	else
		{
		readConsoleLineBuf(_L("login: "******"Password: %S\n"),&buf);
		}
	else
		{
		readConsoleLineBuf(_L("password: "******"Use APOP: %c\n"),choice);
		if (choice=='y' || choice=='Y')
			settings->SetApop(ETrue);
		else
			settings->SetApop(EFalse);
		}
	else
		{
		test.Printf(_L("\n Use APOP? Enter (Y/N): "));
		settings->SetApop(GetTrueOrFalse());
		}
	if (isCmdLine)
		{
		TLex lex(cmdLineArg->Arg(EArgUseSecureSockets));
		choice=lex.Get();
		test.Printf(_L("Use secure sockets: %c\n"),choice);
		if (choice=='y' || choice=='Y')
			settings->SetSecureSockets(ETrue);
		else
			settings->SetSecureSockets(EFalse);
		}
	else
		{
		test.Printf(_L("\n Use secure sockets? Enter (Y/N): "));
		settings->SetSecureSockets(GetTrueOrFalse());
		}
	
	// Add IAP's to iIAPPreferences
	TImIAPChoice iap;
	CImIAPPreferences* prefs = CImIAPPreferences::NewLC();	
	TInt iapId = 0;
	CMDBSession* iDBSession = CMDBSession::NewL(CMDBSession::LatestVersion());
	CCDConnectionPrefsRecord *connPrefRecord = static_cast<CCDConnectionPrefsRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdConnectionPrefsRecord));
	CleanupStack::PushL(connPrefRecord);
	connPrefRecord->iDirection = ECommDbConnectionDirectionOutgoing;
	if(!connPrefRecord->FindL(*iDBSession))
		{
		User::Leave(KErrNotFound);					
		}	
	iapId = iap.iIAP = connPrefRecord->iDefaultIAP;
	
	CleanupStack::PopAndDestroy(connPrefRecord);	
	delete iDBSession;
	iDBSession= NULL;

	iap.iDialogPref = ECommDbDialogPrefDoNotPrompt;
	prefs->AddIAPL(iap);
	iap.iIAP = iapId;
	iap.iDialogPref = ECommDbDialogPrefPrompt;
	prefs->AddIAPL(iap, 1);

	CEmailAccounts* accounts = CEmailAccounts::NewLC();
 	TPopAccount popAccount;
 	accounts->GetPopAccountL(iPop3Service, popAccount);						
 	accounts->SavePopSettingsL(popAccount, *settings);
	accounts->SavePopIapSettingsL(popAccount, *prefs);
	CleanupStack::PopAndDestroy(4, cmdLineArg); // (accounts,) prefs, settings, (store,) cmdLineArg
	test.Printf(_L("\nPerforming Tests\n"));
	}