PTLib  Version 2.10.4
PSMTPServer Class Reference

A TCP/IP socket for the Simple Mail Transfer Protocol. More...

#include <inetmail.h>

Inheritance diagram for PSMTPServer:
PSMTP PInternetProtocol PIndirectChannel PChannel PObject

List of all members.

Public Types

enum  ForwardResult { LocalDomain, WillForward, CannotForward }
enum  LookUpResult { ValidUser, AmbiguousUser, UnknownUser, LookUpError }

Public Member Functions

 PSMTPServer ()
 Create a TCP/IP SMPTP protocol socket channel.
PBoolean ProcessCommand ()
 Process commands, dispatching to the appropriate virtual function.
void ServerReset ()
virtual ForwardResult ForwardDomain (PCaselessString &userDomain, PCaselessString &forwardDomainList)
 Determine if a user for this domain may be on the local system, or should be forwarded.
virtual LookUpResult LookUpName (const PCaselessString &name, PString &expandedName)
 Look up a name in the context of the SMTP server.
virtual PBoolean HandleMessage (PCharArray &buffer, PBoolean starting, PBoolean completed)
 Handle a received message.

Protected Types

enum  { WasMAIL, WasSEND, WasSAML, WasSOML }

Protected Member Functions

PBoolean OnOpen ()
 This callback is executed when the Open() function is called with open channels.
virtual void OnHELO (const PCaselessString &remoteHost)
virtual void OnEHLO (const PCaselessString &remoteHost)
virtual void OnQUIT ()
virtual void OnHELP ()
virtual void OnNOOP ()
virtual void OnTURN ()
virtual void OnRSET ()
virtual void OnVRFY (const PCaselessString &name)
virtual void OnEXPN (const PCaselessString &name)
virtual void OnRCPT (const PCaselessString &recipient)
virtual void OnMAIL (const PCaselessString &sender)
virtual void OnSEND (const PCaselessString &sender)
virtual void OnSAML (const PCaselessString &sender)
virtual void OnSOML (const PCaselessString &sender)
virtual void OnDATA ()
virtual PBoolean OnUnknown (const PCaselessString &command)
 Handle an unknown command.
virtual void OnSendMail (const PCaselessString &sender)
virtual PBoolean OnTextData (PCharArray &buffer, PBoolean &completed)
 Read a standard text message that is being received by the socket.
virtual PBoolean OnMIMEData (PCharArray &buffer, PBoolean &completed)
 Read an eight bit MIME message that is being received by the socket.

Protected Attributes

PBoolean extendedHello
PBoolean eightBitMIME
PString fromAddress
PString fromPath
PStringList toNames
PStringList toDomains
PINDEX messageBufferSize
enum PSMTPServer:: { ... }  sendCommand
StuffState endMIMEDetectState

Detailed Description

A TCP/IP socket for the Simple Mail Transfer Protocol.

When acting as a client, the procedure is to make the connection to a remote server, then to send a message using the following procedure: PSMTPSocket mail("mailserver"); if (mail.IsOpen()) { mail.BeginMessage("Me@here.com.au", "Fred@somwhere.com"); mail.Write(myMessage); if (!mail.EndMessage()) PError << "Mail send failed." << endl; } else PError << "Mail conection failed." << endl;

When acting as a server, a descendant class would be created to override at least the LookUpName() and HandleMessage() functions. Other functions may be overridden for further enhancement to the sockets capabilities, but these two will give a basic SMTP server functionality.

The server socket thread would continuously call the ProcessMessage() function until it returns false. This will then call the appropriate virtual function on parsing the SMTP protocol.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
WasMAIL 
WasSEND 
WasSAML 
WasSOML 
Enumerator:
LocalDomain 

User may be on local machine, do LookUpName().

WillForward 

User may be forwarded to another SMTP host.

CannotForward 

User cannot be forwarded.

Enumerator:
ValidUser 

User name was valid and unique.

AmbiguousUser 

User name was valid but ambiguous.

UnknownUser 

User name was invalid.

LookUpError 

Some other error occurred in look up.


Constructor & Destructor Documentation

Create a TCP/IP SMPTP protocol socket channel.

The parameterless form creates an unopened socket, the form with the address parameter makes a connection to a remote system, opening the socket. The form with the socket parameter opens the socket to an incoming call from a "listening" socket.


Member Function Documentation

virtual ForwardResult PSMTPServer::ForwardDomain ( PCaselessString userDomain,
PCaselessString forwardDomainList 
) [virtual]

Determine if a user for this domain may be on the local system, or should be forwarded.

Returns:
Result of forward check operation.
Parameters:
userDomainDomain for user
forwardDomainListDomains forwarding to
virtual PBoolean PSMTPServer::HandleMessage ( PCharArray buffer,
PBoolean  starting,
PBoolean  completed 
) [virtual]

Handle a received message.

The buffer parameter contains the partial or complete message received, depending on the completed parameter.

The default behaviour is to simply return false;

Returns:
true if message was handled, false if an error occurs.
Parameters:
bufferBuffer containing message data received.
startingThis is the first call for the message.
completedThis is the last call for the message. Indication that the entire message has been received.
virtual LookUpResult PSMTPServer::LookUpName ( const PCaselessString name,
PString expandedName 
) [virtual]

Look up a name in the context of the SMTP server.

The default bahaviour simply returns false.

Returns:
Result of name look up operation.
Parameters:
nameName to look up.
expandedNameExpanded form of name (if found).
virtual void PSMTPServer::OnDATA ( ) [protected, virtual]
virtual void PSMTPServer::OnEHLO ( const PCaselessString remoteHost) [protected, virtual]
Parameters:
remoteHostName of remote host.
virtual void PSMTPServer::OnEXPN ( const PCaselessString name) [protected, virtual]
Parameters:
nameName to expand.
virtual void PSMTPServer::OnHELO ( const PCaselessString remoteHost) [protected, virtual]
Parameters:
remoteHostName of remote host.
virtual void PSMTPServer::OnHELP ( ) [protected, virtual]
virtual void PSMTPServer::OnMAIL ( const PCaselessString sender) [protected, virtual]
Parameters:
senderName of sender.
virtual PBoolean PSMTPServer::OnMIMEData ( PCharArray buffer,
PBoolean completed 
) [protected, virtual]

Read an eight bit MIME message that is being received by the socket.

The MIME message is terminated by the CR/LF/./CR/LF sequence.

The default behaviour is to read the data into the buffer parameter until either the end of the message or when the messageBufferSize bytes have been read.

Returns:
true if partial message received, false if the end of the data was received.
virtual void PSMTPServer::OnNOOP ( ) [protected, virtual]
PBoolean PSMTPServer::OnOpen ( ) [protected, virtual]

This callback is executed when the Open() function is called with open channels.

It may be used by descendent channels to do any handshaking required by the protocol that channel embodies.

The default behaviour is to simply return true.

Returns:
Returns true if the protocol handshaking is successful.

Reimplemented from PIndirectChannel.

virtual void PSMTPServer::OnQUIT ( ) [protected, virtual]
virtual void PSMTPServer::OnRCPT ( const PCaselessString recipient) [protected, virtual]
Parameters:
recipientName of recipient.
virtual void PSMTPServer::OnRSET ( ) [protected, virtual]
virtual void PSMTPServer::OnSAML ( const PCaselessString sender) [protected, virtual]
Parameters:
senderName of sender.
virtual void PSMTPServer::OnSEND ( const PCaselessString sender) [protected, virtual]
Parameters:
senderName of sender.
virtual void PSMTPServer::OnSendMail ( const PCaselessString sender) [protected, virtual]
Parameters:
senderName of sender.
virtual void PSMTPServer::OnSOML ( const PCaselessString sender) [protected, virtual]
Parameters:
senderName of sender.
virtual PBoolean PSMTPServer::OnTextData ( PCharArray buffer,
PBoolean completed 
) [protected, virtual]

Read a standard text message that is being received by the socket.

The text message is terminated by a line with a '.' character alone.

The default behaviour is to read the data into the buffer parameter until either the end of the message or when the messageBufferSize bytes have been read.

Returns:
true if partial message received, false if the end of the data was received.
virtual void PSMTPServer::OnTURN ( ) [protected, virtual]
virtual PBoolean PSMTPServer::OnUnknown ( const PCaselessString command) [protected, virtual]

Handle an unknown command.

Returns:
true if more processing may be done, false if the ProcessCommand() function is to return false.
Parameters:
commandComplete command line received.
virtual void PSMTPServer::OnVRFY ( const PCaselessString name) [protected, virtual]
Parameters:
nameName to verify.

Process commands, dispatching to the appropriate virtual function.

This is used when the socket is acting as a server.

Returns:
true if more processing may be done, false if the QUIT command was received or the OnUnknown() function returns false.

Member Data Documentation

PINDEX PSMTPServer::messageBufferSize [protected]
enum { ... } PSMTPServer::sendCommand [protected]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines