| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* This example provides a basic demonstration of how Mail_IMAP can be used to
|
|
|
5 |
* view multipart messages. 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 |
require_once 'Mail/IMAP.php';
|
|
|
15 |
|
|
|
16 |
// Import the message id and part id from the $_GET array
|
|
|
17 |
$mid = $_GET['mid'];
|
|
|
18 |
$pid = $_GET['pid'];
|
|
|
19 |
|
|
|
20 |
// pop3://user:pass@mail.example.com:110/INBOX#notls
|
|
|
21 |
|
|
|
22 |
$msg =& new Mail_IMAP();
|
|
|
23 |
|
|
|
24 |
// Open up a mail connection
|
|
|
25 |
// pop3://user:pass@mail.example.com:110/INBOX#notls
|
|
|
26 |
// Use an existing imap resource stream, or provide a URI abstraction.
|
|
|
27 |
//
|
|
|
28 |
// If you are unsure of the URI syntax to use here,
|
|
|
29 |
// use the Mail_IMAP_connection_wizard to find the right URI.
|
|
|
30 |
// Or see docs for Mail_IMAP::connect
|
|
|
31 |
//
|
|
|
32 |
// This argument must also be set in MAIL_IMAP.inbox.php.
|
|
|
33 |
|
|
|
34 |
if (PEAR::isError($msg->connect('imap://user:pass@mail.server.net:143/INBOX'))) {
|
|
|
35 |
echo "<span style='font-weight: bold;'>Error:</span> Unable to build a connection.";
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
// Gather header information
|
|
|
39 |
// Sets the seen flag if this is a subpart of a multipart message
|
|
|
40 |
$msg->getHeaders($mid, $pid);
|
|
|
41 |
|
|
|
42 |
// Use this to *not* set the seen flag
|
|
|
43 |
// $msg->getHeaders($mid, $pid, 1024, 1024, NULL, FT_PEEK);
|
|
|
44 |
//
|
|
|
45 |
// Must also use this in the call to getBody below.
|
|
|
46 |
|
|
|
47 |
// Gather inline/attachment parts specific to this part
|
|
|
48 |
$msg->getParts($mid, $pid);
|
|
|
49 |
|
|
|
50 |
// Are there inline or attachment parts?
|
|
|
51 |
if (count($msg->inPid[$mid]) > 0 || count($msg->attachPid[$mid]) > 0)
|
|
|
52 |
{
|
|
|
53 |
echo " <table style='width: 100%; border: 1px solid black; background: white;'>\n",
|
|
|
54 |
" <tr>\n",
|
|
|
55 |
" <td style='font-size: 10px; font-weight: bold;'>\n",
|
|
|
56 |
" attachments\n",
|
|
|
57 |
" </td>\n",
|
|
|
58 |
" </tr>\n",
|
|
|
59 |
" <td style='padding: 5px;'>\n";
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
// Are there inline parts?
|
|
|
63 |
if (count($msg->inPid[$mid]) > 0)
|
|
|
64 |
{
|
|
|
65 |
foreach ($msg->inPid[$mid] as $i => $inid)
|
|
|
66 |
{
|
|
|
67 |
echo " Inline part: <a href='IMAP.message.php?mid={$mid}&pid={$msg->inPid[$mid][$i]}'>{$msg->inFname[$mid][$i]} {$msg->inFtype[$mid][$i]} ".$msg->convertBytes($msg->inFsize[$mid][$i])."</a><br />\n";
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
// Are there attachments?
|
|
|
72 |
if (count($msg->attachPid[$mid]) > 0)
|
|
|
73 |
{
|
|
|
74 |
foreach ($msg->attachPid[$mid] as $i => $aid)
|
|
|
75 |
{
|
|
|
76 |
echo " Attachment: <a href='IMAP.message.php?mid={$mid}&pid={$msg->attachPid[$mid][$i]}'>{$msg->attachFname[$mid][$i]} {$msg->attachFtype[$mid][$i]} ".$msg->convertBytes($msg->attachFsize[$mid][$i])."</a><br />\n";
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
if (count($msg->inPid[$mid]) > 0 || count($msg->attachPid[$mid]) > 0)
|
|
|
81 |
{
|
|
|
82 |
echo " </td>\n",
|
|
|
83 |
" </tr>\n",
|
|
|
84 |
" </table>\n";
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
echo " <table style='width: 100%; border: 1px solid black; background: white; margin-top: 5px;'>\n",
|
|
|
88 |
" <tr>\n",
|
|
|
89 |
" <td>\n",
|
|
|
90 |
" <pre>\n",
|
|
|
91 |
|
|
|
92 |
// Print the Raw Headers
|
|
|
93 |
htmlspecialchars($msg->rawHeaders[$mid]),
|
|
|
94 |
|
|
|
95 |
" </pre>\n",
|
|
|
96 |
" </td>\n",
|
|
|
97 |
" </tr>\n",
|
|
|
98 |
" </table>\n";
|
|
|
99 |
|
|
|
100 |
// Retrieve the message body (sets the seen flag)
|
|
|
101 |
$body = $msg->getBody($mid, $pid);
|
|
|
102 |
|
|
|
103 |
// Use this to *not* set the seen flag
|
|
|
104 |
// $body = $msg->getBody($mid, $pid, 0, 'text/html', FT_PEEK);
|
|
|
105 |
//
|
|
|
106 |
// Must also use this in the call to getHeaders above.
|
|
|
107 |
|
|
|
108 |
if ($body['ftype'] == 'text/plain')
|
|
|
109 |
{
|
|
|
110 |
echo " <table style='width: 100%; border: 1px solid black; background: white; margin-top: 5px;'>\n",
|
|
|
111 |
" <tr>\n",
|
|
|
112 |
" <td>\n",
|
|
|
113 |
|
|
|
114 |
// If this is a plain/text part format it for display
|
|
|
115 |
nl2br(htmlspecialchars($body['message'])),
|
|
|
116 |
|
|
|
117 |
" </td>\n",
|
|
|
118 |
" </tr>\n",
|
|
|
119 |
" </table>\n";
|
|
|
120 |
}
|
|
|
121 |
else
|
|
|
122 |
{
|
|
|
123 |
echo $body['message'];
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
// Close the stream
|
|
|
127 |
$msg->close();
|
|
|
128 |
|
|
|
129 |
?>
|