CPop3Connection
v1.19
Welcome to CPop3Connection, a freeware MFC class to support the POP3 protocol. POP3 for those not familiar with all the internet protocols is the protocol used to retrieve internet email.
For detailed information about the Post Office Protocol Version 3 you should read RFC 1725. You should also refer to RFC 822 which contains details on the layout of messages.
You can find numerous Web Servers which carry these documents by going to www.yahoo.com and look for RFC and 1725 or 822.
Features |
Usage |
History |
API Reference |
Planned Enhancements |
Contacting the Author |
V1.0 (18th May 1998)
V1.1 (28th June 1998)
V1.11 (4th January 1999)
V1.12 (22nd February 1999)
V1.13 (25th March 1999)
V1.14 (15th June 1999)
V1.15 (16th June 1999)
V1.16 (27th June 1999)
V1.17 (29th June 1999)
V1.18 (5th July 1999)
V1.19 (24th August 1999)
The API consists of the public member functions of the class CPop3Connection & CPop3Message
CPop3Connection::Connect
CPop3Connection::Disconnect
CPop3Connection::Statistics
CPop3Connection::Delete
CPop3Connection::GetMessageSize
CPop3Connection::GetMessageID
CPop3Connection::Retrieve
CPop3Connection::Reset
CPop3Connection::UIDL
CPop3Connection::GetMessageHeader
CPop3Connection::Noop
CPop3Connection::GetLastCommandResponse
CPop3Connection::GetTimeout
CPop3Connection::SetTimeout
CPop3Message::GetMessageText
CPop3Message::GetHeader
CPop3Message::GetHeaderItem
CPop3Message::GetBody
CPop3Message::GetReplyTo
CPop3Message::GetRawBody
CPop3Message::GetSubject
CPop3Message::GetFrom
CPop3Message::GetDate
BOOL CPop3Connection::Connect(LPCSTR pszHostName, LPCSTR pszUser, LPCSTR pszPassword, int nPort = 110);
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call ::GetLastError.
Parameters
pszHostName The network address of the socket to connect to: a machine name such as mail.yourisp.com, or a dotted number such as 128.56.22.8.
pszUser This is the POP3 user name of the mailbox.
pszPassword This is the password for the POP3 mailbox.
nPort This is the port number on which to connect. The default value is 110 which is the default POP3 port number.
Remarks
Call this member function to establish a connection to a POP3 mailbox.
See Also
BOOL CPop3Connection::Disconnect();
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call ::GetLastError.
Parameters
None.
Remarks
The corollary function of Connect.
See Also
BOOL CPop3Connection::Statistics(int& nNumberOfMails, int& nTotalMailSize);
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call ::GetLastError.
Parameters
nNumberOfMails Upon a successful return this will contain the number of mails waiting in the mailbox.
nTotalMailSize Upon a successful return this will contain the size in bytes (aka Octets) of all mails waiting in the mailbox.
Remarks
Retrieves the statistics for the Mailbox by issuing the "STAT" command.
See Also
CPop3Connection::GetMessageSize
BOOL CPop3Connection::Delete(int nMsg);
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call ::GetLastError.
Parameters
nMsg The message number of the message to delete. This value starts at 1.
Remarks
Marks a message as "to be deleted" by issuing the "DELE" command.
See Also
CPop3Connection::GetMessageSize
BOOL CPop3Connection::GetMessageSize(int nMsg, DWORD& dwSize);
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call ::GetLastError.
Parameters
nMsg The message number of the message to retrieve the size of.
dwSize Upon a successful return this will contain the size in bytes of the specified message.
Remarks
Retrieves the size of a specified message. Internally this will issue the "LIST" command if required.
See Also
BOOL CPop3Connection::GetMessageID(int nMsg, CString& sID);
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call ::GetLastError.
Parameters
nMsg The message number of the message to retrieve the ID of.
sID Upon a successful return this will contain the ID of the specified message as a string.
Remarks
Retrieves the ID of a specified message. Internally this will issue the "UIDL" command if required. As "UIDL" is an optional POP3 command, your client app should handle the return value if it is to correctly work on all POP3 servers.
See Also
BOOL CPop3Connection::Retrieve(int nMsg, CPop3Message& message);
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call ::GetLastError.
Parameters
nMsg The message number of the message to retrieve the size of.
message Upon a successful return this will contain the POP3 messages.
Remarks
Retrieves the specified message by issuing the "RETR" command.
See Also
CPop3Connection::GetMessageSize
CPop3Connection::GetMessageHeader
BOOL CPop3Connection::GetMessageHeader(int nMsg, CPop3Message& message);
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call ::GetLastError.
Parameters
nMsg The message number of the message to retrieve the header of.
sID Upon a successful return this will contain the POP3 messages.
Remarks
Retrieves the header of a specified message. Internally this will issue the "TOP" command if required. As "TOP" is an optional POP3 command, your client app should handle the return value if it is to correctly work on all POP3 servers.
See Also
BOOL CPop3Connection::Reset();
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call ::GetLastError.
Parameters
None.
Remarks
Resets all messages which were previously marked as deleted. i.e. it undoes the work of all the DELE commands in this session. For further information about how messages are deleted in POP3, please refer to the RFC.
See Also
BOOL CPop3Connection::UIDL();
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call ::GetLastError.
Parameters
None.
Remarks
Sends the "UIDL" command which retrieves the ID for a specified message. As "UIDL" is an optional POP3 command, your client app should handle the return value if it is to correctly work on all POP3 servers.
See Also
BOOL CPop3Connection::Noop();
Return Value
If the function succeeds, the return value is TRUE. If the function fails, the return value is FALSE. To get extended error information, call ::GetLastError.
Parameters
None.
Remarks
Issues a "NOOP" command to the server.
CPop3Connection::GetLastCommandResponse
CString CPop3Connection::GetLastCommandResponse() const;
Return Value
The last command response from the server as a CString.
Parameters
None.
Remarks
The CPop3Connection class can return additional text information along with most errors. This extended error information can be retrieved by using the GetLastCommandResponse function after an unsuccessful function call. An example of this is if the Connect function failed because of a validation problem, GetLastCommandResponse could return something like "-ERR Access is denied". GetLastCommandResponse can be called multiple times until another CPop3Connection function is called which sends a POP3 command.
DWORD CPop3Connection::GetTimeout() const;
Return Value
The timeout in milliseconds which the code will wait for responses from the POP3 server.
Parameters
None.
Remarks
Since CPop3Connection provides a synchronous API, a timeout mechanism is provided. By default the value is 2 seconds in release mode and 20 seconds in debug mode. The value is larger in debug mode so that the code does not time out when you are debugging it.
See Also
void CPop3Connection::SetTimeout(DWORD dwTimeout) const;
Return Value
None.
Parameters
dwTimeout The new timeout value in milliseconds.
Remarks
Sets the timeout to use for connections to the POP3 server.
See Also
LPCSTR CPop3Message::GetMessageText() const;
Return Value
A character pointer to the actual message text this class instance represents.
Parameters
None.
Remarks
Upon a successful call to CPop3Connection::Retrieve, the message class will contain a message. This function allows the text to of the message to be accessed.
See Also
CString CPop3Message::GetHeader() const;
Return Value
A CString containing the header of this message
CString CPop3Message::GetBody() const;
Return Value
A CString containing the body of this message
CString CPop3Message::GetHeaderItem(const CString& sName, int nItem = 0) const;
Return Value
A CString containing the header body of the header field
Remarks
This function allows a specific message header line to be retrieved e.g you could call the function with sName set to "Date" to find the date the mail message was sent at. The return value is a CString which follows the internet convention for that particular header. The nItem parameter allows you to specify that the n'th occurrence of the header field be returned.
CString CPop3Message::GetReplyTo() const;
Return Value
A CString containing the Reply to field
Remarks
Returns the most appropriate address for replies. Looks first for Reply-To, then From, then Sender, then Return-Path as a last resort, returns the first one of the above that is non-empty.
LPCSTR CPop3Message::GetRawBody() const;
Return Value
A const char pointer to the raw message body
CString CPop3Message::GetSubject() const;
Return Value
A CString containing the subject of the message
Remarks
Returns the subject of the message.
CString CPop3Message::GetFrom() const;
Return Value
A CString containing the sender of the message
Remarks
Returns the sender of the message.
CString CPop3Message::GetDate() const;
Return Value
A CString containing the "Date:" header of the message
Remarks
Returns the "Date:" header of the message.
PJ Naughter
Email: pjn@indigo.ie
Web: http://indigo.ie/~pjn
24th August 1999