PTLib  Version 2.10.11
PRFC822Channel Class Reference

A channel for sending/receiving RFC822 compliant mail messages. More...

#include <inetmail.h>

Inheritance diagram for PRFC822Channel:
PIndirectChannel PChannel PObject

Public Types

enum  Direction { Sending, Receiving }
 
- Public Types inherited from PChannel
enum  PXBlockType { PXReadBlock, PXWriteBlock, PXAcceptBlock, PXConnectBlock }
 
enum  ShutdownValue { ShutdownRead = 0, ShutdownWrite = 1, ShutdownReadAndWrite = 2 }
 
enum  Errors {
  NoError, NotFound, FileExists, DiskFull,
  AccessDenied, DeviceInUse, BadParameter, NoMemory,
  NotOpen, Timeout, Interrupted, BufferTooSmall,
  Miscellaneous, ProtocolFailure, NumNormalisedErrors
}
 Normalised error codes. More...
 
enum  ErrorGroup { LastReadError, LastWriteError, LastGeneralError, NumErrorGroups }
 Error groups. More...
 
typedef std::vector< SliceVectorOfSlice
 
- Public Types inherited from PObject
enum  Comparison { LessThan = -1, EqualTo = 0, GreaterThan = 1 }
 Result of the comparison operation performed by the Compare() function. More...
 

Public Member Functions

 PRFC822Channel (Direction direction)
 Construct a RFC822 aware channel. More...
 
 ~PRFC822Channel ()
 Close the channel before destruction. More...
 
PBoolean Close ()
 Close the channel. More...
 
virtual PBoolean Write (const void *buf, PINDEX len)
 Low level write to the channel. More...
 
void NewMessage (Direction direction)
 Begin a new message. More...
 
PString MultipartMessage ()
 Enter multipart MIME message mode. More...
 
PBoolean MultipartMessage (const PString &boundary)
 Enter multipart MIME message mode. More...
 
void NextPart (const PString &boundary)
 Indicate that a new multipart message part is to begin. More...
 
void SetFromAddress (const PString &fromAddress)
 Set the sender address. More...
 
void SetToAddress (const PString &toAddress)
 Set the recipient address(es). More...
 
void SetCC (const PString &ccAddress)
 Set the Carbon Copy address(es). More...
 
void SetBCC (const PString &bccAddress)
 Set the Blind Carbon Copy address(es). More...
 
void SetSubject (const PString &subject)
 Set the message subject. More...
 
void SetContentType (const PString &contentType)
 Set the content type. More...
 
void SetContentAttachment (const PFilePath &filename)
 Set the content disposition for attachments. More...
 
void SetTransferEncoding (const PString &encoding, PBoolean autoTranslate=true)
 Set the content transfer encoding. More...
 
void SetHeaderField (const PString &name, const PString &value)
 Set the and arbitrary header field. More...
 
PBoolean SendWithSMTP (const PString &hostname)
 Send this message using an SMTP socket. More...
 
PBoolean SendWithSMTP (PSMTPClient *smtp)
 Send this message using an SMTP socket. More...
 
- Public Member Functions inherited from PIndirectChannel
 PIndirectChannel ()
 Create a new indirect channel without any channels to redirect to. More...
 
 ~PIndirectChannel ()
 Close the indirect channel, deleting read/write channels if desired. More...
 
Comparison Compare (const PObject &obj) const
 Determine if the two objects refer to the same indirect channel. More...
 
virtual PString GetName () const
 Get the name of the channel. More...
 
virtual PBoolean IsOpen () const
 Determine if the channel is currently open and read and write operations can be executed on it. More...
 
virtual PBoolean Read (void *buf, PINDEX len)
 Low level read from the channel. More...
 
virtual PBoolean Shutdown (ShutdownValue option)
 Close one or both of the data streams associated with a channel. More...
 
virtual bool SetLocalEcho (bool localEcho)
 Set local echo mode. More...
 
virtual PChannelGetBaseReadChannel () const
 This function returns the eventual base channel for reading of a series of indirect channels provided by descendents of PIndirectChannel. More...
 
virtual PChannelGetBaseWriteChannel () const
 This function returns the eventual base channel for writing of a series of indirect channels provided by descendents of PIndirectChannel. More...
 
virtual PString GetErrorText (ErrorGroup group=NumErrorGroups) const
 Get error message description. More...
 
PBoolean Open (PChannel &channel)
 Set the channel for both read and write operations. More...
 
PBoolean Open (PChannel *channel, PBoolean autoDelete=true)
 Set the channel for both read and write operations. More...
 
PBoolean Open (PChannel *readChannel, PChannel *writeChannel, PBoolean autoDeleteRead=true, PBoolean autoDeleteWrite=true)
 Set the channel for both read and write operations. More...
 
PChannelGetReadChannel () const
 Get the channel used for read operations. More...
 
bool SetReadChannel (PChannel *channel, bool autoDelete=true, bool closeExisting=false)
 Set the channel for read operations. More...
 
PChannelGetWriteChannel () const
 Get the channel used for write operations. More...
 
PBoolean SetWriteChannel (PChannel *channel, bool autoDelete=true, bool closeExisting=false)
 Set the channel for read operations. More...
 
- Public Member Functions inherited from PChannel
PBoolean SetErrorValues (Errors errorCode, int osError, ErrorGroup group=LastGeneralError)
 Set error values to those specified. More...
 
 PChannel ()
 Create the channel. More...
 
 ~PChannel ()
 Close down the channel. More...
 
virtual PINDEX HashFunction () const
 Calculate a hash value for use in sets and dictionaries. More...
 
int GetHandle () const
 Get the integer operating system handle for the channel. More...
 
void SetReadTimeout (const PTimeInterval &time)
 Set the timeout for read operations. More...
 
PTimeInterval GetReadTimeout () const
 Get the timeout for read operations. More...
 
virtual PINDEX GetLastReadCount () const
 Get the number of bytes read by the last Read() call. More...
 
virtual int ReadChar ()
 Read a single 8 bit byte from the channel. More...
 
PBoolean ReadBlock (void *buf, PINDEX len)
 Read len bytes into the buffer from the channel. More...
 
PString ReadString (PINDEX len)
 Read len character into a string from the channel. More...
 
virtual PBoolean ReadAsync (void *buf, PINDEX len)
 Begin an asynchronous read from channel. More...
 
virtual void OnReadComplete (void *buf, PINDEX len)
 User callback function for when a ReadAsync() call has completed or timed out. More...
 
void SetWriteTimeout (const PTimeInterval &time)
 Set the timeout for write operations to complete. More...
 
PTimeInterval GetWriteTimeout () const
 Get the timeout for write operations to complete. More...
 
virtual PBoolean Write (const void *buf, PINDEX len, const void *mark)
 Low level write to the channel with marker. More...
 
virtual PINDEX GetLastWriteCount () const
 Get the number of bytes written by the last Write() call. More...
 
PBoolean WriteChar (int c)
 Write a single character to the channel. More...
 
PBoolean WriteString (const PString &str)
 Write a string to the channel. More...
 
virtual PBoolean WriteAsync (const void *buf, PINDEX len)
 Begin an asynchronous write from channel. More...
 
virtual void OnWriteComplete (const void *buf, PINDEX len)
 User callback function for when a WriteAsync() call has completed or timed out. More...
 
virtual bool FlowControl (const void *flowData)
 Flow Control information Pass data to the channel for flowControl determination. More...
 
PBoolean SetBufferSize (PINDEX newSize)
 Set the iostream buffer size for reads and writes. More...
 
PBoolean SendCommandString (const PString &command)
 Send a command meta-string. More...
 
void AbortCommandString ()
 Abort a command string that is in progress. More...
 
Errors GetErrorCode (ErrorGroup group=NumErrorGroups) const
 Get normalised error code. More...
 
int GetErrorNumber (ErrorGroup group=NumErrorGroups) const
 Get OS errro code. More...
 
virtual PBoolean Read (const VectorOfSlice &slices)
 Low level scattered read from the channel. More...
 
virtual PBoolean Write (const VectorOfSlice &slices)
 Low level scattered write to the channel. More...
 
- Public Member Functions inherited from PObject
virtual ~PObject ()
 
virtual PObjectClone () const
 Create a copy of the class on the heap. More...
 
virtual const char * GetClass (unsigned ancestor=0) const
 Get the current dynamic type of the object instance. More...
 
PBoolean IsClass (const char *cls) const
 
virtual PBoolean InternalIsDescendant (const char *clsName) const
 Determine if the dynamic type of the current instance is a descendent of the specified class. More...
 
virtual Comparison CompareObjectMemoryDirect (const PObject &obj) const
 Determine the byte wise comparison of two objects. More...
 
bool operator== (const PObject &obj) const
 Compare the two objects. More...
 
bool operator!= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator< (const PObject &obj) const
 Compare the two objects. More...
 
bool operator> (const PObject &obj) const
 Compare the two objects. More...
 
bool operator<= (const PObject &obj) const
 Compare the two objects. More...
 
bool operator>= (const PObject &obj) const
 Compare the two objects. More...
 
virtual void PrintOn (ostream &strm) const
 Output the contents of the object to the stream. More...
 
virtual void ReadFrom (istream &strm)
 Input the contents of the object from the stream. More...
 

Static Public Member Functions

static const PCaselessStringMimeVersionTag ()
 
static const PCaselessStringFromTag ()
 
static const PCaselessStringToTag ()
 
static const PCaselessStringCCTag ()
 
static const PCaselessStringBCCTag ()
 
static const PCaselessStringSubjectTag ()
 
static const PCaselessStringDateTag ()
 
static const PCaselessStringReturnPathTag ()
 
static const PCaselessStringReceivedTag ()
 
static const PCaselessStringMessageIDTag ()
 
static const PCaselessStringMailerTag ()
 
static const PCaselessStringContentTypeTag ()
 
static const PCaselessStringContentDispositionTag ()
 
static const PCaselessStringContentTransferEncodingTag ()
 
- Static Public Member Functions inherited from PChannel
static PBoolean ConvertOSError (int libcReturnValue, Errors &lastError, int &osError)
 Convert an operating system error into platform independent error. More...
 
static PString GetErrorText (Errors lastError, int osError=0)
 Get error message description. More...
 
- Static Public Member Functions inherited from PObject
static const char * Class ()
 Get the name of the class as a C string. More...
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 

Protected Member Functions

PBoolean OnOpen ()
 This callback is executed when the Open() function is called with open channels. More...
 
- Protected Member Functions inherited from PChannel
 PChannel (const PChannel &)
 
PChanneloperator= (const PChannel &)
 
virtual PBoolean ConvertOSError (int libcReturnValue, ErrorGroup group=LastGeneralError)
 Convert an operating system error into platform independent error. More...
 
int ReadCharWithTimeout (PTimeInterval &timeout)
 Read a character with specified timeout. More...
 
PBoolean ReceiveCommandString (int nextChar, const PString &reply, PINDEX &pos, PINDEX start)
 
PBoolean PXSetIOBlock (PXBlockType type, const PTimeInterval &timeout)
 
int PXClose ()
 
- Protected Member Functions inherited from PObject
 PObject ()
 Constructor for PObject, made protected so cannot ever create one on its own. More...
 

Protected Attributes

PBoolean writeHeaders
 
PMIMEInfo headers
 
PBoolean writePartHeaders
 
PMIMEInfo partHeaders
 
PStringList boundaries
 
PBase64base64
 
- Protected Attributes inherited from PIndirectChannel
PChannelreadChannel
 Channel for read operations. More...
 
PBoolean readAutoDelete
 Automatically delete read channel on destruction. More...
 
PChannelwriteChannel
 Channel for write operations. More...
 
PBoolean writeAutoDelete
 Automatically delete write channel on destruction. More...
 
PReadWriteMutex channelPointerMutex
 Race condition prevention on closing channel. More...
 
- Protected Attributes inherited from PChannel
int os_handle
 The operating system file handle return by standard open() function. More...
 
Errors lastErrorCode [NumErrorGroups+1]
 The platform independant error code. More...
 
int lastErrorNumber [NumErrorGroups+1]
 The operating system error number (eg as returned by errno). More...
 
PINDEX lastReadCount
 Number of byte last read by the Read() function. More...
 
PINDEX lastWriteCount
 Number of byte last written by the Write() function. More...
 
PTimeInterval readTimeout
 Timeout for read operations. More...
 
PTimeInterval writeTimeout
 Timeout for write operations. More...
 
PString channelName
 
PMutex px_threadMutex
 
PXBlockType px_lastBlockType
 
PThreadpx_readThread
 
PThreadpx_writeThread
 
PMutex px_writeMutex
 
PThreadpx_selectThread [3]
 
PMutex px_selectMutex [3]
 

Detailed Description

A channel for sending/receiving RFC822 compliant mail messages.

This encpsulates all that is required to send an RFC822 compliant message via another channel. It automatically adds/strips header information from the stream so the Read() and Write() functions only deal with the message body. For example to send a message using the SMTP classes: PSMTPClient mail("mailserver"); if (mail.IsOpen()) { PRFC822Channel message; message.SetFromAddress("Me@here.com.au"); message.SetToAddress("Fred@somwhere.com"); if (message.Open(mail)) { if (mail.BeginMessage("Me@here.com.au", "Fred@somwhere.com")) { if (!message.Write(myMessageBody)) PError << "Mail write failed." << endl; if (!message.EndMessage()) PError << "Mail send failed." << endl; } } } else PError << "Mail conection failed." << endl;

Member Enumeration Documentation

§ Direction

Enumerator
Sending 
Receiving 

Constructor & Destructor Documentation

§ PRFC822Channel()

PRFC822Channel::PRFC822Channel ( Direction  direction)

Construct a RFC822 aware channel.

Parameters
direction/< Indicates are sending or receiving a message

§ ~PRFC822Channel()

PRFC822Channel::~PRFC822Channel ( )

Close the channel before destruction.

Member Function Documentation

§ BCCTag()

static const PCaselessString& PRFC822Channel::BCCTag ( )
static

§ CCTag()

static const PCaselessString& PRFC822Channel::CCTag ( )
static

§ Close()

PBoolean PRFC822Channel::Close ( )
virtual

Close the channel.

This assures that all mime fields etc are closed off before closing the underliying channel.

Reimplemented from PIndirectChannel.

§ ContentDispositionTag()

static const PCaselessString& PRFC822Channel::ContentDispositionTag ( )
inlinestatic

§ ContentTransferEncodingTag()

static const PCaselessString& PRFC822Channel::ContentTransferEncodingTag ( )
inlinestatic

§ ContentTypeTag()

static const PCaselessString& PRFC822Channel::ContentTypeTag ( )
inlinestatic

§ DateTag()

static const PCaselessString& PRFC822Channel::DateTag ( )
static

§ FromTag()

static const PCaselessString& PRFC822Channel::FromTag ( )
static

§ MailerTag()

static const PCaselessString& PRFC822Channel::MailerTag ( )
static

§ MessageIDTag()

static const PCaselessString& PRFC822Channel::MessageIDTag ( )
static

§ MimeVersionTag()

static const PCaselessString& PRFC822Channel::MimeVersionTag ( )
static

§ MultipartMessage() [1/2]

PString PRFC822Channel::MultipartMessage ( )

Enter multipart MIME message mode.

This indicates that the message, or individual part within a message as MIME is nestable, is a multipart message. This form returns the boundary indicator string generated internally which must then be used in all subsequent NextPart() calls.

Note this must be called before any writes are done to the message or part.

§ MultipartMessage() [2/2]

PBoolean PRFC822Channel::MultipartMessage ( const PString boundary)

Enter multipart MIME message mode.

This indicates that the message, or individual part within a message as MIME is nestable, is a multipart message. In this form the user supplies a boundary indicator string which must then be used in all subsequent NextPart() calls.

Note this must be called before any writes are done to the message or part.

§ NewMessage()

void PRFC822Channel::NewMessage ( Direction  direction)

Begin a new message.

This may be used if the object is to encode 2 or more messages sequentially. It resets the internal state of the object.

Parameters
directionIndicates are sending or receiving a message

§ NextPart()

void PRFC822Channel::NextPart ( const PString boundary)

Indicate that a new multipart message part is to begin.

This will close off the previous part, and any nested multipart messages contained therein, and allow a new part to begin.

The user may adjust the parts content type and other header fields after this call and before the first write of the parts body. The default Content-Type is "text/plain".

Note that all header fields are cleared from the previous part.

§ OnOpen()

PBoolean PRFC822Channel::OnOpen ( )
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.

Returns
Returns true if the protocol handshaking is successful.

Reimplemented from PIndirectChannel.

§ ReceivedTag()

static const PCaselessString& PRFC822Channel::ReceivedTag ( )
static

§ ReturnPathTag()

static const PCaselessString& PRFC822Channel::ReturnPathTag ( )
static

§ SendWithSMTP() [1/2]

PBoolean PRFC822Channel::SendWithSMTP ( const PString hostname)

Send this message using an SMTP socket.

This will create a PSMTPClient and connect to the specified host then send the message to the remote SMTP server.

§ SendWithSMTP() [2/2]

PBoolean PRFC822Channel::SendWithSMTP ( PSMTPClient smtp)

Send this message using an SMTP socket.

This assumes PSMTPClient is open the sends the message to the remote SMTP server.

§ SetBCC()

void PRFC822Channel::SetBCC ( const PString bccAddress)

Set the Blind Carbon Copy address(es).

This must be called before any writes are done to the channel.

Parameters
bccAddressRecipients e-mail address (comma separated)

§ SetCC()

void PRFC822Channel::SetCC ( const PString ccAddress)

Set the Carbon Copy address(es).

This must be called before any writes are done to the channel.

Parameters
ccAddressRecipients e-mail address (comma separated)

§ SetContentAttachment()

void PRFC822Channel::SetContentAttachment ( const PFilePath filename)

Set the content disposition for attachments.

This must be called before any writes are done to the channel. It may be set again immediately after any call to NextPart() when multipart mime is being used.

Note that this will alter the Content-Type field to

Parameters
filenameAttachment filename

§ SetContentType()

void PRFC822Channel::SetContentType ( const PString contentType)

Set the content type.

This must be called before any writes are done to the channel. It may be set again immediately after any call to NextPart() when multipart mime is being used.

The default Content-Type is "text/plain".

Parameters
contentTypeContent type in form major/minor

§ SetFromAddress()

void PRFC822Channel::SetFromAddress ( const PString fromAddress)

Set the sender address.

This must be called before any writes are done to the channel.

Parameters
fromAddressSenders e-mail address

§ SetHeaderField()

void PRFC822Channel::SetHeaderField ( const PString name,
const PString value 
)

Set the and arbitrary header field.

This must be called before any writes are done to the channel.

Parameters
nameMIME fields tag
valueMIME fields contents

§ SetSubject()

void PRFC822Channel::SetSubject ( const PString subject)

Set the message subject.

This must be called before any writes are done to the channel.

Parameters
subjectSubject string

§ SetToAddress()

void PRFC822Channel::SetToAddress ( const PString toAddress)

Set the recipient address(es).

This must be called before any writes are done to the channel.

Parameters
toAddressRecipients e-mail address (comma separated)

§ SetTransferEncoding()

void PRFC822Channel::SetTransferEncoding ( const PString encoding,
PBoolean  autoTranslate = true 
)

Set the content transfer encoding.

This must be called before any writes are done to the channel. It may be set again immediately after any call to NextPart() when multipart mime is being used.

If the encoding is "base64" (case insensitive) and , all writes will be treated as binary and translated into base64 encoding before output to the underlying channel.

Parameters
encodingEncoding type
autoTranslateAutomatically convert to encoding type

§ SubjectTag()

static const PCaselessString& PRFC822Channel::SubjectTag ( )
static

§ ToTag()

static const PCaselessString& PRFC822Channel::ToTag ( )
static

§ Write()

virtual PBoolean PRFC822Channel::Write ( const void *  buf,
PINDEX  len 
)
virtual

Low level write to the channel.

This override assures that the header is written before the body that will be output via this function.

Returns
true if at least len bytes were written to the channel.
Parameters
bufPointer to a block of memory to write.
lenNumber of bytes to write.

Reimplemented from PIndirectChannel.

Member Data Documentation

§ base64

PBase64* PRFC822Channel::base64
protected

§ boundaries

PStringList PRFC822Channel::boundaries
protected

§ headers

PMIMEInfo PRFC822Channel::headers
protected

§ partHeaders

PMIMEInfo PRFC822Channel::partHeaders
protected

§ writeHeaders

PBoolean PRFC822Channel::writeHeaders
protected

§ writePartHeaders

PBoolean PRFC822Channel::writePartHeaders
protected

The documentation for this class was generated from the following file: