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