Back out support for using SM without Frames
[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. Used for finding the next
34 * and previous messages.
35 *
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 /** returns the index of the previous message from the array. */
76 function findPreviousMessage($numMessages, $passed_id) {
77 global $msort, $sort, $msgs,
78 $thread_sort_messages,
79 $allow_server_sort, $server_sort_array;
80 $result = -1;
81 if (!is_array($server_sort_array)) {
82 $thread_sort_messages = 0;
83 $allow_server_sort = FALSE;
84 }
85 if ($thread_sort_messages || $allow_server_sort ) {
86 foreach($server_sort_array as $key=>$value) {
87 if ($passed_id == $value) {
88 if ($key == 0) {
89 break;
90 }
91 $result = $server_sort_array[$key - 1];
92 break;
93 }
94 }
95 } else {
96 if (is_array($msort)) {
97 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
98 if ($passed_id == $msgs[$key]['ID']) {
99 prev($msort);
100 $key = key($msort);
101 if (isset($key)) {
102 $result = $msgs[$key]['ID'];
103 break;
104 }
105 }
106 }
107 }
108 }
109 return $result;
110 }
111
112 /**
113 * Displays a link to a page where the message is displayed more
114 * "printer friendly".
115 */
116 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) {
117 global $javascript_on;
118
119 $params = '?passed_ent_id=' . $passed_ent_id .
120 '&mailbox=' . urlencode($mailbox) .
121 '&passed_id=' . $passed_id;
122
123 $print_text = _("View Printable Version");
124
125 $result = '';
126 /* Output the link. */
127 if ($javascript_on) {
128 $result = '<script language="javascript" type="text/javascript">' . "\n" .
129 '<!--' . "\n" .
130 " function printFormat() {\n" .
131 ' window.open("../src/printer_friendly_main.php' .
132 $params . '","Print","width=800,height=600");' . "\n".
133 " }\n" .
134 "// -->\n" .
135 "</script>\n" .
136 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
137 } else {
138 $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' .
139 "$params\">$print_text</a>\n";
140 }
141 return $result;
142 }
143
144 function ServerMDNSupport($read) {
145 /* escaping $ doesn't work -> \x36 */
146 $ret = preg_match('/(\x36MDNSent|\\\\\*)/i', $read);
147 return $ret;
148 }
149
150 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
151 global $username, $attachment_dir,
152 $version, $attachments, $squirrelmail_language, $default_charset,
153 $languages, $useSendmail, $domain, $sent_folder,
154 $popuser, $data_dir, $username;
155
156 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER);
157
158 $header = $message->rfc822_header;
159 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
160
161 $rfc822_header = new Rfc822Header();
162 $content_type = new ContentType('multipart/report');
163 $content_type->properties['report-type']='disposition-notification';
164
165 set_my_charset();
166 if ($default_charset) {
167 $content_type->properties['charset']=$default_charset;
168 }
169 $rfc822_header->content_type = $content_type;
170 $rfc822_header->to[] = $header->dnt;
171 $rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject);
172
173 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
174 // This merely comes from compose.php and only happens when there is no
175 // email_addr specified in user's identity (which is the startup config)
176 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
177 $popuser = $usernamedata[1];
178 $domain = $usernamedata[2];
179 unset($usernamedata);
180 } else {
181 $popuser = $username;
182 }
183
184 $reply_to = '';
185 $ident = get_identities();
186 if(!isset($identity)) $identity = 0;
187 $full_name = $ident[$identity]['full_name'];
188 $from_mail = $ident[$identity]['email_address'];
189 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
190 $reply_to = $ident[$identity]['reply_to'];
191
192 if (!$from_mail) {
193 $from_mail = "$popuser@$domain";
194 $from_addr = $from_mail;
195 }
196 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
197 if ($reply_to) {
198 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
199 }
200
201 // part 1 (RFC2298)
202 $senton = getLongDateString( $header->date );
203 $to_array = $header->to;
204 $to = '';
205 foreach ($to_array as $line) {
206 $to .= ' '.$line->getAddress();
207 }
208 $now = getLongDateString( time() );
209 set_my_charset();
210 $body = _("Your message") . "\r\n\r\n" .
211 "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" .
212 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject,false,false) . "\r\n" .
213 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
214 "\r\n" .
215 sprintf( _("Was displayed on %s"), $now );
216
217 $special_encoding = '';
218 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
219 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
220 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
221 if (strtolower($default_charset) == 'iso-2022-jp') {
222 if (mb_detect_encoding($body) == 'ASCII') {
223 $special_encoding = '8bit';
224 } else {
225 $body = mb_convert_encoding($body, 'JIS');
226 $special_encoding = '7bit';
227 }
228 }
229 }
230 $part1 = new Message();
231 $part1->setBody($body);
232 $mime_header = new MessageHeader;
233 $mime_header->type0 = 'text';
234 $mime_header->type1 = 'plain';
235 if ($special_encoding) {
236 $mime_header->encoding = $special_encoding;
237 } else {
238 $mime_header->encoding = 'us-ascii';
239 }
240 if ($default_charset) {
241 $mime_header->parameters['charset'] = $default_charset;
242 }
243 $part1->mime_header = $mime_header;
244
245 // part2 (RFC2298)
246 $original_recipient = $to;
247 $original_message_id = $header->message_id;
248
249 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
250 if ($original_recipient != '') {
251 $report .= "Original-Recipient : $original_recipient\r\n";
252 }
253 $final_recipient = $sender;
254 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
255 "Original-Message-ID : $original_message_id\r\n" .
256 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
257
258 $part2 = new Message();
259 $part2->setBody($report);
260 $mime_header = new MessageHeader;
261 $mime_header->type0 = 'message';
262 $mime_header->type1 = 'disposition-notification';
263 $mime_header->encoding = 'us-ascii';
264 $part2->mime_header = $mime_header;
265
266 $composeMessage = new Message();
267 $composeMessage->rfc822_header = $rfc822_header;
268 $composeMessage->addEntity($part1);
269 $composeMessage->addEntity($part2);
270
271
272 if ($useSendmail) {
273 require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
274 global $sendmail_path;
275 $deliver = new Deliver_SendMail();
276 $stream = $deliver->initStream($composeMessage,$sendmail_path);
277 } else {
278 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
279 $deliver = new Deliver_SMTP();
280 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
281 if ($smtp_auth_mech == 'none') {
282 $user = '';
283 $pass = '';
284 } else {
285 global $key, $onetimepad;
286 $user = $username;
287 $pass = OneTimePadDecrypt($key, $onetimepad);
288 }
289 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
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, $uid_support) {
319 $sg = $set?'+':'-';
320 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
321 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
322 $readmessage, $uid_support);
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 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
480 global $base_uri, $draft_folder, $where, $what, $color, $sort,
481 $startMessage, $PHP_SELF, $save_as_draft,
482 $enable_forward_as_attachment;
483
484 $topbar_delimiter = '&nbsp;|&nbsp;';
485 $urlMailbox = urlencode($mailbox);
486 $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
487 ' border="0" bgcolor="'.$color[9].'"><tr>' .
488 html_tag( 'td', '', 'left', '', 'width="33%"' ) . '<small>';
489
490 $msgs_url = $base_uri . 'src/';
491 if (isset($where) && isset($what)) {
492 $msgs_url .= 'search.php?where=' . urlencode($where) .
493 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
494 $msgs_str = _("Search results");
495 } else {
496 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
497 $startMessage . '&amp;mailbox=' . $urlMailbox;
498 $msgs_str = _("Message List");
499 }
500 $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>';
501
502 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
503 '&amp;message=' . $passed_id . '&amp;';
504 if (!(isset($passed_ent_id) && $passed_ent_id)) {
505 if ($where && $what) {
506 $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
507 } else {
508 $delete_url .= 'sort=' . $sort . '&amp;startMessage=' . $startMessage;
509 }
510 $s .= $topbar_delimiter;
511 $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>';
512 }
513
514 $comp_uri = 'src/compose.php' .
515 '?passed_id=' . $passed_id .
516 '&amp;mailbox=' . $urlMailbox .
517 '&amp;startMessage=' . $startMessage .
518 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
519
520 if (($mailbox == $draft_folder) && ($save_as_draft)) {
521 $comp_alt_uri = $comp_uri . '&amp;smaction=draft';
522 $comp_alt_string = _("Resume Draft");
523 } else if (handleAsSent($mailbox)) {
524 $comp_alt_uri = $comp_uri . '&amp;smaction=edit_as_new';
525 $comp_alt_string = _("Edit Message as New");
526 }
527 if (isset($comp_alt_uri)) {
528 $s .= $topbar_delimiter;
529 $s .= makeComposeLink($comp_alt_uri, $comp_alt_string);
530 }
531
532 $s .= '</small></td><td align="center" width="33%"><small>';
533
534 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
535 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
536 $next = findNextMessage($passed_id);
537 if ($prev != -1) {
538 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
539 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
540 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
541 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
542 } else {
543 $s .= _("Previous");
544 }
545 $s .= $topbar_delimiter;
546 if ($next != -1) {
547 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
548 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
549 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
550 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
551 } else {
552 $s .= _("Next");
553 }
554 } else if (isset($passed_ent_id) && $passed_ent_id) {
555 /* code for navigating through attached message/rfc822 messages */
556 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
557 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
558 $entities = array();
559 $entity_count = array();
560 $c = 0;
561
562 foreach($message->parent->entities as $ent) {
563 if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
564 $c++;
565 $entity_count[$c] = $ent->entity_id;
566 $entities[$ent->entity_id] = $c;
567 }
568 }
569 $prev_link = _("Previous");
570 $next_link = _("Next");
571 if($entities[$passed_ent_id] > 1) {
572 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
573 $prev_link = '<a href="'
574 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
575 . '">' . $prev_link . '</a>';
576 }
577 if($entities[$passed_ent_id] < $c) {
578 $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1];
579 $next_link = '<a href="'
580 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
581 . '">' . $next_link . '</a>';
582 }
583 $s .= $topbar_delimiter . $prev_link;
584 $par_ent_id = $message->parent->entity_id;
585 if ($par_ent_id) {
586 $par_ent_id = substr($par_ent_id,0,-2);
587 $s .= $topbar_delimiter;
588 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
589 $s .= '<a href="'.$url.'">'._("Up").'</a>';
590 }
591 $s .= $topbar_delimiter . $next_link;
592 }
593
594 $s .= '</small></td>' . "\n" .
595 html_tag( 'td', '', 'right', '', 'width="33%" nowrap' ) . '<small>';
596 $comp_action_uri = $comp_uri . '&amp;smaction=forward';
597 $s .= makeComposeLink($comp_action_uri, _("Forward"));
598
599 if ($enable_forward_as_attachment) {
600 $comp_action_uri = $comp_uri . '&amp;smaction=forward_as_attachment';
601 $s .= $topbar_delimiter;
602 $s .= makeComposeLink($comp_action_uri, _("Forward as Attachment"));
603 }
604
605 $comp_action_uri = $comp_uri . '&amp;smaction=reply';
606 $s .= $topbar_delimiter;
607 $s .= makeComposeLink($comp_action_uri, _("Reply"));
608
609 $comp_action_uri = $comp_uri . '&amp;smaction=reply_all';
610 $s .= $topbar_delimiter;
611 $s .= makeComposeLink($comp_action_uri, _("Reply All"));
612 $s .= '</small></td></tr></table>';
613 do_hook('read_body_menu_top');
614 echo $s;
615 do_hook('read_body_menu_bottom');
616 }
617
618 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
619 global $base_uri;
620
621 $urlMailbox = urlencode($mailbox);
622 sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER);
623 $url = $base_uri.'src/view_header.php?'.$query_string;
624
625 $s = "<TR>\n" .
626 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
627 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
628 '<a href="'.$url.'">'._("View Full Header").'</a>';
629
630 /* Output the printer friendly link if we are in subtle mode. */
631 $s .= '&nbsp;|&nbsp;' .
632 printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
633 echo $s;
634 do_hook("read_body_header_right");
635 $s = "</SMALL></TD>\n" .
636 "</TR>\n";
637 echo $s;
638
639 }
640
641 /***************************/
642 /* Main of read_body.php */
643 /***************************/
644
645 /* get the globals we may need */
646
647 sqgetGlobalVar('key', $key, SQ_COOKIE);
648 sqgetGlobalVar('username', $username, SQ_SESSION);
649 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
650 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
651 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
652
653 sqgetGlobalVar('msgs', $msgs, SQ_SESSION);
654 sqgetGlobalVar('msort', $msort, SQ_SESSION);
655 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
656 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION);
657 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) {
658 $messages = array();
659 }
660
661 /** GET VARS */
662 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET);
663 sqgetGlobalVar('where', $where, SQ_GET);
664 sqgetGlobalVar('what', $what, SQ_GET);
665 if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) {
666 $show_more = (int) $temp;
667 }
668 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) {
669 $show_more_cc = (int) $temp;
670 }
671 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) {
672 $show_more_bcc = (int) $temp;
673 }
674 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) {
675 $view_hdr = (int) $temp;
676 }
677
678 /** POST VARS */
679 sqgetGlobalVar('move_id', $move_id, SQ_POST);
680
681 /** GET/POST VARS */
682 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
683 sqgetGlobalVar('mailbox', $mailbox);
684
685 if ( sqgetGlobalVar('passed_id', $temp) ) {
686 $passed_id = (int) $temp;
687 }
688 if ( sqgetGlobalVar('sort', $temp) ) {
689 $sort = (int) $temp;
690 }
691 if ( sqgetGlobalVar('startMessage', $temp) ) {
692 $startMessage = (int) $temp;
693 }
694
695 /* end of get globals */
696 global $uid_support, $sqimap_capabilities;
697
698 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
699 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
700
701
702 /**
703 * $message contains all information about the message
704 * including header and body
705 */
706
707 $uidvalidity = $mbx_response['UIDVALIDITY'];
708
709 if (!isset($messages[$uidvalidity])) {
710 $messages[$uidvalidity] = array();
711 }
712 if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
713 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
714 $FirstTimeSee = !$message->is_seen;
715 $message->is_seen = true;
716 $messages[$uidvalidity][$passed_id] = $message;
717 } else {
718 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
719 $message = $messages[$uidvalidity][$passed_id];
720 $FirstTimeSee = !$message->is_seen;
721 }
722
723 if (isset($passed_ent_id) && $passed_ent_id) {
724 $message = $message->getEntity($passed_ent_id);
725 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
726 $message = $message->parent;
727 }
728 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
729 $rfc822_header = new Rfc822Header();
730 $rfc822_header->parseHeader($read);
731 $message->rfc822_header = $rfc822_header;
732 } else {
733 $passed_ent_id = 0;
734 }
735 $header = $message->header;
736
737 do_hook('html_top');
738
739 /****************************************/
740 /* Block for handling incoming url vars */
741 /****************************************/
742
743 if (isset($sendreceipt)) {
744 if ( !$message->is_mdnsent ) {
745 $final_recipient = '';
746 if ((isset($identity)) && ($identity != 0)) //Main identity
747 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
748 if ($final_recipient == '' )
749 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
750 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
751 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
752 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
753 $message->is_mdnsent = true;
754 $messages[$uidvalidity][$passed_id]=$message;
755 }
756 ClearAttachments();
757 }
758 }
759 /***********************************************/
760 /* End of block for handling incoming url vars */
761 /***********************************************/
762
763 $msgs[$passed_id]['FLAG_SEEN'] = true;
764
765 $messagebody = '';
766 do_hook('read_body_top');
767 if ($show_html_default == 1) {
768 $ent_ar = $message->findDisplayEntity(array());
769 } else {
770 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
771 }
772 $cnt = count($ent_ar);
773 for ($i = 0; $i < $cnt; $i++) {
774 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
775 if ($i != $cnt-1) {
776 $messagebody .= '<hr noshade size=1>';
777 }
778 }
779
780 displayPageHeader($color, $mailbox);
781 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
782 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
783 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
784 echo ' <tr><td>';
785 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
786 echo ' <tr><td>';
787 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
788 echo ' <tr bgcolor="'.$color[4].'"><td>';
789 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
790 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
791 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
792 . '</tr>';
793 echo ' </table>';
794 echo ' </td></tr>';
795 echo ' </table></td></tr>';
796 echo ' </table>';
797 echo ' </td></tr>';
798
799 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
800 $color[4].'"></TD></TR>'."\n";
801
802 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
803 if ($attachmentsdisplay) {
804 echo ' </table>';
805 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
806 echo ' <tr><td>';
807 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
808 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
809 echo ' <b>' . _("Attachments") . ':</b>';
810 echo ' </td></tr>';
811 echo ' <tr><td>';
812 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
813 echo $attachmentsdisplay;
814 echo ' </td></tr></table>';
815 echo ' </td></tr></table>';
816 echo ' </td></tr>';
817 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
818 $color[4].'"></TD></TR>';
819 }
820 echo '</table>';
821
822 /* show attached images inline -- if pref'fed so */
823 if (($attachment_common_show_images) &&
824 is_array($attachment_common_show_images_list)) {
825 foreach ($attachment_common_show_images_list as $img) {
826 $imgurl = SM_PATH . 'src/download.php' .
827 '?' .
828 'passed_id=' . urlencode($img['passed_id']) .
829 '&amp;mailbox=' . urlencode($mailbox) .
830 '&amp;ent_id=' . urlencode($img['ent_id']) .
831 '&amp;absolute_dl=true';
832
833 echo html_tag( 'table', "\n" .
834 html_tag( 'tr', "\n" .
835 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
836 )
837 ) ,
838 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
839 }
840 }
841
842 do_hook('read_body_bottom');
843 do_hook('html_bottom');
844 sqimap_logout($imapConnection);
845 /* sessions are written at the end of the script. it's better to register
846 them at the end so we avoid double session_register calls */
847 sqsession_register($messages,'messages');
848
849 ?>
850 </body>
851 </html>