Class MailServer

Description

The MailServer Module

This module provides a simple wrapper around PHP's IMAP library while adding some functionality to make interacting with the mail server as easy as possible.

This module can be used by other modules as follows:-

  • Copy module file to module directory
  • Adjust configuration file as needed (see further below on configuration file requirements)
  • In any action run:
  • $this->exec_module_action('MailServer', 'action')
The MailServer module requires the following entries in the configuration file.

[mailserver] hostname = imap.server.com : Name of the email host to connect to port = number : Port number to connect to for the above host root = Mail/ : Root folder on the server secure = true/false : Set to true to never send password as plain text ssl = true/false : Set to true to connect using SSL novalidate-cert = true/false : Set to true if no need to validate the server certificate tls = true/false : Set to true to force usage of tls notls = true/false : Set to true to not use tls even if available on server

The defaults are as below: [mailserver] hostname = localhost port = 143 root = '' secure = false ssl = false novalidate-cert = false tls = false notls = false

Located in /modules/MailServer.php (line 38)

Module
   |
   --MailServer
Variable Summary
Method Summary
MailServer MailServer ()
resource connect (string $username, string $password)
void copy_messages (string $message_uids, string $mailbox_name)
void create_mailbox (string $mailbox_name)
void delete_mailbox (string $mailbox_name)
void delete_messages (string $message_uids)
void disconnect ()
void expunge ()
array get_all_messages ()
array get_mailboxes ()
array get_mailbox_status ([string $mailbox_name = 'INBOX'])
void get_message_parts ( $message_uid)
string get_raw_headers (int $message_uid)
void mark_messages_as_read (string $message_uids)
void mark_messages_as_unread (string $message_uids)
void move_messages (string $message_uids, string $mailbox_name)
void open_mailbox ([string $mailbox_name = 'INBOX'])
void register ()
void rename_mailbox (string $mailbox_name, string $new_mailbox_name)
void subscribe_mailbox (string $mailbox_name)
void undelete_messages (string $message_uids)
void unsubscribe_mailbox (string $mailbox_name)
Variables
resource $connection = null (line 56)
  • var: Connection to the server
string $current_mailbox = '' (line 66)
  • var: Name of the mailbox currently opened
string $current_user = '' (line 61)
  • var: Name of the user currently logged in to the server
array $server_config = array(
'hostname' => 'localhost',
'port' => 143,
'root' => '',
'secure' => false,
'ssl' => false,
'novalidate-cert' => false,
'tls' => false,
'notls' => false
)
(line 42)
  • var: Connection information loaded from the configuration file

Inherited Variables

Inherited from Module

Module::$application
Module::$controller
Module::$database
Module::$error
Module::$error_strings
Module::$exceptions
Module::$output
Module::$queries
Module::$sql
Module::$template_file
Module::$use_render
Module::$use_template_library
Module::$use_view
Methods
Constructor MailServer (line 76)

Constructor for the email server module

The constructor registers all error messages used by this module.

MailServer MailServer ()
connect (line 123)

Connect to the server in a half-open mode (don't select any mailbox)

Connect to the server using the username and password specified. This action should be invoked from another module before executing any other actions.

Function loads the configuration from config file.

  • return: Returns the server connection
resource connect (string $username, string $password)
  • string $username: Username to connect to the server with
  • string $password: Password to authenticate with
copy_messages (line 517)

Copy the specified messages to the specified mailbox

void copy_messages (string $message_uids, string $mailbox_name)
  • string $message_uids: One or more message uids, comma separated
  • string $mailbox_name: Mailbox to copy the messages to
create_mailbox (line 213)

Create the specified mailbox

void create_mailbox (string $mailbox_name)
  • string $mailbox_name: Name of the mailbox to create
delete_mailbox (line 254)

Delete the specified mailbox

void delete_mailbox (string $mailbox_name)
  • string $mailbox_name: Name of the mailbox to delete
delete_messages (line 612)

Delete specified messages

void delete_messages (string $message_uids)
  • string $message_uids: One or more message uids, comma separated, to delete
disconnect (line 172)

Disconnect from the current server if connected

void disconnect ()
expunge (line 158)

Expunge currently selected mailbox

Select a mailbox using $this->open_mailbox($mailbox_name);

void expunge ()
get_all_messages (line 404)

Get all the message headers for the current mailbox

The object returned has several members which are documented here: http://www.php.net/manual/en/function.imap-headerinfo.php

The Msgno member value is replaced with the message UID instead.

  • return: Returns an array of message header associative arrays with multiple fields
array get_all_messages ()
get_configuration (line 88)

Get the configuration from config file

Load all configuration items under section 'mailserver' in the main configuration file. Default values selected are described in the module description.

void get_configuration ()
get_mailboxes (line 273)

Get all mailboxes for current connection

  • return: Returns an array of mailbox name strings
array get_mailboxes ()
get_mailbox_status (line 329)

Get the status information for the specified mailbox

  • return: Returns an associative array with fields 'num_messages', 'num_recent', 'num_unseen' and 'uid_validity'
array get_mailbox_status ([string $mailbox_name = 'INBOX'])
  • string $mailbox_name: Name of the mailbox, default INBOX
get_message_parts (line 494)
void get_message_parts ( $message_uid)
  • $message_uid
get_raw_headers (line 478)

Get the raw headers for the specified message uid

  • return: Returns a string containing all the header information
string get_raw_headers (int $message_uid)
  • int $message_uid: The message uid to pull headers for
get_subscribed_mailboxes (line 300)

Get only subscribed mailboxes for current connection

  • return: Returns an array of mailbox name strings
array get_subscribed_mailboxes ()
mark_messages_as_read (line 568)

Mark specified messages as read

void mark_messages_as_read (string $message_uids)
  • string $message_uids: One or more message uids, comma separated, to mark as read
mark_messages_as_unread (line 590)

Mark specified messages as unread

void mark_messages_as_unread (string $message_uids)
  • string $message_uids: One or more message uids, comma separated, to mark as unread
move_messages (line 543)

Move the specified messages to the specified mailbox

void move_messages (string $message_uids, string $mailbox_name)
  • string $message_uids: One or more message uids, comma separated
  • string $mailbox_name: Mailbox to move the messages to
open_mailbox (line 192)

Open the specified mailbox

Call $this->connect($username, $password ) before calling this function

void open_mailbox ([string $mailbox_name = 'INBOX'])
  • string $mailbox_name: Name of the mailbox to open, default INBOX
register (line 657)

Register all error messages

This action is called by the constructor. For internal use only.

void register ()
rename_mailbox (line 233)

Rename the specified mailbox as requested

void rename_mailbox (string $mailbox_name, string $new_mailbox_name)
  • string $mailbox_name: Name of the mailbox to rename
  • string $new_mailbox_name: New name of the mailbox
subscribe_mailbox (line 356)

Subscribe to the specified mailbox

void subscribe_mailbox (string $mailbox_name)
  • string $mailbox_name: Name of the mailbox to subscribe to
undelete_messages (line 633)

Undelete specified messages

void undelete_messages (string $message_uids)
  • string $message_uids: One or more message uids, comma separated, to undelete
unsubscribe_mailbox (line 376)

Unsubscribe from the specified mailbox

void unsubscribe_mailbox (string $mailbox_name)
  • string $mailbox_name: Name of the mailbox to unsubscribe from

Inherited Methods

Inherited From Module

Module::disable_render()
Module::disable_template_library()
Module::disable_view()
Module::enable_render()
Module::enable_template_library()
Module::enable_view()
Module::exec_module_action()
Module::get_error_strings()
Module::get_exceptions()
Module::get_queries()
Module::get_templating_library_paths()
Module::initialize()
Module::PHPTAL_render()
Module::register_error()
Module::register_exception()
Module::register_query()
Module::render()
Module::set_references()
Module::set_template_file()
Module::Smarty_render()

Documentation generated on Sat, 23 Jun 2007 21:28:21 -0500 by phpDocumentor 1.3.2