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