s/Deliver_SentMail/Deliver_SendMail/
[squirrelmail.git] / src / read_body.php
1 <?php
2
3 /**
4 * read_body.php
5 *
6 * Copyright (c) 1999-2002 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 require_once('../src/validate.php');
16 require_once('../functions/imap.php');
17 require_once('../functions/mime.php');
18 require_once('../functions/date.php');
19 require_once('../functions/url_parser.php');
20 require_once('../functions/html.php');
21
22 /**
23 * Given an IMAP message id number, this will look it up in the cached
24 * and sorted msgs array and return the index. Used for finding the next
25 * and previous messages.
26 *
27 * @return the index of the next valid message from the array
28 */
29 function findNextMessage($passed_id) {
30 global $msort, $msgs, $sort,
31 $thread_sort_messages, $allow_server_sort,
32 $server_sort_array;
33 if (!is_array($server_sort_array)) {
34 $thread_sort_messages = 0;
35 $allow_server_sort = FALSE;
36 }
37 $result = -1;
38 if ($thread_sort_messages || $allow_server_sort) {
39 reset($server_sort_array);
40 while(list($key, $value) = each ($server_sort_array)) {
41 if ($passed_id == $value) {
42 if ($key == (count($server_sort_array) - 1)) {
43 $result = -1;
44 break;
45 }
46 $result = $server_sort_array[$key + 1];
47 break;
48 }
49 }
50 } else if ($sort == 6 && !$allow_server_sort &&
51 !$thread_sort_messages ) {
52 if ($passed_id != 1) {
53 $result = $passed_id - 1;
54 }
55 } else if (!$allow_server_sort && !$thread_sort_messages ) {
56 if (!is_array($msort)) {
57 return -1;
58 }
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 return ($result);
71 }
72
73 /** returns the index of the previous message from the array. */
74 function findPreviousMessage($numMessages, $passed_id) {
75 global $msort, $sort, $msgs,
76 $thread_sort_messages,
77 $allow_server_sort, $server_sort_array;
78 $result = -1;
79 if (!is_array($server_sort_array)) {
80 $thread_sort_messages = 0;
81 $allow_server_sort = FALSE;
82 }
83 if ($thread_sort_messages || $allow_server_sort ) {
84 reset($server_sort_array);
85 while(list($key, $value) = each ($server_sort_array)) {
86 if ($passed_id == $value) {
87 if ($key == 0) {
88 $result = -1;
89 break;
90 }
91 $result = $server_sort_array[$key -1];
92 break;
93 }
94 }
95 } else if ($sort == 6 && !$allow_server_sort &&
96 !$thread_sort_messages) {
97 if ($passed_id != $numMessages) {
98 $result = $passed_id + 1;
99 }
100 } else if (!$thread_sort_messages && !$allow_server_sort) {
101 if (!is_array($msort)) {
102 return -1;
103 }
104 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
105 if ($passed_id == $msgs[$key]['ID']) {
106 prev($msort);
107 $key = key($msort);
108 if (isset($key)) {
109 //echo $msort[$key]; /* Why again were we echoing here? */
110 $result = $msgs[$key]['ID'];
111 break;
112 }
113 }
114 }
115 }
116 return ($result);
117 }
118
119 /**
120 * Displays a link to a page where the message is displayed more
121 * "printer friendly".
122 */
123 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) {
124 global $javascript_on;
125
126 $params = '?passed_ent_id=' . $passed_ent_id .
127 '&mailbox=' . urlencode($mailbox) .
128 '&passed_id=' . $passed_id;
129
130 $print_text = _("View Printable Version");
131
132 $result = '';
133 /* Output the link. */
134 if ($javascript_on) {
135 $result .= '<script language="javascript" type="text/javascript">' . "\n" .
136 '<!--' . "\n" .
137 " function printFormat() {\n" .
138 ' window.open("../src/printer_friendly_main.php' .
139 $params . '","Print","width=800,height=600");' . "\n".
140 " }\n" .
141 "// -->\n" .
142 "</script>\n" .
143 "<a href=\"javascript:printFormat();\">$print_text</a>\n";
144 } else {
145 $result .= '<A target="_blank" HREF="../src/printer_friendly_bottom.php' .
146 "$params\">$print_text</a>\n";
147 }
148 return ($result);
149 }
150
151 function ServerMDNSupport( $read ) {
152 /* escaping $ doesn't work -> \x36 */
153 $ret = preg_match( '/(\x36MDNSent|\\\*)/i', $read );
154 return ( $ret );
155 }
156
157 function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) {
158 global $username, $attachment_dir, $SERVER_NAME,
159 $version, $attachments, $squirrelmail_language, $default_charset,
160 $languages, $useSendmail, $domain, $sent_folder,
161 $popuser, $data_dir, $username;
162
163 $header = $message->rfc822_header;
164 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
165
166 $rfc822_header = new Rfc822Header();
167 $content_type = new ContentType('multipart/report');
168 $content_type->properties['report-type']='disposition-notification';
169
170 set_my_charset();
171 if ($default_charset) {
172 $content_type->properties['charset']=$default_charset;
173 }
174 $rfc822_header->content_type = $content_type;
175 $rfc822_header->to[] = $header->dnt;
176 $rfc822_header->subject = _("Read:") . ' ' . $header->subject;
177
178
179 $reply_to = '';
180 if (isset($identity) && $identity != 'default') {
181 $from_mail = getPref($data_dir, $username,
182 'email_address' . $identity);
183 $full_name = getPref($data_dir, $username,
184 'full_name' . $identity);
185 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
186 $reply_to = getPref($data_dir, $username,
187 'reply_to' . $identity);
188 } else {
189 $from_mail = getPref($data_dir, $username, 'email_address');
190 $full_name = getPref($data_dir, $username, 'full_name');
191 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
192 $reply_to = getPref($data_dir, $username,'reply_to');
193 }
194 if (!$from_addr) {
195 $from_addr = "$popuser@$domain";
196 $from_mail = $from_addr;
197 }
198 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
199 if ($reply_to) {
200 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
201 }
202
203 // part 1 (RFC2298)
204 $senton = getLongDateString( $header->date );
205 $to_array = $header->to;
206 $to = '';
207 foreach ($to_array as $line) {
208 $to .= ' '.$line->getAddress();
209 }
210 $now = getLongDateString( time() );
211 set_my_charset();
212 $body = _("Your message") . "\r\n\r\n" .
213 "\t" . _("To:") . ' ' . $to . "\r\n" .
214 "\t" . _("Subject:") . ' ' . $header->subject . "\r\n" .
215 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
216 "\r\n" .
217 sprintf( _("Was displayed on %s"), $now );
218
219 $special_encoding = '';
220 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
221 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
222 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
223 if (strtolower($default_charset) == 'iso-2022-jp') {
224 if (mb_detect_encoding($body) == 'ASCII') {
225 $special_encoding = '8bit';
226 } else {
227 $body = mb_convert_encoding($body, 'JIS');
228 $special_encoding = '7bit';
229 }
230 }
231 }
232 $part1 = new Message();
233 $part1->setBody($body);
234 $mime_header = new MessageHeader;
235 $mime_header->type0 = 'text';
236 $mime_header->type1 = 'plain';
237 if ($special_encoding) {
238 $mime_header->encoding = $special_encoding;
239 } else {
240 $mime_header->encoding = 'us-ascii';
241 }
242 if ($default_charset) {
243 $mime_header->parameters['charset'] = $default_charset;
244 }
245 $part1->mime_header = $mime_header;
246
247 // part2 (RFC2298)
248 $original_recipient = $to;
249 $original_message_id = $header->message_id;
250
251 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
252 if ($original_recipient != '') {
253 $report .= "Original-Recipient : $original_recipient\r\n";
254 }
255 $final_recipient = $sender;
256 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
257 "Original-Message-ID : $original_message_id\r\n" .
258 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
259
260 $part2 = new Message();
261 $part2->setBody($report);
262 $mime_header = new MessageHeader;
263 $mime_header->type0 = 'message';
264 $mime_header->type1 = 'disposition-notification';
265 $mime_header->encoding = 'us-ascii';
266 $part2->mime_header = $mime_header;
267
268 $composeMessage = new Message();
269 $composeMessage->rfc822_header = $rfc822_header;
270 $composeMessage->addEntity($part1);
271 $composeMessage->addEntity($part2);
272
273
274 if (!$useSendmail) {
275 require_once('../class/deliver/Deliver_SMTP.class.php');
276 $deliver = new Deliver_SMTP();
277 global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
278 if ($use_authenticated_smtp) {
279 global $key, $onetimepad;
280 $user = $username;
281 $pass = OneTimePadDecrypt($key, $onetimepad);
282 } else {
283 $user = '';
284 $pass = '';
285 }
286 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
287 $stream = $deliver->initStream($composeMessage,$domain,0,
288 $smtpServerAddress, $smtpPort, $authPop);
289 } else {
290 require_once('../class/deliver/Deliver_SendMail.class.php');
291 global $sendmail_path;
292 $deliver = new Deliver_SendMail();
293 $stream = $deliver->initStream($composeMessage,$sendmail_path);
294 }
295 $succes = false;
296 if ($stream) {
297 $length = $deliver->mail($composeMessage, $stream);
298 $succes = $deliver->finalizeStream($stream);
299 }
300 if (!$succes) {
301 $msg = $deliver->dlv_msg . '<br>Server replied: '.$deliver->dlv_ret_nr;
302 require_once('../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('../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 $succes;
316 }
317
318
319 function ToggleMDNflag ( $set ,$imapConnection, $mailbox, $passed_id, $uid_support) {
320 $sg = $set?'+':'-';
321 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
322 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
323 $readmessage, $uid_support);
324 }
325
326 function ClearAttachments() {
327 global $username, $attachments, $attachment_dir;
328
329 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
330
331 $rem_attachments = array();
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 $attachments = $rem_attachments;
343 }
344
345 function formatRecipientString($recipients, $item ) {
346 global $show_more_cc, $show_more, $show_more_bcc,
347 $PHP_SELF;
348
349 if ((is_array($recipients)) && (isset($recipients[0]))) {
350 $string = '';
351 $ary = $recipients;
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 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
364 $show = true;
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 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
371 $show = true;
372 } else {
373 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
374 }
375 }
376
377 $cnt = count($ary);
378 $i = 0;
379 while ($i < $cnt) {
380 $ary[$i] = htmlspecialchars($ary[$i]->getAddress());
381 if ($string) {
382 $string .= '<BR>'.$ary[$i];
383 } else {
384 $string = $ary[$i];
385 if ($cnt>1) {
386 $string .= '&nbsp;(<A HREF="'.$url;
387 if ($show) {
388 $string .= '">'._("less").'</A>)';
389 } else {
390 $string .= '">'._("more").'</A>)';
391 break;
392 }
393 }
394 }
395 $i++;
396 }
397 }
398 else {
399 $string = '';
400 }
401 return $string;
402 }
403
404 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
405 $color, $FirstTimeSee) {
406 global $msn_user_support, $default_use_mdn, $draft_folder, $sent_folder,
407 $default_use_priority, $show_xmailer_default,
408 $mdn_user_support, $PHP_SELF, $javascript_on;
409
410 $header = $message->rfc822_header;
411 $env = array();
412 $env[_("Subject")] = htmlspecialchars(decodeHeader($header->subject));
413 $from_name = $header->getAddr_s('from');
414 if (!$from_name) {
415 $from_name = $header->getAddr_s('sender');
416 if (!$from_name) {
417 $from_name = _("Unknown sender");
418 }
419 }
420 $env[_("From")] = htmlspecialchars(decodeHeader($from_name));
421 $env[_("Date")] = getLongDateString($header->date);
422 $env[_("To")] = formatRecipientString($header->to, "to");
423 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
424 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
425 if ($default_use_priority) {
426 $env[_("Priority")] = getPriorityStr($header->priority);
427 }
428 if ($show_xmailer_default) {
429 $env[_("Mailer")] = decodeHeader($header->xmailer);
430 }
431 if ($default_use_mdn) {
432 if ($mdn_user_support) {
433 if ($header->dnt) {
434 if ($message->is_mdnsent) {
435 $env[_("Read receipt")] = _("send");
436 } else {
437 if ( !($mailbox == $draft_folder ||
438 $mailbox == $sent_folder ||
439 $message->is_deleted ||
440 $passed_ent_id)) {
441 $mdn_url = $PHP_SELF . '&sendreceipt=1';
442 if ($FirstTimeSee && $javascript_on) {
443 $script = '<script language="JavaScript" type="text/javascript">' ."\n";
444 $script .= '<!--'. "\n";
445 $script .= 'if(window.confirm("' .
446 _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") .
447 '")) { '."\n" .
448 ' sendMDN()'.
449 '}' . "\n";
450 $script .= '// -->'. "\n";
451 $script .= '</script>'. "\n";
452 echo $script;
453 }
454 $env[_("Read receipt")] = _("requested") .
455 '&nbsp;<a href="'.$mdn_url.'">['. _("Send read receipt now") .']</a>';
456 } else {
457 $env[_("Read receipt")] = _("requested");
458 }
459 }
460 }
461 }
462 }
463
464 $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="0" BORDER="0"';
465 $s .= ' ALIGN="center" BGCOLOR="' . $color[0] . '">';
466 foreach ($env as $key => $val) {
467 if ($val) {
468 $s .= '<TR>';
469 $s .= html_tag('TD', '<B>' . $key . ':&nbsp;&nbsp;</B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n";
470 $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n";
471 $s .= '</TR>';
472 }
473 }
474 echo $s;
475 do_hook("read_body_header");
476 formatToolbar($mailbox,$passed_id,$passed_ent_id,$message, $color);
477 echo '</table>';
478 }
479
480 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) {
481 global $base_uri, $sent_folder, $draft_folder, $where, $what, $color, $sort,
482 $startMessage, $compose_new_win, $PHP_SELF, $save_as_draft,
483 $enable_forward_as_attachment;
484
485 $topbar_delimiter = '&nbsp;|&nbsp;';
486 $urlMailbox = urlencode($mailbox);
487 $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'.
488 ' border="0" bgcolor="'.$color[9].'"><tr><td align="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 $s .= $topbar_delimiter;
502
503 $delete_url = $base_uri . 'src/delete_message.php?mailbox='.$urlMailbox.
504 '&amp;message='.$passed_id.'&amp;';
505 if (!(isset($passed_ent_id) && $passed_ent_id)) {
506 if ($where && $what) {
507 $delete_url .= 'where=' . urlencode($where) . '&amp;what=' . urlencode($what);
508 } else {
509 $delete_url .= 'sort='. $sort . '&amp;startMessage='. $startMessage;
510 }
511 $s .= '<a href="'. $delete_url.'">'._("Delete").'</a>';
512 }
513
514 $comp_uri = $base_uri . 'src/compose.php'.
515 '?passed_id='.$passed_id.
516 '&amp;mailbox='.$urlMailbox.
517 (isset($passed_ent_id)?'&amp;passed_ent_id='.$passed_ent_id:'');
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 ($mailbox == $sent_folder) {
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 if ($compose_new_win == '1') {
529 $s .= '<a href="javascript:void(0)" '.
530 'onclick="comp_in_new(\''.$comp_alt_uri.'\')">'.$comp_alt_string.'</a>';
531 } else {
532 $s .= '<a href="'.$comp_alt_uri.'">'.$comp_alt_string.'</a>';
533 }
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 $par_ent_id = $message->parent->entity_id;
563 if ($par_ent_id) {
564 $par_ent_id = substr($par_ent_id,0,-2);
565 $s .= $topbar_delimiter;
566 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
567 $s .= '<a href="'.$url.'">'._("Up").'</a>';
568 }
569 }
570
571 $s .= '</small></td><td align="right" width="33%" nowrap><small>';
572 $comp_action_uri = $comp_uri . '&amp;action=forward';
573 if ($compose_new_win == '1') {
574 $s .= '<a href="javascript:void(0)" '.
575 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Forward").'</a>';
576 } else {
577 $s .= '<a href="'.$comp_action_uri.'">'._("Forward").'</a>';
578 }
579 $s .= $topbar_delimiter;
580
581 if ($enable_forward_as_attachment) {
582 $comp_action_uri = $comp_uri . '&amp;action=forward_as_attachment';
583 if ($compose_new_win == '1') {
584 $s .= '<a href="javascript:void(0)" '.
585 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Forward as Attachment").'</a>';
586 } else {
587 $s .= '<a href="'.$comp_action_uri.'">'._("Forward as Attachment").'</a>';
588 }
589 $s .= $topbar_delimiter;
590 }
591
592 $comp_action_uri = decodeHeader($comp_uri . '&amp;action=reply');
593 if ($compose_new_win == '1') {
594 $s .= '<a href="javascript:void(0)" '.
595 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply").'</a>';
596 } else {
597 $s .= '<a href="'.$comp_action_uri.'">'._("Reply").'</a>';
598 }
599 $s .= $topbar_delimiter;
600
601 $comp_action_uri = $comp_uri . '&amp;action=reply_all';
602 if ($compose_new_win == '1') {
603 $s .= '<a href="javascript:void(0)" '.
604 'onclick="comp_in_new(\''.$comp_action_uri.'\')">'._("Reply All").'</a>';
605 } else {
606 $s .= '<a href="'.$comp_action_uri.'">'._("Reply All").'</a>';
607 }
608 $s .= '</small></td></tr></table>';
609 do_hook("read_body_menu_top");
610 echo $s;
611 do_hook("read_body_menu_bottom");
612 }
613
614 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
615 global $QUERY_STRING, $base_uri;
616
617 $urlMailbox = urlencode($mailbox);
618 $url = $base_uri.'src/view_header.php?'.$QUERY_STRING;
619
620 $s = "<TR>\n" .
621 '<TD VALIGN="MIDDLE" ALIGN="RIGHT" WIDTH="20%"><B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
622 '<TD VALIGN="MIDDLE" ALIGN="LEFT" WIDTH="80%"><SMALL>' .
623 '<a href="'.$url.'">'._("View Full Header").'</a>';
624
625 /* Output the printer friendly link if we are in subtle mode. */
626 $s .= '&nbsp;|&nbsp;' .
627 printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color);
628 echo $s;
629 do_hook("read_body_header_right");
630 $s = "</SMALL></TD>\n" .
631 "</TR>\n";
632 echo $s;
633
634 }
635
636 /***************************/
637 /* Main of read_body.php */
638 /***************************/
639
640 /*
641 Urled vars
642 ----------
643 $passed_id
644 */
645
646 global $uid_support, $sqimap_capabilities;
647
648 if (isset($mailbox)) {
649 $mailbox = urldecode( $mailbox );
650 }
651
652 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
653 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
654
655 if (!isset($messages)) {
656 $messages = array();
657 sqsession_register($messages,'messages');
658 }
659
660 /**
661 * $message contains all information about the message
662 * including header and body
663 */
664
665 $uidvalidity = $mbx_response['UIDVALIDITY'];
666
667 if (!isset($messages[$uidvalidity])) {
668 $messages[$uidvalidity] = array();
669 }
670 if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) {
671 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
672 $FirstTimeSee = !$message->is_seen;
673 $message->is_seen = true;
674 $messages[$uidvalidity][$passed_id] = $message;
675 sqsession_register($messages, 'messages');
676 } else {
677 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
678 $message = $messages[$uidvalidity][$passed_id];
679 $FirstTimeSee = !$message->is_seen;
680 }
681 //$FirstTimeSee = !$message->is_seen;
682 //$message->is_seen = true;
683 //$messages[$uidvalidity][$passed_id] = $message;
684
685 if (isset($passed_ent_id) && $passed_ent_id) {
686 $message = $message->getEntity($passed_ent_id);
687 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
688 $message = $message->parent;
689 }
690 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support);
691 $rfc822_header = new Rfc822Header();
692 $rfc822_header->parseHeader($read);
693 $message->rfc822_header = $rfc822_header;
694 } else {
695 $passed_ent_id = 0;
696 }
697 $header = $message->header;
698
699 do_hook('html_top');
700
701 /****************************************/
702 /* Block for handling incoming url vars */
703 /****************************************/
704
705 if (isset($sendreceipt)) {
706 if ( !$message->is_mdnsent ) {
707 if (isset($identity) ) {
708 $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' );
709 } else {
710 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
711 }
712
713 $final_recipient = trim($final_recipient);
714 if ($final_recipient == '' ) {
715 $final_recipient = getPref($data_dir, $username, 'email_address', '' );
716 }
717 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
718 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
719 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support);
720 $message->is_mdnsent = true;
721 $messages[$uidvalidity][$passed_id]=$message;
722 }
723 ClearAttachments();
724 }
725 }
726 /***********************************************/
727 /* End of block for handling incoming url vars */
728 /***********************************************/
729
730 $msgs[$passed_id]['FLAG_SEEN'] = true;
731
732 $messagebody = '';
733 do_hook('read_body_top');
734 if ($show_html_default == 1) {
735 $ent_ar = $message->findDisplayEntity(array());
736 } else {
737 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
738 }
739 $cnt = count($ent_ar);
740 for ($i = 0; $i < $cnt; $i++) {
741 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
742 if ($i != $cnt-1) {
743 $messagebody .= '<hr noshade size=1>';
744 }
745 }
746
747 displayPageHeader($color, $mailbox);
748 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
749 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
750 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
751 echo ' <tr><td>';
752 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
753 echo ' <tr><td>';
754 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
755 echo ' <tr bgcolor="'.$color[4].'"><td>';
756 echo ' <table cellpadding="0" cellspacing="0" align="center" border="0">';
757 echo ' <tr><td><br>' . $messagebody . '</td></td>';
758 echo ' </table>';
759 echo ' </td></tr>';
760 echo ' </table></td></tr>';
761 echo ' </table>';
762 echo ' </td></tr>';
763
764 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
765 if ($attachmentsdisplay) {
766 echo ' <tr><td>';
767 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
768 echo ' <tr><td>';
769 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
770 echo ' <tr><td ALIGN="left" bgcolor="'.$color[9].'">';
771 echo ' <b>' . _("Attachments") . ':</b>';
772 echo ' </td></tr>';
773 echo ' <tr><td>';
774 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
775 echo $attachmentsdisplay;
776 echo ' </td></tr></table>';
777 echo ' </table></td></tr>';
778 echo ' </table></td></tr>';
779 echo ' </table>';
780 echo ' </td></tr>';
781 }
782 echo '</table>';
783
784
785 /* show attached images inline -- if pref'fed so */
786 if (($attachment_common_show_images) &&
787 is_array($attachment_common_show_images_list)) {
788 foreach ($attachment_common_show_images_list as $img) {
789 $imgurl = '../src/download.php' .
790 '?' .
791 'passed_id=' . urlencode($img['passed_id']) .
792 '&amp;mailbox=' . urlencode($mailbox) .
793 '&amp;ent_id=' . urlencode($img['ent_id']) .
794 '&amp;absolute_dl=true';
795
796 echo html_tag( 'table', "\n" .
797 html_tag( 'tr', "\n" .
798 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
799 )
800 ) ,
801 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
802 }
803 }
804
805 do_hook('read_body_bottom');
806 do_hook('html_bottom');
807 //$message->clean_up();
808 sqimap_logout($imapConnection);
809 ?>
810 </body>
811 </html>