* @copyright (c) Copyright 2004, Richard York, All Rights Reserved.
* @package Mail_IMAP
* @subpackage examples
**
*/
error_reporting(E_ALL);
require_once 'Mail/IMAP.php';
// Use an existing imap resource stream, or provide a URI abstraction.
// Example of URI:
// pop3://user:pass@mail.example.com:110/INBOX#notls
//
// If you are unsure of the URI syntax to use here,
// use the Mail_IMAP_connection_wizard to find the right URI.
// Or see docs for Mail_IMAP::connect
//
// The connection URI must also be set in:
// IMAP.inbox.php.
// IMAP.message_viewer.php
// IMAP.part_viewer.php
$connection = 'imap://user:pass@mail.example.net:143/INBOX';
if (!isset($_GET['dump_mid'])) {
$msg =& new Mail_IMAP();
} else {
// Call on debuging automatically.
include 'Mail/IMAP/Debug/Debug.php';
$msg =& new Mail_IMAP_Debug($connection);
if ($msg->error->hasErrors()) {
$msg->dump($msg->error->getErrors(TRUE));
}
}
// Open up a mail connection
if (!$msg->connect($connection)) {
echo $msg->alerts();
echo $msg->errors();
echo "Error: Unable to build a connection.";
}
// Unread messages appear with LIGHTGRAY links
// Read messages appear with WHITE links
// If you are using an IMAP-protocol based mail server,
// POP3 doesn't remember flag settings
// Retrieve message count
$msgcount = $msg->messageCount();
echo "
Mail_IMAP Inbox
\n";
if ($msgcount > 0)
{
/*
* Each message of a mailbox is numbered offset from 1
* Create the $mid (message id) and recursively gather
* message information.
*/
for ($mid = 1; $mid <= $msgcount; $mid++)
{
// Get the headers
$msg->getHeaders($mid);
$style = ((isset($msg->header[$mid]['Recent']) && $msg->header[$mid]['Recent'] == 'N') || (isset($msg->header[$mid]['Unseen']) && $msg->header[$mid]['Unseen'] == 'U'))? 'gray' : 'black';
// Grab inline and attachment parts relevant to top level parts.
// See the docs for the $msg property for more information:
// http://www.smilingsouls.net/index.php?content=Mail_IMAP/msg
$msg->getParts($mid);
if (!isset($msg->header[$mid]['subject']) || empty($msg->header[$mid]['subject']))
{
$msg->header[$mid]['subject'] = "no subject provided";
}
echo "
\n";
// Clean up left over variables
// $msg->unsetParts($mid);
// $msg->unsetHeaders($mid);
}
}
else
{
echo "
\n".
"
No Messages
".
"
\n";
}
echo " \n".
"
\n".
"
\n".
" mailbox: {$msg->mailboxInfo['user']} \n";
// getQuota doesn't work for some servers
if ($quota = $msg->getQuota())
{
echo " Quota: {$quota['STORAGE']['usage']} used of {$quota['STORAGE']['limit']} total\n";
}
echo "
\n".
"
\n".
" \n".
" \n".
" ";
// Close the stream
$msg->close();
// View errors gathered by PEAR_ErrorStack
// Uncommment to see more errors.
// if ($msg->error->hasErrors()) {
// echo "