SophiaFramework UNIVERSE 5.3 |
Procedure to receive a POP3 mail
Precondition | |
---|---|
The POP3 server with the implementation of the UIDL command is required. |
Example 828. The method to receive mails using the SFXPOP3Receiver class
class MyClass { private: SFXPOP3Receiver _receiver; XALLBACK_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 the completion of receiving mails if ((error = _receiver.Receive(XALLBACK_INTERNAL(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 the completion of receiving mails XALLBACK_IMPLEMENT_SFXPOP3RECEIVER(MyClass, POP3Callback, error) { SInt32 i; if (error == SFERR_NO_ERROR) { // succeed to receive mails // get array of received mails SFXPOP3Receiver::MailArrayConstRef 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 the SFXPOP3Receiver class.
|
~SFXPOP3Receiver( Void ) Destructor of the SFXPOP3Receiver class.
|
Public Functions | |
---|---|
Void |
Cancel( Void ) Cancel receiving POP3 mails.
|
Void |
Clear( Void ) Initialize the SFXPOP3Receiver instance.
|
SFCError |
Delete(
CallbackSPP spp
, VoidPtr reference
) Delete the mails.
|
SFCError |
Delete(
SFXAnsiStringConstRef uidl
, CallbackSPP spp
, VoidPtr reference
) Delete the mails.
|
SFCError |
Delete(
UidlArrayPtr targetUidlArray
, Bool invertTarget
, CallbackSPP spp
, VoidPtr reference
) Delete the mails.
|
Bool |
GetAutoDelete( Void ) Get the value of flag indicating whether or not to delete the mail when receiving it.
|
ProgressEnum |
GetProgress( Void ) Get the progress status of receiving POP3 mails.
|
MailArrayConstRef |
GetReceivedMailArray( Void ) Get the array of received mails.
|
SFXPOP3Ref |
GetSFXPOP3( Void ) Get the SFXPOP3 instance 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 the mails.
|
SFCError |
Receive(
SFXAnsiStringConstRef targetUidl
, CallbackSPP spp
, VoidPtr reference
) Receive the mails.
|
SFCError |
Receive(
UidlArrayPtr targetUidlArray
, Bool invertTarget
, CallbackSPP spp
, VoidPtr reference
) Receive the mails.
|
SFCError |
SetAccount(
SFXAnsiStringConstRef user
, SFXAnsiStringConstRef password
, AuthEnum auth = AUTH_APOP_AND_USERPASS
) Set an account information (username and password).
|
Void |
SetAutoDelete(
Bool isAutoDelete
) Set the flag indicating whether or not to delete the mail when receiving it.
|
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 Type that represents the callback function to notify the completion of the POP3 mail receiving.
|
MailArray Type that represents the array of MailInfo structures obtained by the SFXPOP3Receiver::GetReceivedMailArray function.
|
MailInfo Structure that represents a received mail.
|
ProgressEnum Constants that show the progress status of receiving POP3 mails.
|
UidlArray Type that represents an array of unique identifiers.
|
[ public, explicit ] SFXPOP3Receiver(Void);
This constructor does the initialization as follows:
Note | |
---|---|
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. |
SFXPOP3Receiver::Receive | SFXPOP3Receiver::Delete | SFXPOP3Receiver::SetAutoDelete | SFXPOP3Receiver::SetAccount | SFXPOP3Receiver::SetLimit | SFXPOP3Receiver::SetNumberOfLines | SFXPOP3Receiver::SetSSLMode | SFXPOP3Receiver::SetTrustMode | SFXPOP3Receiver::ProgressEnum | SFXPOP3Receiver::AuthEnum
[ public ] ~SFXPOP3Receiver(Void);
This destructor calls the SFXPOP3Receiver::Cancel function to cancel the POP3 mail receiving.
[ public ] Void Cancel(Void);
Interrupt and end the POP3 mail receiving, then release all the allocated resource.
SFXPOP3Receiver::Receive | SFXPOP3Receiver::Delete | SFXPOP3::Close | SFXPOP3Receiver::Clear | SFXPOP3Receiver::~SFXPOP3Receiver | SFXPOP3Receiver::ProgressEnum
[ public ] Void Clear(Void);
Initialize the setting information on the POP3 server, the received mails, and the internal variables of the SFXPOP3Receiver instance.
Note | |
---|---|
This function is called in the SFXPOP3Receiver::Cancel function internally. |
[ 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) | |
---|---|
Reference: RFC1939 (Post Office Protocol - Version 3) |
[ public, const ] Bool GetAutoDelete(Void);
[ public, const ] ProgressEnum GetProgress(Void);
Return the progress status of receiving POP3 mails.
About the return value of SFXPOP3Receiver::GetProgress function | |
---|---|
Reference: 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 array of received mail messages(SFXPOP3Receiver::MailArray).
This function needs to be called in the callback specified in the spp argument of the SFXPOP3Receiver::Receive function.
[ 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 | |
---|---|
Reference: 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) | |
---|---|
Reference: RFC1939 ( Post Office Protocol - Version 3 ) |
SFXPOP3Receiver::GetReceivedMailArray | SFXPOP3Receiver::Delete | SFXPOP3Receiver::MailInfo | SFXPOP3Receiver::SFXPOP3Receiver
[ 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.
SFXPOP3Receiver::SetServer | SFXPOP3Receiver::Receive | SFXPOP3Receiver::Delete | SFXPOP3Receiver::AuthEnum
This function sets the flag indicating whether or not to delete the mail when receiving it using the SFXPOP3Receiver::Receive function.
Default: false
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 this function before the SFXPOP3Receiver::Receive, SFXPOP3Receiver::Delete, and SFXPOP3Receiver::SetAutoDelete functions.
SFXPOP3Receiver::Receive | SFXPOP3Receiver::Delete | SFXPOP3Receiver::SFXPOP3Receiver | SFXSocketAddress
One of the following values are available for the SSL trust mode:
Note | |
---|---|
Reference: ISSL_NegotiateV in the BREW API Reference |
SFXPOP3Receiver::Cancel | SFXPOP3Receiver::SFXPOP3Receiver | SFXSSLSocket::SetTrustMode | BREW API ISSL_NegotiateV
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)
This function prototype represents 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.
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.
For the 2nd argument "reference": Specify the "reference" argument of the SFXPOP3Receiver::Receive or SFXPOP3Receiver::Delete function (in general, instance of the SFXPOP3Receiver class).
SFXPOP3Receiver | SFXPOP3Receiver::Delete | SFXPOP3Receiver::GetReceivedMailArray | SFXPOP3Receiver::GetProgress
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.
This structure is obtained by the SFXPOP3Receiver::GetReceivedMailArray function.
Aboout UIDL (Unique-ID Listing) | |
---|---|
Reference: 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) | |
---|---|
Reference: RFC1939 (Post Office Protocol - Version 3) |
Copyright(c) 2002 - 2024 Sophia Cradle Incorporated All Rights Reserved. |