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