squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

message_details_bottom.php
Go to the documentation of this file.
1 <?php
19 define('SM_PATH','../../');
20 
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 
26 global $color, $uid_support;
27 
28 sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
29 if (!sqGetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM))
30  $passed_ent_id = 0;
31 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
32 
33 sqgetGlobalVar('username', $username, SQ_SESSION);
34 sqgetGlobalVar('key', $key, SQ_COOKIE);
35 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
36 
44 function CalcEntity($entString, $direction) {
45  $result = $entString;
46  if ($direction == -1) {
47  $pos = strrpos($entString,'.');
48  $result = substr($entString,0,$pos);
49  }
50 
51  switch ($direction) {
52  case 0:
53  $pos = strrpos($entString,'.');
54  if ($pos === false) {
55  $entString++;
56  $result= $entString;
57  }
58  else {
59  $level = substr($entString,0,$pos);
60  $sublevel = substr($entString,$pos+1);
61  $sublevel++;
62  $result = "$level".'.'."$sublevel";
63  }
64  break;
65  case 1:
66  $result = "$entString".".0";
67  break;
68  default:
69  break;
70  }
71  return ($result);
72 }
73 
76 if (!empty($passed_ent_id))
77  $body = sqimap_run_command($imapConnection, "FETCH $passed_id BODY[$passed_ent_id]",true, $response, $readmessage, $uid_support);
78 else
79  $body = sqimap_run_command($imapConnection, "FETCH $passed_id RFC822",true, $response, $readmessage, $uid_support);
81 $header = false;
82 $mimepart = false;
83 $bnd_end = false;
86 $boundaries = array();
87 $entities = array();
88 session_unregister("entities");
89 $pre = '<b>';
90 $end = '</b>';
91 $entStr = '';
92 $bla ='';
93 $content = array ();
95 $contentset = false;
96 
97 $count=count($body);
98 $body[$count-1] = substr($body[$count-1], -1);
99 for ($i=1; $i < $count; $i++) {
100  $line = trim($body[$i]);
101  if ($line == '') {
102  $pre = '';
103  $end = '';
104  if ($bnd_end) {
105  $header = true;
106  $mimepart = false;
107  } else if ($messageheader) {
108  if ($header) {
109  $header=false;
110  $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" id="'.$entStr.'B">'."\n \n";
111  }
112  $mimepart = -$header;
113  $bnd_end = false;
114  if ($messageheaderstart) {
115  $messageheaderstart=false;
116  }
117  } else if ($messageheaderstart) {
118  $messageheader= false;
119  } else {
120  if ($header) {
121  $pre = '';
122  $end = "\n \n".'</div>'."\n \n".'<div class="ent_body" id="'.$entStr.'B">'."\n \n";
123  }
124  $header = false;
125  $mimepart=true;
126  }
127  $contentset = false;
128  $nameset = false;
129  } else {
130  if (!$header && $messageheader) {
131  $messageheaderstart=true;
132  if ($pre != '<b>') {
133  $pre = '<i><font color ='."$color[1]>";
134  $end = '</font></i>';
135  }
136  }
137  if (!$messageheader && !$header ) {
138  $mimepart=true;
139  } else {
140  $mimepart=false;
141  }
142  $pre = '';
143  $end = '';
144  }
145  if ( ( $header || $messageheader) && (preg_match("/^.*boundary=\"?(.+(?=\")|.+).*/i",$line,$reg)) ) {
146  $bnd = $reg[1];
147  $bndreg = $bnd;
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);
156 
157  $boundaries[] = array( 'bnd' => $bnd, 'bndreg' => $bndreg);
158  $messageheader = false;
159  $messageheaderstart=false;
160  $mimepart=false;
161  if ($entStr=='') {
162  $entStr='0';
163  } else {
164  $entStr = CalcEntity("$entStr",1);
165  }
166  }
167 
168  if (($line != '' && $line{0} == '-' || $header) && isset($boundaries[0])) {
169  $cnt=count($boundaries)-1;
170  $bnd = $boundaries[$cnt]['bnd'];
171  $bndreg = $boundaries[$cnt]['bndreg'];
172 
173  $regstr = '/^--'."($bndreg)".".*".'/';
174  if (preg_match($regstr,$line,$reg) ) {
175  $bndlen = strlen($reg[1]);
176  $bndend = false;
177  if (strlen($line) > ($bndlen + 3)) {
178  if ($line{$bndlen+2} == '-' && $line{$bndlen+3} == '-')
179  $bndend = true;
180  }
181  if ($bndend) {
182  $entStr = CalcEntity("$entStr",-1);
183  array_pop($boundaries);
184  $pre .= '<b><font color ='."$color[2]>";
185  $end .= '</font></b>';
186  $header = true;
187  $mimepart = false;
188  $bnd_end = true;
189  $encoding = '';
190  } else {
191  $header = true;
192  $bnd_end = false;
193  $entStr = CalcEntity("$entStr",0);
194  $content_indx++;
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="'.
198  $entStr.'H"><a name="'."$entStr".'"><b><font color ='."$color[2]>";
199  $end .= '</font></b>'."\n";
200  $header = true;
201  $mimepart = false;
202  $encoding = '';
203  }
204  } else {
205  if ($header) {
206  if (!$contentset && preg_match("/^.*(content-type:)\s*(\w+)\/(\w+).*/i",$line,$reg)) {
207  if (strtolower($reg[2]) == 'message' && strtolower($reg[3]) == 'rfc822') {
208  $messageheader = true;
209  }
210  $content[$content_indx]['type'] = "$reg[2]/$reg[3]";
211  $contentset = true;
212  if ($reg[2] == 'image') {
213  $entities["$entStr"] = array();
214  $entities["$entStr"]['entity'] = $entStr;
215  $entities["$entStr"]['contenttype']=$reg[2].'/'.$reg[3];
216  }
217  } else if (!$nameset && preg_match("/^.*(name=\s*)\"(.*)\".*/i",$line,$reg)) {
218  $name = htmlspecialchars($reg[2]);
219  $content[$content_indx]['name'] = decodeHeader($name);
220  $nameset = true;
221  if (isset($entities["$entStr"])) {
222  $entities["$entStr"]['name'] = urlEncode($reg[2]);
223  }
224  } else if (preg_match("/^.*(content-transfer-encoding:)\s*(\w+-?(\w+)?).*/i",$line,$reg) ) {
225  $encoding = $reg[2];
226  if (isset($entities["$entStr"])) {
227  $entities["$entStr"]['encoding']=$reg[2];
228  }
229  $content[$content_indx]['encoding'] = $encoding;
230  $mimeentity = '';
231  }
232 
233  $pre .= '<b><font color ='."$color[7]>";
234  $end .= '</font></b>';
235  //$mimepart=false;
236  }
237  }
238  }
239 /*
240  if ($mimepart) {
241  if (isset($entities["$entStr"])) {
242  if (isset($encoding) && $encoding == 'base64') {
243  if (!isset( $entities["$entStr"]['content'])) $entities[$entStr]['content'] = '';
244  $entities["$entStr"]['content'] .= $line;
245  }
246  }
247  }
248 */
249  $line = htmlspecialchars($line);
250  $message_body .= "$pre"."$line"."$end".'<br />'."\r\n";
251 }
252 
253 $xtra = <<<ECHO
254 
255 <style>
256 
257 <!--
258 .ent_body {
259  display:inline;
260 }
261 
262 .header {
263  display:inline;
264 }
265 
266 .entheader {
267  display:inline;
268  width:99%;
269 }
270 //-->
271 
272 </style>
273 
274 ECHO;
275 
276 displayHtmlHeader( _("Message Details"), $xtra, FALSE );
277 /* body */
278 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n";
279 echo '<code>'."\n";
280 echo '<font face = "monospace">'."\n";
281 echo '<br />'."\n";
282 
283 if (count($content) > 0) {
284  echo '<h2>' . _("Bodystructure") . "</h2>\n\n";
285  echo '<table border=1 width="98%"><thead>'.
286  '<tr bgcolor="'."$color[7]".'">'.
287  '<td><b><font color="'."$color[5]".'">' . _("Entity") . '</font></b></td>'.
288  '<td><b><font color="'."$color[5]".'">' . _("Content-Type") . '</font></b></td>'.
289  '<td><b><font color="'."$color[5]".'">' . _("Name") . '</font></b></td>'.
290  '<td><b><font color="'."$color[5]".'">' . _("Encoding") . '</font></b></td>'.
291 
292  '</tr>'.
293  '</thead><tbody>';
294  for ($i = 0; $i < count($content);$i++) {
295  echo '<tr><td>';
296  echo $content[$i]['ent'].'</td><td>';
297  if (isset($content[$i]['type'])) {
298  echo $content[$i]['type'];
299  } else echo 'TEXT/PLAIN';
300  echo '</td><td>';
301  if (isset($content[$i]['name'])) {
302  echo $content[$i]['name'];
303  } else echo '&nbsp;';
304  echo '</td><td>';
305  if (isset($content[$i]['encoding'])) {
306  echo $content[$i]['encoding'];
307  } else echo '&nbsp;';
308  echo '</td></tr>'."\n";
309  }
310  echo '</tbody></table><br>'."\n";
311 }
312 echo '<h2>' . _("RFC822 Message body") . "</h2>\n\n";
313 echo '<div><div class="header">'."\n\n";
314 echo $message_body;
315 echo '</div></div></font></code></body></html>';
316 ?>
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
$imapConnection
$imapConnection
Definition: message_details_bottom.php:74
$bla
$bla
Definition: message_details_bottom.php:92
$cnt
$cnt
Definition: options_identities.php:86
$count
$count
Definition: message_details_bottom.php:97
$messageheaderstart
$messageheaderstart
Definition: message_details_bottom.php:85
$imapServerAddress
$imapServerAddress
Definition: config_default.php:202
sqimap_login
sqimap_login($username, $password, $imap_server_address, $imap_port, $hide)
Definition: imap_general.php:481
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
$mailbox
$mailbox
Definition: options.php:28
$color
global $color
Definition: message_details_bottom.php:22
$message_body
$message_body
Definition: message_details_bottom.php:80
$body
else $body
Definition: message_details_bottom.php:79
$bnd_end
$bnd_end
Definition: message_details_bottom.php:83
$username
global $username
Definition: validate.php:55
sqimap_mailbox_select
sqimap_mailbox_select($imap_stream, $mailbox)
Definition: imap_mailbox.php:238
$content
$content
Definition: message_details_bottom.php:93
$messageheader
$messageheader
Definition: message_details_bottom.php:84
$end
$end
Definition: message_details_bottom.php:90
$mimepart
$mimepart
Definition: message_details_bottom.php:82
SQ_GET
const SQ_GET
Definition: global.php:16
SM_PATH
const SM_PATH
Definition: message_details_bottom.php:19
displayHtmlHeader
displayHtmlHeader( $title='SquirrelMail', $xtra='', $do_hook=TRUE)
Definition: page_header.php:21
$pre
$pre
Definition: message_details_bottom.php:89
decodeHeader
decodeHeader($string, $utfencode=true, $htmlsave=true, $decide=false)
Definition: mime.php:633
$boundaries
$boundaries
Definition: message_details_bottom.php:86
_
_($str)
Definition: gettext.php:160
$content_indx
$content_indx
Definition: message_details_bottom.php:94
$read
$read
Definition: message_details_bottom.php:75
$uid_support
global $uid_support
Definition: message_details_bottom.php:22
sqimap_run_command
sqimap_run_command($imap_stream, $query, $handle_errors, &$response, &$message, $unique_id=false, $filter=false, $outputstream=false, $no_return=false)
Definition: imap_general.php:58
$imapPort
$imapPort
Definition: config_default.php:210
SQ_FORM
const SQ_FORM
Definition: global.php:21
$xtra
for($i=1; $i< $count; $i++) $xtra
Definition: message_details_bottom.php:253
SQ_COOKIE
const SQ_COOKIE
Definition: global.php:19
$encoding
$encoding
Definition: download.php:81
$entities
$entities
Definition: message_details_bottom.php:87
$contentset
$contentset
Definition: message_details_bottom.php:95
$header
$header
Definition: message_details_bottom.php:81
CalcEntity
CalcEntity($entString, $direction)
Definition: message_details_bottom.php:44
$entStr
$entStr
Definition: message_details_bottom.php:91