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