removed includes that are already loaded by include/validate.php.
[squirrelmail.git] / plugins / message_details / message_details_bottom.php
... / ...
CommitLineData
1<?php
2/**
3 * Message Details plugin - bottom frame with message structure and rfc822 body
4 *
5 * Plugin to view the RFC822 raw message output and the bodystructure of a message
6 *
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * @author Marc Groot Koerkamp
10 * @copyright Copyright &copy; 2002 Marc Groot Koerkamp, The Netherlands
11 * @copyright Copyright &copy; 2004 The SquirrelMail Project Team
12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
13 * @version $Id$
14 * @package plugins
15 * @subpackage message_details
16 */
17
18/** @ignore */
19define('SM_PATH','../../');
20
21/* SquirrelMail required files. */
22require_once(SM_PATH . 'include/validate.php');
23require_once(SM_PATH . 'functions/imap.php');
24require_once(SM_PATH . 'functions/mime.php');
25
26global $color;
27
28sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
29sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
30
31sqgetGlobalVar('username', $username, SQ_SESSION);
32sqgetGlobalVar('key', $key, SQ_COOKIE);
33sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
34
35function CalcEntity($entString, $direction) {
36 $result = $entString;
37 if ($direction == -1) {
38 $pos = strrpos($entString,'.');
39 $result = substr($entString,0,$pos);
40 }
41
42 switch ($direction) {
43 case 0:
44 $pos = strrpos($entString,'.');
45 if ($pos === false) {
46 $entString++;
47 $result= $entString;
48 }
49 else {
50 $level = substr($entString,0,$pos);
51 $sublevel = substr($entString,$pos+1);
52 $sublevel++;
53 $result = "$level".'.'."$sublevel";
54 }
55 break;
56 case 1:
57 $result = "$entString".".0";
58 break;
59 default:
60 break;
61 }
62 return ($result);
63}
64
65function returnTime($start) {
66 $stop = gettimeofday();
67 $timepassed = 1000000 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec'];
68 return $timepassed;
69}
70
71function GetMimeProperties($header) {
72}
73
74$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
75$read = sqimap_mailbox_select($imapConnection, $mailbox);
76$start = gettimeofday();
77$body = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, TRUE);
78$message_body = '';
79$header = false;
80$mimepart = false;
81$bnd_end = false;
82$messageheader = true;
83$messageheaderstart=false;
84$boundaries = array();
85$entities = array();
86session_unregister("entities");
87$pre = '<b>';
88$end = '</b>';
89$entStr = '';
90$bla ='';
91$content = array ();
92$content_indx = -1;
93$contentset = false;
94
95$count=count($body);
96$body[$count-1] = substr($body[$count-1], -1);
97for ($i=1; $i < $count; $i++) {
98 $line = trim($body[$i]);
99 if ($line == '') {
100 $pre = '';
101 $end = '';
102 if ($bnd_end) {
103 $header = true;
104 $mimepart = false;
105 } else if ($messageheader) {
106 if ($header) {
107 $header=false;
108 $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" id="'.$entStr.'B">'."\n \n";
109 }
110 $mimepart = -$header;
111 $bnd_end = false;
112 if ($messageheaderstart) {
113 $messageheaderstart=false;
114 }
115 } else if ($messageheaderstart) {
116 $messageheader= false;
117 } else {
118 if ($header) {
119 $pre = '';
120 $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" id="'.$entStr.'B">'."\n \n";
121 }
122 $header = false;
123 $mimepart=true;
124 }
125 $contentset = false;
126 $nameset = false;
127 } else {
128 if (!$header && $messageheader) {
129 $messageheaderstart=true;
130 if ($pre != '<b>') {
131 $pre = '<i><font color ="'.$color[1].'">';
132 $end = '</i></font>';
133 }
134 }
135 if (!$messageheader && !$header ) {
136 $mimepart=true;
137 } else {
138 $mimepart=false;
139 }
140 $pre = '';
141 $end = '';
142 }
143 if ( ( $header || $messageheader) && (preg_match("/^.*boundary=\"?(.+(?=\")|.+).*/i",$line,$reg)) ) {
144 $bnd = $reg[1];
145 $bndreg = $bnd;
146 $bndreg = str_replace("\\","\\\\",$bndreg);
147 $bndreg = str_replace("?","\\?",$bndreg);
148 $bndreg = str_replace("+","\\+",$bndreg);
149 $bndreg = str_replace(".","\\.",$bndreg);
150 $bndreg = str_replace("/","\\/",$bndreg);
151 $bndreg = str_replace("-","\\-",$bndreg);
152 $bndreg = str_replace("(","\\(",$bndreg);
153 $bndreg = str_replace(")","\\)",$bndreg);
154
155 $boundaries[] = array( 'bnd' => $bnd, 'bndreg' => $bndreg);
156 $messageheader = false;
157 $messageheaderstart=false;
158 $mimepart=false;
159 if ($entStr=='') {
160 $entStr='0';
161 } else {
162 $entStr = CalcEntity("$entStr",1);
163 }
164 }
165
166 if (($line != '' && $line{0} == '-' || $header) && isset($boundaries[0])) {
167 $cnt=count($boundaries)-1;
168 $bnd = $boundaries[$cnt]['bnd'];
169 $bndreg = $boundaries[$cnt]['bndreg'];
170
171 $regstr = '/^--'."($bndreg)".".*".'/';
172 if (preg_match($regstr,$line,$reg) ) {
173 $bndlen = strlen($reg[1]);
174 $bndend = false;
175 if (strlen($line) > ($bndlen + 3)) {
176 if ($line{$bndlen+2} == '-' && $line{$bndlen+3} == '-')
177 $bndend = true;
178 }
179 if ($bndend) {
180 $entStr = CalcEntity("$entStr",-1);
181 array_pop($boundaries);
182 $pre .= '<b><font color ="'.$color[2].'">';
183 $end .= '</font></b>';
184 $header = true;
185 $mimepart = false;
186 $bnd_end = true;
187 $encoding = '';
188 } else {
189 $header = true;
190 $bnd_end = false;
191 $entStr = CalcEntity("$entStr",0);
192 $content_indx++;
193 $content[$content_indx]=array();
194 $content[$content_indx]['ent'] = '<a href="#'."$entStr \">$entStr".'</a>';
195 $pre .= "\n \n".'</div>'."\n \n".'<div class="entheader" id="'.$entStr.'H"><a name="'."$entStr".'"><b><font color="'.$color[2].'">';
196 $end .= '</font></b>'."\n";
197 $header = true;
198 $mimepart = false;
199 $encoding = '';
200 }
201 } else {
202 if ($header) {
203 if (!$contentset && preg_match("/^.*(content-type:)\s*(\w+)\/(\w+).*/i",$line,$reg)) {
204 if (strtolower($reg[2]) == 'message' && strtolower($reg[3]) == 'rfc822') {
205 $messageheader = true;
206 }
207 $content[$content_indx]['type'] = "$reg[2]/$reg[3]";
208 $contentset = true;
209 if ($reg[2] == 'image') {
210 $entities["$entStr"] = array();
211 $entities["$entStr"]['entity'] = $entStr;
212 $entities["$entStr"]['contenttype']=$reg[2].'/'.$reg[3];
213 }
214 } else if (!$nameset && preg_match("/^.*(name=\s*)\"(.*)\".*/i",$line,$reg)) {
215 $name = htmlspecialchars($reg[2]);
216 $content[$content_indx]['name'] = decodeHeader($name);
217 $nameset = true;
218 if (isset($entities["$entStr"])) {
219 $entities["$entStr"]['name'] = urlEncode($reg[2]);
220 }
221 } else if (preg_match("/^.*(content-transfer-encoding:)\s*(\w+-?(\w+)?).*/i",$line,$reg) ) {
222 $encoding = $reg[2];
223 if (isset($entities["$entStr"])) {
224 $entities["$entStr"]['encoding']=$reg[2];
225 }
226 $content[$content_indx]['encoding'] = $encoding;
227 $mimeentity = '';
228 }
229
230 $pre .= '<b><font color='.$color[7].'">';
231 $end .= '</font></b>';
232 //$mimepart=false;
233 }
234 }
235 }
236/*
237 if ($mimepart) {
238 if (isset($entities["$entStr"])) {
239 if (isset($encoding) && $encoding == 'base64') {
240 if (!isset( $entities["$entStr"]['content'])) $entities[$entStr]['content'] = '';
241 $entities["$entStr"]['content'] .= $line;
242 }
243 }
244 }
245*/
246 $line = htmlspecialchars($line);
247 $message_body .= "$pre"."$line"."$end".'<br />'."\r\n";
248}
249//echo returnTime($start).'<br />';
250$xtra = <<<ECHO
251
252<style>
253
254<!--
255.ent_body {
256 display:inline;
257}
258
259.header {
260 display:inline;
261}
262
263.entheader {
264 display:inline;
265 width:99%;
266}
267//-->
268
269</style>
270
271ECHO;
272
273displayHtmlHeader( _("Message Details"), $xtra, FALSE );
274/* body */
275echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n";
276echo '<code>'."\n";
277echo '<font face="monospace">'."\n";
278echo '<br />'."\n";
279
280
281//session_register("entities");
282//$keys = array_keys($entities);
283//$start = gettimeofday();
284//foreach ($keys as $key) {
285// if (isset($entities[$key])) {
286// if ($entities[$key]['encoding'] == 'base64') {
287// echo '<img src="message_viewentity.php?ent='.$entities[$key]['entity'].'&amp;name='.$entities[$key]['name'].'"><br />';
288// }
289// }
290//}
291//session_unregister("entities");
292
293if (count($content) > 0) {
294 echo '<h2>'._("Bodystructure")."</h2>\n\n";
295 echo '<table border="1" width="98%"><thead>'.
296 '<tr bgcolor="'.$color[7].'">'.
297 '<td><b><font color="'.$color[5].'">'._("Entity").'</font></b></td>'.
298 '<td><b><font color="'.$color[5].'">'._("Content-Type").'</font></b></td>'.
299 '<td><b><font color="'.$color[5].'">'._("Name").'</font></b></td>'.
300 '<td><b><font color="'.$color[5].'">'._("Encoding").'</font></b></td>'.
301 '</tr>'.
302 '</thead><tbody>';
303 for ($i = 0; $i < count($content);$i++) {
304 echo '<tr><td>';
305 echo $content[$i]['ent'].'</td><td>';
306 if (isset($content[$i]['type'])) {
307 echo $content[$i]['type'];
308 } else echo 'TEXT/PLAIN';
309 echo '</td><td>';
310 if (isset($content[$i]['name'])) {
311 echo $content[$i]['name'];
312 } else echo '&nbsp;';
313 echo '</td><td>';
314 if (isset($content[$i]['encoding'])) {
315 echo $content[$i]['encoding'];
316 } else echo '&nbsp;';
317 echo '</td></tr>'."\n";
318 }
319 echo '</tbody></table><br />'."\n";
320}
321echo '<h2>'._("RFC822 Message body")."</h2>\n\n";
322echo '<div><div class="header">'."\n\n";
323echo $message_body;
324echo '</div></div></font></code></body></html>';
325?>