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