a1d661cb75300715bf1f31c1c9be7b0ad66e44ed
3 * Message Details plugin - bottom frame with message structure and rfc822 body
5 * Plugin to view the RFC822 raw message output and the bodystructure of a message
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * @author Marc Groot Koerkamp
10 * @copyright Copyright © 2002 Marc Groot Koerkamp, The Netherlands
11 * @copyright Copyright © 2004 The SquirrelMail Project Team
12 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
15 * @subpackage message_details
19 define('SM_PATH','../../');
21 /* SquirrelMail required files. */
22 require_once(SM_PATH
. 'include/validate.php');
23 require_once(SM_PATH
. 'functions/imap.php');
24 require_once(SM_PATH
. 'functions/mime.php');
25 require_once(SM_PATH
. 'config/config.php');
26 require_once(SM_PATH
. 'functions/prefs.php');
30 sqgetGlobalVar('passed_id', $passed_id, SQ_GET
);
31 sqgetGlobalVar('mailbox', $mailbox, SQ_GET
);
33 sqgetGlobalVar('username', $username, SQ_SESSION
);
34 sqgetGlobalVar('key', $key, SQ_COOKIE
);
35 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION
);
37 function CalcEntity($entString, $direction) {
39 if ($direction == -1) {
40 $pos = strrpos($entString,'.');
41 $result = substr($entString,0,$pos);
46 $pos = strrpos($entString,'.');
52 $level = substr($entString,0,$pos);
53 $sublevel = substr($entString,$pos+
1);
55 $result = "$level".'.'."$sublevel";
59 $result = "$entString".".0";
67 function returnTime($start) {
68 $stop = gettimeofday();
69 $timepassed = 1000000 * ($stop['sec'] - $start['sec']) +
$stop['usec'] - $start['usec'];
73 function GetMimeProperties($header) {
76 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
77 $read = sqimap_mailbox_select($imapConnection, $mailbox);
78 $start = gettimeofday();
79 $body = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, TRUE);
84 $messageheader = true;
85 $messageheaderstart=false;
86 $boundaries = array();
88 session_unregister("entities");
98 $body[$count-1] = substr($body[$count-1], -1);
99 for ($i=1; $i < $count; $i++
) {
100 $line = trim($body[$i]);
107 } else if ($messageheader) {
110 $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" id="'.$entStr.'B">'."\n \n";
112 $mimepart = -$header;
114 if ($messageheaderstart) {
115 $messageheaderstart=false;
117 } else if ($messageheaderstart) {
118 $messageheader= false;
122 $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" id="'.$entStr.'B">'."\n \n";
130 if (!$header && $messageheader) {
131 $messageheaderstart=true;
133 $pre = '<i><font color ="'.$color[1].'">';
134 $end = '</i></font>';
137 if (!$messageheader && !$header ) {
145 if ( ( $header ||
$messageheader) && (preg_match("/^.*boundary=\"?(.+(?=\")|.+).*/i",$line,$reg)) ) {
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 $bndreg = str_replace("-","\\-",$bndreg);
154 $bndreg = str_replace("(","\\(",$bndreg);
155 $bndreg = str_replace(")","\\)",$bndreg);
157 $boundaries[] = array( 'bnd' => $bnd, 'bndreg' => $bndreg);
158 $messageheader = false;
159 $messageheaderstart=false;
164 $entStr = CalcEntity("$entStr",1);
168 if (($line != '' && $line{0} == '-' ||
$header) && isset($boundaries[0])) {
169 $cnt=count($boundaries)-1;
170 $bnd = $boundaries[$cnt]['bnd'];
171 $bndreg = $boundaries[$cnt]['bndreg'];
173 $regstr = '/^--'."($bndreg)".".*".'/';
174 if (preg_match($regstr,$line,$reg) ) {
175 $bndlen = strlen($reg[1]);
177 if (strlen($line) > ($bndlen +
3)) {
178 if ($line{$bndlen+
2} == '-' && $line{$bndlen+
3} == '-')
182 $entStr = CalcEntity("$entStr",-1);
183 array_pop($boundaries);
184 $pre .= '<b><font color ="'.$color[2].'">';
185 $end .= '</font></b>';
193 $entStr = CalcEntity("$entStr",0);
195 $content[$content_indx]=array();
196 $content[$content_indx]['ent'] = '<a href="#'."$entStr \">$entStr".'</a>';
197 $pre .= "\n \n".'</div>'."\n \n".'<div class="entheader" id="'.$entStr.'H"><a name="'."$entStr".'"><b><font color="'.$color[2].'">';
198 $end .= '</font></b>'."\n";
205 if (!$contentset && preg_match("/^.*(content-type:)\s*(\w+)\/(\w+).*/i",$line,$reg)) {
206 if (strtolower($reg[2]) == 'message' && strtolower($reg[3]) == 'rfc822') {
207 $messageheader = true;
209 $content[$content_indx]['type'] = "$reg[2]/$reg[3]";
211 if ($reg[2] == 'image') {
212 $entities["$entStr"] = array();
213 $entities["$entStr"]['entity'] = $entStr;
214 $entities["$entStr"]['contenttype']=$reg[2].'/'.$reg[3];
216 } else if (!$nameset && preg_match("/^.*(name=\s*)\"(.*)\".*/i",$line,$reg)) {
217 $name = htmlspecialchars($reg[2]);
218 $content[$content_indx]['name'] = decodeHeader($name);
220 if (isset($entities["$entStr"])) {
221 $entities["$entStr"]['name'] = urlEncode($reg[2]);
223 } else if (preg_match("/^.*(content-transfer-encoding:)\s*(\w+-?(\w+)?).*/i",$line,$reg) ) {
225 if (isset($entities["$entStr"])) {
226 $entities["$entStr"]['encoding']=$reg[2];
228 $content[$content_indx]['encoding'] = $encoding;
232 $pre .= '<b><font color='.$color[7].'">';
233 $end .= '</font></b>';
240 if (isset($entities["$entStr"])) {
241 if (isset($encoding) && $encoding == 'base64') {
242 if (!isset( $entities["$entStr"]['content'])) $entities[$entStr]['content'] = '';
243 $entities["$entStr"]['content'] .= $line;
248 $line = htmlspecialchars($line);
249 $message_body .= "$pre"."$line"."$end".'<br />'."\r\n";
251 //echo returnTime($start).'<br />';
275 displayHtmlHeader( _("Message Details"), $xtra, FALSE );
277 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n";
279 echo '<font face="monospace">'."\n";
283 //session_register("entities");
284 //$keys = array_keys($entities);
285 //$start = gettimeofday();
286 //foreach ($keys as $key) {
287 // if (isset($entities[$key])) {
288 // if ($entities[$key]['encoding'] == 'base64') {
289 // echo '<img src="message_viewentity.php?ent='.$entities[$key]['entity'].'&name='.$entities[$key]['name'].'"><br />';
293 //session_unregister("entities");
295 if (count($content) > 0) {
296 echo '<h2>'._("Bodystructure")."</h2>\n\n";
297 echo '<table border="1" width="98%"><thead>'.
298 '<tr bgcolor="'.$color[7].'">'.
299 '<td><b><font color="'.$color[5].'">'._("Entity").'</font></b></td>'.
300 '<td><b><font color="'.$color[5].'">'._("Content-Type").'</font></b></td>'.
301 '<td><b><font color="'.$color[5].'">'._("Name").'</font></b></td>'.
302 '<td><b><font color="'.$color[5].'">'._("Encoding").'</font></b></td>'.
305 for ($i = 0; $i < count($content);$i++
) {
307 echo $content[$i]['ent'].'</td><td>';
308 if (isset($content[$i]['type'])) {
309 echo $content[$i]['type'];
310 } else echo 'TEXT/PLAIN';
312 if (isset($content[$i]['name'])) {
313 echo $content[$i]['name'];
314 } else echo ' ';
316 if (isset($content[$i]['encoding'])) {
317 echo $content[$i]['encoding'];
318 } else echo ' ';
319 echo '</td></tr>'."\n";
321 echo '</tbody></table><br />'."\n";
323 echo '<h2>'._("RFC822 Message body")."</h2>\n\n";
324 echo '<div><div class="header">'."\n\n";
326 echo '</div></div></font></code></body></html>';