CSS: Providing seven essential vitamins and minerals since 1996.
Have a steaming hot, delicious slice of Standards.

Mail_IMAPv2 Inbox Example

* @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
{$msg->mailboxInfo['folder']}: ($msgcount) messages total.
\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", " \n", " \n", " \n", " \n", " \n", " \n", " \n"; // Clean up left over variables // $msg->unsetParts($mid); // $msg->unsetHeaders($mid); } } else { echo " \n". " ". " \n"; } echo " \n". "
subject from received
{$msg->header[$mid]['subject']}\n", " ", (isset($msg->header[$mid]['from_personal'][0]) && !empty($msg->header[$mid]['from_personal'][0]))? ''.$msg->header[$mid]['from_personal'][0]."" : str_replace('@', ' at ', $msg->header[$mid]['from'][0]), "\n", " ".date('D d M, Y h:i:s', $msg->header[$mid]['udate'])."
\n"; // Show inline parts first if (isset($msg->msg[$mid]['in']['pid']) && count($msg->msg[$mid]['in']['pid']) > 0) { foreach ($msg->msg[$mid]['in']['pid'] as $i => $inid) { $fname = (isset($msg->msg[$mid]['in']['fname'][$i]))? $msg->msg[$mid]['in']['fname'][$i] : NULL; echo " Inline part: msg[$mid]['in']['pid'][$i]."' target='_blank'>".$fname." ".$msg->msg[$mid]['in']['ftype'][$i]." ".$msg->convertBytes($msg->msg[$mid]['in']['fsize'][$i])."
\n"; } } // Now the attachments if (isset($msg->msg[$mid]['at']['pid']) && count($msg->msg[$mid]['at']['pid']) > 0) { foreach ($msg->msg[$mid]['at']['pid'] as $i => $aid) { $fname = (isset($msg->msg[$mid]['at']['fname'][$i]))? $msg->msg[$mid]['at']['fname'][$i] : NULL; echo " Attachment: msg[$mid]['at']['pid'][$i]."' target='_blank'>".$fname." ".$msg->msg[$mid]['at']['ftype'][$i]." ".$msg->convertBytes($msg->msg[$mid]['at']['fsize'][$i])."
\n"; } } echo "
No Messages
\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 "
\n";
// 	var_dump($msg->error->getErrors());
// 	echo "
\n"; // } ?>
PHP Powered XHTML 1.0 CSS
Copyright © 1998-2010 Richard York, All Rights Reserved.