c4da8d04bf391049eba7720e6196b82c6fd9b86a
[squirrelmail.git] / src / read_body.php
1 <?php
2 /**
3 * read_body.php
4 *
5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This file is used for reading the msgs array and displaying
9 * the resulting emails in the right frame.
10 *
11 * $Id$
12 * @package squirrelmail
13 */
14
15 /** Path for SquirrelMail required files. */
16 define('SM_PATH','../');
17
18 /* SquirrelMail required files. */
19 require_once(SM_PATH . 'include/validate.php');
20 require_once(SM_PATH . 'functions/global.php');
21 require_once(SM_PATH . 'functions/imap.php');
22 require_once(SM_PATH . 'functions/mime.php');
23 require_once(SM_PATH . 'functions/date.php');
24 require_once(SM_PATH . 'functions/url_parser.php');
25 require_once(SM_PATH . 'functions/html.php');
26 require_once(SM_PATH . 'functions/global.php');
27 require_once(SM_PATH . 'functions/identity.php');
28 require_once(SM_PATH . 'functions/mailbox_display.php');
29
30 /**
31 * Given an IMAP message id number, this will look it up in the cached
32 * and sorted msgs array and return the index of the next message
33 *
34 * @param int $passed_id The current message UID
35 * @return the index of the next valid message from the array
36 */
37 function findNextMessage($passed_id) {
38 global $msort, $msgs, $sort,
39 $thread_sort_messages, $allow_server_sort,
40 $server_sort_array;
41 if (!is_array($server_sort_array)) {
42 $thread_sort_messages = 0;
43 $allow_server_sort = FALSE;
44 }
45 $result = -1;
46 if ($thread_sort_messages || $allow_server_sort) {
47 $count = count($server_sort_array) - 1;
48 foreach($server_sort_array as $key=>$value) {
49 if ($passed_id == $value) {
50 if ($key == $count) {
51 break;
52 }
53 $result = $server_sort_array[$key + 1];
54 break;
55 }
56 }
57 } else {
58 if (is_array($msort)) {
59 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
60 if ($passed_id == $msgs[$key]['ID']) {
61 next($msort);
62 $key = key($msort);
63 if (isset($key)){
64 $result = $msgs[$key]['ID'];
65 break;
66 }
67 }
68 }
69 }
70 }
71 return $result;
72 }
73
74 /**
75 * Given an IMAP message id number, this will look it up in the cached
76 * and sorted msgs array and return the index of the previous message
77 *
78 * @param int $passed_id The current message UID
79 * @return the index of the next valid message from the array
80 */
81 function findPreviousMessage($numMessages, $passed_id) {
82 global $msort, $sort, $msgs,
83 $thread_sort_messages,
84 $allow_server_sort, $server_sort_array;
85 $result = -1;
86 if (!is_array($server_sort_array)) {
87 $thread_sort_messages = 0;
88 $allow_server_sort = FALSE;
89 }
90 if ($thread_sort_messages || $allow_server_sort ) {
91 foreach($server_sort_array as $key=>$value) {
92 if ($passed_id == $value) {
93 if ($key == 0) {
94 break;
95 }
96 $result = $server_sort_array[$key - 1];
97 break;
98 }
99 }
100 } else {
101 if (is_array($msort)) {
102 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
103 if ($passed_id == $msgs[$key]['ID']) {
104 prev($msort);
105 $key = key($msort);
106 if (isset($key)) {
107 $result = $msgs[$key]['ID'];
108 break;
109 }
110 }
111 }
112 }
113 }
114 return $result;
115 }
116
117 /**
118 * Displays a link to a page where the message is displayed more
119 * "printer friendly".
120 * @param string $mailbox Name of current mailbox
121 * @param int $passed_id
122 */
123 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
124 global $javascript_on, $color;
125
126 $params = '?passed_ent_id=' . $passed_ent_id .
127 '&mailbox=' . urlencode($mailbox) .
128 '&passed_id=' . $passed_id;
129
130 $print_text = _("View Printable Version");
131
132 $result = '';
133 /* Output the link. */
134 if ($javascript_on) {
135 $result = '<script language="javascript" type="text/javascript">' . "\n" .
136 '<!--' . "\n" .
137 " function printFormat() {\n" .
138 ' window.open("../src/printer_friendly_main.php' .
139 $params . '","Print","width=800,height=600");' . "\n".
140 " }\n" .
141 "// -->\n" .
142 "</script>\n" .
143 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
144 } else {
145 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
146 "$params\">$print_text</a>\n";
147 }
148 return $result;
149 }
150
151 function ServerMDNSupport($read) {
152 /* escaping $ doesn't work -> \x36 */
153 $ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
154 return $ret;
155 }
156
157 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
158 global $username, $attachment_dir,
159 $version, $attachments, $squirrelmail_language, $default_charset,
160 $languages, $useSendmail, $domain, $sent_folder,
161 $popuser, $data_dir, $username;
162
163 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER);
164
165 $header = $message->rfc822_header;
166 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
167
168 $rfc822_header = new Rfc822Header();
169 $content_type = new ContentType('multipart/report');
170 $content_type->properties['report-type']='disposition-notification';
171
172 set_my_charset();
173 if ($default_charset) {
174 $content_type->properties['charset']=$default_charset;
175 }
176 $rfc822_header->content_type = $content_type;
177 $rfc822_header->to[] = $header->dnt;
178 $rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject);
179
180 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
181 // This merely comes from compose.php and only happens when there is no
182 // email_addr specified in user's identity (which is the startup config)
183 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
184 $popuser = $usernamedata[1];
185 $domain = $usernamedata[2];
186 unset($usernamedata);
187 } else {
188 $popuser = $username;
189 }
190
191 $reply_to = '';
192 $ident = get_identities();
193 if(!isset($identity)) $identity = 0;
194 $full_name = $ident[$identity]['full_name'];
195 $from_mail = $ident[$identity]['email_address'];
196 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
197 $reply_to = $ident[$identity]['reply_to'];
198
199 if (!$from_mail) {
200 $from_mail = "$popuser@$domain";
201 $from_addr = $from_mail;
202 }
203 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
204 if ($reply_to) {
205 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
206 }
207
208 // part 1 (RFC2298)
209 $senton = getLongDateString( $header->date );
210 $to_array = $header->to;
211 $to = '';
212 foreach ($to_array as $line) {
213 $to .= ' '.$line->getAddress();
214 }
215 $now = getLongDateString( time() );
216 set_my_charset();
217 $body = _("Your message") . "\r\n\r\n" .
218 "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" .
219 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject,false,false) . "\r\n" .
220 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
221 "\r\n" .
222 sprintf( _("Was displayed on %s"), $now );
223
224 $special_encoding = '';
225 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
226 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
227 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
228 if (strtolower($default_charset) == 'iso-2022-jp') {
229 if (mb_detect_encoding($body) == 'ASCII') {
230 $special_encoding = '8bit';
231 } else {
232 $body = mb_convert_encoding($body, 'JIS');
233 $special_encoding = '7bit';
234 }
235 }
236 }
237 $part1 = new Message();
238 $part1->setBody($body);
239 $mime_header = new MessageHeader;
240 $mime_header->type0 = 'text';
241 $mime_header->type1 = 'plain';
242 if ($special_encoding) {
243 $mime_header->encoding = $special_encoding;
244 } else {
245 $mime_header->encoding = 'us-ascii';
246 }
247 if ($default_charset) {
248 $mime_header->parameters['charset'] = $default_charset;
249 }
250 $part1->mime_header = $mime_header;
251
252 // part2 (RFC2298)
253 $original_recipient = $to;
254 $original_message_id = $header->message_id;
255
256 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
257 if ($original_recipient != '') {
258 $report .= "Original-Recipient : $original_recipient\r\n";
259 }
260 $final_recipient = $sender;
261 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
262 "Original-Message-ID : $original_message_id\r\n" .
263 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
264
265 $part2 = new Message();
266 $part2->setBody($report);
267 $mime_header = new MessageHeader;
268 $mime_header->type0 = 'message';
269 $mime_header->type1 = 'disposition-notification';
270 $mime_header->encoding = 'us-ascii';
271 $part2->mime_header = $mime_header;
272
273 $composeMessage = new Message();
274 $composeMessage->rfc822_header = $rfc822_header;
275 $composeMessage->addEntity($part1);
276 $composeMessage->addEntity($part2);
277
278
279 if ($useSendmail) {
280 require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
281 global $sendmail_path;
282 $deliver = new Deliver_SendMail();
283 $stream = $deliver->initStream($composeMessage,$sendmail_path);
284 } else {
285 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
286 $deliver = new Deliver_SMTP();
287 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
288 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
289 get_smtp_user($user, $pass);
290 $stream = $deliver->initStream($composeMessage,$domain,0,
291 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
292 }
293 $success = false;
294 if ($stream) {
295 $length = $deliver->mail($composeMessage, $stream);
296 $success = $deliver->finalizeStream($stream);
297 }
298 if (!$success) {
299 $msg = $deliver->dlv_msg . '<br>' .
300 _("Server replied: ") . $deliver->dlv_ret_nr . ' '.
301 $deliver->dlv_server_msg;
302 require_once(SM_PATH . 'functions/display_messages.php');
303 plain_error_message($msg, $color);
304 } else {
305 unset ($deliver);
306 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
307 sqimap_append ($imapConnection, $sent_folder, $length);
308 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
309 $imap_deliver = new Deliver_IMAP();
310 $imap_deliver->mail($composeMessage, $imapConnection);
311 sqimap_append_done ($imapConnection);
312 unset ($imap_deliver);
313 }
314 }
315 return $success;
316 }
317
318 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
319 $sg = $set?'+':'-';
320 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
321 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
322 $readmessage, TRUE);
323 }
324
325 function ClearAttachments() {
326 global $username, $attachments, $attachment_dir;
327
328 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
329
330 $rem_attachments = array();
331 if (isset($attachments)) {
332 foreach ($attachments as $info) {
333 if ($info['session'] == -1) {
334 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
335 if (file_exists($attached_file)) {
336 unlink($attached_file);
337 }
338 } else {
339 $rem_attachments[] = $info;
340 }
341 }
342 }
343 $attachments = $rem_attachments;
344 }
345
346 function formatRecipientString($recipients, $item ) {
347 global $show_more_cc, $show_more, $show_more_bcc,
348 $PHP_SELF;
349
350 $string = '';
351 if ((is_array($recipients)) && (isset($recipients[0]))) {
352 $show = false;
353
354 if ($item == 'to') {
355 if ($show_more) {
356 $show = true;
357 $url = set_url_var($PHP_SELF, 'show_more',0);
358 } else {
359 $url = set_url_var($PHP_SELF, 'show_more',1);
360 }
361 } else if ($item == 'cc') {
362 if ($show_more_cc) {
363 $show = true;
364 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
365 } else {
366 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
367 }
368 } else if ($item == 'bcc') {
369 if ($show_more_bcc) {
370 $show = true;
371 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
372 } else {
373 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
374 }
375 }
376
377 $cnt = count($recipients);
378 foreach($recipients as $r) {
379 $add = decodeHeader($r->getAddress(true));
380 if ($string) {
381 $string .= '<BR>' . $add;
382 } else {
383 $string = $add;
384 if ($cnt > 1) {
385 $string .= '&nbsp;(<A HREF="'.$url;
386 if ($show) {
387 $string .= '">'._("less").'</A>)';
388 } else {
389 $string .= '">'._("more").'</A>)';
390 break;
391 }
392 }
393 }
394 }
395 }
396 return $string;
397 }
398
399 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
400 $color, $FirstTimeSee) {
401 global $msn_user_support, $default_use_mdn, $default_use_priority,
402 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
403 $squirrelmail_language;
404
405 $header = $message->rfc822_header;
406 $env = array();
407 $env[_("Subject")] = str_replace("&nbsp;"," ",decodeHeader($header->subject));
408
409 $from_name = $header->getAddr_s('from');
410 if (!$from_name)
411 $from_name = $header->getAddr_s('sender');
412 if (!$from_name)
413 $env[_("From")] = _("Unknown sender");
414 else
415 $env[_("From")] = decodeHeader($from_name);
416 $env[_("Date")] = getLongDateString($header->date);
417 $env[_("To")] = formatRecipientString($header->to, "to");
418 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
419 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
420 if ($default_use_priority) {
421 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority));
422 }
423 if ($show_xmailer_default) {
424 $env[_("Mailer")] = decodeHeader($header->xmailer);
425 }
426 if ($default_use_mdn) {
427 if ($mdn_user_support) {
428 if ($header->dnt) {
429 if ($message->is_mdnsent) {
430 $env[_("Read receipt")] = _("sent");
431 } else {
432 $env[_("Read receipt")] = _("requested");
433 if (!(handleAsSent($mailbox) ||
434 $message->is_deleted ||
435 $passed_ent_id)) {
436 $mdn_url = $PHP_SELF . '&sendreceipt=1';
437 if ($FirstTimeSee && $javascript_on) {
438 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
439 $script .= '<!--'. "\n";
440 $script .= 'if(window.confirm("' .
441 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
442 '")) { '."\n" .
443 ' sendMDN()'.
444 '}' . "\n";
445 $script .= '// -->'. "\n";
446 $script .= '</script>'. "\n";
447 echo $script;
448 }
449 $env[_("Read receipt")] .= '&nbsp;<a href="' . $mdn_url . '">[' .
450 _("Send read receipt now") . ']</a>';
451 }
452 }
453 }
454 }
455 }
456
457 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
458 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
459 foreach ($env as $key => $val) {
460 if ($val) {
461 $s .= '<TR>';
462 $s .= html_tag('TD', '<B>' . $key . ':&nbsp;&nbsp;</B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
463 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
464 $s .= '</TR>';
465 }
466 }
467 echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
468 ' CELLSPACING="0" BORDER="0" ALIGN="center">'."\n";
469 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
470 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
471 echo $s;
472 do_hook('read_body_header');
473 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
474 echo '</TABLE>';
475 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
476 echo '</TABLE>';
477 }
478
479 /**
480 * Format message toolbar
481 *
482 * @param string $mailbox Name of current mailbox
483 * @param int $passed_id UID of current message
484 * @param int $passed_ent_id Id of entity within message
485 * @param object $message Current message object
486 * @param object $mbx_response
487 */
488 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
489 global $base_uri, $draft_folder, $where, $what, $color, $sort,
490 $startMessage, $PHP_SELF, $save_as_draft,
491 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
492 $data_dir, $username, $delete_prev_next_display;
493
494 $topbar_delimiter = '&nbsp;|&nbsp;';
495 $double_delimiter = '&nbsp;&nbsp;&nbsp;&nbsp;';
496 $urlMailbox = urlencode($mailbox);
497
498 $msgs_url = $base_uri . 'src/';
499
500 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
501 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
502
503 // Create Prev & Next links
504 // Handle nested entities first (i.e. Mime Attach parts)
505 if (isset($passed_ent_id) && $passed_ent_id) {
506 // code for navigating through attached message/rfc822 messages
507 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
508 $entities = array();
509 $entity_count = array();
510 $c = 0;
511
512 foreach($message->parent->entities as $ent) {
513 if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
514 $c++;
515 $entity_count[$c] = $ent->entity_id;
516 $entities[$ent->entity_id] = $c;
517 }
518 }
519
520 $prev_link = _("Previous");
521 if($entities[$passed_ent_id] > 1) {
522 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
523 $prev_link = '<a href="'
524 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
525 . '">' . $prev_link . '</a>';
526 }
527
528 $next_link = _("Next");
529 if($entities[$passed_ent_id] < $c) {
530 $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1];
531 $next_link = '<a href="'
532 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
533 . '">' . $next_link . '</a>';
534 }
535
536 $par_ent_id = $message->parent->entity_id;
537 $up_link = '';
538 if ($par_ent_id) {
539 $par_ent_id = substr($par_ent_id,0,-2);
540 if ( $par_ent_id != 0 ) {
541 $up_link = $topbar_delimiter;
542 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
543 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
544 }
545 }
546
547 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
548 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
549
550 // Prev/Next links for regular messages
551 } else if ( !(isset($where) && isset($what)) ) {
552 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
553 $next = findNextMessage($passed_id);
554
555 $prev_link = _("Previous");
556 if ($prev >= 0) {
557 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
558 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
559 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
560 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
561 }
562
563 $next_link = _("Next");
564 if ($next >= 0) {
565 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
566 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
567 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
568 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
569 }
570
571 // Only bother with Delete & Prev and Delete & Next IF
572 // top display is enabled.
573 if ( $delete_prev_next_display == 1 ) {
574 $del_prev_link = _("Delete & Prev");
575 if ($prev >= 0) {
576 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
577 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
578 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
579 '&amp;delete_id='.$passed_id;
580 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
581 }
582
583 $del_next_link = _("Delete & Next");
584 if ($next >= 0) {
585 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
586 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
587 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
588 '&amp;delete_id='.$passed_id;
589 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
590 }
591 }
592
593 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
594 if ( isset($del_prev_link) && isset($del_next_link) )
595 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
596 }
597
598 // Start with Search Results or Message List link.
599 if (isset($where) && isset($what)) {
600 $msgs_url .= 'search.php?where=' . urlencode($where) .
601 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
602 $msgs_str = _("Search Results");
603 } else {
604 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
605 $startMessage . '&amp;mailbox=' . $urlMailbox;
606 $msgs_str = _("Message List");
607 }
608 $nav_row .= $double_delimiter .
609 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
610
611 $nav_row .= '</small></td></tr>';
612
613
614 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
615 $menu_row = '<tr bgcolor="'.$color[9].'"><td><small>';
616
617 // Start form for reply/reply all/forward..
618 $comp_uri = $base_uri.'src/compose.php' .
619 '?passed_id=' . $passed_id .
620 '&amp;mailbox=' . $urlMailbox .
621 '&amp;startMessage=' . $startMessage .
622 (isset($passed_ent_id) ? '&amp;passed_ent_id='.$passed_ent_id : '');
623 $menu_row .= '<form action="'.$comp_uri.'" method="post"><small>';
624
625 // If Draft folder - create Resume link
626 if (($mailbox == $draft_folder) && ($save_as_draft)) {
627 $new_button = 'draft';
628 $comp_alt_string = _("Resume Draft");
629 } else if (handleAsSent($mailbox)) {
630 // If in Sent folder, edit as new
631 $new_button = 'edit_as_new';
632 $comp_alt_string = _("Edit Message as New");
633 }
634 // Show Alt URI for Draft/Sent
635 if (isset($comp_alt_string))
636 $menu_row .= getButton('SUBMIT', $new_button, $comp_alt_string) . "\n";
637
638 $menu_row .= getButton('SUBMIT', 'smaction_reply', _("Reply"));
639 $menu_row .= '&nbsp;'.getButton('SUBMIT', 'smaction_reply_all', _("Reply All"));
640 $menu_row .= '&nbsp;'.getButton('SUBMIT', 'smaction_forward', _("Forward"));
641
642 if ($enable_forward_as_attachment)
643 $menu_row .= '<input type="checkbox" name="smaction_attache">' . _("Attachment");
644
645 $menu_row .= '</form>'.'&nbsp;&nbsp;';
646
647 // Form for deletion
648 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox;
649 $menu_row .= '<form action="'.$delete_url.'" method="post" style="display: inline"><small>';
650
651 if (!(isset($passed_ent_id) && $passed_ent_id)) {
652 $menu_row .= '<input type="hidden" name="message" value="'.$passed_id.'" />';
653
654 if ($where && $what) {
655 $menu_row .= '<input type="hidden" name="where" value="'.$where.'" />';
656 $menu_row .= '<input type="hidden" name="what" value="'.$what.'" />';
657 } else {
658 $menu_row .= '<input type="hidden" name="sort" value="'.$sort.'" />';
659 $menu_row .= '<input type="hidden" name="startMessage" value="'.$startMessage.'" />';
660 }
661 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"));
662 $menu_row .= '<input type="checkbox" name="bypass_trash">' . _("Bypass Trash");
663 }
664 else
665 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"), FALSE) . "\n"; // delete button is disabled
666
667 $menu_row .= '</form>' . "\n";
668
669
670 // Add top move link
671 $menu_row .= '</small></td><td align="right">';
672 if ( !(isset($passed_ent_id) && $passed_ent_id) ) {
673
674 $current_box = 'mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage;
675
676 // Set subsequent location based on whether or not there is a 'next' message.
677 if ( isset($next) && $next >= 0 ) {
678 $location = $base_uri . 'src/read_body.php?passed_id='.$next.'&';
679 } else {
680 $location = $base_uri . 'src/right_main.php?';
681 }
682
683 $menu_row .= '<form action="'.$base_uri.'src/move_messages.php?'.$current_box.'" method="post">'.
684 '<small><input type="hidden" name="show_more" value="0" />'.
685 '<input type="hidden" name="location" value="'.$location.$current_box.'" />'.
686 '<input type="hidden" name="msg[0]" value="'.$passed_id.'" />'._("Move to:") .
687 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
688
689 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
690 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
691 } else {
692 $menu_row .= sqimap_mailbox_option_list($imapConnection);
693 }
694 $menu_row .= '</select> ';
695
696 $menu_row .= getButton('SUBMIT', 'moveButton',_("Move")) . "\n" . '</form>';
697 }
698 $menu_row .= '</td></tr>';
699
700 // echo rows, with hooks
701 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
702 if (is_array($ret)) {
703 if (isset($ret[0]) && !empty($ret[0])) {
704 $nav_row = $ret[0];
705 }
706 if (isset($ret[1]) && !empty($ret[1])) {
707 $menu_row = $ret[1];
708 }
709 }
710 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
711 echo $nav_on_top ? $nav_row . $menu_row : $menu_row . $nav_row;
712 echo '</table>'."\n";
713 do_hook('read_body_menu_bottom');
714 }
715
716 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
717 global $base_uri;
718
719 $urlMailbox = urlencode($mailbox);
720 sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER);
721 $url = $base_uri.'src/view_header.php?'.$query_string;
722
723 $s = "<TR>\n" .
724 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
725 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
726 '<a href="'.$url.'">'._("View Full Header").'</a>';
727
728 /* Output the printer friendly link if we are in subtle mode. */
729 $s .= '&nbsp;|&nbsp;' .
730 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
731 echo $s;
732 do_hook("read_body_header_right");
733 $s = "</SMALL></TD>\n" .
734 "</TR>\n";
735 echo $s;
736
737 }
738
739 /***************************/
740 /* Main of read_body.php */
741 /***************************/
742
743 /* get the globals we may need */
744
745 sqgetGlobalVar('key', $key, SQ_COOKIE);
746 sqgetGlobalVar('username', $username, SQ_SESSION);
747 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
748 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
749 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
750
751 sqgetGlobalVar('msgs', $msgs, SQ_SESSION);
752 sqgetGlobalVar('msort', $msort, SQ_SESSION);
753 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
754 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION);
755 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) {
756 $messages = array();
757 }
758
759 /** GET VARS */
760 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET);
761 sqgetGlobalVar('where', $where, SQ_GET);
762 sqgetGlobalVar('what', $what, SQ_GET);
763 if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) {
764 $show_more = (int) $temp;
765 }
766 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) {
767 $show_more_cc = (int) $temp;
768 }
769 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) {
770 $show_more_bcc = (int) $temp;
771 }
772 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) {
773 $view_hdr = (int) $temp;
774 }
775
776 /** GET/POST VARS */
777 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
778 sqgetGlobalVar('mailbox', $mailbox);
779
780 if ( sqgetGlobalVar('passed_id', $temp) ) {
781 $passed_id = (int) $temp;
782 }
783 if ( sqgetGlobalVar('sort', $temp) ) {
784 $sort = (int) $temp;
785 }
786 if ( sqgetGlobalVar('startMessage', $temp) ) {
787 $startMessage = (int) $temp;
788 }
789
790 /* end of get globals */
791 global $sqimap_capabilities, $lastTargetMailbox;
792
793 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
794 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
795
796 /**
797 * Process Delete from delete-move-next
798 * but only if delete_id was set
799 */
800 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
801 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
802
803 sqimap_mailbox_expunge_dmn($delete_id);
804 }
805
806 /**
807 * $message contains all information about the message
808 * including header and body
809 */
810
811 $uidvalidity = $mbx_response['UIDVALIDITY'];
812
813 if (!isset($messages[$uidvalidity])) {
814 $messages[$uidvalidity] = array();
815 }
816 if (!isset($messages[$uidvalidity][$passed_id])) {
817 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
818 $FirstTimeSee = !$message->is_seen;
819 $message->is_seen = true;
820 $messages[$uidvalidity][$passed_id] = $message;
821 } else {
822 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
823 $message = $messages[$uidvalidity][$passed_id];
824 $FirstTimeSee = !$message->is_seen;
825 }
826
827 if (isset($passed_ent_id) && $passed_ent_id) {
828 $message = $message->getEntity($passed_ent_id);
829 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
830 $message = $message->parent;
831 }
832 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
833 $rfc822_header = new Rfc822Header();
834 $rfc822_header->parseHeader($read);
835 $message->rfc822_header = $rfc822_header;
836 } else {
837 $passed_ent_id = 0;
838 }
839 $header = $message->header;
840
841 do_hook('html_top');
842
843 /****************************************/
844 /* Block for handling incoming url vars */
845 /****************************************/
846
847 if (isset($sendreceipt)) {
848 if ( !$message->is_mdnsent ) {
849 $final_recipient = '';
850 if ((isset($identity)) && ($identity != 0)) //Main identity
851 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
852 if ($final_recipient == '' )
853 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
854 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
855 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
856 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
857 $message->is_mdnsent = true;
858 $messages[$uidvalidity][$passed_id]=$message;
859 }
860 ClearAttachments();
861 }
862 }
863 /***********************************************/
864 /* End of block for handling incoming url vars */
865 /***********************************************/
866
867 $msgs[$passed_id]['FLAG_SEEN'] = true;
868
869 $messagebody = '';
870 do_hook('read_body_top');
871 if ($show_html_default == 1) {
872 $ent_ar = $message->findDisplayEntity(array());
873 } else {
874 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
875 }
876 $cnt = count($ent_ar);
877 for ($i = 0; $i < $cnt; $i++) {
878 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
879 if ($i != $cnt-1) {
880 $messagebody .= '<hr noshade size=1>';
881 }
882 }
883
884 displayPageHeader($color, $mailbox);
885 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
886 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
887 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
888 echo ' <tr><td>';
889 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
890 echo ' <tr><td>';
891 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
892 echo ' <tr bgcolor="'.$color[4].'"><td>';
893 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
894 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
895 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
896 . '</tr>';
897 echo ' </table>';
898 echo ' </td></tr>';
899 echo ' </table></td></tr>';
900 echo ' </table>';
901 echo ' </td></tr>';
902
903 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
904 $color[4].'"></TD></TR>'."\n";
905
906 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
907 if ($attachmentsdisplay) {
908 echo ' </table>';
909 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
910 echo ' <tr><td>';
911 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
912 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
913 echo ' <b>' . _("Attachments") . ':</b>';
914 echo ' </td></tr>';
915 echo ' <tr><td>';
916 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
917 echo $attachmentsdisplay;
918 echo ' </td></tr></table>';
919 echo ' </td></tr></table>';
920 echo ' </td></tr>';
921 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
922 $color[4].'"></TD></TR>';
923 }
924 echo '</table>';
925
926 /* show attached images inline -- if pref'fed so */
927 if (($attachment_common_show_images) &&
928 is_array($attachment_common_show_images_list)) {
929 foreach ($attachment_common_show_images_list as $img) {
930 $imgurl = SM_PATH . 'src/download.php' .
931 '?' .
932 'passed_id=' . urlencode($img['passed_id']) .
933 '&amp;mailbox=' . urlencode($mailbox) .
934 '&amp;ent_id=' . urlencode($img['ent_id']) .
935 '&amp;absolute_dl=true';
936
937 echo html_tag( 'table', "\n" .
938 html_tag( 'tr', "\n" .
939 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
940 )
941 ) ,
942 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
943 }
944 }
945
946 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
947
948 do_hook('read_body_bottom');
949 do_hook('html_bottom');
950 sqimap_logout($imapConnection);
951 /* sessions are written at the end of the script. it's better to register
952 them at the end so we avoid double session_register calls */
953 sqsession_register($messages,'messages');
954
955 ?>
956 </body>
957 </html>