r2l by Yoav
[squirrelmail.git] / src / printer_friendly_bottom.php
1 <?php
2
3 /**
4 * printer_friendly_bottom.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 * 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
17 require_once('../src/validate.php');
18 require_once('../functions/strings.php');
19 require_once('../config/config.php');
20 require_once('../src/load_prefs.php');
21 require_once('../functions/imap.php');
22 require_once('../functions/page_header.php');
23
24 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
25
26 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
27 sqimap_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_ar = findDisplayEntity ($message, 0);
43 $ent_num = $ent_ar[0];
44
45 $body_message = getEntity($message, $ent_num);
46 if (($body_message->header->type0 == 'text') ||
47 ($body_message->header->type0 == 'rfc822')) {
48 $body = mime_fetch_body ($imap_stream, $id, $ent_num);
49 $body = decodeBody($body, $body_message->header->encoding);
50 $hookResults = do_hook('message_body', $body);
51 $body = $hookResults[1];
52 if ($body_message->header->type1 == 'html') {
53 if( $show_html_default <> 1 ) {
54 $body = strip_tags( $body );
55 translateText($body, $wrap_at, $body_message->header->charset);
56 } else {
57 $body = MagicHTML( $body, $id, $message );
58 }
59 } else {
60 translateText($body, $wrap_at, $body_message->header->charset);
61 }
62 } else {
63 $body = _("Message not printable");
64 }
65
66 $subject = trim(decodeHeader($message->header->subject));
67
68 /* now, if they choose to, we clean up the display a bit... */
69 /*
70 if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
71
72 $num_leading_spaces = 9; // nine leading spaces for indentation
73
74 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
75 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
76 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
77
78 // the body should have no leading zeros
79 $body = pf_clean_string($body, 0);
80
81 // clean up everything else...
82 $subject = pf_clean_string($subject, $num_leading_spaces);
83 $from = pf_clean_string($from, $num_leading_spaces);
84 $date = pf_clean_string($date, $num_leading_spaces);
85
86 } // end cleanup
87 */
88 // --end display setup--
89
90
91 /* --start browser output-- */
92 displayHtmlHeader( _("Printer Friendly"), '', FALSE );
93
94 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
95 /* headers (we use table because translations are not all the same width) */
96 '<table>'.
97 '<tr><td>' . _("From") . ':</td><td>' . htmlentities($from) . "</td></tr>\n".
98 '<tr><td>' . _("To") . ':</td><td>' . htmlentities($to) . "</td></tr>\n";
99 if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
100 echo '<tr><td>' . _("CC") . ':</td><td>' . htmlentities($cc) . "</td></tr>\n";
101 }
102 echo '<tr><td>' . _("Date") . ':</td><td>' . htmlentities($date) . "</td></tr>\n".
103 '<tr><td>' . _("Subject") . ':</td><td>' . htmlentities($subject) . "</td></tr>\n".
104 '</table>'.
105 "\n";
106 /* body */
107 echo "<hr noshade size=1>\n";
108 echo $body;
109
110 /* --end browser output-- */
111
112 echo '</body></html>';
113
114 /* --start pf-specific functions-- */
115
116 /* $string = pf_clean_string($string, 9); */
117 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
118 global $data_dir, $username;
119
120 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
121 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
122
123 $leading_spaces = '';
124 while ( strlen($leading_spaces) < $num_leading_spaces )
125 $leading_spaces .= ' ';
126
127 $clean_string = '';
128 while ( strlen($unclean_string) > $wrap_at )
129 {
130 $this_line = substr($unclean_string, 0, $wrap_at);
131 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
132 {
133 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
134 $clean_string .= $leading_spaces;
135 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
136 }
137 else
138 {
139 $clean_string .= substr( $this_line, 0, strrpos( $this_line, ' ' ));
140 $clean_string .= "\n" . $leading_spaces;
141 $unclean_string = substr($unclean_string, (1+strrpos( $this_line, ' ' )));
142 }
143 }
144
145 $clean_string .= $unclean_string;
146
147 return $clean_string;
148 } /* end pf_clean_string() function */
149
150 /* --end pf-specific functions */
151
152 ?>