Using QUERY_STRING without sanitizing it is BAD... Encoding it for URL use
[squirrelmail.git] / src / read_body.php
1 <?php
2 /**
3 * read_body.php
4 *
5 * Copyright (c) 1999-2004 The SquirrelMail Project Team
6 * Licensed under the GNU GPL. For full terms see the file COPYING.
7 *
8 * This file is used for reading the msgs array and displaying
9 * the resulting emails in the right frame.
10 *
11 * @version $Id$
12 * @package squirrelmail
13 */
14
15 /**
16 * Path for SquirrelMail required files.
17 * @ignore
18 */
19 define('SM_PATH','../');
20
21 /* SquirrelMail required files. */
22 require_once(SM_PATH . 'include/validate.php');
23 require_once(SM_PATH . 'functions/global.php');
24 require_once(SM_PATH . 'functions/imap.php');
25 require_once(SM_PATH . 'functions/mime.php');
26 require_once(SM_PATH . 'functions/date.php');
27 require_once(SM_PATH . 'functions/url_parser.php');
28 require_once(SM_PATH . 'functions/html.php');
29 require_once(SM_PATH . 'functions/global.php');
30 require_once(SM_PATH . 'functions/identity.php');
31 require_once(SM_PATH . 'functions/mailbox_display.php');
32
33 /**
34 * Given an IMAP message id number, this will look it up in the cached
35 * and sorted msgs array and return the index of the next message
36 *
37 * @param int $passed_id The current message UID
38 * @return the index of the next valid message from the array
39 */
40 function findNextMessage($passed_id) {
41 global $msort, $msgs, $sort,
42 $thread_sort_messages, $allow_server_sort,
43 $server_sort_array;
44 if (!is_array($server_sort_array)) {
45 $thread_sort_messages = 0;
46 $allow_server_sort = FALSE;
47 }
48 $result = -1;
49 if ($thread_sort_messages || $allow_server_sort) {
50 $count = count($server_sort_array) - 1;
51 foreach($server_sort_array as $key=>$value) {
52 if ($passed_id == $value) {
53 if ($key == $count) {
54 break;
55 }
56 $result = $server_sort_array[$key + 1];
57 break;
58 }
59 }
60 } else {
61 if (is_array($msort)) {
62 for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) {
63 if ($passed_id == $msgs[$key]['ID']) {
64 next($msort);
65 $key = key($msort);
66 if (isset($key)){
67 $result = $msgs[$key]['ID'];
68 break;
69 }
70 }
71 }
72 }
73 }
74 return $result;
75 }
76
77 /**
78 * Given an IMAP message id number, this will look it up in the cached
79 * and sorted msgs array and return the index of the previous message
80 *
81 * @param int $passed_id The current message UID
82 * @return the index of the next valid message from the array
83 */
84 function findPreviousMessage($numMessages, $passed_id) {
85 global $msort, $sort, $msgs,
86 $thread_sort_messages,
87 $allow_server_sort, $server_sort_array;
88 $result = -1;
89 if (!is_array($server_sort_array)) {
90 $thread_sort_messages = 0;
91 $allow_server_sort = FALSE;
92 }
93 if ($thread_sort_messages || $allow_server_sort ) {
94 foreach($server_sort_array as $key=>$value) {
95 if ($passed_id == $value) {
96 if ($key != 0) {
97 $result = $server_sort_array[$key - 1];
98 }
99 break;
100 }
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 $result = $msgs[$key]['ID'];
110 break;
111 }
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 * @param string $mailbox Name of current mailbox
123 * @param int $passed_id
124 */
125 function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) {
126 global $javascript_on, $color;
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,
161 $version, $attachments, $squirrelmail_language, $default_charset,
162 $languages, $useSendmail, $domain, $sent_folder,
163 $popuser, $data_dir, $username;
164
165 sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER);
166
167 $header = $message->rfc822_header;
168 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
169
170 $rfc822_header = new Rfc822Header();
171 $content_type = new ContentType('multipart/report');
172 $content_type->properties['report-type']='disposition-notification';
173
174 set_my_charset();
175 if ($default_charset) {
176 $content_type->properties['charset']=$default_charset;
177 }
178 $rfc822_header->content_type = $content_type;
179 $rfc822_header->to[] = $header->dnt;
180 $rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject);
181
182 // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md)
183 // This merely comes from compose.php and only happens when there is no
184 // email_addr specified in user's identity (which is the startup config)
185 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
186 $popuser = $usernamedata[1];
187 $domain = $usernamedata[2];
188 unset($usernamedata);
189 } else {
190 $popuser = $username;
191 }
192
193 $reply_to = '';
194 $ident = get_identities();
195 if(!isset($identity)) $identity = 0;
196 $full_name = $ident[$identity]['full_name'];
197 $from_mail = $ident[$identity]['email_address'];
198 $from_addr = '"'.$full_name.'" <'.$from_mail.'>';
199 $reply_to = $ident[$identity]['reply_to'];
200
201 if (!$from_mail) {
202 $from_mail = "$popuser@$domain";
203 $from_addr = $from_mail;
204 }
205 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
206 if ($reply_to) {
207 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
208 }
209
210 // part 1 (RFC2298)
211 $senton = getLongDateString( $header->date );
212 $to_array = $header->to;
213 $to = '';
214 foreach ($to_array as $line) {
215 $to .= ' '.$line->getAddress();
216 }
217 $now = getLongDateString( time() );
218 set_my_charset();
219 $body = _("Your message") . "\r\n\r\n" .
220 "\t" . _("To:") . ' ' . decodeHeader($to,false,false) . "\r\n" .
221 "\t" . _("Subject:") . ' ' . decodeHeader($header->subject,false,false) . "\r\n" .
222 "\t" . _("Sent:") . ' ' . $senton . "\r\n" .
223 "\r\n" .
224 sprintf( _("Was displayed on %s"), $now );
225
226 $special_encoding = '';
227 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
228 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
229 $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body);
230 if (strtolower($default_charset) == 'iso-2022-jp') {
231 if (mb_detect_encoding($body) == 'ASCII') {
232 $special_encoding = '8bit';
233 } else {
234 $body = mb_convert_encoding($body, 'JIS');
235 $special_encoding = '7bit';
236 }
237 }
238 }
239 $part1 = new Message();
240 $part1->setBody($body);
241 $mime_header = new MessageHeader;
242 $mime_header->type0 = 'text';
243 $mime_header->type1 = 'plain';
244 if ($special_encoding) {
245 $mime_header->encoding = $special_encoding;
246 } else {
247 $mime_header->encoding = 'us-ascii';
248 }
249 if ($default_charset) {
250 $mime_header->parameters['charset'] = $default_charset;
251 }
252 $part1->mime_header = $mime_header;
253
254 // part2 (RFC2298)
255 $original_recipient = $to;
256 $original_message_id = $header->message_id;
257
258 $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n";
259 if ($original_recipient != '') {
260 $report .= "Original-Recipient : $original_recipient\r\n";
261 }
262 $final_recipient = $sender;
263 $report .= "Final-Recipient: rfc822; $final_recipient\r\n" .
264 "Original-Message-ID : $original_message_id\r\n" .
265 "Disposition: manual-action/MDN-sent-manually; displayed\r\n";
266
267 $part2 = new Message();
268 $part2->setBody($report);
269 $mime_header = new MessageHeader;
270 $mime_header->type0 = 'message';
271 $mime_header->type1 = 'disposition-notification';
272 $mime_header->encoding = 'us-ascii';
273 $part2->mime_header = $mime_header;
274
275 $composeMessage = new Message();
276 $composeMessage->rfc822_header = $rfc822_header;
277 $composeMessage->addEntity($part1);
278 $composeMessage->addEntity($part2);
279
280
281 if ($useSendmail) {
282 require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
283 global $sendmail_path;
284 $deliver = new Deliver_SendMail();
285 $stream = $deliver->initStream($composeMessage,$sendmail_path);
286 } else {
287 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
288 $deliver = new Deliver_SMTP();
289 global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp;
290 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
291 get_smtp_user($user, $pass);
292 $stream = $deliver->initStream($composeMessage,$domain,0,
293 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
294 }
295 $success = false;
296 if ($stream) {
297 $length = $deliver->mail($composeMessage, $stream);
298 $success = $deliver->finalizeStream($stream);
299 }
300 if (!$success) {
301 $msg = $deliver->dlv_msg . '<br>' .
302 _("Server replied: ") . $deliver->dlv_ret_nr . ' '.
303 $deliver->dlv_server_msg;
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 function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) {
321 $sg = $set?'+':'-';
322 $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)';
323 $read = sqimap_run_command ($imapConnection, $cmd, true, $response,
324 $readmessage, TRUE);
325 }
326
327 function ClearAttachments() {
328 global $username, $attachments, $attachment_dir;
329
330 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
331
332 $rem_attachments = array();
333 if (isset($attachments)) {
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 }
345 $attachments = $rem_attachments;
346 }
347
348 function formatRecipientString($recipients, $item ) {
349 global $show_more_cc, $show_more, $show_more_bcc,
350 $PHP_SELF;
351
352 $string = '';
353 if ((is_array($recipients)) && (isset($recipients[0]))) {
354 $show = false;
355
356 if ($item == 'to') {
357 if ($show_more) {
358 $show = true;
359 $url = set_url_var($PHP_SELF, 'show_more',0);
360 } else {
361 $url = set_url_var($PHP_SELF, 'show_more',1);
362 }
363 } else if ($item == 'cc') {
364 if ($show_more_cc) {
365 $show = true;
366 $url = set_url_var($PHP_SELF, 'show_more_cc',0);
367 } else {
368 $url = set_url_var($PHP_SELF, 'show_more_cc',1);
369 }
370 } else if ($item == 'bcc') {
371 if ($show_more_bcc) {
372 $show = true;
373 $url = set_url_var($PHP_SELF, 'show_more_bcc',0);
374 } else {
375 $url = set_url_var($PHP_SELF, 'show_more_bcc',1);
376 }
377 }
378
379 $cnt = count($recipients);
380 foreach($recipients as $r) {
381 $add = decodeHeader($r->getAddress(true));
382 if ($string) {
383 $string .= '<BR>' . $add;
384 } else {
385 $string = $add;
386 if ($cnt > 1) {
387 $string .= '&nbsp;(<A HREF="'.$url;
388 if ($show) {
389 $string .= '">'._("less").'</A>)';
390 } else {
391 $string .= '">'._("more").'</A>)';
392 break;
393 }
394 }
395 }
396 }
397 }
398 return $string;
399 }
400
401 function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message,
402 $color, $FirstTimeSee) {
403 global $msn_user_support, $default_use_mdn, $default_use_priority,
404 $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on,
405 $squirrelmail_language;
406
407 $header = $message->rfc822_header;
408 $env = array();
409 $env[_("Subject")] = str_replace("&nbsp;"," ",decodeHeader($header->subject));
410
411 $from_name = $header->getAddr_s('from');
412 if (!$from_name)
413 $from_name = $header->getAddr_s('sender');
414 if (!$from_name)
415 $env[_("From")] = _("Unknown sender");
416 else
417 $env[_("From")] = decodeHeader($from_name);
418 $env[_("Date")] = getLongDateString($header->date);
419 $env[_("To")] = formatRecipientString($header->to, "to");
420 $env[_("Cc")] = formatRecipientString($header->cc, "cc");
421 $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc");
422 if ($default_use_priority) {
423 $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority));
424 }
425 if ($show_xmailer_default) {
426 $env[_("Mailer")] = decodeHeader($header->xmailer);
427 }
428 if ($default_use_mdn) {
429 if ($mdn_user_support) {
430 if ($header->dnt) {
431 if ($message->is_mdnsent) {
432 $env[_("Read receipt")] = _("sent");
433 } else {
434 $env[_("Read receipt")] = _("requested");
435 if (!(handleAsSent($mailbox) ||
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="2" 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 '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'.
470 ' CELLSPACING="0" BORDER="0" ALIGN="center">'."\n";
471 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
472 $color[4].'"></TD></TR><TR><TD align=center>'."\n";
473 echo $s;
474 do_hook('read_body_header');
475 formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color);
476 echo '</TABLE>';
477 echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n";
478 echo '</TABLE>';
479 }
480
481 /**
482 * Format message toolbar
483 *
484 * @param string $mailbox Name of current mailbox
485 * @param int $passed_id UID of current message
486 * @param int $passed_ent_id Id of entity within message
487 * @param object $message Current message object
488 * @param object $mbx_response
489 */
490 function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, $nav_on_top = TRUE) {
491 global $base_uri, $draft_folder, $where, $what, $color, $sort,
492 $startMessage, $PHP_SELF, $save_as_draft,
493 $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox,
494 $data_dir, $username, $delete_prev_next_display,
495 $compose_new_win, $javascript_on;
496
497 $topbar_delimiter = '&nbsp;|&nbsp;';
498 $double_delimiter = '&nbsp;&nbsp;&nbsp;&nbsp;';
499 $urlMailbox = urlencode($mailbox);
500
501 $msgs_url = $base_uri . 'src/';
502
503 // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc.
504 $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>';
505
506 // Create Prev & Next links
507 // Handle nested entities first (i.e. Mime Attach parts)
508 if (isset($passed_ent_id) && $passed_ent_id) {
509 // code for navigating through attached message/rfc822 messages
510 $url = set_url_var($PHP_SELF, 'passed_ent_id',0);
511 $entities = array();
512 $entity_count = array();
513 $c = 0;
514
515 foreach($message->parent->entities as $ent) {
516 if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') {
517 $c++;
518 $entity_count[$c] = $ent->entity_id;
519 $entities[$ent->entity_id] = $c;
520 }
521 }
522
523 $prev_link = _("Previous");
524 if($entities[$passed_ent_id] > 1) {
525 $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1];
526 $prev_link = '<a href="'
527 . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id)
528 . '">' . $prev_link . '</a>';
529 }
530
531 $next_link = _("Next");
532 if($entities[$passed_ent_id] < $c) {
533 $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1];
534 $next_link = '<a href="'
535 . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id)
536 . '">' . $next_link . '</a>';
537 }
538
539 $par_ent_id = $message->parent->entity_id;
540 $up_link = '';
541 if ($par_ent_id) {
542 $par_ent_id = substr($par_ent_id,0,-2);
543 if ( $par_ent_id != 0 ) {
544 $up_link = $topbar_delimiter;
545 $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id);
546 $up_link .= '<a href="'.$url.'">'._("Up").'</a>';
547 }
548 }
549
550 $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link;
551 $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]';
552
553 // Prev/Next links for regular messages
554 } else if ( !(isset($where) && isset($what)) ) {
555 $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id);
556 $next = findNextMessage($passed_id);
557
558 $prev_link = _("Previous");
559 if ($prev >= 0) {
560 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
561 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
562 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
563 $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>';
564 }
565
566 $next_link = _("Next");
567 if ($next >= 0) {
568 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
569 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
570 '&amp;startMessage='.$startMessage.'&amp;show_more=0';
571 $next_link = '<a href="'.$uri.'">'.$next_link.'</a>';
572 }
573
574 // Only bother with Delete & Prev and Delete & Next IF
575 // top display is enabled.
576 if ( $delete_prev_next_display == 1 ) {
577 $del_prev_link = _("Delete & Prev");
578 if ($prev >= 0) {
579 $uri = $base_uri . 'src/read_body.php?passed_id='.$prev.
580 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
581 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
582 '&amp;delete_id='.$passed_id;
583 $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>';
584 }
585
586 $del_next_link = _("Delete & Next");
587 if ($next >= 0) {
588 $uri = $base_uri . 'src/read_body.php?passed_id='.$next.
589 '&amp;mailbox='.$urlMailbox.'&amp;sort='.$sort.
590 '&amp;startMessage='.$startMessage.'&amp;show_more=0'.
591 '&amp;delete_id='.$passed_id;
592 $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>';
593 }
594 }
595
596 $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']';
597 if ( isset($del_prev_link) && isset($del_next_link) )
598 $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']';
599 }
600
601 // Start with Search Results or Message List link.
602 if (isset($where) && isset($what)) {
603 $msgs_url .= 'search.php?where=' . urlencode($where) .
604 '&amp;what=' . urlencode($what) . '&amp;mailbox=' . $urlMailbox;
605 $msgs_str = _("Search Results");
606 } else {
607 $msgs_url .= 'right_main.php?sort=' . $sort . '&amp;startMessage=' .
608 $startMessage . '&amp;mailbox=' . $urlMailbox;
609 $msgs_str = _("Message List");
610 }
611 $nav_row .= $double_delimiter .
612 '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]';
613
614 $nav_row .= '</small></td></tr>';
615
616
617 // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc.
618 $menu_row = '<tr bgcolor="'.$color[9].'"><td><small>';
619 $comp_uri = $base_uri.'src/compose.php' .
620 '?passed_id=' . $passed_id .
621 '&amp;mailbox=' . $urlMailbox .
622 '&amp;startMessage=' . $startMessage .
623 (isset($passed_ent_id) ? '&amp;passed_ent_id='.$passed_ent_id : '');
624
625 // Start form for reply/reply all/forward..
626 $target = '';
627 $on_click='';
628 $method='method="post" ';
629 if ($compose_new_win == '1') {
630 if ( $javascript_on ) {
631 $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form)"';
632 $comp_uri = 'javascript:void(0)';
633 $method='method="get" ';
634 } else {
635 $target = 'target="_blank"';
636 }
637 }
638
639 $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" '.$method.$target.' style="display: inline">'."\n";
640
641 // If Draft folder - create Resume link
642 if (($mailbox == $draft_folder) && ($save_as_draft)) {
643 $new_button = 'smaction_draft';
644 $comp_alt_string = _("Resume Draft");
645 } else if (handleAsSent($mailbox)) {
646 // If in Sent folder, edit as new
647 $new_button = 'smaction_edit_new';
648 $comp_alt_string = _("Edit Message as New");
649 }
650 // Show Alt URI for Draft/Sent
651 if (isset($comp_alt_string))
652 $menu_row .= getButton('SUBMIT', $new_button, $comp_alt_string, $on_click) . "\n";
653
654 $menu_row .= getButton('SUBMIT', 'smaction_reply', _("Reply"), $on_click) . "\n";
655 $menu_row .= getButton('SUBMIT', 'smaction_reply_all', _("Reply All"), $on_click) ."\n";
656 $menu_row .= getButton('SUBMIT', 'smaction_forward', _("Forward"), $on_click);
657 if ($enable_forward_as_attachment)
658 $menu_row .= '<input type="checkbox" name="smaction_attache">' . _("As Attachment") .'&nbsp;&nbsp;'."\n";
659
660 $menu_row .= '</form>&nbsp;';
661
662 // Form for deletion
663 $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox;
664 $menu_row .= '<form action="'.$delete_url.'" method="post" style="display: inline">';
665
666 if (!(isset($passed_ent_id) && $passed_ent_id)) {
667 $menu_row .= '<input type="hidden" name="message" value="'.$passed_id.'" />';
668
669 if ($where && $what) {
670 $menu_row .= '<input type="hidden" name="where" value="'.$where.'" />';
671 $menu_row .= '<input type="hidden" name="what" value="'.$what.'" />';
672 } else {
673 $menu_row .= '<input type="hidden" name="sort" value="'.$sort.'" />';
674 $menu_row .= '<input type="hidden" name="startMessage" value="'.$startMessage.'" />';
675 }
676 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"));
677 $menu_row .= '<input type="checkbox" name="bypass_trash">' . _("Bypass Trash");
678 }
679 else
680 $menu_row .= getButton('SUBMIT', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled
681
682 $menu_row .= '</form>';
683
684
685 // Add top move link
686 $menu_row .= '</small></td><td align="right">';
687 if ( !(isset($passed_ent_id) && $passed_ent_id) ) {
688
689 $current_box = 'mailbox='.$mailbox.'&sort='.$sort.'&startMessage='.$startMessage;
690
691 // Set subsequent location based on whether or not there is a 'next' message.
692 if ( isset($next) && $next >= 0 ) {
693 $location = $base_uri . 'src/read_body.php?passed_id='.$next.'&';
694 } elseif (isset($prev) && $prev >= 0) {
695 $location = $base_uri . 'src/read_body.php?passed_id='.$prev.'&';
696 } else {
697 $location = $base_uri . 'src/right_main.php?';
698 }
699
700 $menu_row .= '<form action="'.$base_uri.'src/move_messages.php?'.$current_box.'" method="post" style="display: inline">'.
701 '<small><input type="hidden" name="show_more" value="0" />'.
702 '<input type="hidden" name="dmn" value="1" />'.
703 '<input type="hidden" name="location" value="'.$location.$current_box.'" />'.
704 '<input type="hidden" name="msg[0]" value="'.$passed_id.'" />'._("Move to:") .
705 '<select name="targetMailbox" style="padding: 0px; margin: 0px">';
706
707 if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) {
708 $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox)));
709 } else {
710 $menu_row .= sqimap_mailbox_option_list($imapConnection);
711 }
712 $menu_row .= '</select> ';
713
714 $menu_row .= getButton('SUBMIT', 'moveButton',_("Move")) . "\n" . '</form>';
715 }
716 $menu_row .= '</td></tr>';
717
718 // echo rows, with hooks
719 $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row));
720 if (is_array($ret)) {
721 if (isset($ret[0]) && !empty($ret[0])) {
722 $nav_row = $ret[0];
723 }
724 if (isset($ret[1]) && !empty($ret[1])) {
725 $menu_row = $ret[1];
726 }
727 }
728 echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
729 echo $nav_on_top ? $nav_row . $menu_row : $menu_row . $nav_row;
730 echo '</table>'."\n";
731 do_hook('read_body_menu_bottom');
732 }
733
734 function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) {
735 global $base_uri;
736
737 $urlMailbox = urlencode($mailbox);
738 if (sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER)) {
739 $query_string = urlencode($query_string);
740 } else {
741 $query_string = '';
742 }
743 $url = $base_uri.'src/view_header.php?'.$query_string;
744
745 $s = "<TR>\n" .
746 html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ":&nbsp;&nbsp;</B></TD>\n" .
747 html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' .
748 '<a href="'.$url.'">'._("View Full Header").'</a>';
749
750 /* Output the printer friendly link if we are in subtle mode. */
751 $s .= '&nbsp;|&nbsp;' .
752 printer_friendly_link($mailbox, $passed_id, $passed_ent_id);
753 echo $s;
754 do_hook("read_body_header_right");
755 $s = "</SMALL></TD>\n" .
756 "</TR>\n";
757 echo $s;
758
759 }
760
761 /***************************/
762 /* Main of read_body.php */
763 /***************************/
764
765 /* get the globals we may need */
766
767 sqgetGlobalVar('key', $key, SQ_COOKIE);
768 sqgetGlobalVar('username', $username, SQ_SESSION);
769 sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
770 sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
771 sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
772
773 sqgetGlobalVar('msgs', $msgs, SQ_SESSION);
774 sqgetGlobalVar('msort', $msort, SQ_SESSION);
775 sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION);
776 sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION);
777 if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) {
778 $messages = array();
779 }
780
781 /** GET VARS */
782 sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET);
783 sqgetGlobalVar('where', $where, SQ_GET);
784 sqgetGlobalVar('what', $what, SQ_GET);
785 if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) {
786 $show_more = (int) $temp;
787 }
788 if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) {
789 $show_more_cc = (int) $temp;
790 }
791 if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) {
792 $show_more_bcc = (int) $temp;
793 }
794 if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) {
795 $view_hdr = (int) $temp;
796 }
797
798 /** GET/POST VARS */
799 sqgetGlobalVar('passed_ent_id', $passed_ent_id);
800 sqgetGlobalVar('mailbox', $mailbox);
801
802 if ( sqgetGlobalVar('passed_id', $temp) ) {
803 $passed_id = (int) $temp;
804 }
805 if ( sqgetGlobalVar('sort', $temp) ) {
806 $sort = (int) $temp;
807 }
808 if ( sqgetGlobalVar('startMessage', $temp) ) {
809 $startMessage = (int) $temp;
810 }
811
812 /* end of get globals */
813 global $sqimap_capabilities, $lastTargetMailbox;
814
815 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
816 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true);
817
818 /**
819 * Process Delete from delete-move-next
820 * but only if delete_id was set
821 */
822 if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) {
823 sqimap_messages_delete($imapConnection, $delete_id, $delete_id, $mailbox);
824
825 sqimap_mailbox_expunge_dmn($delete_id);
826 }
827
828 /**
829 * $message contains all information about the message
830 * including header and body
831 */
832
833 $uidvalidity = $mbx_response['UIDVALIDITY'];
834
835 if (!isset($messages[$uidvalidity])) {
836 $messages[$uidvalidity] = array();
837 }
838 if (!isset($messages[$uidvalidity][$passed_id])) {
839 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
840 $FirstTimeSee = !$message->is_seen;
841 $message->is_seen = true;
842 $messages[$uidvalidity][$passed_id] = $message;
843 } else {
844 // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
845 $message = $messages[$uidvalidity][$passed_id];
846 $FirstTimeSee = !$message->is_seen;
847 }
848
849 if (isset($passed_ent_id) && $passed_ent_id) {
850 $message = $message->getEntity($passed_ent_id);
851 if ($message->type0 != 'message' && $message->type1 != 'rfc822') {
852 $message = $message->parent;
853 }
854 $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE);
855 $rfc822_header = new Rfc822Header();
856 $rfc822_header->parseHeader($read);
857 $message->rfc822_header = $rfc822_header;
858 } else {
859 $passed_ent_id = 0;
860 }
861 $header = $message->header;
862
863 do_hook('html_top');
864
865 /****************************************/
866 /* Block for handling incoming url vars */
867 /****************************************/
868
869 if (isset($sendreceipt)) {
870 if ( !$message->is_mdnsent ) {
871 $final_recipient = '';
872 if ((isset($identity)) && ($identity != 0)) //Main identity
873 $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' ));
874 if ($final_recipient == '' )
875 $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' ));
876 $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]);
877 if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) {
878 ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id);
879 $message->is_mdnsent = true;
880 $messages[$uidvalidity][$passed_id]=$message;
881 }
882 ClearAttachments();
883 }
884 }
885 /***********************************************/
886 /* End of block for handling incoming url vars */
887 /***********************************************/
888
889 $msgs[$passed_id]['FLAG_SEEN'] = true;
890
891 $messagebody = '';
892 do_hook('read_body_top');
893 if ($show_html_default == 1) {
894 $ent_ar = $message->findDisplayEntity(array());
895 } else {
896 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
897 }
898 $cnt = count($ent_ar);
899 for ($i = 0; $i < $cnt; $i++) {
900 $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
901 if ($i != $cnt-1) {
902 $messagebody .= '<hr noshade size=1>';
903 }
904 }
905
906 displayPageHeader($color, $mailbox);
907 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response);
908 formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee);
909 echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">';
910 echo ' <tr><td>';
911 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">';
912 echo ' <tr><td>';
913 echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">';
914 echo ' <tr bgcolor="'.$color[4].'"><td>';
915 // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">';
916 echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' );
917 echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left')
918 . '</tr>';
919 echo ' </table>';
920 echo ' </td></tr>';
921 echo ' </table></td></tr>';
922 echo ' </table>';
923 echo ' </td></tr>';
924
925 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
926 $color[4].'"></TD></TR>'."\n";
927
928 $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id);
929 if ($attachmentsdisplay) {
930 echo ' </table>';
931 echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">';
932 echo ' <tr><td>';
933 echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">';
934 echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] );
935 echo ' <b>' . _("Attachments") . ':</b>';
936 echo ' </td></tr>';
937 echo ' <tr><td>';
938 echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>';
939 echo $attachmentsdisplay;
940 echo ' </td></tr></table>';
941 echo ' </td></tr></table>';
942 echo ' </td></tr>';
943 echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.
944 $color[4].'"></TD></TR>';
945 }
946 echo '</table>';
947
948 /* show attached images inline -- if pref'fed so */
949 if (($attachment_common_show_images) &&
950 is_array($attachment_common_show_images_list)) {
951 foreach ($attachment_common_show_images_list as $img) {
952 $imgurl = SM_PATH . 'src/download.php' .
953 '?' .
954 'passed_id=' . urlencode($img['passed_id']) .
955 '&amp;mailbox=' . urlencode($mailbox) .
956 '&amp;ent_id=' . urlencode($img['ent_id']) .
957 '&amp;absolute_dl=true';
958
959 echo html_tag( 'table', "\n" .
960 html_tag( 'tr', "\n" .
961 html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left'
962 )
963 ) ,
964 'center', '', 'cellspacing=0 border="0" cellpadding="2"');
965 }
966 }
967
968 formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response, FALSE);
969
970 do_hook('read_body_bottom');
971 do_hook('html_bottom');
972 sqimap_logout($imapConnection);
973 /* sessions are written at the end of the script. it's better to register
974 them at the end so we avoid double session_register calls */
975 sqsession_register($messages,'messages');
976
977 ?>
978 </body>
979 </html>