email/pop3andsmtpmtm/imapservermtm/test/src/T_ImapBadlyFormedAddressClient.cpp
changeset 25 84d9eb65b26f
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
       
     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:
       
    14 // T_ImapBadlyFormedAddress.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include "T_ImapBadlyFormedAddressClient.h"
       
    19 
       
    20 #include <mtclbase.h>
       
    21 #include <mtclreg.h>
       
    22 #include <miutset.h>
       
    23 #include <imapset.h>
       
    24 #include <smtpset.h>
       
    25 #include <iapprefs.h>
       
    26 #include <imapcmds.h>
       
    27 
       
    28 _LIT(KLoopbackAddress,"127.0.0.1");
       
    29 
       
    30 void TDummySessionObserver::HandleSessionEventL(TMsvSessionEvent /*aEvent*/, TAny* /*aArg1*/, TAny* /*aArg2*/, TAny* /*aArg3*/)
       
    31 	{
       
    32 	}
       
    33 	
       
    34 CImapBadlyFormedAddressClient::CImapBadlyFormedAddressClient(MImapTestEventHandler* aOwner)
       
    35  : CActive(EPriorityStandard), iOwner(aOwner)
       
    36 	{
       
    37 	CActiveScheduler::Add(this);
       
    38 	}
       
    39 
       
    40 EXPORT_C CImapBadlyFormedAddressClient* CImapBadlyFormedAddressClient::NewL(MImapTestEventHandler* aOwner)
       
    41 	{
       
    42 	CImapBadlyFormedAddressClient* self = NewLC(aOwner);
       
    43 	CleanupStack::Pop(self);
       
    44 	return self;
       
    45 	}
       
    46 
       
    47 EXPORT_C CImapBadlyFormedAddressClient* CImapBadlyFormedAddressClient::NewLC(MImapTestEventHandler* aOwner)
       
    48 	{
       
    49 	CImapBadlyFormedAddressClient* self = new(ELeave) CImapBadlyFormedAddressClient(aOwner);
       
    50 	CleanupStack::PushL(self);
       
    51 	self->ConstructL();
       
    52 	return self;
       
    53 	}
       
    54 	
       
    55 CImapBadlyFormedAddressClient::~CImapBadlyFormedAddressClient()
       
    56 	{
       
    57 	Cancel();
       
    58 	delete iMsvOperation;	
       
    59 	delete iSelection;
       
    60 	delete iClientMtm;
       
    61 	delete iClientRegistry;	
       
    62 	delete iSession;
       
    63 	delete iSessionObserver;
       
    64 	delete iAccounts;
       
    65 	}
       
    66 	
       
    67 	
       
    68 void CImapBadlyFormedAddressClient::ConstructL()
       
    69 	{
       
    70 	// create an account
       
    71 	iAccounts = CEmailAccounts::NewL();	
       
    72 	CreateImapAccountL();
       
    73 	// Session observer. Needed to create a session
       
    74 	iSessionObserver = new (ELeave) TDummySessionObserver;
       
    75 	// Session. Needed to create a client registry.
       
    76 	iSession=CMsvSession::OpenSyncL(*iSessionObserver);
       
    77 	// Client registry. Needed to get the MTM component
       
    78 	iClientRegistry=CClientMtmRegistry::NewL(*iSession,KMsvDefaultTimeoutMicroSeconds32);
       
    79 	// get the client mtm
       
    80 	iClientMtm=iClientRegistry->NewMtmL(KUidMsgTypeIMAP4);	
       
    81 	
       
    82 	// Load the serial comms device drivers.  If this is not done,
       
    83 	// connecting via NT-RAS returns KErrNotFound (-1).
       
    84 	TInt driverErr;
       
    85 	driverErr=User::LoadPhysicalDevice(PDD_NAME);
       
    86 	if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists)
       
    87 		User::Leave(driverErr);
       
    88 	driverErr=User::LoadLogicalDevice(LDD_NAME);
       
    89 	if (driverErr!=KErrNone && driverErr!=KErrAlreadyExists)
       
    90 		User::Leave(driverErr);
       
    91 	}
       
    92 	
       
    93 TImapAccount CImapBadlyFormedAddressClient::GetImapAccount()
       
    94 	{
       
    95 	return iImapAccount;
       
    96 	}
       
    97 	
       
    98 void CImapBadlyFormedAddressClient::CreateImapAccountL()
       
    99 	{
       
   100 	// create objects and initialise with the defaults
       
   101 	CImImap4Settings* imap4Settings=new(ELeave)CImImap4Settings;
       
   102 	CleanupStack::PushL(imap4Settings);
       
   103 	CImSmtpSettings* smtpSettings=new(ELeave)CImSmtpSettings;
       
   104 	CleanupStack::PushL(smtpSettings);
       
   105 	CImIAPPreferences* imapIap = CImIAPPreferences::NewLC();
       
   106 	CImIAPPreferences* smtpIap = CImIAPPreferences::NewLC();
       
   107 	
       
   108 	iAccounts->PopulateDefaultImapSettingsL(*imap4Settings, *imapIap);
       
   109 	iAccounts->PopulateDefaultSmtpSettingsL(*smtpSettings, *smtpIap);
       
   110 	
       
   111 	// override some of the defaults
       
   112 	imap4Settings->SetPasswordL(_L8("roberth"));
       
   113 	imap4Settings->SetLoginNameL(_L8("roberth"));
       
   114 	imap4Settings->SetServerAddressL(KLoopbackAddress);
       
   115 	imap4Settings->SetFolderPathL(_L8(""));
       
   116 	imap4Settings->SetSynchronise(EUseLocal);
       
   117 	
       
   118 	// create the account
       
   119 	iImapAccount = iAccounts->CreateImapAccountL(_L("TestAccount"), *imap4Settings, *imapIap, EFalse);
       
   120 	TSmtpAccount smtpAccount;
       
   121 	smtpAccount = iAccounts->CreateSmtpAccountL(iImapAccount, *smtpSettings, *smtpIap, EFalse);
       
   122 
       
   123 	// clean up
       
   124 	CleanupStack::PopAndDestroy(smtpIap);
       
   125 	CleanupStack::PopAndDestroy(imapIap);	
       
   126 	CleanupStack::PopAndDestroy(smtpSettings);
       
   127 	CleanupStack::PopAndDestroy(imap4Settings); 
       
   128 	}
       
   129 
       
   130 void CImapBadlyFormedAddressClient::StartL()
       
   131 	{
       
   132 	// we are to collect the whole email: the next operation will be to fetch it
       
   133 	iNextStep = EDisconnect;
       
   134 	iSelection = new (ELeave) CMsvEntrySelection;
       
   135 	TPckg<MMsvImapConnectionObserver*> param(this);
       
   136 	// select the imap service entry
       
   137 	iSelection->AppendL(iImapAccount.iImapService);
       
   138 	// make the service entry the current context
       
   139 	iClientMtm->SwitchCurrentEntryL(iImapAccount.iImapService);
       
   140 	// sync the account
       
   141 	iMsvOperation = iClientMtm->InvokeAsyncFunctionL(KIMAP4MTMConnectAndSyncCompleteAfterFullSync,*iSelection,param,iStatus);
       
   142 	SetActive();
       
   143 	}
       
   144 
       
   145 void CImapBadlyFormedAddressClient::DoCancel()
       
   146 	{	
       
   147 	__ASSERT_DEBUG(iMsvOperation!=NULL, User::Panic(_L("CImapBadlyFormedAddressClient"), -3));
       
   148 	iMsvOperation->Cancel();
       
   149 	}
       
   150 
       
   151 void CImapBadlyFormedAddressClient::RunL()
       
   152 	{
       
   153 	TPckg<MMsvImapConnectionObserver*> param(this);
       
   154 	
       
   155 	switch(iNextStep)
       
   156 		{
       
   157 		case EDisconnect:
       
   158 			{
       
   159 			// We have finished, so do a disconnect
       
   160 			iNextStep=EComplete;
       
   161 			delete iMsvOperation;
       
   162 			iMsvOperation=NULL;
       
   163 			iMsvOperation = iClientMtm->InvokeAsyncFunctionL(KIMAP4MTMDisconnect,*iSelection,param,iStatus);
       
   164 			SetActive();
       
   165 			break;
       
   166 			}
       
   167 
       
   168 		case EComplete:
       
   169 			{
       
   170 			// inform the owning object that the process is complete
       
   171 			iOwner->TestComplete(KErrNone);
       
   172 			break;
       
   173 			}
       
   174 
       
   175 		default:
       
   176 			{
       
   177 			__ASSERT_DEBUG(0, User::Panic(_L("CImapBadlyFormedAddressClient unknown state"), KErrUnknown));
       
   178 			break;			
       
   179 			}
       
   180 		}
       
   181 	}
       
   182 	
       
   183 TInt CImapBadlyFormedAddressClient::RunError(TInt aError)
       
   184 	{
       
   185 	iOwner->TestComplete(aError);
       
   186 	return KErrNone;
       
   187 	}
       
   188 	
       
   189 void CImapBadlyFormedAddressClient::HandleImapConnectionEvent(TImapConnectionEvent /*aConnectionState*/)
       
   190 	{
       
   191 	// this method does nothing
       
   192 	}