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