32696e37fcddfbdd756b580e5a6e5511692584eb
6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * This file is used for reading the msgs array and displaying
10 * the resulting emails in the right frame.
15 require_once('../src/validate.php');
16 require_once('../functions/imap.php');
17 require_once('../functions/mime.php');
18 require_once('../functions/date.php');
19 require_once('../functions/url_parser.php');
20 require_once('../functions/smtp.php');
21 require_once('../functions/html.php');
24 * Given an IMAP message id number, this will look it up in the cached
25 * and sorted msgs array and return the index. Used for finding the next
26 * and previous messages.
28 * @return the index of the next valid message from the array
30 function findNextMessage($passed_id) {
31 global $msort, $msgs, $sort,
32 $thread_sort_messages, $allow_server_sort,
34 if (!is_array($server_sort_array)) {
35 $thread_sort_messages = 0;
36 $allow_server_sort = FALSE;
39 if ($thread_sort_messages ||
$allow_server_sort) {
40 reset($server_sort_array);
41 while(list($key, $value) = each ($server_sort_array)) {
42 if ($passed_id == $value) {
43 if ($key == (count($server_sort_array) - 1)) {
47 $result = $server_sort_array[$key +
1];
52 elseif ($sort == 6 && !$allow_server_sort &&
53 !$thread_sort_messages ) {
54 if ($passed_id != 1) {
55 $result = $passed_id - 1;
58 elseif (!$allow_server_sort && !$thread_sort_messages ) {
59 if (!is_array($msort)) {
62 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
63 if ($passed_id == $msgs[$key]['ID']) {
67 $result = $msgs[$key]['ID'];
76 /** returns the index of the previous message from the array. */
77 function findPreviousMessage($numMessages, $passed_id) {
78 global $msort, $sort, $msgs,
79 $thread_sort_messages,
80 $allow_server_sort, $server_sort_array;
82 if (!is_array($server_sort_array)) {
83 $thread_sort_messages = 0;
84 $allow_server_sort = FALSE;
86 if ($thread_sort_messages ||
$allow_server_sort ) {
87 reset($server_sort_array);
88 while(list($key, $value) = each ($server_sort_array)) {
89 if ($passed_id == $value) {
94 $result = $server_sort_array[$key -1];
99 elseif ($sort == 6 && !$allow_server_sort &&
100 !$thread_sort_messages) {
101 if ($passed_id != $numMessages) {
102 $result = $passed_id +
1;
105 elseif (!$thread_sort_messages && !$allow_server_sort) {
106 if (!is_array($msort)) {
109 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
110 if ($passed_id == $msgs[$key]['ID']) {
115 $result = $msgs[$key]['ID'];
125 * Displays a link to a page where the message is displayed more
126 * "printer friendly".
128 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) {
129 global $javascript_on;
131 $params = '?passed_ent_id=' . $passed_ent_id .
132 '&mailbox=' . urlencode($mailbox) .
133 '&passed_id=' . $passed_id;
135 $print_text = _("View Printable Version");
138 /* Output the link. */
139 if ($javascript_on) {
140 $result .= '<script language="javascript" type="text/javascript">' . "\n" .
142 " function printFormat() {\n" .
143 ' window.open("../src/printer_friendly_main.php' .
144 $params . '","Print","width=800,height=600");' . "\n".
148 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
150 $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' .
151 "$params\">$print_text</a>\n";
156 function ServerMDNSupport( $read ) {
157 /* escaping $ doesn't work -> \x36 */
158 $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read );
162 function SendMDN ( $mailbox, $passed_id, $sender, $message) {
163 global $username, $attachment_dir, $SERVER_NAME,
164 $version, $attachments;
166 $header = $message->rfc822_header
;
167 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
169 $recipient_o = $header->dnt
;
170 $recipient = $recipient_o->getAddress(true);
174 $senton = getLongDateString( $header->date
);
175 $to_array = $header->to
;
177 foreach ($to_array as $line) {
178 $to .= ' '.$line->getAddress();
181 $subject = $header->subject
;
182 $now = getLongDateString( time() );
186 $body = _("Your message") . "\r\n\r\n" .
187 "\t" . _("To:") . ' ' . $to . "\r\n" .
188 "\t" . _("Subject:") . ' ' . $subject . "\r\n" .
189 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
191 sprintf( _("Was displayed on %s"), $now );
194 $original_recipient = $to;
195 $original_message_id = $header->message_id
;
197 $part2 = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
198 if ($original_recipient != '') {
199 $part2 .= "Original-Recipient : $original_recipient\r\n";
201 $final_recipient = $sender;
202 $part2 .= "Final-Recipient: rfc822; $final_recipient\r\n" .
203 "Original-Message-ID : $original_message_id\r\n" .
204 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
206 $localfilename = GenerateRandomString(32, 'FILE', 7);
207 $full_localfilename = "$hashed_attachment_dir/$localfilename";
209 $fp = fopen( $full_localfilename, 'w');
210 fwrite ($fp, $part2);
213 $newAttachment = array();
214 $newAttachment['localfilename'] = $localfilename;
215 $newAttachment['type'] = "message/disposition-notification";
216 $newAttachment['session']=-1;
217 $attachments[] = $newAttachment;
219 return (SendMessage($recipient, '', '', _("Read:") . ' ' . $subject,
220 $body, 0, True, 3, -1) );
224 function ToggleMDNflag ( $set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
226 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
227 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
228 $readmessage, $uid_support);
231 function ClearAttachments() {
232 global $username, $attachments, $attachment_dir;
234 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
236 $rem_attachments = array();
237 foreach ($attachments as $info) {
238 if ($info['session'] == -1) {
239 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
240 if (file_exists($attached_file)) {
241 unlink($attached_file);
244 $rem_attachments[] = $info;
247 $attachments = $rem_attachments;
250 function formatRecipientString($recipients, $item ) {
251 global $show_more_cc, $show_more, $show_more_bcc,
254 if ((is_array($recipients)) && (isset($recipients[0]))) {
262 $url = set_url_var($PHP_SELF, 'show_more',0);
264 $url = set_url_var($PHP_SELF, 'show_more',1);
266 } else if ($item == 'cc') {
268 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
271 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
273 } else if ($item == 'bcc') {
274 if ($show_more_bcc) {
275 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
278 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
285 $ary[$i] = htmlspecialchars($ary[$i]->getAddress());
287 $string .= '<BR>'.$ary[$i];
291 $string .= ' (<A HREF="'.$url;
293 $string .= '">'._("less").'</A>)';
295 $string .= '">'._("more").'</A>)';
309 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
310 $color, $FirstTimeSee) {
311 global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder,
312 $default_use_priority, $show_xmailer_default,
313 $mdn_user_support, $PHP_SELF, $javascript_on;
315 $header = $message->rfc822_header
;
317 $env[_("Subject")] = htmlspecialchars($header->subject
);
318 $from_name = $header->getAddr_s('from');
320 $from_name = $header->getAddr_s('sender');
322 $from_name = _("Unknown sender");
325 $env[_("From")] = htmlspecialchars($from_name);
326 $env[_("Date")] = getLongDateString($header->date
);
327 $env[_("To")] = formatRecipientString($header->to
, "to");
328 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
329 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
330 if ($default_use_priority) {
331 $env[_("Priority")] = getPriorityStr($header->priority
);
333 if ($show_xmailer_default) {
334 $env[_("Mailer")] = $header->xmailer
;
336 if ($default_use_mdn) {
337 if ($mdn_user_support) {
339 if ($message->is_mdnsent
) {
340 $env[_("Read receipt")] = _("send");
342 if ( !($mailbox == $draft_folder ||
343 $mailbox == $sent_folder ||
$message->is_deleted
)) {
344 $mdn_url = $PHP_SELF . '&sendreceipt=1';
345 if ($FirstTimeSee && $javascript_on) {
346 $script = '<script language="JavaScript" type="text/javascript">' ."\n";
347 $script .= '<!--'. "\n";
348 $script .= 'if(window.confirm("' .
349 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
353 $script .= '// -->'. "\n";
354 $script .= '</script>'. "\n";
357 $env[_("Read receipt")] = _("requested") .
358 ' <a href="'.$mdn_url.'">['. _("Send read receipt now") .']</a>';
360 $env[_("Read receipt")] = _("requested");
367 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"';
368 $s .= ' ALIGN="center" BGCOLOR="' . $color[0] . '">';
369 foreach ($env as $key => $val) {
372 $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
373 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
378 do_hook("read_body_header");
379 formatToolbar($mailbox,$passed_id,$passed_ent_id,$message, $color);
383 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
384 global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort,
385 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft;
387 $topbar_delimiter = ' | ';
388 $urlMailbox = urlencode($mailbox);
389 $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
390 ' border="0" bgcolor="'.$color[9].'"><tr><td align="left" width="33%"><small>';
392 $msgs_url = $base_uri . 'src/';
393 if (isset($where) && isset($what)) {
394 $msgs_url .= 'search.php?where='.urlencode($where).
395 '&what='.urlencode($what).'&mailbox='.$urlMailbox;
396 $msgs_str = _("Search results");
398 $msgs_url .= 'right_main.php?sort='.$sort.'&startMessage='.
399 $startMessage.'&mailbox='.$urlMailbox;
400 $msgs_str = _("Message List");
402 $s .= '<a href="'. $msgs_url.'">'.$msgs_str.'</a>';
403 $s .= $topbar_delimiter;
405 $delete_url = $base_uri . 'src/delete_message.php?mailbox='.$urlMailbox.
406 '&message='.$passed_id.'&';
407 if (!(isset($passed_ent_id) && $passed_ent_id)) {
408 if ($where && $what) {
409 $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what);
411 $delete_url .= 'sort='. $sort . '&startMessage='. $startMessage;
413 $s .= '<a href="'. $delete_url.'">'._("Delete").'</a>';
416 $comp_uri = $base_uri . 'src/compose.php'.
417 '?passed_id='.$passed_id.
418 '&mailbox='.$urlMailbox.
419 (isset($passed_ent_id)?
'&passed_ent_id='.$passed_ent_id:'');
421 if (($mailbox == $draft_folder) && ($save_as_draft)) {
422 $comp_alt_uri = $comp_uri . '&action=draft';
423 $comp_alt_string = _("Resume Draft");
424 } else if ($mailbox == $sent_folder) {
425 $comp_alt_uri = $comp_uri . '&action=edit_as_new';
426 $comp_alt_string = _("Edit Message as New");
428 if (isset($comp_alt_uri)) {
429 $s .= $topbar_delimiter;
430 if ($compose_new_win == '1') {
431 $s .= '<a href="javascript:void(0)" '.
432 'onclick="comp_in_new(\''.$comp_alt_uri.'\')">'.$comp_alt_string.'</a>';
434 $s .= '<a href="'.$comp_alt_uri.'">'.$comp_alt_string.'</a>';
438 $s .= '</small></td><td align="center" width="33%"><small>';
440 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
441 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
442 $next = findNextMessage($passed_id);
444 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
445 '&mailbox='.$urlMailbox.'&sort='.$sort.
446 '&startMessage='.$startMessage.'&show_more=0';
447 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
451 $s .= $topbar_delimiter;
453 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
454 '&mailbox='.$urlMailbox.'&sort='.$sort.
455 '&startMessage='.$startMessage.'&show_more=0';
456 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
460 } else if (isset($passed_ent_id) && $passed_ent_id) {
461 /* code for navigating through attached message/rfc822 messages */
462 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
463 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
464 $par_ent_id = $message->parent
->entity_id
;
466 $par_ent_id = substr($par_ent_id,0,-2);
467 $s .= $topbar_delimiter;
468 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
469 $s .= '<a href="'.$url.'">'._("Up").'</a>';
473 $s .= '</small></td><td align="right" width="33%" nowrap><small>';
474 $comp_action_uri = $comp_uri . '&action=forward';
475 if ($compose_new_win == '1') {
476 $s .= '<a href="javascript:void(0)" '.
477 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Forward").'</a>';
479 $s .= '<a href="'.$comp_action_uri.'">'._("Forward").'</a>';
481 $s .= $topbar_delimiter;
483 $comp_action_uri = $comp_uri . '&action=forward_as_attachment';
484 if ($compose_new_win == '1') {
485 $s .= '<a href="javascript:void(0)" '.
486 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Forward as attachment").'</a>';
488 $s .= '<a href="'.$comp_action_uri.'">'._("Forward as attachment").'</a>';
490 $s .= $topbar_delimiter;
494 $comp_action_uri = decodeHeader($comp_uri . '&action=reply');
495 if ($compose_new_win == '1') {
496 $s .= '<a href="javascript:void(0)" '.
497 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply").'</a>';
499 $s .= '<a href="'.$comp_action_uri.'">'._("Reply").'</a>';
501 $s .= $topbar_delimiter;
503 $comp_action_uri = $comp_uri . '&action=reply_all';
504 if ($compose_new_win == '1') {
505 $s .= '<a href="javascript:void(0)" '.
506 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply All").'</a>';
508 $s .= '<a href="'.$comp_action_uri.'">'._("Reply All").'</a>';
510 $s .= '</small></td></tr></table>';
514 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
515 global $QUERY_STRING, $base_uri;
517 $urlMailbox = urlencode($mailbox);
518 $url = $base_uri.'src/view_header.php?'.$QUERY_STRING;
521 $s .= '<TD VALIGN="MIDDLE" ALIGN="RIGHT" WIDTH="20%"><B>' . _("Options") . ": </B></TD>\n";
522 $s .= '<TD VALIGN="MIDDLE" ALIGN="LEFT" WIDTH="80%"><SMALL>';
523 $s .= '<a href="'.$url.'">'.("View Full Header").'</a>';
525 /* Output the printer friendly link if we are in subtle mode. */
526 $s .= ' | ';
527 $s .= printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
529 do_hook("read_body_header_right");
530 $s = "</SMALL></TD>\n";
539 * Main of read_boby.php --------------------------------------------------
548 global $uid_support, $sqimap_capabilities;
550 if (isset($mailbox)) {
551 $mailbox = urldecode( $mailbox );
554 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
557 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
559 if (!isset($messages)) {
561 session_register('messages');
565 * $message contains all information about the message
566 * including header and body
569 $uidvalidity = $mbx_response['UIDVALIDITY'];
571 if (!isset($messages[$uidvalidity])) {
572 $messages[$uidvalidity] = array();
574 if (!isset($messages[$uidvalidity][$passed_id]) ||
!$uid_support) {
575 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
576 $messages[$uidvalidity][$passed_id] = $message;
578 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
579 // $message = $messages[$uidvalidity][$passed_id];
581 $FirstTimeSee = !$message->is_seen
;
582 $message->is_seen
= true;
583 $messages[$uidvalidity][$passed_id] = $message;
585 if (isset($passed_ent_id)) {
586 $message = $message->getEntity($passed_ent_id);
587 $message->id
= $passed_id;
588 $message->mailbox
= $mailbox;
592 $header = $message->header
;
594 //do_hook('html_top');
596 /* =============================================================================
597 * block for handling incoming url vars
599 * =============================================================================
602 if (isset($sendreceipt)) {
603 if ( !$message->is_mdnsent
) {
604 if (isset($identity) ) {
605 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
607 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
610 $final_recipient = trim($final_recipient);
611 if ($final_recipient == '' ) {
612 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
614 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
615 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message ) > 0 && $supportMDN ) {
616 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
617 $message->is_mdnsent
= true;
618 $messages[$uidvalidity][$passed_id]=$message;
623 /* =============================================================================
624 * end block for handling incoming url vars
626 * =============================================================================
628 $msgs[$passed_id]['FLAG_SEEN'] = true;
631 $ent_ar = $message->findDisplayEntity(array());
632 $cnt = count($ent_ar);
633 for ($i = 0; $i < $cnt; $i++
) {
634 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
636 $messagebody .= '<hr noshade size=1>';
640 displayPageHeader($color, $mailbox);
641 do_hook('read_body_top');
642 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
643 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
644 echo '<table width="100%" cellpadding="0" cellspacing="5" align="center" border="0">';
646 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
648 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
649 echo ' <tr bgcolor="'.$color[4].'"><td>'.$messagebody. '</td></tr>';
650 echo ' </table></td></tr>';
654 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
655 if ($attachmentsdisplay) {
657 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
659 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
660 echo ' <tr><td ALIGN="left" bgcolor="'.$color[9].'"><b>';
661 echo _("Attachments").':</b></td></tr><tr><td>';
662 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'">';
663 echo $attachmentsdisplay;
664 echo ' </td></tr></table></table></td></tr>';
665 echo ' </table></td></tr>';
672 /* show attached images inline -- if pref'fed so */
673 if (($attachment_common_show_images) &&
674 is_array($attachment_common_show_images_list)) {
675 foreach ($attachment_common_show_images_list as $img) {
676 $imgurl = '../src/download.php' .
678 'passed_id=' . urlencode($img['passed_id']) .
679 '&mailbox=' . urlencode($mailbox) .
680 '&passed_ent_id=' . urlencode($img['ent_id']) .
681 '&absolute_dl=true';
683 echo html_tag( 'table', "\n" .
684 html_tag( 'tr', "\n" .
685 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
688 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
692 do_hook('read_body_bottom');
693 do_hook('html_bottom');
694 //$message->clean_up();
695 sqimap_logout($imapConnection);