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