![]() ![]() ![]()
|
BREW C++ Class Library & GUI Framework & XML Middleware : SophiaFramework 4.1 |

Procedure to receive a POP3 mail
![]() |
Precondition |
|---|---|
The POP3 server with the implementation of the UIDL command is required. | |
Example 479. The method to receive mails using the SFXPOP3Receiver class
class MyClass {
private:
SFXPOP3Receiver _receiver;
CALLBACK_DECLARE_SFXPOP3RECEIVER(POP3Callback)
public:
Void Start(Void);
};
Void MyClass::Start(Void)
{
// set IP address and port number of POP3 server (domain is automatically resolved)
_receiver.SetServer(SFXSocketAddress("pop3server.example.com:110"));
// set username and password
_receiver.SetAccount("user", "password");
// register POP3Callback as callback function, and then receive mails
// POP3Callback function is notified of completion of receiving mails
if ((error = _receiver.Receive(CALLBACK_FUNCTION(POP3Callback)))
!= SFERR_NO_ERROR) {
// callback will never be notifiled to POP3Callback function if error is not SFERR_NO_ERROR
// error handling for this case
.....
}
}
// callback function notified of completion of receiving mails
CALLBACK_IMPLEMENT_SFXPOP3RECEIVER(MyClass, POP3Callback, error)
{
SInt32 i;
if (error == SFERR_NO_ERROR) {
// succeed to receive mails
// get array of received mails
const SFXArray<SFXPOP3Receiver::MailInfoPtr>& mailArray =
receiver.GetReceivedMailArray();
// display mail
TRACE("received %d mails", mailArray.GetSize());
for (i = 0; i < mailArray.GetSize() ; i++) {
SFXPOP3Receiver::MailInfoPtr minfo = mailArray[i];
// display mail size, UIDL, mail message including mail header and mail body
TRACE("%d, %s, %s", minfo->size, minfo->uidl.GetCString(), minfo->mail.GetCString());
}
}
}
| Constructor/Destructor |
|---|
|
SFXPOP3Receiver( Void ) Constructor of SFXPOP3Receiver class.
|
|
~SFXPOP3Receiver( Void ) Destructor of SFXPOP3Receiver class.
|
| Public Functions | |
|---|---|
| Void |
Cancel( Void ) Cancel receiving POP3 mails.
|
| Void |
Clear( Void ) Initialize the instance of the SFXPOP3Receiver class.
|
| SFCError |
Delete(
CallbackSPP spp
, VoidPtr reference
) Delete( UidlArrayPtr targetUidlArray , Bool invertTarget , CallbackSPP spp , VoidPtr reference ) Delete( SFXAnsiStringConstRef uidl , CallbackSPP spp , VoidPtr reference ) Delete the mails.
|
| ProgressEnum |
GetProgress( Void ) Get the progress status of receiving POP3 mails.
|
| MailArrayConstRef |
GetReceivedMailArray( Void ) Get the array of received mails.
|
| UidlArrayConstRef |
GetReceivedUidlArray( Void ) Get the UIDL array of received mails.
|
| SFXPOP3Ref |
GetSFXPOP3( Void ) Get the instance of the SFXPOP3 class that is internally used.
|
| Bool |
GetSSLMode( Void ) Get the SSL connection mode.
|
| UInt32 |
GetTrustMode( Void ) Get the SSL trust mode.
|
| SFCError |
Receive(
CallbackSPP spp
, VoidPtr reference
) Receive( UidlArrayPtr targetUidlArray , Bool invertTarget , CallbackSPP spp , VoidPtr reference ) Receive( SFXAnsiStringConstRef targetUidl , CallbackSPP spp , VoidPtr reference ) Receive the mails.
|
| SFCError |
ReceiveAndDelete(
CallbackSPP spp
, VoidPtr reference
) ReceiveAndDelete( UidlArrayPtr targetUidlArray , Bool invertTarget , CallbackSPP spp , VoidPtr reference ) ReceiveAndDelete( SFXAnsiStringConstRef targetUidl , CallbackSPP spp , VoidPtr reference ) Receive the mails, and then delete them.
|
| SFCError |
SetAccount(
SFXAnsiStringConstRef user
, SFXAnsiStringConstRef password
, AuthEnum auth = AUTH_APOP_AND_USERPASS
) Set an account information (username and password).
|
| Void |
SetLimit(
UInt32 limit
) Set the number of mails that can be received at a time.
|
| Void |
SetNumberOfLines(
SInt32 number
) Set the number of lines when receiving mails.
|
| Void |
SetSSLMode(
Bool isSSL
) Set the SSL connection mode.
|
| Void |
SetServer(
SFXSocketAddressConstRef server
) Set the IP address and port number of the POP3 server.
|
| Void |
SetTrustMode(
UInt32 sslTrustMode
) Set the SSL trust mode.
|
| Types |
|---|
|
AuthEnum Constants that represent the POP3 authorization methods.
|
|
CallbackSPP Prototype of the callback function.
|
|
MailArray Type that represents the array of MailInfo structures obtained by the function.
|
|
MailInfo Structure that represents a received mail.
|
|
ProgressEnum Constants that show the progress status of receiving POP3 mails.
|
|
UidlArray Type that represents the mail array received by function.
|
[ public, explicit ] SFXPOP3Receiver(Void);
The resources necessary to receive POP3 mails are not allocated immediately after the SFXPOP3Receiver instance is created by this constructor. When calling the SFXPOP3Receiver::Receive or SFXPOP3Receiver::Delete function, those resources will be allocated.
[ public ] ~SFXPOP3Receiver(Void);
When receiving POP3 mails is in progress, release this instance after canceling it using the SFXPOP3Receiver::Cancel function.
[ public ] Void Cancel(Void);
Interrupt and end the POP3 mail receiving, then release all the allocated resource.
[ public ] Void Clear(Void);
Initialize the setting information on the POP3 server, the received mails, and the internal variables of the SFXPOP3Receiver instance.
[ public ] SFCError Delete( CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
[ public ] SFCError Delete( SFXAnsiStringConstRef uidl // UIDL of deleted mail CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
[ public ] SFCError Delete( UidlArrayPtr targetUidlArray // array of UIDL of deleted mails Bool invertTarget // whether or not to delete mails other than specified ones CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
UIDL of deleted mail.
Mail UIDL array that becomes the target. If null is set, all the mails in POP3 server are specified.
It is null by default.
Whether or not to delete mails other than the specified ones.
false: delete mails specified by targetUidlArray.
true: delete mails not specified by targetUidlArray.
Default: false.
![]() |
Result of deleteing POP3 mails |
|---|---|
The result of deleteing POP3 mails is notified to the callback function. It is not reflected in the return value of the SFXPOP3Receiver::Delete function. | |
![]() |
About UIDL (Unique-ID Listing) |
|---|---|
Detailed information: RFC1939 (Post Office Protocol - Version 3) | |
[ public, const ] ProgressEnum GetProgress(Void);
Return the progress status of receiving POP3 mails.
![]() |
About the return value of SFXPOP3Receiver::GetProgress function |
|---|---|
Detailed information: SFXPOP3Receiver::ProgressEnum | |
If receiving POP3 mails failed, call the SFXPOP3Receiver::GetProgress function in the callback function to get the stage where an error occurred.
[ public, const ] MailArrayConstRef GetReceivedMailArray(Void);
Return the SFXArray array of the SFXPOP3Receiver::MailInfo (pointers).
The SFXPOP3Receiver::GetReceivedMailArray function needs to be called after the SFXPOP3Receiver::Receive function.
SFXPOP3Receiver::MailInfo | SFXPOP3Receiver::Receive | SFXPOP3Receiver::GetReceivedUidlArray
[ public, const ] UidlArrayConstRef GetReceivedUidlArray(Void);
Return the UIDL array of received mails.
Get the UIDL array of received mails.
The SFXPOP3Receiver::GetReceivedUidlArray function needs to be called after the SFXPOP3Receiver::Receive function.
![]() |
About UIDL (Unique-ID Listing) |
|---|---|
Detailed information: RFC1939 (Post Office Protocol - Version 3) | |
[ public ] SFXPOP3Ref GetSFXPOP3(Void);
[ public, const ] Bool GetSSLMode(Void);
[ public, const ] UInt32 GetTrustMode(Void);
The SSL trust mode can be one of the following values.
![]() |
Note |
|---|---|
| Detailed information: ISSL_NegotiateV in the BREW API Reference | |
[ public ] SFCError Receive( CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
[ public ] SFCError Receive( SFXAnsiStringConstRef targetUidl // received UIDL of mail CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
[ public ] SFCError Receive( UidlArrayPtr targetUidlArray // array of UIDLs of received mails Bool invertTarget // whether or not to receive mail other than the specified ones CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
Specify the UIDL of the mail to be received.
array of the UIDLs of the mails to be received.
If null is set, it is regarded that all the mail in the POP3 server will be received.
This argument is null by default.
Whether or not to receive mails other than the specified ones.
false: receive mails specified by targetUidlArray.
true: receive mails not specified by targetUidlArray.
Default: false.
Get the received mails from the SFXPOP3Receiver::MailInfo array obtained by the SFXPOP3Receiver::GetReceivedMailArray function.
![]() |
Result of receiving POP3 mails |
|---|---|
Result of receiving POP3 mails is notified to the callback function. It is not reflected in the return value of the SFXPOP3Receiver::Receive function. | |
![]() |
About UIDL (Unique-ID Listing) |
|---|---|
Detailed information: RFC1939 ( Post Office Protocol - Version 3 ) | |
SFXPOP3Receiver::GetReceivedMailArray | SFXPOP3Receiver::Delete | SFXPOP3Receiver::MailInfo
[ public ] SFCError ReceiveAndDelete( CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
[ public ] SFCError ReceiveAndDelete( SFXAnsiStringConstRef targetUidl // UIDL of the mail to be received CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
[ public ] SFCError ReceiveAndDelete( UidlArrayPtr targetUidlArray // array of UIDLs of the mails to be received Bool invertTarget // whether or not to receive mails other than the specified ones CallbackSPP spp // callback function VoidPtr reference // data passed to callback function );
Specify the UIDL of the mail to be received.
array of the UIDLs of the mails to be received.
If null is set, it is regarded that all the mail in the POP3 server will be received.
This argument is null by default.
Whether or not to receive mails specified by targetUidlArray.
false: receive mails specified by targetUidlArray.
true: receive mails not specified by targetUidlArray.
Default: false.
To use the SFXPOP3Receiver::ReceiveAndDelete function is more efficient than to receive the mails by the SFXPOP3Receiver::Receive function and delete them by the SFXPOP3Receiver::Delete function.
Get the received mails from the SFXPOP3Receiver::MailInfo array obtained by the SFXPOP3Receiver::GetReceivedMailArray function.
![]() |
Result of receiving POP3 mails |
|---|---|
Result of receiving POP3 mails is notified to the callback function. It is not reflected in the return value of the SFXPOP3Receiver::Receive function. | |
![]() |
About UIDL (Unique-ID Listing) |
|---|---|
Detailed information: RFC1939 (Post Office Protocol - Version 3) | |
SFXPOP3Receiver::GetReceivedMailArray | SFXPOP3Receiver::Delete | SFXPOP3Receiver::MailInfo
[ public ] SFCError SetAccount( SFXAnsiStringConstRef user // username SFXAnsiStringConstRef password // password AuthEnum auth = AUTH_APOP_AND_USERPASS // authorization method );
Username.
Password.
Call the SFXPOP3Receiver::SetAccount function before the SFXPOP3Receiver::Receive or SFXPOP3Receiver::Delete function.
Set the number of mails to receive at a time.
Only the number of lines (set by the SetNumberOfLines function) from the head are received.
To use the SSL connection, set true to the isSSL parameter.
[ public ] Void SetServer( SFXSocketAddressConstRef server // IP address and port number of the POP3 server );
POP3 server's IP address and port number.
Call the SFXPOP3Receiver::SetServer function before the SFXPOP3Receiver::Receive, SFXPOP3Receiver::Delete, and SFXPOP3Receiver::ReceiveAndDelete functions.
SFXPOP3Receiver::SetAccount | SFXPOP3Receiver::Receive | SFXPOP3Receiver::Delete | SFXPOP3Receiver::ReceiveAndDelete
One of the following values are available for the SSL trust mode:
![]() |
Note |
|---|---|
| Detailed information: ISSL_NegotiateV in the BREW API Reference | |
enum AuthEnum {
AUTH_APOP_AND_USERPASS,
AUTH_ONLY_APOP,
AUTH_ONLY_USERPASS
};
To set the POP3 authorization method, use the SFXPOP3Receiver::SetAccount function.
The APOP authorization is performed. If failed, the username/password authorization is performed.
Only the APOP authorization is performed.
Only the username/password authorization is performed.
typedef Void(* SFXPOP3Receiver::CallbackSPP)(SFCError error, VoidPtr reference)
The SFXPOP3Receiver::CallbackSPP function is the callback function called when receiving POP3 mails is finished.
To register this function, use the SFXPOP3Receiver::Receive or SFXPOP3Receiver::Delete function.
The result of receiving POP3 mails is obtained in this callback function.
As for the 1st argument "error": SFERR_NO_ERROR will be set if receiving POP3 mails succeeds, but an error code other than SFERR_NO_ERROR will be set if it fails.
As for the 2nd argument "reference": Specify the "reference" argument of the SFXPOP3Receiver::Receive or SFXPOP3Receiver::Delete function (in general, instance of the SFXPOP3Receiver class).
SFMTYPEDEFALIAS(SFXArray<MailInfoPtr>, MailArray)
Similar to SFXArray<MailInfoPtr>.
struct MailInfo {
UInt32 size;
SFXAnsiString uidl;
SFXAnsiString mail;
};
The "size" variable is the size of the mail, the "uidl" variable is the UIDL of the mail, and the "mail" variable is the data of the mail.
The SFXPOP3Receiver::MailInfo structure is obtained by the SFXPOP3Receiver::GetReceivedMailArray function.
![]() |
Aboout UIDL (Unique-ID Listing) |
|---|---|
Detailed information: RFC1939 (Post Office Protocol - Version 3) | |
enum ProgressEnum {
PROGRESS_NONE,
PROGRESS_CONNECT,
PROGRESS_USER,
PROGRESS_PASS,
PROGRESS_LIST,
PROGRESS_UIDL,
PROGRESS_TOP,
PROGRESS_RETR,
PROGRESS_DELE,
PROGRESS_QUIT,
PROGRESS_DONE
};
Constants that show the progress status of receiving POP3 mail with the SFXPOP3Receiver.
The following values can be obtained using SFXPOP3Receiver::GetProgress function.
The connection is not started.
Connection to POP3 server is in progress.
Waiting for the response of the USER command.
Waiting for the response of the PASS command.
Waiting for the response of the LIST command.
Waiting for the response of the UIDL command.
Waiting for the response of the RETR command.
Waiting for the response of the TOP command.
Waiting for the response of the DELE command.
Waiting for the response of the QUIT command.
Receiving POP3 mails is finished.
SFMTYPEDEFALIAS(SFXArray<SFXAnsiStringPtr>, UidlArray)
Similar to SFXArray<SFXAnsiStringPtr>.
![]() |
About UIDL (Unique-ID Listing) |
|---|---|
Detailed information: RFC1939 (Post Office Protocol - Version 3) | |
|
Copyright (C) 2002 - 2009 Sophia Cradle, Inc. All Rights Reserved. |
![]() ![]() ![]()
|