More UI changes - message list is more compact. Prev & Next links are
[squirrelmail.git] / src / read_body.php
1 <?php
2
3 /**
4 * read_body.php
5 *
6 * Copyright (c) 1999-2003 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * This file is used for reading the msgs array and displaying
10 * the resulting emails in the right frame.
11 *
12 * $Id$
13 * @package squirrelmail
14 */
15
16 /** Path for SquirrelMail required files. */
17 define('SM_PATH','../');
18
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');
30
31 /**
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
34 *
35 * @param int $passed_id The current message UID
36 * @return the index of the next valid message from the array
37 */
38 function findNextMessage($passed_id) {
39 global $msort, $msgs, $sort,
40 $thread_sort_messages, $allow_server_sort,
41 $server_sort_array;
42 if (!is_array($server_sort_array)) {
43 $thread_sort_messages = 0;
44 $allow_server_sort = FALSE;
45 }
46 $result = -1;
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) {
51 if ($key == $count) {
52 break;
53 }
54 $result = $server_sort_array[$key + 1];
55 break;
56 }
57 }
58 } else {
59 if (is_array($msort)) {
60 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
61 if ($passed_id == $msgs[$key]['ID']) {
62 next($msort);
63 $key = key($msort);
64 if (isset($key)){
65 $result = $msgs[$key]['ID'];
66 break;
67 }
68 }
69 }
70 }
71 }
72 return $result;
73 }
74
75 /**
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
78 *
79 * @param int $passed_id The current message UID
80 * @return the index of the next valid message from the array
81 */
82 function findPreviousMessage($numMessages, $passed_id) {
83 global $msort, $sort, $msgs,
84 $thread_sort_messages,
85 $allow_server_sort, $server_sort_array;
86 $result = -1;
87 if (!is_array($server_sort_array)) {
88 $thread_sort_messages = 0;
89 $allow_server_sort = FALSE;
90 }
91 if ($thread_sort_messages || $allow_server_sort ) {
92 foreach($server_sort_array as $key=>$value) {
93 if ($passed_id == $value) {
94 if ($key == 0) {
95 break;
96 }
97 $result = $server_sort_array[$key - 1];
98 break;
99 }
100 }
101 } else {
102 if (is_array($msort)) {
103 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
104 if ($passed_id == $msgs[$key]['ID']) {
105 prev($msort);
106 $key = key($msort);
107 if (isset($key)) {
108 $result = $msgs[$key]['ID'];
109 break;
110 }
111 }
112 }
113 }
114 }
115 return $result;
116 }
117
118 /**
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
123 */
124 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
125 global $javascript_on, $color;
126
127 $params = '?passed_ent_id=' . $passed_ent_id .
128 '&mailbox=' . urlencode($mailbox) .
129 '&passed_id=' . $passed_id;
130
131 $print_text = _("View Printable Version");
132
133 $result = '';
134 /* Output the link. */
135 if ($javascript_on) {
136 $result = '<script language="javascript" type="text/javascript">' . "\n" .
137 '<!--' . "\n" .
138 " function printFormat() {\n" .
139 ' window.open("../src/printer_friendly_main.php' .
140 $params . '","Print","width=800,height=600");' . "\n".
141 " }\n" .
142 "// -->\n" .
143 "</script>\n" .
144 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
145 } else {
146 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
147 "$params\">$print_text</a>\n";
148 }
149 return $result;
150 }
151
152 function ServerMDNSupport($read) {
153 /* escaping $ doesn't work -> \x36 */
154 $ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
155 return $ret;
156 }
157
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;
163
164 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER);
165
166 $header = $message->rfc822_header;
167 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
168
169 $rfc822_header = new Rfc822Header();
170 $content_type = new ContentType('multipart/report');
171 $content_type->properties['report-type']='disposition-notification';
172
173 set_my_charset();
174 if ($default_charset) {
175 $content_type->properties['charset']=$default_charset;
176 }
177 $rfc822_header->content_type = $content_type;
178 $rfc822_header->to[] = $header->dnt;
179 $rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject);
180
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);
188 } else {
189 $popuser = $username;
190 }
191
192 $reply_to = '';
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'];
199
200 if (!$from_mail) {
201 $from_mail = "$popuser@$domain";
202 $from_addr = $from_mail;
203 }
204 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
205 if ($reply_to) {
206 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
207 }
208
209 // part 1 (RFC2298)
210 $senton = getLongDateString( $header->date );
211 $to_array = $header->to;
212 $to = '';
213 foreach ($to_array as $line) {
214 $to .= ' '.$line->getAddress();
215 }
216 $now = getLongDateString( time() );
217 set_my_charset();
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" .
222 "\r\n" .
223 sprintf( _("Was displayed on %s"), $now );
224
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';
232 } else {
233 $body = mb_convert_encoding($body, 'JIS');
234 $special_encoding = '7bit';
235 }
236 }
237 }
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;
245 } else {
246 $mime_header->encoding = 'us-ascii';
247 }
248 if ($default_charset) {
249 $mime_header->parameters['charset'] = $default_charset;
250 }
251 $part1->mime_header = $mime_header;
252
253 // part2 (RFC2298)
254 $original_recipient = $to;
255 $original_message_id = $header->message_id;
256
257 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
258 if ($original_recipient != '') {
259 $report .= "Original-Recipient : $original_recipient\r\n";
260 }
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";
265
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;
273
274 $composeMessage = new Message();
275 $composeMessage->rfc822_header = $rfc822_header;
276 $composeMessage->addEntity($part1);
277 $composeMessage->addEntity($part2);
278
279
280 if ($useSendmail) {
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);
285 } else {
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);
293 }
294 $success = false;
295 if ($stream) {
296 $length = $deliver->mail($composeMessage, $stream);
297 $success = $deliver->finalizeStream($stream);
298 }
299 if (!$success) {
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);
305 } else {
306 unset ($deliver);
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);
314 }
315 }
316 return $success;
317 }
318
319 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
320 $sg = $set?'+':'-';
321 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
322 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
323 $readmessage, $uid_support);
324 }
325
326 function ClearAttachments() {
327 global $username, $attachments, $attachment_dir;
328
329 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
330
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);
338 }
339 } else {
340 $rem_attachments[] = $info;
341 }
342 }
343 }
344 $attachments = $rem_attachments;
345 }
346
347 function formatRecipientString($recipients, $item ) {
348 global $show_more_cc, $show_more, $show_more_bcc,
349 $PHP_SELF;
350
351 $string = '';
352 if ((is_array($recipients)) && (isset($recipients[0]))) {
353 $show = false;
354
355 if ($item == 'to') {
356 if ($show_more) {
357 $show = true;
358 $url = set_url_var($PHP_SELF, 'show_more',0);
359 } else {
360 $url = set_url_var($PHP_SELF, 'show_more',1);
361 }
362 } else if ($item == 'cc') {
363 if ($show_more_cc) {
364 $show = true;
365 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
366 } else {
367 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
368 }
369 } else if ($item == 'bcc') {
370 if ($show_more_bcc) {
371 $show = true;
372 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
373 } else {
374 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
375 }
376 }
377
378 $cnt = count($recipients);
379 foreach($recipients as $r) {
380 $add = decodeHeader($r->getAddress(true));
381 if ($string) {
382 $string .= '<BR>' . $add;
383 } else {
384 $string = $add;
385 if ($cnt > 1) {
386 $string .= '&nbsp;(<A HREF="'.$url;
387 if ($show) {
388 $string .= '">'._("less").'</A>)';
389 } else {
390 $string .= '">'._("more").'</A>)';
391 break;
392 }
393 }
394 }
395 }
396 }
397 return $string;
398 }
399
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;
405
406 $header = $message->rfc822_header;
407 $env = array();
408 $env[_("Subject")] = str_replace("&nbsp;"," ",decodeHeader($header->subject));
409
410 $from_name = $header->getAddr_s('from');
411 if (!$from_name)
412 $from_name = $header->getAddr_s('sender');
413 if (!$from_name)
414 $env[_("From")] = _("Unknown sender");
415 else
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));
423 }
424 if ($show_xmailer_default) {
425 $env[_("Mailer")] = decodeHeader($header->xmailer);
426 }
427 if ($default_use_mdn) {
428 if ($mdn_user_support) {
429 if ($header->dnt) {
430 if ($message->is_mdnsent) {
431 $env[_("Read receipt")] = _("sent");
432 } else {
433 $env[_("Read receipt")] = _("requested");
434 if (!(handleAsSent($mailbox) ||
435 $message->is_deleted ||
436 $passed_ent_id)) {
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?") .
443 '")) { '."\n" .
444 ' sendMDN()'.
445 '}' . "\n";
446 $script .= '// -->'. "\n";
447 $script .= '</script>'. "\n";
448 echo $script;
449 }
450 $env[_("Read receipt")] .= '&nbsp;<a href="' . $mdn_url . '">[' .
451 _("Send read receipt now") . ']</a>';
452 }
453 }
454 }
455 }
456 }
457
458 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
459 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
460 foreach ($env as $key => $val) {
461 if ($val) {
462 $s .= '<TR>';
463 $s .= html_tag('TD', '<B>' . $key . ':&nbsp;&nbsp;</B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
464 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
465 $s .= '</TR>';
466 }
467 }
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";
472 echo $s;
473 do_hook('read_body_header');
474 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
475 echo '</TABLE>';
476 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
477 echo '</TABLE>';
478 }
479
480 /**
481 * Format message toolbar
482 *
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
488 */
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;
494
495 $topbar_delimiter = '&nbsp;|&nbsp;';
496 $double_delimiter = '&nbsp;&nbsp;&nbsp;&nbsp;';
497 $urlMailbox = urlencode($mailbox);
498
499 $comp_uri = 'src/compose.php' .
500 '?passed_id=' . $passed_id .
501 '&amp;mailbox=' . $urlMailbox .
502 '&amp;startMessage=' . $startMessage .
503 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
504
505 $msgs_url = $base_uri . 'src/';
506
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>';
509
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);
515 $entities = array();
516 $entity_count = array();
517 $c = 0;
518
519 foreach($message->parent->entities as $ent) {
520 if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
521 $c++;
522 $entity_count[$c] = $ent->entity_id;
523 $entities[$ent->entity_id] = $c;
524 }
525 }
526
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>';
533 }
534
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>';
541 }
542
543 $par_ent_id = $message->parent->entity_id;
544 $up_link = '';
545 if ($par_ent_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>';
551 }
552 }
553
554 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
555 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
556
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);
561
562 $prev_link = _("Previous");
563 if ($prev >= 0) {
564 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
565 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
566 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
567 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
568 }
569
570 $next_link = _("Next");
571 if ($next >= 0) {
572 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
573 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
574 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
575 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
576 }
577
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");
583 if ($prev >= 0) {
584 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
585 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
586 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
587 '&amp;delete_id='.$passed_id;
588 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
589 }
590
591 $del_next_link = _("Delete & Next");
592 if ($next >= 0) {
593 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
594 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
595 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
596 '&amp;delete_id='.$passed_id;
597 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
598 }
599 }
600
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.']';
604 }
605
606 // Start with Search Results or Message List link.
607 if (isset($where) && isset($what)) {
608 $msgs_url .= 'search.php?where=' . urlencode($where) .
609 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
610 $msgs_str = _("Search Results");
611 } else {
612 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
613 $startMessage . '&amp;mailbox=' . $urlMailbox;
614 $msgs_str = _("Message List");
615 }
616 $nav_row .= $double_delimiter .
617 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
618
619 $nav_row .= '</small></td></tr>';
620
621
622 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
623 $menu_row = '<tr bgcolor="'.$color[9].'"><td><small>';
624
625 // If Draft folder - create Resume link
626 if (($mailbox == $draft_folder) && ($save_as_draft)) {
627 $comp_alt_uri = $comp_uri . '&amp;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 . '&amp;smaction=edit_as_new';
632 $comp_alt_string = _("Edit Message as New");
633 }
634
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;
640 }
641
642 $comp_action_uri = $comp_uri . '&amp;smaction=reply';
643 $menu_row .= makeComposeLink($comp_action_uri, _("Reply"));
644
645 $comp_action_uri = $comp_uri . '&amp;smaction=reply_all';
646 $menu_row .= $topbar_delimiter;
647 $menu_row .= makeComposeLink($comp_action_uri, _("Reply All"));
648
649
650 $comp_action_uri = $comp_uri . '&amp;smaction=forward';
651 $menu_row .= $topbar_delimiter;
652 $menu_row .= makeComposeLink($comp_action_uri, _("Forward"));
653
654 if ($enable_forward_as_attachment) {
655 $comp_action_uri = $comp_uri . '&amp;smaction=forward_as_attachment';
656 $menu_row .= $topbar_delimiter;
657 $menu_row .= makeComposeLink($comp_action_uri, _("Forward as Attachment"));
658 }
659
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 '&amp;message=' . $passed_id . '&amp;';
664
665 if ($where && $what) {
666 $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
667 } else {
668 $delete_url .= 'sort=' . $sort . '&amp;startMessage=' . $startMessage;
669 }
670 $delete_link = '<a href="' . $delete_url . '">' . $delete_link . '</a>';
671 $delete_link .= '&nbsp;(<a href="' . $delete_url.'&amp;bypass_trash=1">'
672 ._("Bypass Trash").'</a>)';
673
674 }
675 $menu_row .= $topbar_delimiter.$delete_link;
676
677
678 // Add top move 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)));
687 } else {
688 $menu_row .= sqimap_mailbox_option_list($imapConnection);
689 }
690 $menu_row .= '</select> '.
691 '<input type="submit" value="' . _("Move") . '" style="padding: 0px; margin: 0px"/>'.
692 '</small></form>';
693 }
694 $menu_row .= '</td></tr>';
695
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');
702 }
703
704 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
705 global $base_uri;
706
707 $urlMailbox = urlencode($mailbox);
708 sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER);
709 $url = $base_uri.'src/view_header.php?'.$query_string;
710
711 $s = "<TR>\n" .
712 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
713 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
714 '<a href="'.$url.'">'._("View Full Header").'</a>';
715
716 /* Output the printer friendly link if we are in subtle mode. */
717 $s .= '&nbsp;|&nbsp;' .
718 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
719 echo $s;
720 do_hook("read_body_header_right");
721 $s = "</SMALL></TD>\n" .
722 "</TR>\n";
723 echo $s;
724
725 }
726
727 /***************************/
728 /* Main of read_body.php */
729 /***************************/
730
731 /* get the globals we may need */
732
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);
738
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) ) {
744 $messages = array();
745 }
746
747 /** GET VARS */
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;
753 }
754 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) {
755 $show_more_cc = (int) $temp;
756 }
757 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) {
758 $show_more_bcc = (int) $temp;
759 }
760 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) {
761 $view_hdr = (int) $temp;
762 }
763
764 /** GET/POST VARS */
765 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
766 sqgetGlobalVar('mailbox', $mailbox);
767
768 if ( sqgetGlobalVar('passed_id', $temp) ) {
769 $passed_id = (int) $temp;
770 }
771 if ( sqgetGlobalVar('sort', $temp) ) {
772 $sort = (int) $temp;
773 }
774 if ( sqgetGlobalVar('startMessage', $temp) ) {
775 $startMessage = (int) $temp;
776 }
777
778 /* end of get globals */
779 global $uid_support, $sqimap_capabilities, $lastTargetMailbox;
780
781 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
782 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
783
784 /**
785 * Process Delete from delete-move-next
786 * but only if delete_id was set
787 */
788 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
789 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
790
791 sqimap_mailbox_expunge_dmn($delete_id);
792 }
793
794 /**
795 * Process Move from delete-move-next
796 * but only if move_id and target_mailbox were set
797 */
798 if ( sqgetGlobalVar('move_id', $move_id, SQ_POST) &&
799 sqgetGlobalVar('targetMailbox', $targetMailbox, SQ_POST) ) {
800 // Move message
801 sqimap_messages_copy($imapConnection, $move_id, $move_id, $targetMailbox);
802 sqimap_messages_flag($imapConnection, $move_id, $move_id, 'Deleted', true);
803
804 sqimap_mailbox_expunge_dmn($move_id);
805
806 if ($targetMailbox != $lastTargetMailbox) {
807 $lastTargetMailbox = $targetMailbox;
808 sqsession_register('lastTargetMailbox' , $lastTargetMailbox);
809 }
810 }
811
812
813 /**
814 * $message contains all information about the message
815 * including header and body
816 */
817
818 $uidvalidity = $mbx_response['UIDVALIDITY'];
819
820 if (!isset($messages[$uidvalidity])) {
821 $messages[$uidvalidity] = array();
822 }
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;
828 } else {
829 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
830 $message = $messages[$uidvalidity][$passed_id];
831 $FirstTimeSee = !$message->is_seen;
832 }
833
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;
838 }
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;
843 } else {
844 $passed_ent_id = 0;
845 }
846 $header = $message->header;
847
848 do_hook('html_top');
849
850 /****************************************/
851 /* Block for handling incoming url vars */
852 /****************************************/
853
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;
866 }
867 ClearAttachments();
868 }
869 }
870 /***********************************************/
871 /* End of block for handling incoming url vars */
872 /***********************************************/
873
874 $msgs[$passed_id]['FLAG_SEEN'] = true;
875
876 $messagebody = '';
877 do_hook('read_body_top');
878 if ($show_html_default == 1) {
879 $ent_ar = $message->findDisplayEntity(array());
880 } else {
881 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
882 }
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);
886 if ($i != $cnt-1) {
887 $messagebody .= '<hr noshade size=1>';
888 }
889 }
890
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">';
895 echo ' <tr><td>';
896 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
897 echo ' <tr><td>';
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')
903 . '</tr>';
904 echo ' </table>';
905 echo ' </td></tr>';
906 echo ' </table></td></tr>';
907 echo ' </table>';
908 echo ' </td></tr>';
909
910 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
911 $color[4].'"></TD></TR>'."\n";
912
913 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
914 if ($attachmentsdisplay) {
915 echo ' </table>';
916 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
917 echo ' <tr><td>';
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>';
921 echo ' </td></tr>';
922 echo ' <tr><td>';
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>';
927 echo ' </td></tr>';
928 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
929 $color[4].'"></TD></TR>';
930 }
931 echo '</table>';
932
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' .
938 '?' .
939 'passed_id=' . urlencode($img['passed_id']) .
940 '&amp;mailbox=' . urlencode($mailbox) .
941 '&amp;ent_id=' . urlencode($img['ent_id']) .
942 '&amp;absolute_dl=true';
943
944 echo html_tag( 'table', "\n" .
945 html_tag( 'tr', "\n" .
946 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
947 )
948 ) ,
949 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
950 }
951 }
952
953 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
954
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');
961
962 ?>
963 </body>
964 </html>