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)  

read_body.php
Go to the documentation of this file.
1 <?php
2 
16 define('PAGE_NAME', 'read_body');
17 
22 define('SM_PATH','../');
23 
24 /* SquirrelMail required files. */
25 require_once(SM_PATH . 'include/validate.php');
26 require_once(SM_PATH . 'functions/imap.php');
27 require_once(SM_PATH . 'functions/mime.php');
28 require_once(SM_PATH . 'functions/date.php');
29 require_once(SM_PATH . 'functions/url_parser.php');
30 require_once(SM_PATH . 'functions/html.php');
31 
39 function findNextMessage($passed_id) {
40  global $msort, $msgs, $sort,
41  $thread_sort_messages, $allow_server_sort,
42  $server_sort_array;
43  if (!is_array($server_sort_array)) {
44  $thread_sort_messages = 0;
45  $allow_server_sort = FALSE;
46  }
47  $result = -1;
48  if ($thread_sort_messages || $allow_server_sort) {
49  $count = count($server_sort_array) - 1;
50  foreach($server_sort_array as $key=>$value) {
51  if ($passed_id == $value) {
52  if ($key == $count) {
53  break;
54  }
55  $result = $server_sort_array[$key + 1];
56  break;
57  }
58  }
59  } else {
60  if (is_array($msort)) {
61  for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
62  if ($passed_id == $msgs[$key]['ID']) {
63  next($msort);
64  $key = key($msort);
65  if (isset($key)){
66  $result = $msgs[$key]['ID'];
67  break;
68  }
69  }
70  }
71  }
72  }
73  return $result;
74 }
75 
77 function findPreviousMessage($numMessages, $passed_id) {
78  global $msort, $sort, $msgs,
79  $thread_sort_messages,
80  $allow_server_sort, $server_sort_array;
81  $result = -1;
82  if (!is_array($server_sort_array)) {
83  $thread_sort_messages = 0;
84  $allow_server_sort = FALSE;
85  }
86  if ($thread_sort_messages || $allow_server_sort ) {
87  foreach($server_sort_array as $key=>$value) {
88  if ($passed_id == $value) {
89  if ($key == 0) {
90  break;
91  }
92  $result = $server_sort_array[$key - 1];
93  break;
94  }
95  }
96  } else {
97  if (is_array($msort)) {
98  for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
99  if ($passed_id == $msgs[$key]['ID']) {
100  prev($msort);
101  $key = key($msort);
102  if (isset($key)) {
103  $result = $msgs[$key]['ID'];
104  break;
105  }
106  }
107  }
108  }
109  }
110  return $result;
111 }
112 
117 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) {
118  global $javascript_on;
119 
120  /* hackydiehack */
121 
122  // Pull "view_unsafe_images" from the URL to find out if the unsafe images
123  // should be displayed. The default is not to display unsafe images.
124  if( !sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET) ) {
125  // If "view_unsafe_images" isn't part of the URL, default to not
126  // displaying unsafe images.
127  $view_unsafe_images = false;
128  } else {
129  // If "view_unsafe_images" is part of the URL, display unsafe images
130  // regardless of the value of the URL variable.
131  // FIXME: Do we really want to display the unsafe images regardless of the value in URL variable?
132  $view_unsafe_images = true;
133  }
134 
135  $params = '?passed_ent_id=' . urlencode($passed_ent_id) .
136  '&mailbox=' . urlencode($mailbox) .
137  '&passed_id=' . urlencode($passed_id).
138  '&view_unsafe_images='. (bool) $view_unsafe_images;
139 
140  $print_text = _("View Printable Version");
141 
142  $result = '';
143  /* Output the link. */
144  if ($javascript_on) {
145  $result = '<script language="javascript" type="text/javascript">' . "\n" .
146  '<!--' . "\n" .
147  " function printFormat() {\n" .
148  ' window.open("../src/printer_friendly_main.php' .
149  $params . '","Print","width=800,height=600");' . "\n".
150  " }\n" .
151  "// -->\n" .
152  "</script>\n" .
153  "<a href=\"javascript:printFormat();\">$print_text</a>\n";
154  } else {
155  $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
156  "$params\">$print_text</a>\n";
157  }
158  return $result;
159 }
160 
162  /* escaping $ doesn't work -> \x36 */
163  $ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
164  return $ret;
165 }
166 
167 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
171  $popuser, $data_dir;
172 
173  sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER);
174 
175  $header = $message->rfc822_header;
176  $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
177 
179  $content_type = new ContentType('multipart/report');
180  $content_type->properties['report-type']='disposition-notification';
181 
182  set_my_charset();
183  if ($default_charset) {
184  $content_type->properties['charset']=$default_charset;
185  }
186  $rfc822_header->content_type = $content_type;
187  $rfc822_header->to[] = $header->dnt;
188  $rfc822_header->subject = _("Read:") . ' ' . decodeHeader($header->subject, true, false);
189 
190  // FIXME: use identity.php from SM 1.5. Change this also in compose.php
191 
192  $reply_to = '';
193  if (isset($identity) && $identity != 'default') {
194  $from_mail = getPref($data_dir, $username,
195  'email_address' . $identity);
196  $full_name = getPref($data_dir, $username,
197  'full_name' . $identity);
198  $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
199  $reply_to = getPref($data_dir, $username,
200  'reply_to' . $identity);
201  } else {
202  $from_mail = getPref($data_dir, $username, 'email_address');
203  $full_name = getPref($data_dir, $username, 'full_name');
204  $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
205  $reply_to = getPref($data_dir, $username,'reply_to');
206  }
207 
208  // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
209  // This merely comes from compose.php and only happens when there is no
210  // email_addr specified in user's identity (which is the startup config)
211  if (preg_match('|^([^@%/]+)[@%/](.+)$|', $username, $usernamedata)) {
212  $popuser = $usernamedata[1];
213  $domain = $usernamedata[2];
214  unset($usernamedata);
215  } else {
216  $popuser = $username;
217  }
218 
219  if (!$from_mail) {
220  $from_mail = "$popuser@$domain";
221  $from_addr = $from_mail;
222  }
223 
224  $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
225  if ($reply_to) {
226  $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
227  }
228 
229  // part 1 (RFC2298)
230  $senton = getLongDateString( $header->date, $header->date_unparsed );
231  $to_array = $header->to;
232  $to = '';
233  foreach ($to_array as $line) {
234  $to .= ' '.$line->getAddress();
235  }
236  $now = getLongDateString( time() );
237  set_my_charset();
238  $body = _("Your message") . "\r\n\r\n" .
239  "\t" . _("To") . ': ' . decodeHeader($to,false,false,true) . "\r\n" .
240  "\t" . _("Subject") . ': ' . decodeHeader($header->subject,false,false,true) . "\r\n" .
241  "\t" . _("Sent") . ': ' . $senton . "\r\n" .
242  "\r\n" .
243  sprintf( _("Was displayed on %s"), $now );
244 
245  $special_encoding = '';
246  if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
247  function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
248  $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
249  if (strtolower($default_charset) == 'iso-2022-jp') {
250  if (mb_detect_encoding($body) == 'ASCII') {
251  $special_encoding = '8bit';
252  } else {
253  $body = mb_convert_encoding($body, 'JIS');
254  $special_encoding = '7bit';
255  }
256  }
257  } elseif (sq_is8bit($body)) {
258  // detect 8bit symbols added by translations
259  $special_encoding = '8bit';
260  }
261  $part1 = new Message();
262  $part1->setBody($body);
263  $mime_header = new MessageHeader;
264  $mime_header->type0 = 'text';
265  $mime_header->type1 = 'plain';
266  if ($special_encoding) {
267  $mime_header->encoding = $special_encoding;
268  } else {
269  $mime_header->encoding = '7bit';
270  }
271  if ($default_charset) {
272  $mime_header->parameters['charset'] = $default_charset;
273  }
274  $part1->mime_header = $mime_header;
275 
276  // part2 (RFC2298)
277  $original_recipient = $to;
278  $original_message_id = $header->message_id;
279 
280  $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
281  if ($original_recipient != '') {
282  $report .= "Original-Recipient : $original_recipient\r\n";
283  }
284  $final_recipient = $sender;
285  $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
286  "Original-Message-ID : $original_message_id\r\n" .
287  "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
288 
289  $part2 = new Message();
290  $part2->setBody($report);
291  $mime_header = new MessageHeader;
292  $mime_header->type0 = 'message';
293  $mime_header->type1 = 'disposition-notification';
294  $mime_header->encoding = '7bit';
295  $part2->mime_header = $mime_header;
296 
297  $composeMessage = new Message();
298  $composeMessage->rfc822_header = $rfc822_header;
299  $composeMessage->addEntity($part1);
300  $composeMessage->addEntity($part2);
301 
302 
303  if ($useSendmail) {
304  require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
306  // Check for outdated configuration
307  if (!isset($sendmail_args)) {
308  if ($sendmail_path=='/var/qmail/bin/qmail-inject') {
309  $sendmail_args = '';
310  } else {
311  $sendmail_args = '-i -t';
312  }
313  }
314  $deliver = new Deliver_SendMail(array('sendmail_args'=>$sendmail_args));
315  $stream = $deliver->initStream($composeMessage,$sendmail_path);
316  } else {
317  require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
318  $deliver = new Deliver_SMTP();
320 
321  $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
322 
323  $user = '';
324  $pass = '';
325  if (empty($pop_before_smtp_host))
327 
328  get_smtp_user($user, $pass);
329 
330  $stream = $deliver->initStream($composeMessage,$domain,0,
331  $smtpServerAddress, $smtpPort, $user, $pass, $authPop, $pop_before_smtp_host);
332  }
333  $success = false;
334  if ($stream) {
335  $deliver->mail($composeMessage, $stream);
336  $success = $deliver->finalizeStream($stream);
337  }
338  if (!$success) {
339  $msg = _("Message not sent.") .' '. _("Server replied:") .
340  "\n<blockquote>\n" . $deliver->dlv_msg . '<br />' .
341  $deliver->dlv_ret_nr . ' ' .
342  $deliver->dlv_server_msg . "</blockquote>\n\n";
343  require_once(SM_PATH . 'functions/display_messages.php');
345  } else {
346  unset ($deliver);
347 
348  // copy message to sent folder
349  $move_to_sent = getPref($data_dir,$username,'move_to_sent');
350  if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
351  $svr_allow_sent = true;
352  } else {
353  $svr_allow_sent = false;
354  }
355 
356  if (isset($sent_folder) && (($sent_folder != '') || ($sent_folder != 'none'))
358  $fld_sent = true;
359  } else {
360  $fld_sent = false;
361  }
362 
363  if ((isset($move_to_sent) && ($move_to_sent != 0)) || (!isset($move_to_sent))) {
364  $lcl_allow_sent = true;
365  } else {
366  $lcl_allow_sent = false;
367  }
368 
369  if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) || ($fld_sent && $lcl_allow_sent)) {
370  require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
371  $imap_deliver = new Deliver_IMAP();
372  $imap_deliver->mail($composeMessage, $imapConnection, 0, 0, $imapConnection, $sent_folder);
373  unset ($imap_deliver);
374  }
375  }
376  return $success;
377 }
378 
379 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
380  $sg = $set?'+':'-';
381  $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
382  $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
383  $readmessage, $uid_support);
384 }
385 
386 function formatRecipientString($recipients, $item ) {
387  global $show_more_cc, $show_more, $show_more_bcc,
388  $PHP_SELF;
389 
390  $string = '';
391  if ((is_array($recipients)) && (isset($recipients[0]))) {
392  $show = false;
393 
394  if ($item == 'to') {
395  if ($show_more) {
396  $show = true;
397  $url = set_url_var($PHP_SELF, 'show_more',0);
398  } else {
399  $url = set_url_var($PHP_SELF, 'show_more',1);
400  }
401  } else if ($item == 'cc') {
402  if ($show_more_cc) {
403  $show = true;
404  $url = set_url_var($PHP_SELF, 'show_more_cc',0);
405  } else {
406  $url = set_url_var($PHP_SELF, 'show_more_cc',1);
407  }
408  } else if ($item == 'bcc') {
409  if ($show_more_bcc) {
410  $show = true;
411  $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
412  } else {
413  $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
414  }
415  }
416 
417  $cnt = count($recipients);
418  foreach($recipients as $r) {
419  $add = decodeHeader($r->getAddress(true));
420  if ($string) {
421  $string .= '<br />' . $add;
422  } else {
423  $string = $add;
424  if ($cnt > 1) {
425  $string .= '&nbsp;(<a href="'.$url;
426  if ($show) {
427  $string .= '">'._("less").'</a>)';
428  } else {
429  $string .= '">'._("more").'</a>)';
430  break;
431  }
432  }
433  }
434  }
435  }
436  return $string;
437 }
438 
439 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
444 
445  $header = $message->rfc822_header;
446  $env = array();
447  $env[_("Subject")] = decodeHeader($header->subject);
448  $from_name = $header->getAddr_s('from');
449  if (!$from_name) {
450  $from_name = $header->getAddr_s('sender');
451  if (!$from_name) {
452  $from_name = _("Unknown sender");
453  }
454  }
455  $env[_("From")] = decodeHeader($from_name);
456  $env[_("Date")] = getLongDateString($header->date, $header->date_unparsed);
457  $env[_("To")] = formatRecipientString($header->to, "to");
458  $env[_("Cc")] = formatRecipientString($header->cc, "cc");
459  $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
460  if ($default_use_priority) {
461  $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority));
462  }
463  if ($show_xmailer_default) {
464  $env[_("Mailer")] = decodeHeader($header->xmailer);
465  }
466  if ($default_use_mdn) {
467  if ($mdn_user_support) {
468  if ($header->dnt) {
469  if ($message->is_mdnsent) {
470  $env[_("Read receipt")] = _("sent");
471  } else {
472  $env[_("Read receipt")] = _("requested");
473  if (!(handleAsSent($mailbox) ||
474  $message->is_deleted ||
475  $passed_ent_id)) {
476  $mdn_url = $PHP_SELF;
477  $mdn_url = set_url_var($mdn_url, 'mailbox', urlencode($mailbox));
478  $mdn_url = set_url_var($mdn_url, 'passed_id', $passed_id);
479  $mdn_url = set_url_var($mdn_url, 'passed_ent_id', $passed_ent_id);
480  $mdn_url = set_url_var($mdn_url, 'sendreceipt', 1);
481  if ($FirstTimeSee && $javascript_on) {
482  $script = '<script language="JavaScript" type="text/javascript">' . "\n";
483  $script .= '<!--'. "\n";
484  $script .= 'if(window.confirm("' .
485  _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
486  '")) { '."\n" .
487  ' sendMDN()'.
488  '}' . "\n";
489  $script .= '// -->'. "\n";
490  $script .= '</script>'. "\n";
491  echo $script;
492  }
493  $env[_("Read receipt")] .= '&nbsp;<a href="' . $mdn_url . '">[' .
494  _("Send read receipt now") . ']</a>';
495  }
496  }
497  }
498  }
499  }
500 
501  $s = '<table width="100%" cellpadding="0" cellspacing="2" border="0"';
502  $s .= ' align="center" bgcolor="'.$color[0].'">';
503  foreach ($env as $key => $val) {
504  if ($val) {
505  $s .= '<tr>';
506  $s .= html_tag('td', '<b>' . $key . ':&nbsp;&nbsp;</b>', 'right', '', 'valign="top" width="20%"') . "\n";
507  $s .= html_tag('td', $val, 'left', '', 'valign="top" width="80%"') . "\n";
508  $s .= '</tr>';
509  }
510  }
511  echo '<table bgcolor="'.$color[9].'" width="100%" cellpadding="1"'.
512  ' cellspacing="0" border="0" align="center">'."\n";
513  echo '<tr><td height="5" colspan="2" bgcolor="'.
514  $color[4].'"></td></tr><tr><td align="center">'."\n";
515  echo $s;
516  do_hook('read_body_header');
517  formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
518  echo '</table>';
519  echo '</td></tr><tr><td height="5" colspan="2" bgcolor="'.$color[4].'"></td></tr>'."\n";
520  echo '</table>';
521 }
522 
523 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
524  global $base_uri, $draft_folder, $where, $what, $color, $sort,
525  $startMessage, $PHP_SELF, $save_as_draft,
527 
528  $topbar_delimiter = '&nbsp;|&nbsp;';
529  $urlMailbox = urlencode($mailbox);
530  $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
531  ' border="0" bgcolor="'.$color[9].'"><tr>' .
532  html_tag( 'td', '', 'left', '', 'width="33%"' ) . '<small>';
533 
534  $msgs_url = $base_uri . 'src/';
535  if (isset($where) && isset($what)) {
536  $msgs_url .= 'search.php?smtoken=' . sm_generate_security_token() . '&amp;where=' . urlencode($where) .
537  '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
538  $msgs_str = _("Search Results");
539  } else {
540  $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
541  $startMessage . '&amp;mailbox=' . $urlMailbox;
542  $msgs_str = _("Message List");
543  }
544  $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>';
545 
546  $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
547  '&amp;message=' . $passed_id . '&amp;smtoken=' . sm_generate_security_token() . '&amp;';
548  $unread_url = $base_uri . 'src/';
549  if (!(isset($passed_ent_id) && $passed_ent_id)) {
550  if ($where && $what) {
551  $unread_url .= 'search.php?unread_passed_id=' . $passed_id . '&amp;smtoken=' . sm_generate_security_token() . '&amp;where=' . urlencode($where) . '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
552  } else {
553  $unread_url .= 'right_main.php?unread_passed_id=' . $passed_id . '&amp;sort=' . $sort . '&amp;startMessage=' . $startMessage . '&amp;mailbox=' . $urlMailbox;
554  }
555  $s .= $topbar_delimiter;
556  $s .= '<a href="' . $unread_url . '">' . _("Unread") . '</a>';
557 
558  if ($where && $what) {
559  $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
560  } else {
561  $delete_url .= 'sort=' . $sort . '&amp;startMessage=' . $startMessage;
562  }
563  $s .= $topbar_delimiter;
564  $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>';
565  }
566 
567  $comp_uri = 'src/compose.php' .
568  '?passed_id=' . $passed_id .
569  '&amp;mailbox=' . $urlMailbox .
570  '&amp;startMessage=' . $startMessage .
571  (isset($passed_ent_id)?'&amp;passed_ent_id='.urlencode($passed_ent_id):'');
572 
573  if (($mailbox == $draft_folder) && ($save_as_draft)) {
574  $comp_alt_uri = $comp_uri . '&amp;smaction=draft';
575  $comp_alt_string = _("Resume Draft");
576  } else if (handleAsSent($mailbox)) {
577  $comp_alt_uri = $comp_uri . '&amp;smaction=edit_as_new';
578  $comp_alt_string = _("Edit Message as New");
579  }
580  if (isset($comp_alt_uri)) {
581  $s .= $topbar_delimiter;
582  $s .= makeComposeLink($comp_alt_uri, $comp_alt_string);
583  }
584 
585  $s .= '</small></td><td align="center" width="33%"><small>';
586 
587  if (!(isset($where) && isset($what)) && !$passed_ent_id) {
588  $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
589  $next = findNextMessage($passed_id);
590  if ($prev != -1) {
591  $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
592  '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
593  '&amp;startMessage='.$startMessage.'&amp;show_more=0';
594  $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
595  } else {
596  $s .= _("Previous");
597  }
598  $s .= $topbar_delimiter;
599  if ($next != -1) {
600  $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
601  '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
602  '&amp;startMessage='.$startMessage.'&amp;show_more=0';
603  $s .= '<a href="'.$uri.'">'._("Next").'</a>';
604  } else {
605  $s .= _("Next");
606  }
607  } else if (isset($passed_ent_id) && $passed_ent_id) {
608  /* code for navigating through attached message/rfc822 messages */
609  $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
610  $s .= '<a href="'.$url.'">'._("View Message").'</a>';
611  $entities = array();
612  $entity_count = array();
613  $c = 0;
614 
615  foreach($message->parent->entities as $ent) {
616  if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
617  $c++;
618  $entity_count[$c] = $ent->entity_id;
619  $entities[$ent->entity_id] = $c;
620  }
621  }
622 
623  $prev_link = _("Previous");
624  if (!empty($entities[$passed_ent_id]) && ($entities[$passed_ent_id] > 1)) {
625  $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
626  $prev_link = '<a href="'
627  . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
628  . '">' . $prev_link . '</a>';
629  }
630 
631  $next_link = _("Next");
632  if (!empty($entities[$passed_ent_id]) && ($entities[$passed_ent_id] < $c)) {
633  $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1];
634  $next_link = '<a href="'
635  . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
636  . '">' . $next_link . '</a>';
637  }
638  $s .= $topbar_delimiter . $prev_link;
639  $par_ent_id = $message->parent->entity_id;
640  if ($par_ent_id) {
641  $par_ent_id = substr($par_ent_id,0,-2);
642  $s .= $topbar_delimiter;
643  $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
644  $s .= '<a href="'.$url.'">'._("Up").'</a>';
645  }
646  $s .= $topbar_delimiter . $next_link;
647  }
648 
649  $s .= '</small></td>' . "\n" .
650  html_tag( 'td', '', 'right', '', 'width="33%" nowrap' ) . '<small>';
651  $comp_action_uri = $comp_uri . '&amp;smaction=forward';
652  $s .= makeComposeLink($comp_action_uri, _("Forward"));
653 
655  $comp_action_uri = $comp_uri . '&amp;smaction=forward_as_attachment';
656  $s .= $topbar_delimiter;
657  $s .= makeComposeLink($comp_action_uri, _("Forward as Attachment"));
658  }
659 
660  $comp_action_uri = $comp_uri . '&amp;smaction=reply';
661  $s .= $topbar_delimiter;
662  $s .= makeComposeLink($comp_action_uri, _("Reply"));
663 
664  $comp_action_uri = $comp_uri . '&amp;smaction=reply_all';
665  $s .= $topbar_delimiter;
666  $s .= makeComposeLink($comp_action_uri, _("Reply All"));
667  $s .= '</small></td></tr></table>';
668  $ret = concat_hook_function('read_body_menu_top', $s);
669  if($ret != '') {
670  $s = $ret;
671  }
672  echo $s;
673  do_hook('read_body_menu_bottom');
674 }
675 
676 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
677  global $base_uri, $where, $what, $download_and_unsafe_link;
678 
679  $urlMailbox = urlencode($mailbox);
680  $urlPassed_id = urlencode($passed_id);
681  $urlPassed_ent_id = urlencode($passed_ent_id);
682 
683  $query_string = 'mailbox=' . $urlMailbox . '&amp;passed_id=' . $urlPassed_id . '&amp;passed_ent_id=' . $urlPassed_ent_id;
684 
685  if (!empty($where)) {
686  $query_string .= '&amp;where=' . urlencode($where);
687  }
688 
689  if (!empty($what)) {
690  $query_string .= '&amp;what=' . urlencode($what);
691  }
692 
693  $url = $base_uri.'src/view_header.php?'.$query_string;
694 
695  $s = "<tr>\n" .
696  html_tag( 'td', '', 'right', '', 'valign="middle" width="20%"' ) . '<b>' . _("Options") . ":&nbsp;&nbsp;</b></td>\n" .
697  html_tag( 'td', '', 'left', '', 'valign="middle" width="80%"' ) . '<small>' .
698  '<a href="'.$url.'">'._("View Full Header").'</a>';
699 
700  /* Output the printer friendly link if we are in subtle mode. */
701  $s .= '&nbsp;|&nbsp;' .
702  printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
703  echo $s;
704 
705  /* Output the download and/or unsafe images link/-s, if any. */
706  if ($download_and_unsafe_link) {
707  echo $download_and_unsafe_link;
708  }
709 
710  do_hook("read_body_header_right");
711  $s = "</small></td>\n" .
712  "</tr>\n";
713  echo $s;
714 
715 }
716 
717 /***************************/
718 /* Main of read_body.php */
719 /***************************/
720 
721 /* get the globals we may need */
722 
723 sqgetGlobalVar('key', $key, SQ_COOKIE);
724 sqgetGlobalVar('username', $username, SQ_SESSION);
725 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
726 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
727 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
728 
730 sqgetGlobalVar('msort', $msort, SQ_SESSION);
731 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
732 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION);
733 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) {
734  $messages = array();
735 }
736 
738 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET);
739 sqgetGlobalVar('where', $where, SQ_GET);
740 sqgetGlobalVar('what', $what, SQ_GET);
741 if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) {
742  $show_more = (int) $temp;
743 }
744 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) {
745  $show_more_cc = (int) $temp;
746 }
747 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) {
748  $show_more_bcc = (int) $temp;
749 }
750 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) {
751  $view_hdr = (int) $temp;
752 }
753 
755 sqgetGlobalVar('move_id', $move_id, SQ_POST);
756 
758 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
759 sqgetGlobalVar('mailbox', $mailbox);
760 
761 if ( sqgetGlobalVar('passed_id', $temp) ) {
762  $passed_id = (int) $temp;
763 }
764 if ( sqgetGlobalVar('sort', $temp) ) {
765  $sort = (int) $temp;
766 }
767 if ( sqgetGlobalVar('startMessage', $temp) ) {
768  $startMessage = (int) $temp;
769 }
770 
771 /* end of get globals */
773 
776 
777 
783 $uidvalidity = $mbx_response['UIDVALIDITY'];
784 
785 if (!isset($messages[$uidvalidity])) {
786  $messages[$uidvalidity] = array();
787 }
788 if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
790  $FirstTimeSee = !$message->is_seen;
791  $message->is_seen = true;
792  $messages[$uidvalidity][$passed_id] = $message;
793 } else {
794 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
795  $message = $messages[$uidvalidity][$passed_id];
796  $FirstTimeSee = !$message->is_seen;
797 }
798 
799 if (isset($passed_ent_id) && $passed_ent_id) {
800  $message = $message->getEntity($passed_ent_id);
801  if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
802  $message = $message->parent;
803  }
804  $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
806  $rfc822_header->parseHeader($read);
807  $message->rfc822_header = $rfc822_header;
808 } else {
809  $passed_ent_id = 0;
810 }
811 $header = $message->header;
812 
813 // gmail does not mark messages as read when retrieving the message body
814 // even though RFC 3501, section 6.4.5 (FETCH Command) says:
815 // "The \Seen flag is implicitly set; if this causes the flags to change,
816 // they SHOULD be included as part of the FETCH responses."
817 //
818 if ($imap_server_type == 'gmail') {
819  sqimap_toggle_flag($imapConnection, $passed_id, '\\Seen', true, true);
820 }
821 
822 do_hook('html_top');
823 
824 /****************************************/
825 /* Block for handling incoming url vars */
826 /****************************************/
827 
828 if (isset($sendreceipt)) {
829  if ( !$message->is_mdnsent ) {
830  if (isset($identity) ) {
831  $final_recipient = getPref($data_dir, $username, 'email_address0', '' );
832  } else {
833  $final_recipient = getPref($data_dir, $username, 'email_address', '' );
834  }
835 
836  $final_recipient = trim($final_recipient);
837  if ($final_recipient == '' ) {
838  $final_recipient = getPref($data_dir, $username, 'email_address', '' );
839  }
840  $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
841  if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
842  ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
843  $message->is_mdnsent = true;
844  $messages[$uidvalidity][$passed_id]=$message;
845  }
846  }
847 }
848 /***********************************************/
849 /* End of block for handling incoming url vars */
850 /***********************************************/
851 
852 $msgs[$passed_id]['FLAG_SEEN'] = true;
853 
855 do_hook('read_body_top');
856 if ($show_html_default == 1) {
857  $ent_ar = $message->findDisplayEntity(array());
858 } else {
859  $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
860 }
861 $cnt = count($ent_ar);
862 for ($i = 0; $i < $cnt; $i++) {
863  $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
864  if ($i != $cnt-1) {
865  $messagebody .= '<hr noshade size=1>';
866  }
867 }
868 
870 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
871 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
872 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
873 echo ' <tr><td>';
874 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
875 echo ' <tr><td>';
876 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
877 echo ' <tr bgcolor="'.$color[4].'"><td>';
878 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
879 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
880 echo ' <tr>' . html_tag( 'td', '<br />'. $messagebody."\n", 'left')
881  . '</tr>';
882 echo ' </table>';
883 echo ' </td></tr>';
884 echo ' </table></td></tr>';
885 echo ' </table>';
886 echo ' </td></tr>';
887 
888 echo '<tr><td height="5" colspan="2" bgcolor="'.
889  $color[4].'"></td></tr>'."\n";
890 
893  echo ' <tr><td>';
894  echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
895  echo ' <tr><td>';
896  echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
897  echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
898  echo ' <b>' . _("Attachments") . ':</b>';
899  echo ' </td></tr>';
900  echo ' <tr><td>';
901  echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
902  echo $attachmentsdisplay;
903  echo ' </td></tr></table>';
904  echo ' </td></tr></table>';
905  echo ' </td></tr></table>';
906  echo ' </td></tr>';
907  echo '<tr><td height="5" colspan="2" bgcolor="'.
908  $color[4].'"></td></tr>';
909 }
910 echo '</table>';
911 
912 /* show attached images inline -- if pref'fed so */
915  foreach ($attachment_common_show_images_list as $img) {
916  $imgurl = SM_PATH . 'src/download.php' .
917  '?' .
918  'passed_id=' . urlencode($img['passed_id']) .
919  '&amp;mailbox=' . urlencode($mailbox) .
920  '&amp;ent_id=' . urlencode($img['ent_id']) .
921  '&amp;absolute_dl=true';
922 
923  echo html_tag( 'table', "\n" .
924  html_tag( 'tr', "\n" .
925  html_tag( 'td', '<img src="' . $imgurl . '" />' ."\n", 'left'
926  )
927  ) ,
928  'center', '', 'cellspacing="0" border="0" cellpadding="2"');
929  }
930 }
931 
932 //FIXME: one of these hooks should be removed if we can verify disuse (html_bottom?)
933 do_hook('read_body_bottom');
934 do_hook('html_bottom');
936 /* sessions are written at the end of the script. it's better to register
937  them at the end so we avoid double session_register calls */
938 sqsession_register($messages,'messages');
939 
940 ?>
941 </body></html>
plain_error_message
plain_error_message($message, $color)
Definition: display_messages.php:40
$enable_forward_as_attachment
$enable_forward_as_attachment
Definition: load_prefs.php:228
$body
if(isset($ldap_server) && $ldap_server[0] &&! extension_loaded('ldap')) $body
Definition: bug_report.php:106
elseif
if(! sqgetGlobalVar('sound', $sound, SQ_GET)) elseif($sound=='(none)')
Definition: testsound.php:25
ServerMDNSupport
ServerMDNSupport($read)
Definition: read_body.php:161
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
$attachment_common_show_images_list
global $attachment_common_show_images_list
Definition: attachment_common.php:17
Deliver_SMTP
Definition: Deliver_SMTP.class.php:21
$ret
$ret
Definition: webmail.php:172
getPref
getPref($data_dir, $username, $string, $default='')
Definition: db_prefs.php:316
$useSendmail
$useSendmail
Definition: config_default.php:140
formatBody
formatBody($imap_stream, $message, $color, $wrap_at, $ent_num, $id, $mailbox='INBOX', $clean=false)
Definition: mime.php:306
$sendmail_path
$sendmail_path
Definition: config_default.php:180
SM_PATH
const SM_PATH
Definition: read_body.php:22
$default_use_mdn
$default_use_mdn
Definition: config_default.php:575
html_tag
html_tag( $tag, $val='', $align='', $bgcolor='', $xtra='')
Definition: html.php:27
$count
$count
Definition: message_details_bottom.php:97
$imapServerAddress
$imapServerAddress
Definition: config_default.php:202
formatRecipientString
formatRecipientString($recipients, $item)
Definition: read_body.php:386
findNextMessage
findNextMessage($passed_id)
Definition: read_body.php:39
sqimap_login
sqimap_login($username, $password, $imap_server_address, $imap_port, $hide)
Definition: imap_general.php:481
$draft_folder
$draft_folder
Definition: config_default.php:396
getPriorityStr
getPriorityStr($priority)
Definition: mime.php:215
formatAttachments
formatAttachments($message, $exclude_id, $mailbox, $id)
Definition: mime.php:425
formatToolbar
formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color)
Definition: read_body.php:676
$show_html_default
$show_html_default
Definition: load_prefs.php:222
$rfc822_header
$rfc822_header
Definition: compose.php:362
$data_dir
$data_dir
Definition: config_default.php:499
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
formatMenubar
formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response)
Definition: read_body.php:523
$imap_server_type
$imap_server_type
Definition: config_default.php:231
sqimap_toggle_flag
sqimap_toggle_flag($imap_stream, $id, $flag, $set, $handle_errors)
Definition: imap_messages.php:1173
sqimap_mailbox_exists
sqimap_mailbox_exists($imap_stream, $mailbox)
Definition: imap_mailbox.php:226
$default_move_to_sent
$default_move_to_sent
Definition: config_default.php:392
displayPageHeader
displayPageHeader($color, $mailbox, $xtra='', $session=false)
Definition: page_header.php:105
$mailbox
$mailbox
Definition: options.php:28
get_smtp_user
get_smtp_user(&$user, &$pass)
Definition: auth.php:346
concat_hook_function
concat_hook_function($name, $parm=NULL)
Definition: plugin.php:96
sprintf
powered by Systran sprintf(_("Number of supported language pairs: %s"), '36').' '
Definition: options.php:107
set_url_var
set_url_var($url, $var, $val=null, $link=true)
Definition: html.php:109
html
Definition: html.class.php:18
$pop_before_smtp_host
$pop_before_smtp_host
Definition: config_default.php:321
$url
$url
Definition: mailto.php:81
$messagebody
$messagebody
Definition: read_body.php:854
$username
global $username
Definition: validate.php:55
do_hook
do_hook($name)
Definition: plugin.php:42
$sendmail_args
$sendmail_args
Definition: config_default.php:194
$sqimap_capabilities
if(sqgetGlobalVar('passed_id', $temp)) if(sqgetGlobalVar('sort', $temp)) if(sqgetGlobalVar('startMessage', $temp)) global $sqimap_capabilities
Definition: read_body.php:767
sqimap_mailbox_select
sqimap_mailbox_select($imap_stream, $mailbox)
Definition: imap_mailbox.php:238
$mdn_user_support
$mdn_user_support
Definition: load_prefs.php:237
$sort
$sort
Definition: load_prefs.php:170
sq_is8bit
sq_is8bit($string, $charset='')
Definition: strings.php:784
$message
$message
Definition: download.php:54
handleAsSent
handleAsSent($mailbox)
Definition: mailbox_display.php:1348
$header
$header
Definition: read_body.php:811
$PHP_SELF
$PHP_SELF
Definition: strings.php:1458
printer_friendly_link
printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color)
Definition: read_body.php:117
$smtpPort
$smtpPort
Definition: config_default.php:151
$languages
global $languages
Definition: i18n.php:774
$mbx_response
$mbx_response
Definition: read_body.php:775
getHashedDir
getHashedDir($username, $dir, $hash_dirs='')
Definition: prefs.php:109
makeComposeLink
makeComposeLink($url, $text=null, $target='')
Definition: strings.php:704
$attachments
$attachments
Definition: printer_friendly_bottom.php:113
$sent_folder
$sent_folder
Definition: config_default.php:395
Deliver_SendMail
Definition: Deliver_SendMail.class.php:23
Rfc822Header
Definition: Rfc822Header.class.php:26
$cnt
$cnt
Definition: read_body.php:861
$attachment_dir
$attachment_dir
Definition: config_default.php:517
ToggleMDNflag
ToggleMDNflag($set, $imapConnection, $mailbox, $passed_id, $uid_support)
Definition: read_body.php:379
sqimap_logout
sqimap_logout($imap_stream)
Definition: imap_general.php:639
$save_as_draft
$save_as_draft
Definition: load_prefs.php:86
getLongDateString
getLongDateString( $stamp, $fallback='')
Definition: date.php:309
Deliver_IMAP
Definition: Deliver_IMAP.class.php:22
sm_generate_security_token
sm_generate_security_token()
Definition: strings.php:1340
SQ_GET
const SQ_GET
Definition: global.php:16
$default_use_priority
$default_use_priority
Definition: config_default.php:558
$show_xmailer_default
$show_xmailer_default
Definition: load_prefs.php:231
$r
while(count($Left) > 0) $r
Definition: darkness.php:103
$smtpServerAddress
$smtpServerAddress
Definition: config_default.php:146
$view_unsafe_images
$view_unsafe_images
Definition: printer_friendly_main.php:33
$uidvalidity
$uidvalidity
Definition: read_body.php:783
SQ_SERVER
const SQ_SERVER
Definition: global.php:20
MessageHeader
Definition: MessageHeader.class.php:25
SQ_POST
const SQ_POST
Definition: global.php:17
decodeHeader
decodeHeader($string, $utfencode=true, $htmlsave=true, $decide=false)
Definition: mime.php:633
$wrap_at
$wrap_at
Definition: load_prefs.php:132
$attachmentsdisplay
$attachmentsdisplay
Definition: read_body.php:891
$pop_before_smtp
$pop_before_smtp
Definition: config_default.php:309
sqsession_register
sqsession_register($var, $name)
Definition: global.php:289
_
_($str)
Definition: gettext.php:160
$imapConnection
$imapConnection
Definition: read_body.php:774
$read
$read
Definition: message_details_bottom.php:75
$default_charset
$default_charset
Definition: config_default.php:1027
$base_uri
if(!(bool) ini_get('session.use_cookies')||ini_get('session.use_cookies')=='off') $base_uri
Definition: global.php:173
set_my_charset
set_my_charset()
Definition: i18n.php:511
$FirstTimeSee
$FirstTimeSee
Definition: read_body.php:796
sqimap_get_message
sqimap_get_message($imap_stream, $id, $mailbox)
Definition: imap_messages.php:1050
$version
global $version
Definition: config_default.php:26
$allow_server_sort
$allow_server_sort
Definition: config_default.php:625
$attachment_common_show_images
$attachment_common_show_images
Definition: load_prefs.php:233
formatEnvheader
formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee)
Definition: read_body.php:439
$to
$to
Definition: printer_friendly_bottom.php:66
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
Message
Definition: Message.class.php:27
$uid_support
if(sqgetGlobalVar('passed_id', $temp)) if(sqgetGlobalVar('sort', $temp)) if(sqgetGlobalVar('startMessage', $temp)) global $uid_support
Definition: read_body.php:767
$color
$color
Definition: load_prefs.php:28
$stream
$stream
Definition: configtest.php:429
SQ_COOKIE
const SQ_COOKIE
Definition: global.php:19
$squirrelmail_language
global $squirrelmail_language
Definition: i18n.php:774
SendMDN
SendMDN( $mailbox, $passed_id, $sender, $message, $imapConnection)
Definition: read_body.php:167
$entities
$entities
Definition: message_details_bottom.php:87
$msgs
if(isset($sendreceipt)) $msgs[$passed_id]['FLAG_SEEN']
Definition: read_body.php:852
findPreviousMessage
findPreviousMessage($numMessages, $passed_id)
Definition: read_body.php:77
$domain
$domain
Definition: config_default.php:118
$javascript_on
$javascript_on
Definition: load_prefs.php:270
ContentType
Definition: ContentType.class.php:25