The implementation supports most of the commands specified in: - {@link http://www.faqs.org/rfcs/rfc1730.html} (IMAP4) - {@link http://www.faqs.org/rfcs/rfc2060.html} (IMAP4rev1) Each user account on the IMAP server has it's own folders (mailboxes). Mailboxes can be created, renamed or deleted. All accounts have a special mailbox called Inbox which cannot be deleted or renamed. Messages are organized in mailboxes, and are identified by a message number (which can change over time) and a unique ID (which does not change under normal circumstances). The commands operating on messages can handle both modes (message numbers or unique IDs). Messages are marked by certain flags (SEEN, DRAFT, etc). Deleting a message actually sets it's DELETED flag, and a later call to {@link expunge()} will delete all the messages marked with the DELETED flag. The IMAP server can be in different states. Most IMAP commands require that a connection is established and a user is authenticated. Certain commands require in addition that a mailbox is selected. The IMAP transport class allows developers to interface with an IMAP server. The commands which support unique IDs to refer to messages are marked with [*] (see {@link ezcMailImapTransportOptions} to find out how to enable unique IDs referencing): Basic commands: - connect to an IMAP server ({@link __construct()}) - authenticate a user with a username and password ({@link authenticate()}) - select a mailbox ({@link selectMailbox()}) - disconnect from the IMAP server ({@link disconnect()}) Work with mailboxes: - get the list of mailboxes of the user ({@link listMailboxes()}) - create a mailbox ({@link createMailbox()}) - rename a mailbox ({@link renameMailbox()}) - delete a mailbox ({@link deleteMailbox()}) - append a message to a mailbox ({@link append()}) - select a mailbox ({@link selectMailbox()}) - get the status of messages in the current mailbox ({@link status()}) - get the number of messages with a certain flag ({@link countByFlag()}) Work with message numbers (on the currently selected mailbox): - get the message numbers and sizes of all the messages ({@link listMessages()}) - get the message numbers and IDs of all the messages ({@link listUniqueIdentifiers()}) - [*] get the headers of a certain message ({@link top()}) - [*] delete a message ({@link delete()} and {@link expunge()}) - [*] copy messages to another mailbox ({@link copyMessages()}) - [*] get the sizes of the specified messages ({@link fetchSizes()}) Work with flags (on the currently selected mailbox): - [*] get the flags of the specified messages ({@link fetchFlags()}) - [*] set a flag on the specified messages ({@link setFlag()}) - [*] clear a flag from the specified messages ({@link clearFlag()}) Work with {@link ezcMailImapSet} sets (parseable with {@link ezcMailParser}) (on the currently selected mailbox): - [*] create a set from all messages ({@link fetchAll()}) - [*] create a set from a certain message ({@link fetchByMessageNr()}) - [*] create a set from a range of messages ({@link fetchFromOffset()}) - [*] create a set from messages with a certain flag ({@link fetchByFlag()}) - [*] create a set from a sorted range of messages ({@link sortFromOffset()}) - [*] create a set from a sorted list of messages ({@link sortMessages()}) - [*] create a set from a free-form search ({@link searchMailbox()}) Miscellaneous commands: - get the capabilities of the IMAP server ({@link capability()}) - get the hierarchy delimiter (useful for nested mailboxes) ({@link getHierarchyDelimiter()}) - issue a NOOP command to keep the connection alive ({@link noop()}) The usual operation with an IMAP server is illustrated by this example: create a new IMAP transport object by specifying the server name, optional port and optional SSL mode $options = new ezcMailImapTransportOptions(); $options->ssl = true; $imap = new ezcMailImapTransport( 'imap.example.com', null, $options ); Authenticate to the IMAP server $imap->authenticate( 'username', 'password' ); Select a mailbox (here 'Inbox') $imap->selectMailbox( 'Inbox' ); issue commands to the IMAP server for example get the number of RECENT messages $recent = $imap->countByFlag( 'RECENT' ); see the above list of commands or consult the online documentation for the full list of commands you can issue to an IMAP server and examples disconnect from the IMAP server $imap->disconnect(); See {@link ezcMailImapTransportOptions} for other options you can specify for IMAP.
 public function testUidDelete()
 {
     $imap = new ezcMailImapTransport(self::$server, self::$port, array('uidReferencing' => true));
     $imap->authenticate(self::$user, self::$password);
     $imap->createMailbox("Guybrush");
     $imap->selectMailbox('inbox');
     $imap->copyMessages(self::$ids[0], "Guybrush");
     $imap->selectMailbox("Guybrush");
     $imap->delete(1);
     $imap->selectMailbox('inbox');
     $imap->deleteMailbox("Guybrush");
 }
<?php

require_once 'tutorial_autoload.php';
// Create a new IMAP transport object by specifying the server name
$imap = new ezcMailImapTransport("imap.example.com");
// Authenticate to the IMAP server
$imap->authenticate("user", "password");
// Select the Inbox mailbox
$imap->selectMailbox('Inbox');
// List the capabilities of the IMAP server
$capabilities = $imap->capability();
// List existing mailboxes
$mailboxes = $imap->listMailboxes("", "*");
// Fetch the hierarchy delimiter character (usually "/")
$delimiter = $imap->getHierarchyDelimiter();
// Create a new mailbox
$imap->createMailbox("Reports 2006");
// Delete a mailbox
$imap->deleteMailbox("Reports 2005");
// Rename a mailbox
$imap->renameMailbox("Reports 2006", "Reports");
// Copy messages from the selected mailbox (here: Inbox) to another mailbox
$imap->copyMessages("1,2,4", "Reports");
// Set a flag to messages
// See the function description for a list of supported flags
$imap->setFlag("1,2,4", "DELETED");
// Clears a flag from messages
// See the function description for a list of supported flags
$imap->clearFlag("1,2,4", "SEEN");
// Append a message to a mailbox. $mail must contain the mail as text
// Use this with a "Sent" or "Drafts" mailbox
Exemple #3
0
 /**
  * Generates the next IMAP tag to prepend to client commands.
  *
  * The structure of the IMAP tag is Axxxx, where
  *  - A is a letter (uppercase for conformity)
  *  - x is a digit from 0 to 9
  * example of generated tag: T5439
  * It uses the class variable {@link $this->currentTag}.
  * Everytime it is called, the tag increases by 1.
  * If it reaches the last tag, it wraps around to the first tag.
  * By default, the first generated tag is A0001.
  *
  * @return string
  */
 public function getNextTag()
 {
     return parent::getNextTag();
 }
 /**
  * Get the password reset URL.
  *
  * @return string
  */
 public static function getPasswordResetURL()
 {
     $options = new \ezcMailImapTransportOptions();
     $options->ssl = true;
     $imap = new \ezcMailImapTransport('imap.gmail.com', null, $options);
     $imap->authenticate('*****@*****.**', Config::get('kinvey::testMail'));
     $imap->selectMailbox('Inbox');
     $set = $imap->searchMailbox('FROM "*****@*****.**"');
     $parser = new \ezcMailParser();
     $mail = $parser->parseMail($set);
     preg_match("#https.*#", $mail[0]->generateBody(), $matches);
     $url = html_entity_decode($matches[0]);
     $url = mb_substr($url, 0, -1);
     foreach ($set->getMessageNumbers() as $msgNum) {
         $imap->delete($msgNum);
     }
     $imap->expunge();
     return $url;
 }
 public function tearDown()
 {
     $this->removeTempDir();
     $transport = new ezcMailImapTransport("mta1.ez.no");
     $transport->authenticate("*****@*****.**", "ezcomponents");
     try {
         $transport->deleteMailbox("Guybrush");
     } catch (ezcMailTransportException $e) {
     }
 }
Exemple #6
0
// Include the PagingLinks custom block
require 'app/paging_links.php';
// Required method to be able to use the eZ Components
function __autoload($className)
{
    ezcBase::autoload($className);
}
// Start counting how much the execution time will be
$start = microtime(true);
// Read configuration file app.ini with the Configuration component
$iniFile = 'app';
$config = ezcConfigurationManager::getInstance();
$config->init('ezcConfigurationIniReader', dirname(__FILE__));
$options = array('templatePath' => dirname(__FILE__) . $config->getSetting($iniFile, 'TemplateOptions', 'TemplatePath'), 'compilePath' => dirname(__FILE__) . $config->getSetting($iniFile, 'TemplateOptions', 'CompilePath'), 'server' => $config->getSetting($iniFile, 'MailOptions', 'Server'), 'user' => $config->getSetting($iniFile, 'MailOptions', 'User'), 'password' => $config->getSetting($iniFile, 'MailOptions', 'Password'), 'mailbox' => isset($_GET['mailbox']) ? $_GET['mailbox'] : $config->getSetting($iniFile, 'MailOptions', 'Mailbox'), 'pageSize' => $config->getSetting($iniFile, 'MailOptions', 'PageSize'), 'currentPage' => isset($_GET['page']) ? $_GET['page'] : null);
// Create a mail IMAP transport object
$transport = new ezcMailImapTransport($options["server"]);
$transport->authenticate($options["user"], $options["password"]);
$transport->selectMailbox($options["mailbox"]);
// Get the mailboxes names from the server
$mailboxes = $transport->listMailboxes();
sort($mailboxes);
// Get the UIDs of the messages in the selected mailbox
// and the sizes of the messages
$mailIDs = $transport->listUniqueIdentifiers();
$messages = $transport->listMessages();
// Calculate how many pages of mails there will be based on pageSize
$numberOfPages = (int) floor(count($messages) / $options["pageSize"] + 1);
// See if currentPage fits in the range 1..numberOfPages
if ($options["currentPage"] <= 0 || $options["currentPage"] > $numberOfPages || count($messages) % $options["pageSize"] === 0 && $options["currentPage"] >= $numberOfPages) {
    $options["currentPage"] = 1;
}
 /**
  * Test for issue #14360: problems with $imap->top() command in gmail.
  */
 public function testTopGmailHeadersOnly()
 {
     $options = new ezcMailImapTransportOptions();
     $options->ssl = true;
     $imap = new ezcMailImapTransport('imap.gmail.com', '993', $options);
     // please don't use this account :)
     $imap->authenticate('ezcomponents' . '@' . 'gmail.com', 'wee12345');
     $imap->selectMailbox('inbox');
     $text = $imap->top(1, 1);
     $this->assertEquals(382, strlen($text));
 }
Exemple #8
0
<?php

require_once '/home/dotxp/dev/PHP/zetacomponents/trunk/Base/src/ezc_bootstrap.php';
require_once 'blog_entry.php';
require_once 'blog_entry_creator.php';
$imapOptions = new ezcMailImapTransportOptions();
$imapOptions->ssl = true;
$imap = new ezcMailImapTransport('example.com', 993, $imapOptions);
$imap->authenticate('*****@*****.**', 'foo23bar');
$imap->selectMailbox('Inbox');
$messageSet = $imap->fetchAll();
$parser = new ezcMailParser();
$mails = $parser->parseMail($messageSet);
$blogEntryCreator = new qaBlogEntryCreator();
foreach ($mails as $mail) {
    $entry = $blogEntryCreator->createEntry($mail);
    $entry->save();
}
<?php

require_once 'tutorial_autoload.php';
// Create a new IMAP transport object by specifying the server name, default port
// and that the IMAP commands will work with unique IDs instead of message numbers
$options = new ezcMailImapTransportOptions();
$options->uidReferencing = true;
$imap = new ezcMailImapTransport("imap.example.com", null, $options);
// Authenticate to the IMAP server
$imap->authenticate("user", "password");
// Select the Inbox mailbox
$imap->selectMailbox('Inbox');
// The other IMAP examples apply here, with the distinction that unique IDs are
// used to refer to messages instead of message numbers
Exemple #10
0
<?php

require_once 'tutorial_autoload.php';
// Create a new IMAP transport object by specifying the server name
$imap = new ezcMailImapTransport("imap.example.com");
// Authenticate to the IMAP server
$imap->authenticate("user", "password");
// Select the Inbox mailbox
$imap->selectMailbox('Inbox');
// Get the number of messages on the server, combined size, number of recent
// messages and number of unseen messages
// in the variables $num, $size, $recent, $unseen
$imap->status($num, $size, $recent, $unseen);
// Get the list of message numbers on the server and their sizes
// the returned array is something like: array( 1 => 1500, 2 => 45200 )
// where the key is a message number and the value is the message size
$messages = $imap->listMessages();
// Get the list of message unique ids on the server and their sizes
// the returned array is something like: array( 1 => '15', 2 => '16' )
// where the key is an message number and the value is the message unique id
$messages = $imap->listUniqueIdentifiers();
// Usually you will call one of these fetch functions:
// Fetch all messages on the server
$set = $imap->fetchAll();
// Fetch one message from the server (here: get the message no. 2)
$set = $imap->fetchByMessageNr(2);
// Fetch a range of messages from the server (here: get 4 messages starting from message no. 2)
$set = $imap->fetchFromOffset(2, 4);
// Fetch messages which have a certain flag
// See the function description for a list of supported flags
$set = $imap->fetchByFlag("DELETED");