| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* Demonstrates how to set-up a basic inbox using Mail_IMAP.
|
|
|
5 |
* See {@link connect} for extended documentation on
|
|
|
6 |
* how to set the connection URI.
|
|
|
7 |
*
|
|
|
8 |
* @author Richard York <rich_y@php.net>
|
|
|
9 |
* @copyright (c) Copyright 2004, Richard York, All Rights Reserved.
|
|
|
10 |
* @package Mail_IMAP
|
|
|
11 |
* @subpackage examples
|
|
|
12 |
**
|
|
|
13 |
*/
|
|
|
14 |
|
|
|
15 |
require_once 'Mail/IMAP.php';
|
|
|
16 |
|
|
|
17 |
// Set up class, initiate a mailbox connection
|
|
|
18 |
$msg =& new Mail_IMAP();
|
|
|
19 |
|
|
|
20 |
// Open up a mail connection
|
|
|
21 |
// pop3://user:pass@mail.example.com:110/INBOX#notls
|
|
|
22 |
// Use an existing imap resource stream, or provide a URI abstraction.
|
|
|
23 |
//
|
|
|
24 |
// If you are unsure of the URI syntax to use here,
|
|
|
25 |
// use the Mail_IMAP_connection_wizard to find the right URI.
|
|
|
26 |
// Or see docs for Mail_IMAP::connect
|
|
|
27 |
//
|
|
|
28 |
// This argument must also be set in MAIL_IMAP.message.php.
|
|
|
29 |
if (PEAR::isError($msg->connect('imap://user:pass@mail.server.net:143/INBOX'))) {
|
|
|
30 |
echo "<span style='font-weight: bold;'>Error:</span> Unable to build a connection.";
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
// Unread messages appear with LIGHTGRAY links
|
|
|
35 |
// Read messages appear with WHITE links
|
|
|
36 |
// If you are using an IMAP-protocol based mail server,
|
|
|
37 |
// POP3 doesn't remember flag settings
|
|
|
38 |
|
|
|
39 |
// Retrieve message count
|
|
|
40 |
$msgcount = $msg->messageCount();
|
|
|
41 |
|
|
|
42 |
echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
|
|
|
43 |
<html>
|
|
|
44 |
<head>
|
|
|
45 |
<title> Mail_IMAP Inbox </title>
|
|
|
46 |
<style type='text/css' media='screen'>
|
|
|
47 |
* {
|
|
|
48 |
font-family: Arial, sans-serif;
|
|
|
49 |
font-size: 100%;
|
|
|
50 |
}
|
|
|
51 |
body {
|
|
|
52 |
max-width: 1000px;
|
|
|
53 |
min-width: 500px;
|
|
|
54 |
margin: 10px auto;
|
|
|
55 |
border: thick solid black;
|
|
|
56 |
}
|
|
|
57 |
a {
|
|
|
58 |
text-decoration: none;
|
|
|
59 |
color: royalblue;
|
|
|
60 |
padding: 1px;
|
|
|
61 |
}
|
|
|
62 |
a:hover {
|
|
|
63 |
color: white !important;
|
|
|
64 |
background: black;
|
|
|
65 |
}
|
|
|
66 |
div#inboxbody {
|
|
|
67 |
background: lightgrey;
|
|
|
68 |
padding: 10px;
|
|
|
69 |
}
|
|
|
70 |
div#msgcount {
|
|
|
71 |
padding: 10px 0;
|
|
|
72 |
font-size: 120%;
|
|
|
73 |
}
|
|
|
74 |
table {
|
|
|
75 |
border: thin solid black;
|
|
|
76 |
background: white;
|
|
|
77 |
width: 100%;
|
|
|
78 |
}
|
|
|
79 |
#inboxheader {
|
|
|
80 |
border: medium solid black;
|
|
|
81 |
}
|
|
|
82 |
th {
|
|
|
83 |
background: gray;
|
|
|
84 |
vertical-align: baseline;
|
|
|
85 |
color: white;
|
|
|
86 |
font-weight: bold;
|
|
|
87 |
}
|
|
|
88 |
td.msgattach {
|
|
|
89 |
font-size: 80%;
|
|
|
90 |
text-decoration: none;
|
|
|
91 |
padding: 5px 5px 5px 40px;
|
|
|
92 |
}
|
|
|
93 |
td.msgcount, td.footer, td.msgitem {
|
|
|
94 |
padding: 5px;
|
|
|
95 |
font-size: 90%;
|
|
|
96 |
}
|
|
|
97 |
td.footer {
|
|
|
98 |
font-size: 8pt;
|
|
|
99 |
text-align: right;
|
|
|
100 |
}
|
|
|
101 |
h1 {
|
|
|
102 |
font-size: 200%;
|
|
|
103 |
padding-bottom: 10px;
|
|
|
104 |
margin: 0;
|
|
|
105 |
}
|
|
|
106 |
div#quota {
|
|
|
107 |
text-align: right;
|
|
|
108 |
padding: 10px 0;
|
|
|
109 |
font-size: 90%;
|
|
|
110 |
}
|
|
|
111 |
#header, #footer {
|
|
|
112 |
padding: 10px;
|
|
|
113 |
background: black;
|
|
|
114 |
color: white;
|
|
|
115 |
margin: 0;
|
|
|
116 |
}
|
|
|
117 |
#footer {
|
|
|
118 |
text-align: center;
|
|
|
119 |
}
|
|
|
120 |
#footer p {
|
|
|
121 |
margin: 0;
|
|
|
122 |
}
|
|
|
123 |
</style>
|
|
|
124 |
</head>
|
|
|
125 |
<body>
|
|
|
126 |
<div id='header'>
|
|
|
127 |
<h1>
|
|
|
128 |
PEAR :: Mail_IMAP
|
|
|
129 |
</h1>
|
|
|
130 |
</div>
|
|
|
131 |
<div id='inboxbody'>
|
|
|
132 |
<div id='msgcount'>
|
|
|
133 |
{$msg->mailboxInfo['folder']}: ($msgcount) messages total.
|
|
|
134 |
</div>
|
|
|
135 |
<table class='msg'>
|
|
|
136 |
<tr>
|
|
|
137 |
<th>
|
|
|
138 |
subject
|
|
|
139 |
</th>
|
|
|
140 |
<th>
|
|
|
141 |
from
|
|
|
142 |
</th>
|
|
|
143 |
<th>
|
|
|
144 |
received
|
|
|
145 |
</th>
|
|
|
146 |
</tr>\n";
|
|
|
147 |
|
|
|
148 |
if ($msgcount > 0)
|
|
|
149 |
{
|
|
|
150 |
/*
|
|
|
151 |
* Each message of a mailbox is numbered offset from 1
|
|
|
152 |
* Create the $mid (message id) and recursively gather
|
|
|
153 |
* message information.
|
|
|
154 |
*/
|
|
|
155 |
for ($mid = 1; $mid <= $msgcount; $mid++)
|
|
|
156 |
{
|
|
|
157 |
// Get the default part id
|
|
|
158 |
$pid = $msg->getDefaultPid($mid);
|
|
|
159 |
|
|
|
160 |
// Parse header information
|
|
|
161 |
$msg->getHeaders($mid, $pid);
|
|
|
162 |
|
|
|
163 |
$style = ((isset($msg->header[$mid]['Recent']) && $msg->header[$mid]['Recent'] == 'N') || (isset($msg->header[$mid]['Unseen']) && $msg->header[$mid]['Unseen'] == 'U'))? 'gray' : 'black';
|
|
|
164 |
|
|
|
165 |
// Parse inline/attachment information specific to this part id
|
|
|
166 |
//
|
|
|
167 |
// See member variables begining with in or attach for
|
|
|
168 |
// available information
|
|
|
169 |
$msg->getParts($mid, $pid);
|
|
|
170 |
|
|
|
171 |
if (!isset($msg->header[$mid]['subject']) || empty($msg->header[$mid]['subject']))
|
|
|
172 |
{
|
|
|
173 |
$msg->header[$mid]['subject'] = "<span style='font-style: italic;'>no subject provided</a>";
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
echo " <tr>\n",
|
|
|
177 |
" <td class='msgitem'><a href='IMAP.message.php?mid={$mid}&pid={$pid}' target='_blank' style='color: {$style};'>{$msg->header[$mid]['subject']}</a></td>\n",
|
|
|
178 |
" <td class='msgitem'>\n",
|
|
|
179 |
" ", (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",
|
|
|
180 |
" </td>\n",
|
|
|
181 |
" <td class='msgitem'>".date('D d M, Y h:i:s', $msg->header[$mid]['udate'])."</td>\n",
|
|
|
182 |
" </tr>\n",
|
|
|
183 |
" <tr>\n",
|
|
|
184 |
" <td colspan='3' class='msgattach'>\n";
|
|
|
185 |
|
|
|
186 |
// Show inline parts first
|
|
|
187 |
if (isset($msg->inPid[$mid]) && count($msg->inPid[$mid]) > 0)
|
|
|
188 |
{
|
|
|
189 |
foreach ($msg->inPid[$mid] as $i => $inid)
|
|
|
190 |
{
|
|
|
191 |
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";
|
|
|
192 |
}
|
|
|
193 |
}
|
|
|
194 |
|
|
|
195 |
// Now the attachments
|
|
|
196 |
if (isset($msg->attachPid[$mid]) && count($msg->attachPid[$mid]) > 0)
|
|
|
197 |
{
|
|
|
198 |
foreach ($msg->attachPid[$mid] as $i => $aid)
|
|
|
199 |
{
|
|
|
200 |
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";
|
|
|
201 |
}
|
|
|
202 |
}
|
|
|
203 |
|
|
|
204 |
echo " </td>\n",
|
|
|
205 |
" </tr>\n";
|
|
|
206 |
|
|
|
207 |
// Clean up left over variables
|
|
|
208 |
$msg->unsetParts($mid);
|
|
|
209 |
$msg->unsetHeaders($mid);
|
|
|
210 |
}
|
|
|
211 |
}
|
|
|
212 |
else
|
|
|
213 |
{
|
|
|
214 |
echo " <tr>\n",
|
|
|
215 |
" <td colspan='3' style='font-size: 30pt; text-align: center; padding: 50px 0px 50px 0px;'>No Messages</td>",
|
|
|
216 |
" </tr>\n";
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
echo " <tr>\n",
|
|
|
220 |
" </table>\n",
|
|
|
221 |
" <div id='quota'>\n",
|
|
|
222 |
" mailbox: {$msg->mailboxInfo['user']}<br />\n";
|
|
|
223 |
|
|
|
224 |
// getQuota doesn't work for some servers
|
|
|
225 |
if (!PEAR::isError($quota = $msg->getQuota()))
|
|
|
226 |
{
|
|
|
227 |
echo " Quota: {$quota['STORAGE']['usage']} used of {$quota['STORAGE']['limit']} total\n";
|
|
|
228 |
}
|
|
|
229 |
|
|
|
230 |
echo " </div>\n",
|
|
|
231 |
" </div>\n",
|
|
|
232 |
" <div id='footer'>\n",
|
|
|
233 |
" <p>\n",
|
|
|
234 |
" © Copyright 2004 Richard York, All Rights Reserved.<br />\n",
|
|
|
235 |
" Best viewed with <a href='http://www.mozilla.org'>Mozilla</a>. Visit the <a href='http://www.spicypeanut.net'>Mail_IMAP</a> homepage.\n",
|
|
|
236 |
" </p>\n",
|
|
|
237 |
" </div>\n",
|
|
|
238 |
" </body>\n",
|
|
|
239 |
" </html>";
|
|
|
240 |
|
|
|
241 |
// Close the stream
|
|
|
242 |
$msg->close();
|
|
|
243 |
?>
|