email/pop3andsmtpmtm/smtpservermtm/src/IMSMSEND.H
changeset 0 72b543305e3a
child 76 60a8a215b0ec
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 1998-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 //
       
    15 
       
    16 #ifndef __IMSMSEND_H__
       
    17 #define __IMSMSEND_H__
       
    18 
       
    19 #ifndef __IMSK_H__
       
    20 #include <imsk.h>				// for KImMailMaxBufferSize
       
    21 #endif
       
    22 
       
    23 #include <cdbcols.h>
       
    24 #include "smtpauthhelpers.h"
       
    25 
       
    26 // forward declarations for CImSmtpFile
       
    27 class CImHeader;
       
    28 class CImSendMessage;
       
    29 class TImImailFileProgress;
       
    30 class CMsgImOutboxSend;
       
    31 class CImIAPPreferences;
       
    32 class CImConnect;
       
    33 class CImLogMessage;
       
    34 
       
    35 class CImSmtpFile : public CMsgActive
       
    36 	{
       
    37 public: 
       
    38 	static	CImSmtpFile* NewL(CImTextServerSession& aSession,
       
    39 	                          CMsvServerEntry& aServerEntry,
       
    40 	                          TTime& aTime,
       
    41 	                          TBuf8<KImMailMaxBufferSize>& aSmtpBuffer,
       
    42 	                          CSmtpSettings& aSmtpSettings,
       
    43 	                          TBool aIsBccRcpt);
       
    44 	~CImSmtpFile();
       
    45 
       
    46 	void StartL(TRequestStatus& aClientStatus);
       
    47 	void GetProgress(TImImailFileProgress& aFileProgress);		// return progress of sending current file
       
    48     void DoCancel();
       
    49 
       
    50 	TInt TotalMsgSizeL();
       
    51 	void SetBytesToSend(TInt aNumBytes);
       
    52 	TInt BytesToSend() const;
       
    53 
       
    54 protected:
       
    55     void DoRunL();
       
    56 
       
    57 private: 
       
    58 	CImSmtpFile(CImTextServerSession& aSocket,TBuf8<KImMailMaxBufferSize>& aSmtpBuffer,CMsvServerEntry &aServerEntry);  		// constructor
       
    59 	void ConstructL(TTime& aTimeNow,CSmtpSettings& aSettings,TBool aIsBccRcpt);
       
    60 	void GetHeaderFromStoreL(CMsvStore& aStore, CMsvServerEntry&, TTime&);
       
    61 	TBool NextRecipientL();					// returns pointer to next recipient address in header field
       
    62 	TInt SelectNextStateL();					// chooses next state to go to
       
    63 	void SendOneLineOfData();				// send 1 line of RFC822 message to remote server
       
    64 	TInt SmtpFilePositiveResponse(TInt);
       
    65 	void ChangeStateL();						// initiates the next state operation
       
    66 	TInt SmtpFileError(TInt);				// Decode SMTP 3 digit response code into return code
       
    67 	TInt State();							// return current state of state machine
       
    68 	void DoComplete(TInt&);
       
    69 	void SelectBodyEncodingTypeL(TMsgOutboxBodyEncoding anSettingsEncodingType, 
       
    70 								  TMsgOutboxBodyEncoding anHeaderEncodingType);
       
    71 	void SendAndQueueRead(const TDesC8&);
       
    72 	TBool GetCurrentTextLine();
       
    73 
       
    74 private: 	
       
    75 	CImTextServerSession&			iSocket;
       
    76 	CMsvServerEntry&				iServerEntry;
       
    77 	TMsvId							iEntryId;
       
    78 	TInt							iSuspendCheck;
       
    79 	TBuf8<KImMailMaxBufferSize>&	iSmtpBuffer;		// SMTP data will not exceed 1000 characters
       
    80 	
       
    81 	TInt							iBytesToSend;
       
    82 	TInt							iBytesSent;
       
    83 
       
    84 	enum TRcptType
       
    85 		{
       
    86 		ERcptTo,
       
    87 		ERcptCc,
       
    88 		ERcptBcc
       
    89 		};
       
    90 
       
    91 	enum TSmtpFileStates		// legal states that the CImSmtpFile object's state machine may be set to...
       
    92 		{
       
    93 		EResettingSmtp,
       
    94 		EMailFromSmtp,
       
    95 		ERcptToSmtp,
       
    96 		EBeginData,
       
    97 		ESendData,
       
    98 		EEndData
       
    99 		};
       
   100 
       
   101     CImHeader*				iHeader;
       
   102 	CImSendMessage*			iSendMessage;
       
   103 
       
   104     TInt					iState;
       
   105 	TInt					iCompleted;		// termination status of server class, 
       
   106 											// e.g. KErrNone
       
   107 
       
   108 	CDesCArray* 			iRecipientArray;  // points to member array owned by iHeader
       
   109 	TInt					iRecipientIndex;
       
   110 	TInt					iRecipientType;
       
   111 	TPtrC   				iRecipient;		// local copy of 1 recipient Email address
       
   112 
       
   113 	TBool					iSmtpMultiLineResponse;
       
   114 	TBool					iSmtpLastMultiLineResponse;
       
   115 	TBool					iMoreRfc822Data;
       
   116 
       
   117 	TImSendMethod			iBodyType;
       
   118 	TImSMTPSendCopyToSelf	iSendCopyToSelf;
       
   119     };
       
   120 
       
   121 
       
   122 class CImSmtpSession : public CMsgActive
       
   123     {
       
   124 	public: 
       
   125 		static CImSmtpSession* NewL(CMsvServerEntry& aServerEntry, CSmtpSettings& aSettings, RSocketServ& aServ, CImConnect& aConnect, TMsvId aServiceId);
       
   126 		~CImSmtpSession();
       
   127 	
       
   128 	public:
       
   129 		void ConnectL(TRequestStatus& aStatus);
       
   130 		void SendFilesL(CMsgImOutboxSend& aSendFiles, TRequestStatus& aStatus);
       
   131 		void QuitL(TRequestStatus& aStatus);
       
   132 		TImImailFileProgress FileProgress();		// Return snapshot of session progress to client
       
   133 		inline TBool IsConnected();
       
   134 		TInt GetConnectionIAP();			// The value of the connecting IAP
       
   135 		inline TInt GetConnectionStage();			// The value of the connecting stage
       
   136 
       
   137 	private:				// CActive
       
   138 		void DoCancel();			// Allows client to stop the SMTP session prematurely
       
   139 
       
   140 	private:				// CMsgActive
       
   141 		virtual void DoRunL();
       
   142 		virtual void DoComplete(TInt& aStatus);
       
   143 
       
   144 	private:
       
   145 		CImSmtpSession(CMsvServerEntry& aServerEntry, CSmtpSettings& aSettings, TMsvId aServiceId);
       
   146 		void ConstructL(RSocketServ& aServ, CImConnect& aConnect);
       
   147 
       
   148 	private:
       
   149 		void SendFileL();						
       
   150 		void DoStateL();						// the state machine engine
       
   151 		TInt NextStateL();						// logic which calculates next state from result of current operation
       
   152 		TInt NextStateFromWaitingForReply();
       
   153 		TInt NextStateFromAuthorisingSmtpL();
       
   154 		TInt NextStateFromSendStarttls();
       
   155 		TInt NextStateFromSettingSecurityL();
       
   156 		TInt NextStateFromAuthInProgressL();
       
   157 		TInt NextStateFromResetSmtp();
       
   158 		TInt SmtpSessionError(const TInt aSmtpErrorCode);		// Decode SMTP 3 digit response code into return code
       
   159 		TBool GetCurrentTextLine();
       
   160 		HBufC* CreateFormattedAddressLC(const TDesC& aString, const TDesC& aAlias);
       
   161 		TBool SelectNextSMTPAuthProfileL();
       
   162 		void GetIpAddress(TDes8& aAddress);
       
   163 		CSmtpAuthMechanismHelper::TSmtpAuthProfileFlag NextSMTPAuthProfile(CSmtpAuthMechanismHelper::TSmtpAuthProfileFlag aPreviousProfile);
       
   164 		TInt NextStateFromNextFile();
       
   165 		TBool CommandAccepted();
       
   166 		void UpdateAuthorisingInfo();
       
   167 
       
   168 	private:
       
   169 		enum TSessionType
       
   170 			{
       
   171 			ESmtpSession,			// SMTP   session
       
   172 			EEnhancedSmtpSession,	// ESMTP  session
       
   173 			ESecureSession          // ESMTP + TLS session
       
   174 			};
       
   175 
       
   176 	private:
       
   177 		// input references to input arguments...
       
   178 		CMsvServerEntry& iServerEntry;		// handle to the current server entry object
       
   179 		
       
   180 		CMsgImOutboxSend* iSendFiles;			// handle to owner object. Not owned by this class
       
   181 		CSmtpSettings& iSettings;
       
   182 
       
   183 		// SMTP service ID
       
   184 		TMsvId iServiceId;
       
   185 
       
   186 		TInt iState;
       
   187 		TInt iCompleted;	// stores completion code from previous session state
       
   188 		CImTextServerSession* iSocket;	// handle to the socket session (IMSK.DLL)
       
   189 		CImSmtpFile* iSmtpFile;	// handle to the Smtp File object
       
   190 		TBuf8<KImMailMaxBufferSize>	iSmtpBuffer;	// stores SMTP command string & response
       
   191 													// from server
       
   192 		TInt iLastSmtpCode;		// Stores the last STMP response code
       
   193 		TBool iRetryAuthWithHostname;	// Flag to indicate whether to retry Smtp Auth with name instead of IP Address
       
   194 		
       
   195 		TInt iBccRcptIndex;
       
   196 		TBool iToRcptHeaderUpdated;
       
   197 		TBool iBccRcptFound;
       
   198 		TBool iFinishedWithBccRcpts;
       
   199 
       
   200 		TTime iTimeNow;				// stores time/date when each message file is sent
       
   201 
       
   202 		TBool iSmtpMultiLineResponse;
       
   203 		TBool iSmtpLastMultiLineResponse;
       
   204 		TBool iSocketIsConnected;
       
   205 
       
   206 		// ESMTP variables
       
   207 		TSessionType iThisSession;
       
   208 		TBool iEsmtpSpokenHere;
       
   209 		TBool i8BitMimeAcceptedHere;
       
   210 		TBool iSizeAcceptedHere;
       
   211 		TBool iStartTlsAcceptedHere;
       
   212 		TUint32 iInterAddress;
       
   213 		CImLogMessage* iLogMessage;
       
   214 
       
   215 		// Used to track the progress of sent messages
       
   216 		TInt iTotalBytesToSend;
       
   217 		TInt iNumMsgsToSend;
       
   218 		TInt iNumMsgsSent;
       
   219 
       
   220 		TInt iSupportedAuthProfiles; // for TSmtpAuthProfileFlags
       
   221 		CSmtpAuthMechanismHelper::TSmtpAuthProfileFlag iCurrentAuthProfile;
       
   222 		CSmtpAuthMechanismHelper* iSmtpAuthHelper;
       
   223 
       
   224 		TBool iOperationComplete;
       
   225     };
       
   226 
       
   227 // inline functions
       
   228 TBool CImSmtpSession::IsConnected()			{   return iSocketIsConnected;	}
       
   229 TInt CImSmtpSession::GetConnectionStage()	{	return iSocket->GetConnectionStage();	}
       
   230 
       
   231 #endif