1807cf771746126d34b86506a5dd624c3b6c9ec7
[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 */
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/imap.php');
21 require_once(SM_PATH . 'functions/mime.php');
22 require_once(SM_PATH . 'functions/date.php');
23 require_once(SM_PATH . 'functions/url_parser.php');
24 require_once(SM_PATH . 'functions/html.php');
25 require_once(SM_PATH . 'functions/set_language_align.php');
26
27
28 /* --------------------- Get globals ------------------------------------- */
29 $language_align = set_language_align();
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, $_SERVER,
152 $version, $attachments, $squirrelmail_language, $default_charset,
153 $languages, $useSendmail, $domain, $sent_folder,
154 $popuser, $data_dir, $username;
155
156 $SERVER_NAME = $_SERVER['SERVER_NAME'];
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:") . ' ' . $header->subject;
172
173
174 $reply_to = '';
175 if (isset($identity) && $identity != 'default') {
176 $from_mail = getPref($data_dir, $username,
177 'email_address' . $identity);
178 $full_name = getPref($data_dir, $username,
179 'full_name' . $identity);
180 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
181 $reply_to = getPref($data_dir, $username,
182 'reply_to' . $identity);
183 } else {
184 $from_mail = getPref($data_dir, $username, 'email_address');
185 $full_name = getPref($data_dir, $username, 'full_name');
186 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
187 $reply_to = getPref($data_dir, $username,'reply_to');
188 }
189 if (!$from_addr) {
190 $from_addr = "$popuser@$domain";
191 $from_mail = $from_addr;
192 }
193 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
194 if ($reply_to) {
195 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
196 }
197
198 // part 1 (RFC2298)
199 $senton = getLongDateString( $header->date );
200 $to_array = $header->to;
201 $to = '';
202 foreach ($to_array as $line) {
203 $to .= ' '.$line->getAddress();
204 }
205 $now = getLongDateString( time() );
206 set_my_charset();
207 $body = _("Your message") . "\r\n\r\n" .
208 "\t" . _("To:") . ' ' . $to . "\r\n" .
209 "\t" . _("Subject:") . ' ' . $header->subject . "\r\n" .
210 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
211 "\r\n" .
212 sprintf( _("Was displayed on %s"), $now );
213
214 $special_encoding = '';
215 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
216 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
217 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
218 if (strtolower($default_charset) == 'iso-2022-jp') {
219 if (mb_detect_encoding($body) == 'ASCII') {
220 $special_encoding = '8bit';
221 } else {
222 $body = mb_convert_encoding($body, 'JIS');
223 $special_encoding = '7bit';
224 }
225 }
226 }
227 $part1 = new Message();
228 $part1->setBody($body);
229 $mime_header = new MessageHeader;
230 $mime_header->type0 = 'text';
231 $mime_header->type1 = 'plain';
232 if ($special_encoding) {
233 $mime_header->encoding = $special_encoding;
234 } else {
235 $mime_header->encoding = 'us-ascii';
236 }
237 if ($default_charset) {
238 $mime_header->parameters['charset'] = $default_charset;
239 }
240 $part1->mime_header = $mime_header;
241
242 // part2 (RFC2298)
243 $original_recipient = $to;
244 $original_message_id = $header->message_id;
245
246 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
247 if ($original_recipient != '') {
248 $report .= "Original-Recipient : $original_recipient\r\n";
249 }
250 $final_recipient = $sender;
251 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
252 "Original-Message-ID : $original_message_id\r\n" .
253 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
254
255 $part2 = new Message();
256 $part2->setBody($report);
257 $mime_header = new MessageHeader;
258 $mime_header->type0 = 'message';
259 $mime_header->type1 = 'disposition-notification';
260 $mime_header->encoding = 'us-ascii';
261 $part2->mime_header = $mime_header;
262
263 $composeMessage = new Message();
264 $composeMessage->rfc822_header = $rfc822_header;
265 $composeMessage->addEntity($part1);
266 $composeMessage->addEntity($part2);
267
268
269 if ($useSendmail) {
270 require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
271 global $sendmail_path;
272 $deliver = new Deliver_SendMail();
273 $stream = $deliver->initStream($composeMessage,$sendmail_path);
274 } else {
275 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
276 $deliver = new Deliver_SMTP();
277 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
278 if ($smtp_auth_mech == 'none') {
279 $user = '';
280 $pass = '';
281 } else {
282 global $key, $onetimepad;
283 $user = $username;
284 $pass = OneTimePadDecrypt($key, $onetimepad);
285 }
286 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
287 $stream = $deliver->initStream($composeMessage,$domain,0,
288 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
289 }
290 $success = false;
291 if ($stream) {
292 $length = $deliver->mail($composeMessage, $stream);
293 $success = $deliver->finalizeStream($stream);
294 }
295 if (!$success) {
296 $msg = $deliver->dlv_msg . '<br>' .
297 _("Server replied: ") . $deliver->dlv_ret_nr . ' '.
298 $deliver->dlv_server_msg;
299 require_once(SM_PATH . 'functions/display_messages.php');
300 plain_error_message($msg, $color);
301 } else {
302 unset ($deliver);
303 if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) {
304 sqimap_append ($imapConnection, $sent_folder, $length);
305 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
306 $imap_deliver = new Deliver_IMAP();
307 $imap_deliver->mail($composeMessage, $imapConnection);
308 sqimap_append_done ($imapConnection);
309 unset ($imap_deliver);
310 }
311 }
312 return $success;
313 }
314
315 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
316 $sg = $set?'+':'-';
317 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
318 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
319 $readmessage, $uid_support);
320 }
321
322 function ClearAttachments() {
323 global $username, $attachments, $attachment_dir;
324
325 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
326
327 $rem_attachments = array();
328 foreach ($attachments as $info) {
329 if ($info['session'] == -1) {
330 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
331 if (file_exists($attached_file)) {
332 unlink($attached_file);
333 }
334 } else {
335 $rem_attachments[] = $info;
336 }
337 }
338 $attachments = $rem_attachments;
339 }
340
341 function formatRecipientString($recipients, $item ) {
342 global $show_more_cc, $show_more, $show_more_bcc,
343 $PHP_SELF;
344
345 $string = '';
346 if ((is_array($recipients)) && (isset($recipients[0]))) {
347 $show = false;
348
349 if ($item == 'to') {
350 if ($show_more) {
351 $show = true;
352 $url = set_url_var($PHP_SELF, 'show_more',0);
353 } else {
354 $url = set_url_var($PHP_SELF, 'show_more',1);
355 }
356 } else if ($item == 'cc') {
357 if ($show_more_cc) {
358 $show = true;
359 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
360 } else {
361 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
362 }
363 } else if ($item == 'bcc') {
364 if ($show_more_bcc) {
365 $show = true;
366 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
367 } else {
368 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
369 }
370 }
371
372 $cnt = count($recipients);
373 foreach($recipients as $r) {
374 $add = htmlspecialchars($r->getAddress());
375 if ($string) {
376 $string .= '<BR>' . $add;
377 } else {
378 $string = $add;
379 if ($cnt > 1) {
380 $string .= '&nbsp;(<A HREF="'.$url;
381 if ($show) {
382 $string .= '">'._("less").'</A>)';
383 } else {
384 $string .= '">'._("more").'</A>)';
385 break;
386 }
387 }
388 }
389 }
390 }
391 return $string;
392 }
393
394 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
395 $color, $FirstTimeSee) {
396 global $msn_user_support, $default_use_mdn, $default_use_priority, $language_align,
397 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
398 $squirrelmail_language;
399
400 $header = $message->rfc822_header;
401 $env = array();
402 if ($squirrelmail_language == 'ja_JP') {
403 $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject));
404 } else {
405 $env[_("Subject")] = decodeHeader(htmlspecialchars($header->subject));
406 }
407 $from_name = $header->getAddr_s('from');
408 if (!$from_name) {
409 $from_name = $header->getAddr_s('sender');
410 if (!$from_name) {
411 $from_name = _("Unknown sender");
412 }
413 }
414 $env[_("From")] = htmlspecialchars(decodeHeader($from_name));
415 $env[_("Date")] = getLongDateString($header->date);
416 $env[_("To")] = formatRecipientString($header->to, "to");
417 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
418 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
419 if ($default_use_priority) {
420 $env[_("Priority")] = getPriorityStr($header->priority);
421 }
422 if ($show_xmailer_default) {
423 $env[_("Mailer")] = decodeHeader($header->xmailer);
424 }
425 if ($default_use_mdn) {
426 if ($mdn_user_support) {
427 if ($header->dnt) {
428 if ($message->is_mdnsent) {
429 $env[_("Read receipt")] = _("send");
430 } else {
431 $env[_("Read receipt")] = _("requested");
432 if (!(handleAsSent($mailbox) ||
433 $message->is_deleted ||
434 $passed_ent_id)) {
435 $mdn_url = $PHP_SELF . '&sendreceipt=1';
436 if ($FirstTimeSee && $javascript_on) {
437 $script = '<script language="JavaScript" type="text/javascript">' . "\n";
438 $script .= '<!--'. "\n";
439 $script .= 'if(window.confirm("' .
440 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
441 '")) { '."\n" .
442 ' sendMDN()'.
443 '}' . "\n";
444 $script .= '// -->'. "\n";
445 $script .= '</script>'. "\n";
446 echo $script;
447 }
448 $env[_("Read receipt")] .= '&nbsp;<a href="' . $mdn_url . '">[' .
449 _("Send read receipt now") . ']</a>';
450 }
451 }
452 }
453 }
454 }
455
456 $s = '<TABLE dir="' . $language_align['dir'] . '" WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"';
457 $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">';
458 foreach ($env as $key => $val) {
459 if ($val) {
460 $s .= '<TR>';
461 $s .= html_tag('TD', '<B>' . $key . ':&nbsp;&nbsp;</B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
462 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
463 $s .= '</TR>';
464 }
465 }
466 echo '<TABLE dir="' . $language_align['dir'] . '" BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
467 ' CELLSPACING="0" BORDER="0" ALIIGN="center">'."\n";
468 echo '<TR dir="' . $language_align['dir'] . '"><TD dir="' . $language_align['dir'] . '" HEIGHT="5" COLSPAN="2" BGCOLOR="'.
469 $color[4].'"></TD></TR><TR><TD dir="' . $language_align['dir'] . '" align=center>'."\n";
470 echo $s;
471 do_hook('read_body_header');
472 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
473 echo '</TABLE>';
474 echo '</TD></TR><TR dir="' . $language_align['dir'] . '"><TD dir="' . $language_align['dir'] . '" HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
475 echo '</TABLE>';
476 }
477
478 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
479 global $base_uri, $draft_folder, $where, $what, $color, $sort, $language_align,
480 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft,
481 $enable_forward_as_attachment;
482
483 $topbar_delimiter = '&nbsp;|&nbsp;';
484 $urlMailbox = urlencode($mailbox);
485 $s = '<table dir=' . $language_align['dir'] . ' width="100%" cellpadding="3" cellspacing="0" align="center"'.
486 ' border="0" bgcolor="'.$color[9].'"><tr><td align="' . $language_align['left'] . '" width="33%"><small>';
487
488 $msgs_url = $base_uri . 'src/';
489 if (isset($where) && isset($what)) {
490 $msgs_url .= 'search.php?where=' . urlencode($where) .
491 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
492 $msgs_str = _("Search results");
493 } else {
494 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
495 $startMessage . '&amp;mailbox=' . $urlMailbox;
496 $msgs_str = _("Message List");
497 }
498 $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>';
499
500 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox .
501 '&amp;message=' . $passed_id . '&amp;';
502 if (!(isset($passed_ent_id) && $passed_ent_id)) {
503 if ($where && $what) {
504 $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
505 } else {
506 $delete_url .= 'sort=' . $sort . '&amp;startMessage=' . $startMessage;
507 }
508 $s .= $topbar_delimiter;
509 $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>';
510 }
511
512 $comp_uri = $base_uri . 'src/compose.php' .
513 '?passed_id=' . $passed_id .
514 '&amp;mailbox=' . $urlMailbox .
515 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
516
517 if ($compose_new_win == '1') {
518 $link_open = '<a href="javascript:void(0)" onclick="comp_in_new(\'';
519 $link_close = '\')">';
520 } else {
521 $link_open = '<a href="';
522 $link_close = '">';
523 }
524 if (($mailbox == $draft_folder) && ($save_as_draft)) {
525 $comp_alt_uri = $comp_uri . '&amp;action=draft';
526 $comp_alt_string = _("Resume Draft");
527 } else if (handleAsSent($mailbox)) {
528 $comp_alt_uri = $comp_uri . '&amp;action=edit_as_new';
529 $comp_alt_string = _("Edit Message as New");
530 }
531 if (isset($comp_alt_uri)) {
532 $s .= $topbar_delimiter;
533 $s .= $link_open . $comp_alt_uri . $link_close . $comp_alt_string . '</a>';
534 }
535
536 $s .= '</small></td><td align="center" width="33%"><small>';
537
538 if (!(isset($where) && isset($what)) && !$passed_ent_id) {
539 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
540 $next = findNextMessage($passed_id);
541 if ($prev != -1) {
542 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
543 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
544 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
545 $s .= '<a href="'.$uri.'">'._("Previous").'</a>';
546 } else {
547 $s .= _("Previous");
548 }
549 $s .= $topbar_delimiter;
550 if ($next != -1) {
551 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
552 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
553 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
554 $s .= '<a href="'.$uri.'">'._("Next").'</a>';
555 } else {
556 $s .= _("Next");
557 }
558 } else if (isset($passed_ent_id) && $passed_ent_id) {
559 /* code for navigating through attached message/rfc822 messages */
560 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
561 $s .= '<a href="'.$url.'">'._("View Message").'</a>';
562 $entities = array();
563 $entity_count = array();
564 $c = 0;
565
566 foreach($message->parent->entities as $ent) {
567 if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
568 $c++;
569 $entity_count[$c] = $ent->entity_id;
570 $entities[$ent->entity_id] = $c;
571 }
572 }
573 $prev_link = _("Previous");
574 $next_link = _("Next");
575 if($entities[$passed_ent_id] > 1) {
576 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
577 $prev_link = '<a href="'
578 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
579 . '">' . $prev_link . '</a>';
580 }
581 if($entities[$passed_ent_id] < $c) {
582 $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1];
583 $next_link = '<a href="'
584 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
585 . '">' . $next_link . '</a>';
586 }
587 $s .= $topbar_delimiter . $prev_link;
588 $par_ent_id = $message->parent->entity_id;
589 if ($par_ent_id) {
590 $par_ent_id = substr($par_ent_id,0,-2);
591 $s .= $topbar_delimiter;
592 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
593 $s .= '<a href="'.$url.'">'._("Up").'</a>';
594 }
595 $s .= $topbar_delimiter . $next_link;
596 }
597
598 $s .= '</small></td>' . "\n" . '<td align="right" width="33%" nowrap><small>';
599 $comp_action_uri = $comp_uri . '&amp;action=forward';
600 $s .= $link_open . $comp_action_uri . $link_close . _("Forward") . '</a>';
601
602 if ($enable_forward_as_attachment) {
603 $comp_action_uri = $comp_uri . '&amp;action=forward_as_attachment';
604 $s .= $topbar_delimiter;
605 $s .= $link_open . $comp_action_uri . $link_close . _("Forward as Attachment") . '</a>';
606 }
607
608 $comp_action_uri = decodeHeader($comp_uri . '&amp;action=reply');
609 $s .= $topbar_delimiter;
610 $s .= $link_open . $comp_action_uri . $link_close . _("Reply") . '</a>';
611
612 $comp_action_uri = $comp_uri . '&amp;action=reply_all';
613 $s .= $topbar_delimiter;
614 $s .= $link_open . $comp_action_uri . $link_close . _("Reply All") . '</a>';
615 $s .= '</small></td></tr></table>';
616 do_hook("read_body_menu_top");
617 echo $s;
618 do_hook("read_body_menu_bottom");
619 }
620
621 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
622 global $base_uri, $language_align;
623
624 $urlMailbox = urlencode($mailbox);
625 $url = $base_uri.'src/view_header.php?'.$_SERVER['QUERY_STRING'];
626
627 $s = "<TR dir=" . $language_align['dir'] . ">\n" .
628 '<TD dir=' . $language_align['dir'] . ' VALIGN="MIDDLE" ALIGN=' . $language_align['right'] . ' WIDTH="20%"><B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
629 '<TD dir=' . $language_align['dir'] . ' VALIGN="MIDDLE" ALIGN=' . $language_align['left'] . ' WIDTH="80%"><SMALL>' .
630 '<a href="'.$url.'">'._("View Full Header").'</a>';
631
632 /* Output the printer friendly link if we are in subtle mode. */
633 $s .= '&nbsp;|&nbsp;' .
634 printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
635 echo $s;
636 do_hook("read_body_header_right");
637 $s = "</SMALL></TD>\n" .
638 "</TR>\n";
639 echo $s;
640
641 }
642
643 /***************************/
644 /* Main of read_body.php */
645 /***************************/
646
647 /* get the globals we may need */
648
649 $username = $_SESSION['username'];
650 $key = $_COOKIE['key'];
651 $onetimepad = $_SESSION['onetimepad'];
652 $msgs = $_SESSION['msgs'];
653 $base_uri = $_SESSION['base_uri'];
654 $delimiter = $_SESSION['delimiter'];
655
656 if (isset($_GET['passed_id'])) {
657 $passed_id = (int) $_GET['passed_id'];
658 }
659 elseif (isset($_POST['passed_id'])) {
660 $passed_id = (int) $_POST['passed_id'];
661 }
662
663 if (isset($_GET['passed_ent_id'])) {
664 $passed_ent_id = $_GET['passed_ent_id'];
665 }
666 elseif (isset($_POST['passed_ent_id'])) {
667 $passed_ent_id = $_POST['passed_ent_id'];
668 }
669
670 if (isset($_GET['sendreceipt'])) {
671 $sendreceipt = $_GET['sendreceipt'];
672 }
673
674 if (isset($_GET['sort'])) {
675 $sort = (int) $_GET['sort'];
676 }
677 elseif (isset($_POST['sort'])) {
678 $sort = (int) $_POST['sort'];
679 }
680 if (isset($_GET['startMessage'])) {
681 $startMessage = (int) $_GET['startMessage'];
682 }
683 elseif (isset($_POST['startMessage'])) {
684 $startMessage = (int) $_POST['startMessage'];
685 }
686 if (isset($_GET['show_more'])) {
687 $show_more = (int) $_GET['show_more'];
688 }
689 if (isset($_GET['show_more_cc'])) {
690 $show_more_cc = (int) $_GET['show_more_cc'];
691 }
692 if (isset($_GET['show_more_bcc'])) {
693 $show_more_bcc = (int) $_GET['show_more_bcc'];
694 }
695 if (isset($_GET['mailbox'])) {
696 $mailbox = $_GET['mailbox'];
697 }
698 elseif (isset($_POST['mailbox'])) {
699 $mailbox = $_POST['mailbox'];
700 }
701 if (isset($_GET['where'])) {
702 $where = $_GET['where'];
703 }
704 if (isset($_GET['what'])) {
705 $what = $_GET['what'];
706 }
707 if (isset($_GET['view_hdr'])) {
708 $view_hdr = (int) $_GET['view_hdr'];
709 }
710 if (isset($_SESSION['server_sort_array'])) {
711 $server_sort_array = $_SESSION['server_sort_array'];
712 }
713 if (isset($_SESSION['msgs'])) {
714 $msgs = $_SESSION['msgs'];
715 }
716 if (isset($_SESSION['msort'])) {
717 $msort = $_SESSION['msort'];
718 }
719 if (isset($_POST['move_id'])) {
720 $move_id = $_POST['move_id'];
721 }
722 if (isset($_SESSION['lastTargetMailbox'])) {
723 $lastTargetMailbox = $_SESSION['lastTargetMailbox'];
724 }
725 if (isset($_SESSION['messages'])) {
726 $messages = $_SESSION['messages'];
727 } else {
728 $messages = array();
729 }
730
731
732
733 /* end of get globals */
734 global $uid_support, $sqimap_capabilities;
735
736 if (isset($mailbox)) {
737 $mailbox = urldecode( $mailbox );
738 }
739
740 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
741 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
742
743
744 /**
745 * $message contains all information about the message
746 * including header and body
747 */
748
749 $uidvalidity = $mbx_response['UIDVALIDITY'];
750
751 if (!isset($messages[$uidvalidity])) {
752 $messages[$uidvalidity] = array();
753 }
754 if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
755 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
756 $FirstTimeSee = !$message->is_seen;
757 $message->is_seen = true;
758 $messages[$uidvalidity][$passed_id] = $message;
759 } else {
760 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
761 $message = $messages[$uidvalidity][$passed_id];
762 $FirstTimeSee = !$message->is_seen;
763 }
764
765 if (isset($passed_ent_id) && $passed_ent_id) {
766 $message = $message->getEntity($passed_ent_id);
767 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
768 $message = $message->parent;
769 }
770 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
771 $rfc822_header = new Rfc822Header();
772 $rfc822_header->parseHeader($read);
773 $message->rfc822_header = $rfc822_header;
774 } else {
775 $passed_ent_id = 0;
776 }
777 $header = $message->header;
778
779 do_hook('html_top');
780
781 /****************************************/
782 /* Block for handling incoming url vars */
783 /****************************************/
784
785 if (isset($sendreceipt)) {
786 if ( !$message->is_mdnsent ) {
787 if (isset($identity) ) {
788 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
789 } else {
790 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
791 }
792
793 $final_recipient = trim($final_recipient);
794 if ($final_recipient == '' ) {
795 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
796 }
797 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
798 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
799 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
800 $message->is_mdnsent = true;
801 $messages[$uidvalidity][$passed_id]=$message;
802 }
803 ClearAttachments();
804 }
805 }
806 /***********************************************/
807 /* End of block for handling incoming url vars */
808 /***********************************************/
809
810 $msgs[$passed_id]['FLAG_SEEN'] = true;
811
812 $messagebody = '';
813 do_hook('read_body_top');
814 if ($show_html_default == 1) {
815 $ent_ar = $message->findDisplayEntity(array());
816 } else {
817 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
818 }
819 $cnt = count($ent_ar);
820 for ($i = 0; $i < $cnt; $i++) {
821 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
822 if ($i != $cnt-1) {
823 $messagebody .= '<hr noshade size=1>';
824 }
825 }
826
827 displayPageHeader($color, $mailbox);
828 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
829 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
830 echo '<table dir="' . $language_align['dir'] . '" width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
831 echo ' <tr><td>';
832 echo ' <table dir="' . $language_align['dir'] . '" width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
833 echo ' <tr><td>';
834 echo ' <table dir="' . $language_align['dir'] . '" width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
835 echo ' <tr bgcolor="'.$color[4].'"><td>';
836 echo ' <table dir="' . $language_align['dir'] . '" cellpadding="1" cellspacing="5" align="' . $language_align['left'] . '" border="0">';
837 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
838 . '</tr>';
839 echo ' </table>';
840 echo ' </td></tr>';
841 echo ' </table></td></tr>';
842 echo ' </table>';
843 echo ' </td></tr>';
844
845 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
846 $color[4].'"></TD></TR>'."\n";
847
848 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
849 if ($attachmentsdisplay) {
850 echo ' <tr><td>';
851 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
852 echo ' <tr><td>';
853 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
854 echo ' <tr><td align="' . $language_align['left'] . '" bgcolor="'.$color[9].'">';
855 echo ' <b>' . _("Attachments") . ':</b>';
856 echo ' </td></tr>';
857 echo ' <tr><td>';
858 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
859 echo $attachmentsdisplay;
860 echo ' </td></tr></table>';
861 echo ' </td></tr></table>';
862 echo ' </td></tr></table>';
863 echo ' </td></tr>';
864 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
865 $color[4].'"></TD></TR>';
866 }
867 echo '</table>';
868
869 /* show attached images inline -- if pref'fed so */
870 if (($attachment_common_show_images) &&
871 is_array($attachment_common_show_images_list)) {
872 foreach ($attachment_common_show_images_list as $img) {
873 $imgurl = SM_PATH . 'src/download.php' .
874 '?' .
875 'passed_id=' . urlencode($img['passed_id']) .
876 '&amp;mailbox=' . urlencode($mailbox) .
877 '&amp;ent_id=' . urlencode($img['ent_id']) .
878 '&amp;absolute_dl=true';
879
880 echo html_tag( 'table', "\n" .
881 html_tag( 'tr', "\n" .
882 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
883 )
884 ) ,
885 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
886 }
887 }
888
889 do_hook('read_body_bottom');
890 do_hook('html_bottom');
891 sqimap_logout($imapConnection);
892 /* sessions are written at the end of the script. it's better to register
893 them at the end so we avoid double session_register calls */
894 sqsession_register($messages,'messages');
895
896 ?>
897 </body>
898 </html>