| 1 |
lars |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/**
|
|
|
4 |
* @package Content-management
|
|
|
5 |
* @author Lars Tiefland <tiefland@weban.de>
|
|
|
6 |
* @copyright 2009 Webagentur Niewerth
|
|
|
7 |
* @license propietary http://www.weban.de
|
|
|
8 |
* @version $Rev$
|
|
|
9 |
* @filesource
|
|
|
10 |
*
|
|
|
11 |
*/
|
|
|
12 |
|
|
|
13 |
/**
|
|
|
14 |
*
|
|
|
15 |
* @package Content-management
|
|
|
16 |
* @author Lars Tiefland <tiefland@weban.de>
|
|
|
17 |
* @copyright 2009 Webagentur Niewerth
|
|
|
18 |
*/
|
|
|
19 |
|
|
|
20 |
// SVN: $Id: functions.common.php 51 2009-10-07 09:43:24Z tiefland $
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* Demonstrates how to set-up a basic inbox using Mail_IMAP.
|
|
|
24 |
* See {@link connect} for extended documentation on
|
|
|
25 |
* how to set the connection URI.
|
|
|
26 |
*
|
|
|
27 |
* @author Richard York <rich_y@php.net?>
|
|
|
28 |
* @copyright (c) Copyright 2004, Richard York, All Rights Reserved.
|
|
|
29 |
* @package Mail_IMAP
|
|
|
30 |
* @subpackage examples
|
|
|
31 |
**
|
|
|
32 |
*/
|
|
|
33 |
|
|
|
34 |
error_reporting( E_ALL );
|
|
|
35 |
|
|
|
36 |
require_once 'Mail/IMAP.php';
|
|
|
37 |
|
|
|
38 |
// Use an existing imap resource stream, or provide a URI abstraction.
|
|
|
39 |
// Example of URI:
|
|
|
40 |
// pop3://user:pass@mail.example.com:110/INBOX#notls
|
|
|
41 |
//
|
|
|
42 |
// If you are unsure of the URI syntax to use here,
|
|
|
43 |
// use the Mail_IMAP_connection_wizard to find the right URI.
|
|
|
44 |
// Or see docs for Mail_IMAP::connect
|
|
|
45 |
//
|
|
|
46 |
// The connection URI must also be set in:
|
|
|
47 |
// IMAP.inbox.php.
|
|
|
48 |
// IMAP.message_viewer.php
|
|
|
49 |
// IMAP.part_viewer.php
|
|
|
50 |
$connection = 'imap://'.urlencode("rs@mediaran.de").':EW-ad-1055@mail.mediaran.de:143/INBOX#notls';
|
|
|
51 |
|
|
|
52 |
if ( !isset($_GET['dump_mid']) )
|
|
|
53 |
{
|
|
|
54 |
$msg = &new Mail_IMAP();
|
|
|
55 |
}
|
|
|
56 |
else
|
|
|
57 |
{
|
|
|
58 |
// Call on debuging automatically.
|
|
|
59 |
include 'Mail/IMAP/Debug/Debug.php';
|
|
|
60 |
$msg = &new Mail_IMAP_Debug( $connection );
|
|
|
61 |
if ( $msg->error->hasErrors() )
|
|
|
62 |
{
|
|
|
63 |
$msg->dump( $msg->error->getErrors(true) );
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
// Open up a mail connection
|
|
|
68 |
|
|
|
69 |
if ( !$msg->connect($connection) )
|
|
|
70 |
{
|
|
|
71 |
echo $msg->alerts();
|
|
|
72 |
echo $msg->errors();
|
|
|
73 |
echo
|
|
|
74 |
"<SPAN style='font-weight: bold;'>Error:</SPAN> Unable to build a connection.";
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
// Unread messages appear with LIGHTGRAY links
|
|
|
78 |
// Read messages appear with WHITE links
|
|
|
79 |
// If you are using an IMAP-protocol based mail server,
|
|
|
80 |
// POP3 doesn't remember flag settings
|
|
|
81 |
|
|
|
82 |
// Retrieve message count
|
|
|
83 |
$msgcount = $msg->messageCount();
|
|
|
84 |
|
|
|
85 |
echo "
|
|
|
86 |
|
|
|
87 |
|
|
|
88 |
<TITLE> Mail_IMAP Inbox </TITLE>
|
|
|
89 |
<LINK rel='stylesheet' type='text/css' href='IMAP.css' media='all'>
|
|
|
90 |
|
|
|
91 |
|
|
|
92 |
<DIV id='header'>
|
|
|
93 |
<H1>
|
|
|
94 |
PEAR :: Mail_IMAP
|
|
|
95 |
</H1>
|
|
|
96 |
</DIV>
|
|
|
97 |
<DIV id='inboxbody'>
|
|
|
98 |
<DIV id='msgcount'>
|
|
|
99 |
{$msg->mailboxInfo['folder']}: ($msgcount) messages total.
|
|
|
100 |
</DIV>
|
|
|
101 |
<TABLE class='msg'>
|
|
|
102 |
<THEAD><TR><TH>
|
|
|
103 |
subject
|
|
|
104 |
</TH><TH>
|
|
|
105 |
from
|
|
|
106 |
</TH><TH>
|
|
|
107 |
received
|
|
|
108 |
</TH></TR></THEAD>
|
|
|
109 |
<TBODY>\n";
|
|
|
110 |
|
|
|
111 |
if ( $msgcount > 0 )
|
|
|
112 |
{
|
|
|
113 |
/*
|
|
|
114 |
* Each message of a mailbox is numbered offset from 1
|
|
|
115 |
* Create the $mid (message id) and recursively gather
|
|
|
116 |
* message information.
|
|
|
117 |
*/
|
|
|
118 |
for ( $mid = 1; $mid <= $msgcount; $mid++ )
|
|
|
119 |
{
|
|
|
120 |
// Get the headers
|
|
|
121 |
$msg->getHeaders( $mid );
|
|
|
122 |
|
|
|
123 |
$style = ( (isset($msg->header[$mid]['Recent']) && $msg->header[$mid]['Recent'] ==
|
|
|
124 |
'N') || (isset($msg->header[$mid]['Unseen']) && $msg->
|
|
|
125 |
header[$mid]['Unseen'] == 'U') ) ? 'gray' : 'black';
|
|
|
126 |
|
|
|
127 |
// Grab inline and attachment parts relevant to top level parts.
|
|
|
128 |
// See the docs for the $msg property for more information:
|
|
|
129 |
// http://www.smilingsouls.net/index.php?content=Mail_IMAP/msg
|
|
|
130 |
$msg->getParts( $mid );
|
|
|
131 |
|
|
|
132 |
if ( !isset($msg->header[$mid]['subject']) || empty($msg->
|
|
|
133 |
header[$mid]['subject']) )
|
|
|
134 |
{
|
|
|
135 |
$msg->header[$mid]['subject'] =
|
|
|
136 |
"<SPAN style='font-style: italic;'>no subject provided";
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
echo " <TR>\n",
|
|
|
140 |
" <TD class='msgitem'><A href='IMAP.message_viewer.php?mid={$mid}&pid=" .
|
|
|
141 |
$msg->msg[$mid]['pid'] . "' target='_blank' style='color: {$style};'>" .
|
|
|
142 |
$msg->header[$mid]['subject'] . "</A></TD>\n",
|
|
|
143 |
" <TD class='msgitem'>\n",
|
|
|
144 |
" ", ( isset($msg->header[$mid]['from_personal'][0]) &&
|
|
|
145 |
!empty($msg->header[$mid]['from_personal'][0]) ) ?
|
|
|
146 |
'<SPAN title="' . str_replace( '@', ' at ', $msg->header[$mid]['from'][0] ) .
|
|
|
147 |
'">' . $msg->header[$mid]['from_personal'][0] . "</SPAN>" :
|
|
|
148 |
str_replace( '@', ' at ', $msg->header[$mid]['from'][0] ), "\n",
|
|
|
149 |
" </TD>\n",
|
|
|
150 |
" <TD class='msgitem'>" . date( 'D d M, Y h:i:s',
|
|
|
151 |
$msg->header[$mid]['udate'] ) . "</TD>\n",
|
|
|
152 |
" </TR>\n",
|
|
|
153 |
" <TR>\n",
|
|
|
154 |
" <TD colspan='3' class='msgattach'>\n";
|
|
|
155 |
|
|
|
156 |
// Show inline parts first
|
|
|
157 |
if ( isset($msg->msg[$mid]['in']['pid']) && count($msg->msg[$mid]['in']['pid']) >
|
|
|
158 |
|
|
|
159 |
{
|
|
|
160 |
foreach ( $msg->msg[$mid]['in']['pid'] as $i => $inid )
|
|
|
161 |
{
|
|
|
162 |
$fname = ( isset($msg->msg[$mid]['in']['fname'][$i]) ) ?
|
|
|
163 |
$msg->msg[$mid]['in']['fname'][$i] : null;
|
|
|
164 |
|
|
|
165 |
echo
|
|
|
166 |
" Inline part: <A href='IMAP.message_viewer.php?mid={$mid}&pid=" .
|
|
|
167 |
$msg->msg[$mid]['in']['pid'][$i] .
|
|
|
168 |
"' target='_blank'>" . $fname . " " . $msg->msg[$mid]['in']['ftype'][$i] .
|
|
|
169 |
" " . $msg->convertBytes( $msg->msg[$mid]['in']['fsize'][$i] ) .
|
|
|
170 |
"</A><BR>\n";
|
|
|
171 |
}
|
|
|
172 |
}
|
|
|
173 |
|
|
|
174 |
// Now the attachments
|
|
|
175 |
if ( isset($msg->msg[$mid]['at']['pid']) && count($msg->msg[$mid]['at']['pid']) >
|
|
|
176 |
|
|
|
177 |
{
|
|
|
178 |
foreach ( $msg->msg[$mid]['at']['pid'] as $i => $aid )
|
|
|
179 |
{
|
|
|
180 |
$fname = ( isset($msg->msg[$mid]['at']['fname'][$i]) ) ?
|
|
|
181 |
$msg->msg[$mid]['at']['fname'][$i] : null;
|
|
|
182 |
|
|
|
183 |
echo
|
|
|
184 |
" Attachment: <A href='
|
|
|
185 |
IMAP . message_viewer . php ? mid =
|
|
|
186 |
{
|
|
|
187 |
$mid}
|
|
|
188 |
&pid = " .$msg->msg[$mid]['at']['pid'][$i]."
|
|
|
189 |
' target='_blank'>".$fname." ".$msg->msg[$mid]['at
|
|
|
190 |
']['ftype
|
|
|
191 |
'][$i]." ".$msg->convertBytes($msg->msg[$mid]['at
|
|
|
192 |
']['fsize'][$i])."</A><BR>\n";
|
|
|
193 |
}
|
|
|
194 |
}
|
|
|
195 |
|
|
|
196 |
echo " </TD>\n",
|
|
|
197 |
" </TR>\n";
|
|
|
198 |
|
|
|
199 |
// Clean up left over variables
|
|
|
200 |
// $msg->unsetParts($mid);
|
|
|
201 |
// $msg->unsetHeaders($mid);
|
|
|
202 |
}
|
|
|
203 |
}
|
|
|
204 |
else
|
|
|
205 |
{
|
|
|
206 |
echo " <TR>\n".
|
|
|
207 |
" <TD colspan='3' style='font-size: 30pt; text-align: center; padding: 50px 0;'>No Messages</TD>".
|
|
|
208 |
" </TR>\n";
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
echo " </TBODY>\n".
|
|
|
212 |
" </TABLE>\n".
|
|
|
213 |
" <DIV id='quota'>\n".
|
|
|
214 |
" mailbox: {$msg->mailboxInfo['user']}<BR>\n";
|
|
|
215 |
|
|
|
216 |
// getQuota doesn't work for some servers if ( $quota = $msg->getQuota() )
|
|
|
217 |
{
|
|
|
218 |
echo " Quota: {$quota['STORAGE']['usage']} used of {$quota['STORAGE']['limit']} total\n";
|
|
|
219 |
}
|
|
|
220 |
|
|
|
221 |
echo " </DIV>\n" .
|
|
|
222 |
" </DIV>\n" . " <DIV id='
|
|
|
223 |
footer'>\n" . " <P>\n" .
|
|
|
224 |
" © Copyright 2004 Richard York, All Rights Reserved.<BR>\n" .
|
|
|
225 |
" Best viewed with <A href='
|
|
|
226 |
http ://www.mozilla.org'>Mozilla</A> and other standards-based browsers. Visit the <A href='http://www.smilingsouls.net'>Mail_IMAP</A> homepage.\n".
|
|
|
227 |
" </P>\n" . " </DIV>\n" .
|
|
|
228 |
" \n" . " ";
|
|
|
229 |
|
|
|
230 |
// Close the stream
|
|
|
231 |
$msg->close();
|
|
|
232 |
|
|
|
233 |
// View errors gathered by PEAR_ErrorStack
|
|
|
234 |
// Uncommment to see more errors.
|
|
|
235 |
|
|
|
236 |
// if ($msg->error->hasErrors()) {
|
|
|
237 |
// echo "<PRE style="display: block; white-space: pre;">\n";
|
|
|
238 |
// var_dump($msg->error->getErrors());
|
|
|
239 |
// echo "</PRE>\n";
|
|
|
240 |
// }
|
|
|
241 |
|
|
|
242 |
?>
|