updating pot
[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) {
796f91d9 42 case 0:
43 $pos = strrpos($entString,'.');
44 if ($pos === false) {
45 $entString++;
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;
bbdea028 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 == '') {
796f91d9 99 $pre = '';
100 $end = '';
bbdea028 101 if ($bnd_end) {
796f91d9 102 $header = true;
103 $mimepart = false;
104 } else if ($messageheader) {
105 if ($header) {
106 $header=false;
e1728a7a 107 $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" id="'.$entStr.'B">'."\n \n";
796f91d9 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 = '';
e1728a7a 119 $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" id="'.$entStr.'B">'."\n \n";
796f91d9 120 }
121 $header = false;
122 $mimepart=true;
123 }
124 $contentset = false;
125 $nameset = false;
bbdea028 126 } else {
127 if (!$header && $messageheader) {
796f91d9 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 = '';
bbdea028 141 }
142 if ( ( $header || $messageheader) && (preg_match("/^.*boundary=\"?(.+(?=\")|.+).*/i",$line,$reg)) ) {
796f91d9 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);
bbdea028 153
796f91d9 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 }
bbdea028 163 }
164
165 if (($line != '' && $line{0} == '-' || $header) && isset($boundaries[0])) {
166 $cnt=count($boundaries)-1;
796f91d9 167 $bnd = $boundaries[$cnt]['bnd'];
168 $bndreg = $boundaries[$cnt]['bndreg'];
bbdea028 169
796f91d9 170 $regstr = '/^--'."($bndreg)".".*".'/';
171 if (preg_match($regstr,$line,$reg) ) {
172 $bndlen = strlen($reg[1]);
173 $bndend = false;
bbdea028 174 if (strlen($line) > ($bndlen + 3)) {
796f91d9 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>';
e1728a7a 194 $pre .= "\n \n".'</div>'."\n \n".'<div class="entheader" id="'.$entStr.'H"><a name="'."$entStr".'"><b><font color="'.$color[2].'">';
796f91d9 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 }
bbdea028 228
796f91d9 229 $pre .= '<b><font color='.$color[7].'">';
230 $end .= '</font></b>';
231 //$mimepart=false;
232 }
233 }
234 }
bbdea028 235/*
236 if ($mimepart) {
796f91d9 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 }
bbdea028 242 }
796f91d9 243 }
bbdea028 244*/
245 $line = htmlspecialchars($line);
796f91d9 246 $message_body .= "$pre"."$line"."$end".'<br />'."\r\n";
bbdea028 247}
796f91d9 248//echo returnTime($start).'<br />';
bbdea028 249$xtra = <<<ECHO
250
796f91d9 251<style>
bbdea028 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
796f91d9 268</style>
bbdea028 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";
796f91d9 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') {
796f91d9 286// echo '<img src="message_viewentity.php?ent='.$entities[$key]['entity'].'&amp;name='.$entities[$key]['name'].'"><br />';
bbdea028 287// }
288// }
289//}
290//session_unregister("entities");
291
292if (count($content) > 0) {
293 echo '<h2> Bodystructure </h2>'."\n\n";
796f91d9 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 '</tr>'.
301 '</thead><tbody>';
bbdea028 302 for ($i = 0; $i < count($content);$i++) {
796f91d9 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";
bbdea028 317 }
796f91d9 318 echo '</tbody></table><br />'."\n";
bbdea028 319}
320echo '<h2> RFC822 Message body </h2>'."\n\n";
321echo '<div><div class="header">'."\n\n";
322echo $message_body;
323echo '</div></div></font></code></body></html>';
324?>