Fix for bug 554789 Loose of attachements when using the html addressbook
[squirrelmail.git] / src / printer_friendly_bottom.php
CommitLineData
f226cba7 1<?php
2
35586184 3/**
4 * printer_friendly_bottom.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * with javascript on, it is the bottom frame of printer_friendly_main.php
10 * else, it is alone in a new window
11 *
12 * - this is the page that does all the work, really.
13 *
14 * $Id$
15 */
16
35586184 17require_once('../src/validate.php');
18require_once('../functions/strings.php');
19require_once('../config/config.php');
20require_once('../src/load_prefs.php');
21require_once('../functions/imap.php');
22require_once('../functions/page_header.php');
f226cba7 23
32f4e318 24$pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
25
26$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
27sqimap_mailbox_select($imap_stream, $mailbox);
28$message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
29
30/* --start display setup-- */
31
32/* From and Date are usually fine as they are... */
33$from = decodeHeader($message->header->from);
34$date = getLongDateString($message->header->date);
35
36/* we can clean these up if the list is too long... */
37$cc = decodeHeader(getLineOfAddrs($message->header->cc));
38$to = decodeHeader(getLineOfAddrs($message->header->to));
39
40/* and Body and Subject could easily stream off the page... */
41$id = $message->header->id;
42$ent_num = findDisplayEntity ($message, 0);
43$body_message = getEntity($message, $ent_num);
44if (($body_message->header->type0 == 'text') ||
45 ($body_message->header->type0 == 'rfc822')) {
46 $body = mime_fetch_body ($imap_stream, $id, $ent_num);
47 $body = decodeBody($body, $body_message->header->encoding);
48 $hookResults = do_hook('message_body', $body);
49 $body = $hookResults[1];
50 if ($body_message->header->type1 == 'html') {
51 if( $show_html_default <> 1 ) {
52 $body = strip_tags( $body );
3bbf5974 53 translateText($body, $wrap_at, $body_message->header->charset);
3bbf5974 54 } else {
32f4e318 55 $body = MagicHTML( $body, $id );
3bbf5974 56 }
32f4e318 57 } else {
58 translateText($body, $wrap_at, $body_message->header->charset);
59 }
60} else {
61 $body = _("Message not printable");
62}
3bbf5974 63
32f4e318 64$subject = trim(decodeHeader($message->header->subject));
f226cba7 65
32f4e318 66 /* now, if they choose to, we clean up the display a bit... */
67 /*
68if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
f226cba7 69
32f4e318 70 $num_leading_spaces = 9; // nine leading spaces for indentation
f226cba7 71
32f4e318 72 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
73 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
74 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
f226cba7 75
32f4e318 76 // the body should have no leading zeros
77 $body = pf_clean_string($body, 0);
f226cba7 78
32f4e318 79 // clean up everything else...
80 $subject = pf_clean_string($subject, $num_leading_spaces);
81 $from = pf_clean_string($from, $num_leading_spaces);
82 $date = pf_clean_string($date, $num_leading_spaces);
f226cba7 83
32f4e318 84} // end cleanup
85*/
86// --end display setup--
f226cba7 87
f226cba7 88
32f4e318 89/* --start browser output-- */
90displayHtmlHeader( _("Printer Friendly"), '', FALSE );
f226cba7 91
32f4e318 92echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
ae426785 93 /* headers (we use table because translations are not all the same width) */
32f4e318 94 '<table>'.
ae426785 95 '<tr><td>' . _("From") . ':</td><td>' . htmlentities($from) . "</td></tr>\n".
96 '<tr><td>' . _("To") . ':</td><td>' . htmlentities($to) . "</td></tr>\n";
32f4e318 97if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
ae426785 98 echo '<tr><td>' . _("CC") . ':</td><td>' . htmlentities($cc) . "</td></tr>\n";
32f4e318 99}
ae426785 100echo '<tr><td>' . _("Date") . ':</td><td>' . htmlentities($date) . "</td></tr>\n".
101 '<tr><td>' . _("Subject") . ':</td><td>' . htmlentities($subject) . "</td></tr>\n".
32f4e318 102 '</table>'.
103 "\n";
104/* body */
105echo "<hr noshade size=1>\n";
106echo $body;
f226cba7 107
32f4e318 108/* --end browser output-- */
f226cba7 109
ae426785 110echo '</body></html>';
f226cba7 111
32f4e318 112/* --start pf-specific functions-- */
f226cba7 113
32f4e318 114/* $string = pf_clean_string($string, 9); */
f226cba7 115function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
116 global $data_dir, $username;
117
f6d2358f 118 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
32f4e318 119 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
f226cba7 120
121 $leading_spaces = '';
122 while ( strlen($leading_spaces) < $num_leading_spaces )
123 $leading_spaces .= ' ';
124
125 $clean_string = '';
126 while ( strlen($unclean_string) > $wrap_at )
127 {
128 $this_line = substr($unclean_string, 0, $wrap_at);
32f4e318 129 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
f226cba7 130 {
131 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
132 $clean_string .= $leading_spaces;
133 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
134 }
135 else
136 {
137 $clean_string .= substr( $this_line, 0, strrpos( $this_line, ' ' ));
138 $clean_string .= "\n" . $leading_spaces;
139 $unclean_string = substr($unclean_string, (1+strrpos( $this_line, ' ' )));
140 }
141 }
32f4e318 142
f226cba7 143 $clean_string .= $unclean_string;
144
145 return $clean_string;
32f4e318 146} /* end pf_clean_string() function */
f226cba7 147
32f4e318 148/* --end pf-specific functions */
f226cba7 149
ae426785 150?>