updating pot
[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 * @package plugins
12 * @subpackage message_details
13 */
14
15 /** @ignore */
16 define('SM_PATH','../../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'include/validate.php');
20 require_once(SM_PATH . 'functions/imap.php');
21 require_once(SM_PATH . 'functions/mime.php');
22 require_once(SM_PATH . 'config/config.php');
23 require_once(SM_PATH . 'functions/prefs.php');
24
25 global $color;
26
27 sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
28 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
29
30 sqgetGlobalVar('username', $username, SQ_SESSION);
31 sqgetGlobalVar('key', $key, SQ_COOKIE);
32 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
33
34 function CalcEntity($entString, $direction) {
35 $result = $entString;
36 if ($direction == -1) {
37 $pos = strrpos($entString,'.');
38 $result = substr($entString,0,$pos);
39 }
40
41 switch ($direction) {
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;
60 }
61 return ($result);
62 }
63
64 function returnTime($start) {
65 $stop = gettimeofday();
66 $timepassed = 1000000 * ($stop['sec'] - $start['sec']) + $stop['usec'] - $start['usec'];
67 return $timepassed;
68 }
69
70 function GetMimeProperties($header) {
71 }
72
73 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
74 $read = sqimap_mailbox_select($imapConnection, $mailbox);
75 $start = gettimeofday();
76 $body = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, TRUE);
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();
85 session_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);
96 for ($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;
264 width:99%;
265 }
266 //-->
267
268 </style>
269
270 ECHO;
271
272 displayHtmlHeader( _("Message Details"), $xtra, FALSE );
273 /* body */
274 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n";
275 echo '<code>'."\n";
276 echo '<font face="monospace">'."\n";
277 echo '<br />'."\n";
278
279
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
292 if (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 '</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 ?>