<?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 <richy@smilingsouls.net>
* @copyright (c) Copyright 2004, Richard York, All Rights Reserved.
* @package Mail_IMAP
* @subpackage examples
**
*/
require_once 'Mail/IMAP.php';
// Set up class, initiate a mailbox connection
// Open up a mail connection
// pop3://user:pass@mail.example.com:110/INBOX#notls
// Use an existing imap resource stream, or provide a URI abstraction.
//
// 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
//
// This argument must also be set in MAIL_IMAP.message.php.
if (PEAR
::isError
($msg->connect('imap://user:pass@mail.someserver.net:143/INBOX'))) {
echo "<span style='font-weight: bold;'>Error:</span> Unable to build a connection.";
}
// Retrieve message count
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>
<style type='text/css' media='screen'>
*
{
font-family: Arial;
}
a:hover
{
border: 1px solid olive;
background: greenyellow;
color: black;
text-decoration: none;
}
table.msg, td.msghead, td.footer, #inboxheader, td.msgcount
{
border: 1px solid black;
}
table.msg
{
width: 100%;
background: aliceblue;
}
td.msgattach
{
font-size: 8pt;
text-decoration: none;
padding: 5px;
}
td.msgattach a
{
color: darkgreen;
}
td.msghead, td.footer, td.msgitem
{
padding: 5px;
font-weight: bold;
}
td.msghead
{
font-size: 14pt;
background: palegreen;
}
td.footer
{
font-size: 8pt;
text-align: right;
background: palegreen;
}
td.msgcount
{
background: skyblue;
font-size: 14pt;
}
#inboxheader
{
font-size: 25pt;
vertical-align: top;
padding: 10px;
background: palegreen;
}
</style>
</head>
<body>
<table class='msg'>
<tr>
<td id='inboxheader'>
Mail_IMAP
</td>
<td colspan='2' class='msghead'>
Unread messages are <span style='font-weight: bold; color: green;'>GREEN</span><br />
Read messages are <span style='font-weight: bold; color: black;'>BLACK</span><br />
<span style='font-size: 8pt;'>If you are using an IMAP-protocol based mail server, POP3 doesn't remember flag settings.</span>
</td>
</tr>
<tr>
<td colspan='3' class='msgcount'>
{$msg->mailboxInfo['folder']}: ($msgcount) messages total.
</td>
</tr>
<tr>
<td class='msghead'>
subject
</td>
<td class='msghead'>
from
</td>
<td class='msghead'>
received
</td>
</tr>\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 default part id
// Parse header information
$style =
((isset
($msg->header[$mid]['Recent']) &&
$msg->header[$mid]['Recent'] ==
'N') ||
(isset
($msg->header[$mid]['Unseen']) &&
$msg->header[$mid]['Unseen'] ==
'U'))?
'green' :
'black';
// Parse inline/attachment information specific to this part id
//
// See member variables begining with in or attach for
// available information
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.php?mid={$mid}&pid={$pid}' target='_blank' style='color: {$style};'>{$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="'.
$msg->header[$mid]['from'][0
].
'">'.
$msg->header[$mid]['from_personal'][0
].
"</span>" :
$msg->header[$mid]['from'][0
], "\n",
" </td>\n",
" <td class='msgitem'>".
date('D, M d, Y h:i:s', $msg->header[$mid]['udate']).
"</td>\n",
" </tr>\n",
" <tr>\n",
" <td colspan='3' class='msgattach'>\n";
// Show inline parts first
{
foreach ($msg->inPid[$mid] as
$i =>
$inid)
{
echo "
Inline part: <a href='IMAP.message.php?mid={$mid}&pid={$msg->inPid
[$mid][$i]}' target='_blank'>{
$msg->inFname
[$mid][$i]} {
$msg->inFtype
[$mid][$i]} ".
$msg->convertBytes($msg->inFsize[$mid][$i]).
"</a><br />\n";
}
}
// Now the attachments
{
foreach ($msg->attachPid[$mid] as
$i =>
$aid)
{
echo "
Attachment: <a href='IMAP.message.php?mid={$mid}&pid={$msg->attachPid
[$mid][$i]}' target='_blank'>{
$msg->attachFname
[$mid][$i]} {
$msg->attachFtype
[$mid][$i]} ".
$msg->convertBytes($msg->attachFsize[$mid][$i]).
"</a><br />\n";
}
}
echo " </td>\n",
" </tr>\n";
// Clean up left over variables
}
}
else
{
echo " <tr>\n",
" <td colspan='3' style='font-size: 30pt; text-align: center; padding: 50px 0px 50px 0px;'>No Messages</td>",
" </tr>\n";
}
echo " <tr>\n",
" <td colspan='3' class='footer'>\n",
" mailbox: {$msg->mailboxInfo['user']}<br />\n";
// getQuota doesn't work for some servers
if (!PEAR
::isError
($quota =
$msg->getQuota()))
{
echo " Quota: {$quota['STORAGE']['usage']} used of {$quota['STORAGE']['limit']} total\n";
}
echo " </td>\n",
" </tr>\n",
" </table>\n",
" </body>\n",
" </html>";
// Close the stream
?>