OScript API/Built-in Package Index

Class: POP3Session

The built-in functions in the POP3Session class provide the ability to connect to a POP3 server with a variety of methods and retrieve email and send POP3 commands.

The POP3Session class offers the following functionality:

Instance Attributes

List messages by IDs

List messages by UIDs

Login with username and password

Login with OAuth2 token

The standard POP3 port, 110

The standard Secure POP3 port, 995

Class Methods

New( String host, Integer port )

Returns a new POP3Session instance, or undefined if an error occured.

NewSSL( String host, Integer port, SSLOptions options )

Returns a new POP3Session instance using a SSL socket, or undefined if an error occured.

Instance Methods

Close( )

Close a connection to an POP3 server.

DeleteMessage( Dynamic messageIndex )

deletes a message from the POP3 server.

Retrieve the a string for the last error code.

GetMessageTable( Integer listType )

Retrieves a table of message IDs from the POP3 server.

Returns the POP3 timeout in milliseconds.

GetUID( Integer messageIndex )

retrieves a UID for a message on the POP3 server.

InitContext( SSLOptions options )

Used to initialize a security context for SecureLogin().

ListMessage( Dynamic messageIndex )

retrieves the size of a message from the POP3 server.

ListMessages( Integer listType )

retrieves a list of messages from the POP3 server.

Login( String username, String password, [Integer loginMethod] )

Initiate a connection to an POP3 server.

returns the number of messages for the logged in account.

RetrieveHeader( Dynamic messageIndex )

retrieves a message header from the POP3 server.

RetrieveHeaderAssoc( Dynamic messageIndex )

retrieves a message header from the POP3 server.

RetrieveMessage( Dynamic messageIndex )

retrieves a message from the POP3 server.

SecureLogin( String username, String password, [Integer loginMethod] )

Initiate a secure connection to an POP3 server.

SendCommand( String command, String arguments )

Sends raw POP3 commands.

Determines if the server supports the UIDL command.

SetTimeout( Integer timeout )

Set POP3 timeout in milliseconds.

Instance Attributes

Integer LIST_BY_IDS

List messages by IDs

Integer LIST_BY_UIDS

List messages by UIDs

Integer LOGIN_PLAIN

Login with username and password

Integer LOGIN_XOAUTH2

Login with OAuth2 token

Integer POP3_PORT

The standard POP3 port, 110

The standard Secure POP3 port, 995

Class Methods

New

POP3Session New( String host,
                 Integer port )

Returns a new POP3Session object

Parameters

host

IP address or domain name of POP3 host.

port

POP3 connection port, optional and defaults to 110

Returns:

A new POP3Session object or undefined if there was an error constructing the object.

NewSSL

POP3Session NewSSL( String host,
                    Integer port,
                    SSLOptions options )

Returns a new POP3Session object using a SSL socket.

Parameters

host

IP address or domain name of POP3 host.

port

POP3 connection port, optional and defaults to 110

options

SSL options

Returns:

A new POP3Session object using a SSL socket or undefined if there was an error constructing the object.

Instance Methods

Close

Integer Close()

No parameters. Closes the session.

Returns:

Returns 0 for success and -1 if an error occurred.

DeleteMessage

Integer DeleteMessage( Dynamic messageIndex )

The messageIndex parameter can be either an Integer ID or a String UID. Marks the specified message for deletion on the server.

Parameters

messageIndex

either an Integer ID or a String UID of the message to retrieve

Returns:

Returns 0 if successful, -1 if any errors occurred.

GetLastError

String GetLastError()

No parameters. Returns an error string for the last error that occured.

Returns:

Returns an error string for the last error that occured.

GetMessageTable

RecArray GetMessageTable( Integer listType )

If listType is not specified or LIST_BY_IDS, then it returns a RecArray of message IDs and sizes. If listType is LIST_BY_UIDS, then it returns a RecArray of the message ids and their UID strings, one after the other.

Parameters

listType

type of list to return, either LIST_BY_IDS, or LIST_BY_UIDS.

Returns:

Returns a table of ids.

GetTimeout

Integer GetTimeout()

Gets the timeout value for POP3 commands. The timeout is in milliseconds.

Returns:

Returns the timeout in milliseconds, -1 if an error occured.

GetUID

String GetUID( Integer messageIndex )

Returns the UID for the given message. If no message exists, returns and empty string.

Parameters

messageIndex

ID of the message to retrieve

Returns:

Returns the UID for the given message. If no message exists, returns and empty string.

InitContext

Integer InitContext( SSLOptions options )

Sets the SSL options for a secure connection. You must call this before attempting to do a SecureLogin() call.

Parameters

options

an instance of SSLOptions.

Returns:

Returns 0 for success and -1 if an error occurred.

ListMessage

Integer ListMessage( Dynamic messageIndex )

The messageIndex parameter can be either an Integer ID or a String UID.
Returns the size of the message specified by mesgIndex or -1 if any errors occurred.

Parameters

messageIndex

either an Integer ID or a String UID of the message to retrieve

Returns:

Returns the size of the message specified by mesgIndex or -1 if any errors occurred.

ListMessages

List ListMessages( Integer listType )

If listType is not specified or LIST_BY_IDS, then it returns a List of the message ids and sizes, one after the other. i.e. {1,234,2,3435,3,5430}.

If listType is LIST_BY_UIDS, then it returns a List of the message ids and their UID strings, one after the other, i.e., {1,34DF32EAC3,2,64EA32EDC3,3,354456CAE3}.

The return value will be Undefined if the server returned an error.

Parameters

listType

type of list to return, either LIST_BY_IDS, or LIST_BY_UIDS.

Returns:

Returns a list of ids.

Login

Integer Login( String username,
               String password,
               [Integer loginMethod] )

The client will check server capabilities and authenticate using CRAM-MD5 if available automatically, otherwise, it will login with CLEAR.

Parameters

username

username used to login to POP3 server.

password

user password or authentication token for POP3 server.

loginMethod

type of login authentication to use: either POP3Session.LOGIN_PLAIN or POP3Session.LOGIN_XOAUTH2.

Returns:

Returns 1 for success and 0 if an error occurred.

MessageCount

Integer MessageCount()

No parameters. Returns the number of messages for the logged in user on the POP3 server.

Returns:

Returns the number of messages for the logged in user on the POP3 server.

RetrieveHeader

List RetrieveHeader( Dynamic messageIndex )

The messageIndex parameter can be either an Integer ID or a String UID.

Returns a List composed of the key/value string pairs found in the header of the given message.

The return value will be Undefined if no message exists at that index. i.e. key1, value1, key2, value2, etc.

Parameters

messageIndex

either an Integer ID or a String UID of the message to retrieve

Returns:

Returns a List for the given messageIndex. The return value will be Undefined if no message exists at that index.

RetrieveHeaderAssoc

Assoc RetrieveHeaderAssoc( Dynamic messageIndex )

The messageIndex parameter can be either an Integer ID or a String UID.

Returns an Assoc composed of the key/value string pairs found in the header of the given message.

The return value will be Undefined if no message exists at that index.

Parameters

messageIndex

either an Integer ID or a String UID of the message to retrieve

Returns:

Returns an Assoc for the given messageIndex. The return value will be Undefined if no message exists at that index.

RetrieveMessage

MailMessage RetrieveMessage( Dynamic messageIndex )

The messageIndex parameter can be either an Integer ID or a String UID.

Returns a MailMessage class for the given messageIndex.

The return value will be Undefined if no message exists at that index.

Parameters

messageIndex

either an Integer ID or a String UID of the message to retrieve

Returns:

Returns a MailMessage class for the given mesgIndex. The return value will be Undefined if no message exists at that index.

SecureLogin

Integer SecureLogin( String username,
                     String password,
                     [Integer loginMethod] )

Does an SSL secure login. You must have called InitContext() before this.

Parameters

username

user login on POP3 server.

password

user password or authentication token for POP3 server.

loginMethod

type of login authentication to use: either LOGIN_PLAIN or LOGIN_XOAUTH2.

Returns:

Returns 0 for success and -1 if an error occurred.

SendCommand

Integer SendCommand( String command,
                     String arguments )

Use this to send other raw POP3 commands. The arguments param is optional.

Parameters

command

command to send

arguments

command arguments to send

Returns:

Returns 0 for success and -1 if an error occurred.

ServerHasUIDs

Boolean ServerHasUIDs()

Determines if the server supports the UIDL command that is used to list messages by UID.

Returns:

TRUE if the server supports the UIDL command, FALSE otherwise. If support cannot be determined, then the return value will be Undefined.

SetTimeout

Integer SetTimeout( Integer timeout )

Sets the timeout value for POP3 commands. The timeout is in milliseconds.

Parameters

timeout

timeout in milliseconds.

Returns:

Returns 0 for success and -1 if an error occurred.

 Copyright © 2022 OpenText Corporation. All rights reserved.