<?php
/**
* Demonstrates how to set-up a basic inbox using Mail_IMAP.
* See {@link connect} for extended documentation on
* how to set the connection URI.
*
* @author Richard York <rich_y@php.net>
* @copyright (c) Copyright 2004, Richard York, All Rights Reserved.
* @package Mail_IMAP
* @subpackage examples
**
*/
error_reporting(E_ALL);
require_once '../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 "<span style='font-weight: bold;'>Error:</span> 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 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html>
<head>
<title> Mail_IMAP Inbox </title>
<link rel='stylesheet' type='text/css' href='/IMAP.css' media='all' />
</head>
<body>
<div id='header'>
<h1>
PEAR :: Mail_IMAP
</h1>
</div>
<div id='inboxbody'>
<div id='msgcount'>
{$msg->mailboxInfo['folder']}: ($msgcount) messages total.
</div>
<table class='msg'>
<thead>
<tr>
<th>
subject
</th>
<th>
from
</th>
<th>
received
</th>
</tr>
</thead>
<tbody>";
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'] = "<span style='font-style: italic;'>no subject provided</a>";
}
echo " <tr>\n".
" <td class='msgitem'><a href='/IMAP.message_viewer.php?mid=&pid={$msg->msg[$mid]['pid']}' target='_blank' style='color: ;'>{$msg->header[$mid]['subject']}</a></td>\n".
" <td class='msgitem'>\n".
" ".(isset($msg->header[$mid]['from_personal'][0]) && !empty($msg->header[$mid]['from_personal'][0]))? '<span title="'.str_replace('@', ' at ', $msg->header[$mid]['from'][0]).'">'.$msg->header[$mid]['from_personal'][0]."</span>" : str_replace('@', ' at ', $msg->header[$mid]['from'][0])."\n".
" </td>\n".
" <td class='msgitem'>".date('D d M, Y h:i:s', $msg->header[$mid]['udate'])."</td>\n".
" </tr>\n".
" <tr>\n".
" <td colspan='3' class='msgattach'>\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: <a href='/IMAP.message_viewer.php?mid=&pid='".$msg->msg[$mid]['in']['pid'][$i]."' target='_blank'>".$fname." ".$msg->msg[$mid]['in']['ftype'][$i]." ".$msg->convertBytes($msg->msg[$mid]['in']['fsize'][$i])."</a><br />\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: <a href='/IMAP.message_viewer.php?mid=&pid='".$msg->msg[$mid]['at']['pid'][$i]."' target='_blank'>".$fname." ".$msg->msg[$mid]['at']['ftype'][$i]." ".$msg->convertBytes($msg->msg[$mid]['at']['fsize'][$i])."</a><br />\n";
}
}
echo " </td>\n".
" </tr>\n";
// Clean up left over variables
// $msg->unsetParts($mid);
// $msg->unsetHeaders($mid);
}
}
else
{
echo " <tr>\n".
" <td colspan='3' style='font-size: 30pt; text-align: center; padding: 50px 0;'>No Messages</td>\n".
" </tr>\n";
}
echo " </tbody>\n".
" </table>\n".
" <div id='quota'>\n".
" mailbox: {$msg->mailboxInfo['user']}<br />\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 " </div>\n".
" </div>\n".
" <div id='footer'>\n".
" <p>\n".
" © Copyright 2004 Richard York, All Rights Reserved.<br />\n".
" Best viewed with <a href='http://www.mozilla.org'>Mozilla</a> and other standards-based browsers. Visit the <a href='http://www.deadmarshes.com/?hFileLastModified=1364984515'>Mail_IMAP</a> homepage.\n".
" </p>\n".
" </div>\n".
" </body>\n".
" </html>";
// Close the stream
$msg->close();
// View errors gathered by PEAR_ErrorStack
// Uncommment to see more errors.
// if ($msg->error->hasErrors()) {
// echo "<pre style='display: block; white-space: pre;'>\n";
// var_dump($msg->error->getErrors());
// echo "</pre>\n";
// }
?>
There are no comments posted at this time.
* All comments are moderated and are subject to approval.
Your comment will appear once it has been approved.
Posting multiple times will not expedite the approval process.
Comments are closed at this time.