6 * Copyright (c) 1999-2003 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.
13 * @package squirrelmail
16 /** Path for SquirrelMail required files. */
17 define('SM_PATH','../');
19 /* SquirrelMail required files. */
20 require_once(SM_PATH
. 'include/validate.php');
21 require_once(SM_PATH
. 'functions/global.php');
22 require_once(SM_PATH
. 'functions/imap.php');
23 require_once(SM_PATH
. 'functions/mime.php');
24 require_once(SM_PATH
. 'functions/date.php');
25 require_once(SM_PATH
. 'functions/url_parser.php');
26 require_once(SM_PATH
. 'functions/html.php');
27 require_once(SM_PATH
. 'functions/global.php');
28 require_once(SM_PATH
. 'functions/identity.php');
29 require_once(SM_PATH
. 'functions/mailbox_display.php');
32 * Given an IMAP message id number, this will look it up in the cached
33 * and sorted msgs array and return the index of the next message
35 * @param int $passed_id The current message UID
36 * @return the index of the next valid message from the array
38 function findNextMessage($passed_id) {
39 global $msort, $msgs, $sort,
40 $thread_sort_messages, $allow_server_sort,
42 if (!is_array($server_sort_array)) {
43 $thread_sort_messages = 0;
44 $allow_server_sort = FALSE;
47 if ($thread_sort_messages ||
$allow_server_sort) {
48 $count = count($server_sort_array) - 1;
49 foreach($server_sort_array as $key=>$value) {
50 if ($passed_id == $value) {
54 $result = $server_sort_array[$key +
1];
59 if (is_array($msort)) {
60 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
61 if ($passed_id == $msgs[$key]['ID']) {
65 $result = $msgs[$key]['ID'];
76 * Given an IMAP message id number, this will look it up in the cached
77 * and sorted msgs array and return the index of the previous message
79 * @param int $passed_id The current message UID
80 * @return the index of the next valid message from the array
82 function findPreviousMessage($numMessages, $passed_id) {
83 global $msort, $sort, $msgs,
84 $thread_sort_messages,
85 $allow_server_sort, $server_sort_array;
87 if (!is_array($server_sort_array)) {
88 $thread_sort_messages = 0;
89 $allow_server_sort = FALSE;
91 if ($thread_sort_messages ||
$allow_server_sort ) {
92 foreach($server_sort_array as $key=>$value) {
93 if ($passed_id == $value) {
97 $result = $server_sort_array[$key - 1];
102 if (is_array($msort)) {
103 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
104 if ($passed_id == $msgs[$key]['ID']) {
108 $result = $msgs[$key]['ID'];
119 * Displays a link to a page where the message is displayed more
120 * "printer friendly".
121 * @param string $mailbox Name of current mailbox
122 * @param int $passed_id
124 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
125 global $javascript_on, $color;
127 $params = '?passed_ent_id=' . $passed_ent_id .
128 '&mailbox=' . urlencode($mailbox) .
129 '&passed_id=' . $passed_id;
131 $print_text = _("View Printable Version");
134 /* Output the link. */
135 if ($javascript_on) {
136 $result = '<script language="javascript" type="text/javascript">' . "\n" .
138 " function printFormat() {\n" .
139 ' window.open("../src/printer_friendly_main.php' .
140 $params . '","Print","width=800,height=600");' . "\n".
144 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
146 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
147 "$params\">$print_text</a>\n";
152 function ServerMDNSupport($read) {
153 /* escaping $ doesn't work -> \x36 */
154 $ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
158 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
159 global $username, $attachment_dir,
160 $version, $attachments, $squirrelmail_language, $default_charset,
161 $languages, $useSendmail, $domain, $sent_folder,
162 $popuser, $data_dir, $username;
164 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER
);
166 $header = $message->rfc822_header
;
167 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
169 $rfc822_header = new Rfc822Header();
170 $content_type = new ContentType('multipart/report');
171 $content_type->properties
['report-type']='disposition-notification';
174 if ($default_charset) {
175 $content_type->properties
['charset']=$default_charset;
177 $rfc822_header->content_type
= $content_type;
178 $rfc822_header->to
[] = $header->dnt
;
179 $rfc822_header->subject
= _("Read:") . ' ' . encodeHeader($header->subject
);
181 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
182 // This merely comes from compose.php and only happens when there is no
183 // email_addr specified in user's identity (which is the startup config)
184 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
185 $popuser = $usernamedata[1];
186 $domain = $usernamedata[2];
187 unset($usernamedata);
189 $popuser = $username;
193 $ident = get_identities();
194 if(!isset($identity)) $identity = 0;
195 $full_name = $ident[$identity]['full_name'];
196 $from_mail = $ident[$identity]['email_address'];
197 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
198 $reply_to = $ident[$identity]['reply_to'];
201 $from_mail = "$popuser@$domain";
202 $from_addr = $from_mail;
204 $rfc822_header->from
= $rfc822_header->parseAddress($from_addr,true);
206 $rfc822_header->reply_to
= $rfc822_header->parseAddress($reply_to,true);
210 $senton = getLongDateString( $header->date
);
211 $to_array = $header->to
;
213 foreach ($to_array as $line) {
214 $to .= ' '.$line->getAddress();
216 $now = getLongDateString( time() );
218 $body = _("Your message") . "\r\n\r\n" .
219 "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" .
220 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject
,false,false) . "\r\n" .
221 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
223 sprintf( _("Was displayed on %s"), $now );
225 $special_encoding = '';
226 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
227 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
228 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
229 if (strtolower($default_charset) == 'iso-2022-jp') {
230 if (mb_detect_encoding($body) == 'ASCII') {
231 $special_encoding = '8bit';
233 $body = mb_convert_encoding($body, 'JIS');
234 $special_encoding = '7bit';
238 $part1 = new Message();
239 $part1->setBody($body);
240 $mime_header = new MessageHeader
;
241 $mime_header->type0
= 'text';
242 $mime_header->type1
= 'plain';
243 if ($special_encoding) {
244 $mime_header->encoding
= $special_encoding;
246 $mime_header->encoding
= 'us-ascii';
248 if ($default_charset) {
249 $mime_header->parameters
['charset'] = $default_charset;
251 $part1->mime_header
= $mime_header;
254 $original_recipient = $to;
255 $original_message_id = $header->message_id
;
257 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
258 if ($original_recipient != '') {
259 $report .= "Original-Recipient : $original_recipient\r\n";
261 $final_recipient = $sender;
262 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
263 "Original-Message-ID : $original_message_id\r\n" .
264 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
266 $part2 = new Message();
267 $part2->setBody($report);
268 $mime_header = new MessageHeader
;
269 $mime_header->type0
= 'message';
270 $mime_header->type1
= 'disposition-notification';
271 $mime_header->encoding
= 'us-ascii';
272 $part2->mime_header
= $mime_header;
274 $composeMessage = new Message();
275 $composeMessage->rfc822_header
= $rfc822_header;
276 $composeMessage->addEntity($part1);
277 $composeMessage->addEntity($part2);
281 require_once(SM_PATH
. 'class/deliver/Deliver_SendMail.class.php');
282 global $sendmail_path;
283 $deliver = new Deliver_SendMail();
284 $stream = $deliver->initStream($composeMessage,$sendmail_path);
286 require_once(SM_PATH
. 'class/deliver/Deliver_SMTP.class.php');
287 $deliver = new Deliver_SMTP();
288 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
289 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ?
true : false;
290 get_smtp_user($user, $pass);
291 $stream = $deliver->initStream($composeMessage,$domain,0,
292 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
296 $length = $deliver->mail($composeMessage, $stream);
297 $success = $deliver->finalizeStream($stream);
300 $msg = $deliver->dlv_msg
. '<br>' .
301 _("Server replied: ") . $deliver->dlv_ret_nr
. ' '.
302 $deliver->dlv_server_msg
;
303 require_once(SM_PATH
. 'functions/display_messages.php');
304 plain_error_message($msg, $color);
307 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
308 sqimap_append ($imapConnection, $sent_folder, $length);
309 require_once(SM_PATH
. 'class/deliver/Deliver_IMAP.class.php');
310 $imap_deliver = new Deliver_IMAP();
311 $imap_deliver->mail($composeMessage, $imapConnection);
312 sqimap_append_done ($imapConnection);
313 unset ($imap_deliver);
319 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
321 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
322 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
323 $readmessage, $uid_support);
326 function ClearAttachments() {
327 global $username, $attachments, $attachment_dir;
329 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
331 $rem_attachments = array();
332 if (isset($attachments)) {
333 foreach ($attachments as $info) {
334 if ($info['session'] == -1) {
335 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
336 if (file_exists($attached_file)) {
337 unlink($attached_file);
340 $rem_attachments[] = $info;
344 $attachments = $rem_attachments;
347 function formatRecipientString($recipients, $item ) {
348 global $show_more_cc, $show_more, $show_more_bcc,
352 if ((is_array($recipients)) && (isset($recipients[0]))) {
358 $url = set_url_var($PHP_SELF, 'show_more',0);
360 $url = set_url_var($PHP_SELF, 'show_more',1);
362 } else if ($item == 'cc') {
365 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
367 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
369 } else if ($item == 'bcc') {
370 if ($show_more_bcc) {
372 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
374 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
378 $cnt = count($recipients);
379 foreach($recipients as $r) {
380 $add = decodeHeader($r->getAddress(true));
382 $string .= '<BR>' . $add;
386 $string .= ' (<A HREF="'.$url;
388 $string .= '">'._("less").'</A>)';
390 $string .= '">'._("more").'</A>)';
400 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
401 $color, $FirstTimeSee) {
402 global $msn_user_support, $default_use_mdn, $default_use_priority,
403 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
404 $squirrelmail_language;
406 $header = $message->rfc822_header
;
408 $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject
));
410 $from_name = $header->getAddr_s('from');
412 $from_name = $header->getAddr_s('sender');
414 $env[_("From")] = _("Unknown sender");
416 $env[_("From")] = decodeHeader($from_name);
417 $env[_("Date")] = getLongDateString($header->date
);
418 $env[_("To")] = formatRecipientString($header->to
, "to");
419 $env[_("Cc")] = formatRecipientString($header->cc
, "cc");
420 $env[_("Bcc")] = formatRecipientString($header->bcc
, "bcc");
421 if ($default_use_priority) {
422 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority
));
424 if ($show_xmailer_default) {
425 $env[_("Mailer")] = decodeHeader($header->xmailer
);
427 if ($default_use_mdn) {
428 if ($mdn_user_support) {
430 if ($message->is_mdnsent
) {
431 $env[_("Read receipt")] = _("sent");
433 $env[_("Read receipt")] = _("requested");
434 if (!(handleAsSent($mailbox) ||
435 $message->is_deleted ||
437 $mdn_url = $PHP_SELF . '&sendreceipt=1';
438 if ($FirstTimeSee && $javascript_on) {
439 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
440 $script .= '<!--'. "\n";
441 $script .= 'if(window.confirm("' .
442 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
446 $script .= '// -->'. "\n";
447 $script .= '</script>'. "\n";
450 $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' .
451 _("Send read receipt now") . ']</a>';
458 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
459 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
460 foreach ($env as $key => $val) {
463 $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
464 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
468 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
469 ' CELLSPACING="0" BORDER="0" ALIGN="center">'."\n";
470 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
471 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
473 do_hook('read_body_header');
474 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
476 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
481 * Format message toolbar
483 * @param string $mailbox Name of current mailbox
484 * @param int $passed_id UID of current message
485 * @param int $passed_ent_id Id of entity within message
486 * @param object $message Current message object
487 * @param object $mbx_response
489 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
490 global $base_uri, $draft_folder, $where, $what, $color, $sort,
491 $startMessage, $PHP_SELF, $save_as_draft, $uid_support,
492 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
493 $data_dir, $username;
495 $topbar_delimiter = ' | ';
496 $double_delimiter = ' ';
497 $urlMailbox = urlencode($mailbox);
499 $comp_uri = 'src/compose.php' .
500 '?passed_id=' . $passed_id .
501 '&mailbox=' . $urlMailbox .
502 '&startMessage=' . $startMessage .
503 (isset($passed_ent_id)?
'&passed_ent_id='.$passed_ent_id:'');
505 $msgs_url = $base_uri . 'src/';
507 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
508 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
510 // Create Prev & Next links
511 // Handle nested entities first (i.e. Mime Attach parts)
512 if (isset($passed_ent_id) && $passed_ent_id) {
513 // code for navigating through attached message/rfc822 messages
514 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
516 $entity_count = array();
519 foreach($message->parent
->entities
as $ent) {
520 if ($ent->type0
== 'message' && $ent->type1
== 'rfc822') {
522 $entity_count[$c] = $ent->entity_id
;
523 $entities[$ent->entity_id
] = $c;
527 $prev_link = _("Previous");
528 if($entities[$passed_ent_id] > 1) {
529 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
530 $prev_link = '<a href="'
531 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
532 . '">' . $prev_link . '</a>';
535 $next_link = _("Next");
536 if($entities[$passed_ent_id] < $c) {
537 $next_ent_id = $entity_count[$entities[$passed_ent_id] +
1];
538 $next_link = '<a href="'
539 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
540 . '">' . $next_link . '</a>';
543 $par_ent_id = $message->parent
->entity_id
;
546 $par_ent_id = substr($par_ent_id,0,-2);
547 if ( $par_ent_id != 0 ) {
548 $up_link = $topbar_delimiter;
549 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
550 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
554 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
555 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
557 // Prev/Next links for regular messages
558 } else if ( !(isset($where) && isset($what)) ) {
559 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
560 $next = findNextMessage($passed_id);
562 $prev_link = _("Previous");
564 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
565 '&mailbox='.$urlMailbox.'&sort='.$sort.
566 '&startMessage='.$startMessage.'&show_more=0';
567 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
570 $next_link = _("Next");
572 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
573 '&mailbox='.$urlMailbox.'&sort='.$sort.
574 '&startMessage='.$startMessage.'&show_more=0';
575 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
578 // Only bother with Delete & Prev and Delete & Next IF
579 // we have UID support, and top display is enabled.
580 $delete_prev_next_display = getPref($data_dir, $username, 'delete_prev_next_display', 1);
581 if ( $uid_support && $delete_prev_next_display == 1 ) {
582 $del_prev_link = _("Delete & Prev");
584 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
585 '&mailbox='.$urlMailbox.'&sort='.$sort.
586 '&startMessage='.$startMessage.'&show_more=0'.
587 '&delete_id='.$passed_id;
588 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
591 $del_next_link = _("Delete & Next");
593 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
594 '&mailbox='.$urlMailbox.'&sort='.$sort.
595 '&startMessage='.$startMessage.'&show_more=0'.
596 '&delete_id='.$passed_id;
597 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
601 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
602 if ( isset($del_prev_link) && isset($del_next_link) )
603 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
606 // Start with Search Results or Message List link.
607 if (isset($where) && isset($what)) {
608 $msgs_url .= 'search.php?where=' . urlencode($where) .
609 '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox;
610 $msgs_str = _("Search Results");
612 $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' .
613 $startMessage . '&mailbox=' . $urlMailbox;
614 $msgs_str = _("Message List");
616 $nav_row .= $double_delimiter .
617 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
619 $nav_row .= '</small></td></tr>';
622 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
623 $menu_row = '<tr bgcolor="'.$color[9].'"><td><small>';
625 // If Draft folder - create Resume link
626 if (($mailbox == $draft_folder) && ($save_as_draft)) {
627 $comp_alt_uri = $comp_uri . '&smaction=draft';
628 $comp_alt_string = _("Resume Draft");
629 } else if (handleAsSent($mailbox)) {
630 // If in Sent folder, edit as new
631 $comp_alt_uri = $comp_uri . '&smaction=edit_as_new';
632 $comp_alt_string = _("Edit Message as New");
635 // Show Alt URI for Draft/Sent
636 if (isset($comp_alt_uri)) {
637 $menu_row .= $topbar_delimiter;
638 $menu_row .= makeComposeLink($comp_alt_uri, $comp_alt_string);
639 $menu_row .= $topbar_delimiter;
642 $comp_action_uri = $comp_uri . '&smaction=reply';
643 $menu_row .= makeComposeLink($comp_action_uri, _("Reply"));
645 $comp_action_uri = $comp_uri . '&smaction=reply_all';
646 $menu_row .= $topbar_delimiter;
647 $menu_row .= makeComposeLink($comp_action_uri, _("Reply All"));
650 $comp_action_uri = $comp_uri . '&smaction=forward';
651 $menu_row .= $topbar_delimiter;
652 $menu_row .= makeComposeLink($comp_action_uri, _("Forward"));
654 if ($enable_forward_as_attachment) {
655 $comp_action_uri = $comp_uri . '&smaction=forward_as_attachment';
656 $menu_row .= $topbar_delimiter;
657 $menu_row .= makeComposeLink($comp_action_uri, _("Forward as Attachment"));
660 $delete_link = _("Delete");
661 if (!(isset($passed_ent_id) && $passed_ent_id)) {
662 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
663 '&message=' . $passed_id . '&';
665 if ($where && $what) {
666 $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what);
668 $delete_url .= 'sort=' . $sort . '&startMessage=' . $startMessage;
670 $delete_link = '<a href="' . $delete_url . '">' . $delete_link . '</a>';
671 $delete_link .= ' (<a href="' . $delete_url.'&bypass_trash=1">'
672 ._("Bypass Trash").'</a>)';
675 $menu_row .= $topbar_delimiter.$delete_link;
679 $menu_row .= '</small></td><td align="right">';
680 if (!(isset($passed_ent_id) && $passed_ent_id)) {
681 $menu_row .= '<form action="read_body.php?mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage.'&passed_id='.$next.'" method="post">'.
682 '<small><input type="hidden" name="show_more" value="0" />'.
683 '<input type="hidden" name="move_id" value="'.$passed_id.'" />'._("Move to:") .
684 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
685 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
686 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
688 $menu_row .= sqimap_mailbox_option_list($imapConnection);
690 $menu_row .= '</select> '.
691 '<input type="submit" value="' . _("Move") . '" style="padding: 0px; margin: 0px"/>'.
694 $menu_row .= '</td></tr>';
696 // echo rows, with hooks
697 do_hook('read_body_menu_top');
698 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
699 echo $nav_on_top ?
$nav_row . $menu_row : $menu_row . $nav_row;
700 echo '</table>'."\n";
701 do_hook('read_body_menu_bottom');
704 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
707 $urlMailbox = urlencode($mailbox);
708 sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER
);
709 $url = $base_uri.'src/view_header.php?'.$query_string;
712 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ": </B></TD>\n" .
713 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
714 '<a href="'.$url.'">'._("View Full Header").'</a>';
716 /* Output the printer friendly link if we are in subtle mode. */
717 $s .= ' | ' .
718 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
720 do_hook("read_body_header_right");
721 $s = "</SMALL></TD>\n" .
727 /***************************/
728 /* Main of read_body.php */
729 /***************************/
731 /* get the globals we may need */
733 sqgetGlobalVar('key', $key, SQ_COOKIE
);
734 sqgetGlobalVar('username', $username, SQ_SESSION
);
735 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION
);
736 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION
);
737 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION
);
739 sqgetGlobalVar('msgs', $msgs, SQ_SESSION
);
740 sqgetGlobalVar('msort', $msort, SQ_SESSION
);
741 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION
);
742 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION
);
743 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION
) ) {
748 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET
);
749 sqgetGlobalVar('where', $where, SQ_GET
);
750 sqgetGlobalVar('what', $what, SQ_GET
);
751 if ( sqgetGlobalVar('show_more', $temp, SQ_GET
) ) {
752 $show_more = (int) $temp;
754 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET
) ) {
755 $show_more_cc = (int) $temp;
757 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET
) ) {
758 $show_more_bcc = (int) $temp;
760 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET
) ) {
761 $view_hdr = (int) $temp;
765 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
766 sqgetGlobalVar('mailbox', $mailbox);
768 if ( sqgetGlobalVar('passed_id', $temp) ) {
769 $passed_id = (int) $temp;
771 if ( sqgetGlobalVar('sort', $temp) ) {
774 if ( sqgetGlobalVar('startMessage', $temp) ) {
775 $startMessage = (int) $temp;
778 /* end of get globals */
779 global $uid_support, $sqimap_capabilities, $lastTargetMailbox;
781 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
782 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
785 * Process Delete from delete-move-next
786 * but only if delete_id was set
788 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET
) ) {
789 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
791 sqimap_mailbox_expunge_dmn($delete_id);
795 * Process Move from delete-move-next
796 * but only if move_id and target_mailbox were set
798 if ( sqgetGlobalVar('move_id', $move_id, SQ_POST
) &&
799 sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST
) ) {
801 sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
802 sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted', true);
804 sqimap_mailbox_expunge_dmn($move_id);
806 if ($targetMailbox != $lastTargetMailbox) {
807 $lastTargetMailbox = $targetMailbox;
808 sqsession_register('lastTargetMailbox' , $lastTargetMailbox);
814 * $message contains all information about the message
815 * including header and body
818 $uidvalidity = $mbx_response['UIDVALIDITY'];
820 if (!isset($messages[$uidvalidity])) {
821 $messages[$uidvalidity] = array();
823 if (!isset($messages[$uidvalidity][$passed_id]) ||
!$uid_support) {
824 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
825 $FirstTimeSee = !$message->is_seen
;
826 $message->is_seen
= true;
827 $messages[$uidvalidity][$passed_id] = $message;
829 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
830 $message = $messages[$uidvalidity][$passed_id];
831 $FirstTimeSee = !$message->is_seen
;
834 if (isset($passed_ent_id) && $passed_ent_id) {
835 $message = $message->getEntity($passed_ent_id);
836 if ($message->type0
!= 'message' && $message->type1
!= 'rfc822') {
837 $message = $message->parent
;
839 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
840 $rfc822_header = new Rfc822Header();
841 $rfc822_header->parseHeader($read);
842 $message->rfc822_header
= $rfc822_header;
846 $header = $message->header
;
850 /****************************************/
851 /* Block for handling incoming url vars */
852 /****************************************/
854 if (isset($sendreceipt)) {
855 if ( !$message->is_mdnsent
) {
856 $final_recipient = '';
857 if ((isset($identity)) && ($identity != 0)) //Main identity
858 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
859 if ($final_recipient == '' )
860 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
861 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
862 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
863 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
864 $message->is_mdnsent
= true;
865 $messages[$uidvalidity][$passed_id]=$message;
870 /***********************************************/
871 /* End of block for handling incoming url vars */
872 /***********************************************/
874 $msgs[$passed_id]['FLAG_SEEN'] = true;
877 do_hook('read_body_top');
878 if ($show_html_default == 1) {
879 $ent_ar = $message->findDisplayEntity(array());
881 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
883 $cnt = count($ent_ar);
884 for ($i = 0; $i < $cnt; $i++
) {
885 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
887 $messagebody .= '<hr noshade size=1>';
891 displayPageHeader($color, $mailbox);
892 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
893 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
894 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
896 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
898 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
899 echo ' <tr bgcolor="'.$color[4].'"><td>';
900 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
901 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
902 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
906 echo ' </table></td></tr>';
910 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
911 $color[4].'"></TD></TR>'."\n";
913 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
914 if ($attachmentsdisplay) {
916 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
918 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
919 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
920 echo ' <b>' . _("Attachments") . ':</b>';
923 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
924 echo $attachmentsdisplay;
925 echo ' </td></tr></table>';
926 echo ' </td></tr></table>';
928 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
929 $color[4].'"></TD></TR>';
933 /* show attached images inline -- if pref'fed so */
934 if (($attachment_common_show_images) &&
935 is_array($attachment_common_show_images_list)) {
936 foreach ($attachment_common_show_images_list as $img) {
937 $imgurl = SM_PATH
. 'src/download.php' .
939 'passed_id=' . urlencode($img['passed_id']) .
940 '&mailbox=' . urlencode($mailbox) .
941 '&ent_id=' . urlencode($img['ent_id']) .
942 '&absolute_dl=true';
944 echo html_tag( 'table', "\n" .
945 html_tag( 'tr', "\n" .
946 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
949 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
953 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
955 do_hook('read_body_bottom');
956 do_hook('html_bottom');
957 sqimap_logout($imapConnection);
958 /* sessions are written at the end of the script. it's better to register
959 them at the end so we avoid double session_register calls */
960 sqsession_register($messages,'messages');