PTLib
Version 2.10.10
|
A channel for sending/receiving RFC822 compliant mail messages. More...
#include <inetmail.h>
Public Types | |
enum | Direction { Sending, Receiving } |
Public Member Functions | |
PRFC822Channel (Direction direction) | |
Construct a RFC822 aware channel. | |
~PRFC822Channel () | |
Close the channel before destruction. | |
PBoolean | Close () |
Close the channel. | |
virtual PBoolean | Write (const void *buf, PINDEX len) |
Low level write to the channel. | |
void | NewMessage (Direction direction) |
Begin a new message. | |
PString | MultipartMessage () |
Enter multipart MIME message mode. | |
PBoolean | MultipartMessage (const PString &boundary) |
Enter multipart MIME message mode. | |
void | NextPart (const PString &boundary) |
Indicate that a new multipart message part is to begin. | |
void | SetFromAddress (const PString &fromAddress) |
Set the sender address. | |
void | SetToAddress (const PString &toAddress) |
Set the recipient address(es). | |
void | SetCC (const PString &ccAddress) |
Set the Carbon Copy address(es). | |
void | SetBCC (const PString &bccAddress) |
Set the Blind Carbon Copy address(es). | |
void | SetSubject (const PString &subject) |
Set the message subject. | |
void | SetContentType (const PString &contentType) |
Set the content type. | |
void | SetContentAttachment (const PFilePath &filename) |
Set the content disposition for attachments. | |
void | SetTransferEncoding (const PString &encoding, PBoolean autoTranslate=true) |
Set the content transfer encoding. | |
void | SetHeaderField (const PString &name, const PString &value) |
Set the and arbitrary header field. | |
PBoolean | SendWithSMTP (const PString &hostname) |
Send this message using an SMTP socket. | |
PBoolean | SendWithSMTP (PSMTPClient *smtp) |
Send this message using an SMTP socket. | |
![]() | |
PIndirectChannel () | |
Create a new indirect channel without any channels to redirect to. | |
~PIndirectChannel () | |
Close the indirect channel, deleting read/write channels if desired. | |
Comparison | Compare (const PObject &obj) const |
Determine if the two objects refer to the same indirect channel. | |
virtual PString | GetName () const |
Get the name of the channel. | |
virtual PBoolean | IsOpen () const |
Determine if the channel is currently open and read and write operations can be executed on it. | |
virtual PBoolean | Read (void *buf, PINDEX len) |
Low level read from the channel. | |
virtual PBoolean | Shutdown (ShutdownValue option) |
Close one or both of the data streams associated with a channel. | |
virtual bool | SetLocalEcho (bool localEcho) |
Set local echo mode. | |
virtual PChannel * | GetBaseReadChannel () const |
This function returns the eventual base channel for reading of a series of indirect channels provided by descendents of PIndirectChannel . | |
virtual PChannel * | GetBaseWriteChannel () const |
This function returns the eventual base channel for writing of a series of indirect channels provided by descendents of PIndirectChannel . | |
virtual PString | GetErrorText (ErrorGroup group=NumErrorGroups) const |
Get error message description. | |
PBoolean | Open (PChannel &channel) |
Set the channel for both read and write operations. | |
PBoolean | Open (PChannel *channel, PBoolean autoDelete=true) |
Set the channel for both read and write operations. | |
PBoolean | Open (PChannel *readChannel, PChannel *writeChannel, PBoolean autoDeleteRead=true, PBoolean autoDeleteWrite=true) |
Set the channel for both read and write operations. | |
PChannel * | GetReadChannel () const |
Get the channel used for read operations. | |
bool | SetReadChannel (PChannel *channel, bool autoDelete=true, bool closeExisting=false) |
Set the channel for read operations. | |
PChannel * | GetWriteChannel () const |
Get the channel used for write operations. | |
PBoolean | SetWriteChannel (PChannel *channel, bool autoDelete=true, bool closeExisting=false) |
Set the channel for read operations. | |
![]() | |
PBoolean | SetErrorValues (Errors errorCode, int osError, ErrorGroup group=LastGeneralError) |
Set error values to those specified. | |
PChannel () | |
Create the channel. | |
~PChannel () | |
Close down the channel. | |
virtual PINDEX | HashFunction () const |
Calculate a hash value for use in sets and dictionaries. | |
int | GetHandle () const |
Get the integer operating system handle for the channel. | |
void | SetReadTimeout (const PTimeInterval &time) |
Set the timeout for read operations. | |
PTimeInterval | GetReadTimeout () const |
Get the timeout for read operations. | |
virtual PINDEX | GetLastReadCount () const |
Get the number of bytes read by the last Read() call. | |
virtual int | ReadChar () |
Read a single 8 bit byte from the channel. | |
PBoolean | ReadBlock (void *buf, PINDEX len) |
Read len bytes into the buffer from the channel. | |
PString | ReadString (PINDEX len) |
Read len character into a string from the channel. | |
virtual PBoolean | ReadAsync (void *buf, PINDEX len) |
Begin an asynchronous read from channel. | |
virtual void | OnReadComplete (void *buf, PINDEX len) |
User callback function for when a ReadAsync() call has completed or timed out. | |
void | SetWriteTimeout (const PTimeInterval &time) |
Set the timeout for write operations to complete. | |
PTimeInterval | GetWriteTimeout () const |
Get the timeout for write operations to complete. | |
virtual PBoolean | Write (const void *buf, PINDEX len, const void *mark) |
Low level write to the channel with marker. | |
virtual PINDEX | GetLastWriteCount () const |
Get the number of bytes written by the last Write() call. | |
PBoolean | WriteChar (int c) |
Write a single character to the channel. | |
PBoolean | WriteString (const PString &str) |
Write a string to the channel. | |
virtual PBoolean | WriteAsync (const void *buf, PINDEX len) |
Begin an asynchronous write from channel. | |
virtual void | OnWriteComplete (const void *buf, PINDEX len) |
User callback function for when a WriteAsync() call has completed or timed out. | |
virtual bool | FlowControl (const void *flowData) |
Flow Control information Pass data to the channel for flowControl determination. | |
PBoolean | SetBufferSize (PINDEX newSize) |
Set the iostream buffer size for reads and writes. | |
PBoolean | SendCommandString (const PString &command) |
Send a command meta-string. | |
void | AbortCommandString () |
Abort a command string that is in progress. | |
Errors | GetErrorCode (ErrorGroup group=NumErrorGroups) const |
Get normalised error code. | |
int | GetErrorNumber (ErrorGroup group=NumErrorGroups) const |
Get OS errro code. | |
virtual PBoolean | Read (const VectorOfSlice &slices) |
Low level scattered read from the channel. | |
virtual PBoolean | Write (const VectorOfSlice &slices) |
Low level scattered write to the channel. | |
![]() | |
virtual | ~PObject () |
virtual PObject * | Clone () const |
Create a copy of the class on the heap. | |
virtual const char * | GetClass (unsigned ancestor=0) const |
Get the current dynamic type of the object instance. | |
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. | |
virtual Comparison | CompareObjectMemoryDirect (const PObject &obj) const |
Determine the byte wise comparison of two objects. | |
bool | operator== (const PObject &obj) const |
Compare the two objects. | |
bool | operator!= (const PObject &obj) const |
Compare the two objects. | |
bool | operator< (const PObject &obj) const |
Compare the two objects. | |
bool | operator> (const PObject &obj) const |
Compare the two objects. | |
bool | operator<= (const PObject &obj) const |
Compare the two objects. | |
bool | operator>= (const PObject &obj) const |
Compare the two objects. | |
virtual void | PrintOn (ostream &strm) const |
Output the contents of the object to the stream. | |
virtual void | ReadFrom (istream &strm) |
Input the contents of the object from the stream. |
Static Public Member Functions | |
static const PCaselessString & | MimeVersionTag () |
static const PCaselessString & | FromTag () |
static const PCaselessString & | ToTag () |
static const PCaselessString & | CCTag () |
static const PCaselessString & | BCCTag () |
static const PCaselessString & | SubjectTag () |
static const PCaselessString & | DateTag () |
static const PCaselessString & | ReturnPathTag () |
static const PCaselessString & | ReceivedTag () |
static const PCaselessString & | MessageIDTag () |
static const PCaselessString & | MailerTag () |
static const PCaselessString & | ContentTypeTag () |
static const PCaselessString & | ContentDispositionTag () |
static const PCaselessString & | ContentTransferEncodingTag () |
Protected Member Functions | |
PBoolean | OnOpen () |
This callback is executed when the Open() function is called with open channels. |
Protected Attributes | |
PBoolean | writeHeaders |
PMIMEInfo | headers |
PBoolean | writePartHeaders |
PMIMEInfo | partHeaders |
PStringList | boundaries |
PBase64 * | base64 |
![]() | |
PChannel * | readChannel |
Channel for read operations. | |
PBoolean | readAutoDelete |
Automatically delete read channel on destruction. | |
PChannel * | writeChannel |
Channel for write operations. | |
PBoolean | writeAutoDelete |
Automatically delete write channel on destruction. | |
PReadWriteMutex | channelPointerMutex |
Race condition prevention on closing channel. | |
![]() | |
int | os_handle |
The operating system file handle return by standard open() function. | |
Errors | lastErrorCode [NumErrorGroups+1] |
The platform independant error code. | |
int | lastErrorNumber [NumErrorGroups+1] |
The operating system error number (eg as returned by errno). | |
PINDEX | lastReadCount |
Number of byte last read by the Read() function. | |
PINDEX | lastWriteCount |
Number of byte last written by the Write() function. | |
PTimeInterval | readTimeout |
Timeout for read operations. | |
PTimeInterval | writeTimeout |
Timeout for write operations. | |
PString | channelName |
PMutex | px_threadMutex |
PXBlockType | px_lastBlockType |
PThread * | px_readThread |
PThread * | px_writeThread |
PMutex | px_writeMutex |
PThread * | px_selectThread [3] |
PMutex | px_selectMutex [3] |
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;
PRFC822Channel::PRFC822Channel | ( | Direction | direction | ) |
Construct a RFC822 aware channel.
direction | /< Indicates are sending or receiving a message |
PRFC822Channel::~PRFC822Channel | ( | ) |
Close the channel before destruction.
|
static |
|
static |
|
virtual |
Close the channel.
This assures that all mime fields etc are closed off before closing the underliying channel.
Reimplemented from PIndirectChannel.
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
|
static |
|
static |
|
static |
|
static |
|
static |
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.
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.
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.
direction | Indicates are sending or receiving a message |
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.
|
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.
|
static |
|
static |
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.
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.
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.
bccAddress | Recipients e-mail address (comma separated) |
void PRFC822Channel::SetCC | ( | const PString & | ccAddress | ) |
Set the Carbon Copy address(es).
This must be called before any writes are done to the channel.
ccAddress | Recipients e-mail address (comma separated) |
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
filename | Attachment filename |
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".
contentType | Content type in form major/minor |
void PRFC822Channel::SetFromAddress | ( | const PString & | fromAddress | ) |
Set the sender address.
This must be called before any writes are done to the channel.
fromAddress | Senders e-mail address |
Set the and arbitrary header field.
This must be called before any writes are done to the channel.
name | MIME fields tag |
value | MIME fields contents |
void PRFC822Channel::SetSubject | ( | const PString & | subject | ) |
Set the message subject.
This must be called before any writes are done to the channel.
subject | Subject string |
void PRFC822Channel::SetToAddress | ( | const PString & | toAddress | ) |
Set the recipient address(es).
This must be called before any writes are done to the channel.
toAddress | Recipients e-mail address (comma separated) |
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.
encoding | Encoding type |
autoTranslate | Automatically convert to encoding type |
|
static |
|
static |
|
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.
buf | Pointer to a block of memory to write. |
len | Number of bytes to write. |
Reimplemented from PIndirectChannel.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |