PTLib
Version 2.14.3
|
A TCP/IP socket for the Simple Mail Transfer Protocol. More...
#include <inetmail.h>
Public Types | |
enum | ForwardResult { LocalDomain, WillForward, CannotForward } |
enum | LookUpResult { ValidUser, AmbiguousUser, UnknownUser, LookUpError } |
![]() | |
enum | Commands { HELO, EHLO, QUIT, HELP, NOOP, TURN, RSET, VRFY, EXPN, RCPT, MAIL, SEND, SAML, SOML, DATA, AUTH, NumCommands } |
Public Member Functions | |
PSMTPServer () | |
Create a TCP/IP SMPTP protocol socket channel. More... | |
PBoolean | ProcessCommand () |
Process commands, dispatching to the appropriate virtual function. More... | |
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. More... | |
virtual LookUpResult | LookUpName (const PCaselessString &name, PString &expandedName) |
Look up a name in the context of the SMTP server. More... | |
virtual PBoolean | HandleMessage (PCharArray &buffer, PBoolean starting, PBoolean completed) |
Handle a received message. More... | |
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. More... | |
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. More... | |
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. More... | |
virtual PBoolean | OnMIMEData (PCharArray &buffer, PBoolean &completed) |
Read an eight bit MIME message that is being received by the socket. More... | |
![]() | |
PSMTP () | |
![]() | |
PInternetProtocol (const char *defaultServiceName, PINDEX cmdCount, char const *const *cmdNames) | |
virtual PINDEX | ParseResponse (const PString &line) |
Parse a response line string into a response code and any extra info on the line. More... | |
Protected Attributes | |
PBoolean | extendedHello |
PBoolean | eightBitMIME |
PString | fromAddress |
PString | fromPath |
PStringList | toNames |
PStringList | toDomains |
PINDEX | messageBufferSize |
enum PSMTPServer:: { ... } | sendCommand |
StuffState | endMIMEDetectState |
Additional Inherited Members | |
![]() | |
static PString | GetErrorText (Errors lastError, int osError=0) |
Get error message description. More... | |
![]() | |
static const char * | Class () |
Get the name of the class as a C string. More... | |
static __inline const PObject * | PTraceObjectInstance (const char *) |
static __inline const PObject * | PTraceObjectInstance (const PObject *obj) |
static Comparison | InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size) |
Internal function caled from CompareObjectMemoryDirect() More... | |
![]() |
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.
Enumerator | |
---|---|
LocalDomain |
User may be on local machine, do LookUpName(). |
WillForward |
User may be forwarded to another SMTP host. |
CannotForward |
User cannot be forwarded. |
PSMTPServer::PSMTPServer | ( | ) |
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.
|
virtual |
Determine if a user for this domain may be on the local system, or should be forwarded.
userDomain | Domain for user |
forwardDomainList | Domains forwarding to |
|
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;
buffer | Buffer containing message data received. |
starting | This is the first call for the message. |
completed | This is the last call for the message. Indication that the entire message has been received. |
|
virtual |
Look up a name in the context of the SMTP server.
The default bahaviour simply returns false.
name | Name to look up. |
expandedName | Expanded form of name (if found). |
|
protectedvirtual |
|
protectedvirtual |
remoteHost | Name of remote host. |
|
protectedvirtual |
name | Name to expand. |
|
protectedvirtual |
remoteHost | Name of remote host. |
|
protectedvirtual |
|
protectedvirtual |
sender | Name of sender. |
|
protectedvirtual |
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.
|
protectedvirtual |
|
protectedvirtual |
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.
Reimplemented from PIndirectChannel.
|
protectedvirtual |
|
protectedvirtual |
recipient | Name of recipient. |
|
protectedvirtual |
|
protectedvirtual |
sender | Name of sender. |
|
protectedvirtual |
sender | Name of sender. |
|
protectedvirtual |
sender | Name of sender. |
|
protectedvirtual |
sender | Name of sender. |
|
protectedvirtual |
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.
|
protectedvirtual |
|
protectedvirtual |
Handle an unknown command.
command | Complete command line received. |
|
protectedvirtual |
name | Name to verify. |
PBoolean PSMTPServer::ProcessCommand | ( | ) |
Process commands, dispatching to the appropriate virtual function.
This is used when the socket is acting as a server.
void PSMTPServer::ServerReset | ( | ) |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
enum { ... } PSMTPServer::sendCommand |
|
protected |
|
protected |