📄 inetmail.h
字号:
protected:
BOOL OnOpen();
virtual void OnHELO(
const PCaselessString & remoteHost ///< Name of remote host.
);
// Start connection.
virtual void OnEHLO(
const PCaselessString & remoteHost ///< Name of remote host.
);
// Start extended SMTP connection.
virtual void OnQUIT();
// close connection and die.
virtual void OnHELP();
// get help.
virtual void OnNOOP();
// do nothing
virtual void OnTURN();
// switch places
virtual void OnRSET();
// Reset state.
virtual void OnVRFY(
const PCaselessString & name ///< Name to verify.
);
// Verify address.
virtual void OnEXPN(
const PCaselessString & name ///< Name to expand.
);
// Expand alias.
virtual void OnRCPT(
const PCaselessString & recipient ///< Name of recipient.
);
// Designate recipient
virtual void OnMAIL(
const PCaselessString & sender ///< Name of sender.
);
// Designate sender
virtual void OnSEND(
const PCaselessString & sender ///< Name of sender.
);
// send message to screen
virtual void OnSAML(
const PCaselessString & sender ///< Name of sender.
);
// send AND mail
virtual void OnSOML(
const PCaselessString & sender ///< Name of sender.
);
// send OR mail
virtual void OnDATA();
// Message text.
/** Handle an unknown command.
@return
TRUE if more processing may be done, FALSE if the
<A>ProcessCommand()</A> function is to return FALSE.
*/
virtual BOOL OnUnknown(
const PCaselessString & command ///< Complete command line received.
);
virtual void OnSendMail(
const PCaselessString & sender ///< Name of sender.
);
// Common code for OnMAIL(), OnSEND(), OnSOML() and OnSAML() funtions.
/** 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 <CODE>buffer</CODE>
parameter until either the end of the message or when the
<CODE>messageBufferSize</CODE> bytes have been read.
@return
TRUE if partial message received, FALSE if the end of the data was
received.
*/
virtual BOOL OnTextData(PCharArray & buffer, BOOL & completed);
/** 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 <CODE>buffer</CODE>
parameter until either the end of the message or when the
<CODE>messageBufferSize</CODE> bytes have been read.
@return
TRUE if partial message received, FALSE if the end of the data was
received.
*/
virtual BOOL OnMIMEData(PCharArray & buffer, BOOL & completed);
// Member variables
BOOL extendedHello;
BOOL eightBitMIME;
PString fromAddress;
PString fromPath;
PStringList toNames;
PStringList toDomains;
PINDEX messageBufferSize;
enum { WasMAIL, WasSEND, WasSAML, WasSOML } sendCommand;
StuffState endMIMEDetectState;
};
//////////////////////////////////////////////////////////////////////////////
// PPOP3
/** A TCP/IP socket for the Post Office Protocol version 3.
When acting as a client, the procedure is to make the connection to a
remote server, then to retrieve a message using the following procedure:
<PRE><CODE>
PPOP3Client mail("popserver");
if (mail.IsOpen()) {
if (mail.LogIn("Me", "password")) {
if (mail.GetMessageCount() > 0) {
PUnsignedArray sizes = mail.GetMessageSizes();
for (PINDEX i = 0; i < sizes.GetSize(); i++) {
if (mail.BeginMessage(i+1))
mail.Read(myMessage, sizes[i]);
else
PError << "Error getting mail message." << endl;
}
}
else
PError << "No mail messages." << endl;
}
else
PError << "Mail log in failed." << endl;
}
else
PError << "Mail conection failed." << endl;
</PRE></CODE>
When acting as a server, a descendant class would be created to override
at least the <A>HandleOpenMailbox()</A>, <A>HandleSendMessage()</A> and
<A>HandleDeleteMessage()</A> functions. Other functions may be overridden
for further enhancement to the sockets capabilities, but these will give a
basic POP3 server functionality.
The server socket thread would continuously call the
<A>ProcessMessage()</A> function until it returns FALSE. This will then
call the appropriate virtual function on parsing the POP3 protocol.
*/
class PPOP3 : public PInternetProtocol
{
PCLASSINFO(PPOP3, PInternetProtocol)
public:
enum Commands {
USER, PASS, QUIT, RSET, NOOP, STATcmd,
LIST, RETR, DELE, APOP, TOP, UIDL,
AUTH, NumCommands
};
protected:
PPOP3();
/** Parse a response line string into a response code and any extra info
on the line. Results are placed into the member variables
<CODE>lastResponseCode</CODE> and <CODE>lastResponseInfo</CODE>.
The default bahaviour looks for a space or a '-' and splits the code
and info either side of that character, then returns FALSE.
@return
Position of continuation character in response, 0 if no continuation
lines are possible.
*/
virtual PINDEX ParseResponse(
const PString & line ///< Input response line to be parsed
);
// Member variables
static PString okResponse;
static PString errResponse;
};
/** A TCP/IP socket for the Post Office Protocol version 3.
When acting as a client, the procedure is to make the connection to a
remote server, then to retrieve a message using the following procedure:
<PRE><CODE>
PPOP3Client mail;
if (mail.Connect("popserver")) {
if (mail.LogIn("Me", "password")) {
if (mail.GetMessageCount() > 0) {
PUnsignedArray sizes = mail.GetMessageSizes();
for (PINDEX i = 0; i < sizes.GetSize(); i++) {
if (mail.BeginMessage(i+1))
mail.Read(myMessage, sizes[i]);
else
PError << "Error getting mail message." << endl;
}
}
else
PError << "No mail messages." << endl;
}
else
PError << "Mail log in failed." << endl;
}
else
PError << "Mail conection failed." << endl;
</PRE></CODE>
*/
class PPOP3Client : public PPOP3
{
PCLASSINFO(PPOP3Client, PPOP3)
public:
/** Create a TCP/IP POP3 protocol socket channel. The parameterless form
creates an unopened socket, the form with the <CODE>address</CODE>
parameter makes a connection to a remote system, opening the socket. The
form with the <CODE>socket</CODE> parameter opens the socket to an
incoming call from a "listening" socket.
*/
PPOP3Client();
/** Destroy the channel object. This will close the channel and as a
client, QUIT from remote POP3 server.
*/
~PPOP3Client();
// Overrides from class PChannel.
/** Close the socket, and if connected as a client, QUITs from server.
@return
TRUE if the channel was closed and the QUIT accepted by the server.
*/
virtual BOOL Close();
// New functions for class.
enum LoginOptions
{
AllowUserPass = 1, ///< Allow the use of the plain old USER/PASS if APOP
///< or SASL are not available
UseSASL = 2, ///< Use SASL if the AUTH command is supported by
///< the server
AllowClearTextSASL = 4 ///< Allow LOGIN and PLAIN mechanisms to be used
};
/** Log into the POP server using the mailbox and access codes specified.
@return
TRUE if logged in.
*/
BOOL LogIn(
const PString & username, ///< User name on remote system.
const PString & password, ///< Password for user name.
int options = AllowUserPass ///< See LoginOptions above
);
/** Get a count of the number of messages in the mail box.
@return
Number of messages in mailbox or -1 if an error occurred.
*/
int GetMessageCount();
/** Get an array of a integers representing the sizes of each of the
messages in the mail box.
@return
Array of integers representing the size of each message.
*/
PUnsignedArray GetMessageSizes();
/** Get an array of a strings representing the standard internet message
headers of each of the messages in the mail box.
Note that the remote server may not support this function, in which
case an empty array will be returned.
@return
Array of strings continaing message headers.
*/
PStringArray GetMessageHeaders();
/* Begin the retrieval of an entire message. The application may then use
the <A>PApplicationSocket::ReadLine()</A> function with the
<CODE>unstuffLine</CODE> parameter set to TRUE. Repeated calls until
its return valus is FALSE will read the message headers and body.
@return
Array of strings continaing message headers.
*/
BOOL BeginMessage(
PINDEX messageNumber
/** Number of message to retrieve. This is an integer from 1 to the
maximum number of messages available.
*/
);
/** Delete the message specified from the mail box.
@return
Array of strings continaing message headers.
*/
BOOL DeleteMessage(
PINDEX messageNumber
/* Number of message to retrieve. This is an integer from 1 to the
maximum number of messages available.
*/
);
protected:
BOOL OnOpen();
// Member variables
BOOL loggedIn;
PString apopBanner;
};
/** A TCP/IP socket for the Post Office Protocol version 3.
When acting as a server, a descendant class would be created to override
at least the <A>HandleOpenMailbox()</A>, <A>HandleSendMessage()</A> and
<A>HandleDeleteMessage()</A> functions. Other functions may be overridden
for further enhancement to the sockets capabilities, but these will give a
basic POP3 server functionality.
The server socket thread would continuously call the
<A>ProcessMessage()</A> function until it returns FALSE. This will then
call the appropriate virtual function on parsing the POP3 protocol.
*/
class PPOP3Server : public PPOP3
{
PCLASSINFO(PPOP3Server, PPOP3)
public:
/** Create a TCP/IP POP3 protocol socket channel. The parameterless form
creates an unopened socket, the form with the <CODE>address</CODE>
parameter makes a connection to a remote system, opening the socket. The
form with the <CODE>socket</CODE> parameter opens the socket to an
incoming call from a "listening" socket.
*/
PPOP3Server();
// New functions for class.
/** Process commands, dispatching to the appropriate virtual function. This
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -