Reworked subfolder message count and all. Open to suggestions for the
[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 require_once('../functions/html.php');
24
25 $pf_cleandisplay = getPref($data_dir, $username, 'pf_cleandisplay');
26 $mailbox = urldecode($mailbox);
27 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
28 sqimap_mailbox_select($imapConnection, $mailbox);
29 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
30 $id = $passed_id;
31 if (isset($passed_ent_id)) {
32 $message = $message->getEntity($passed_ent_id);
33 }
34
35
36 /* --start display setup-- */
37
38 $rfc822_header = $message->rfc822_header;
39 /* From and Date are usually fine as they are... */
40 $from = decodeHeader($rfc822_header->getAddr_s('from'));
41 $date = getLongDateString($rfc822_header->date);
42 $subject = trim(decodeHeader($rfc822_header->subject));
43
44 /* we can clean these up if the list is too long... */
45 $cc = decodeHeader($rfc822_header->getAddr_s('cc'));
46 $to = decodeHeader($rfc822_header->getAddr_s('to'));
47
48 if ($show_html_default == 1) {
49 $ent_ar = $message->findDisplayEntity(array());
50 } else {
51 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
52 }
53 $body = '';
54 if ($ent_ar[0] != '') {
55 for ($i = 0; $i < count($ent_ar); $i++) {
56 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox);
57 $body .= '<hr noshade size=1>';
58 }
59 $hookResults = do_hook('message_body', $body);
60 $body = $hookResults[1];
61 } else {
62 $body = _("Message not printable");
63 }
64
65 /* now, if they choose to, we clean up the display a bit... */
66
67 if ( empty($pf_cleandisplay) || $pf_cleandisplay != 'no' ) {
68
69 $num_leading_spaces = 9; // nine leading spaces for indentation
70
71 // sometimes I see ',,' instead of ',' seperating addresses *shrug*
72 $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces);
73 $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces);
74
75 // the body should have no leading zeros
76 // disabled because it destroys html mail
77
78 // $body = pf_clean_string($body, 0);
79
80 // clean up everything else...
81 $subject = pf_clean_string($subject, $num_leading_spaces);
82 $from = pf_clean_string($from, $num_leading_spaces);
83 $date = pf_clean_string($date, $num_leading_spaces);
84
85 } // end cleanup
86
87 // --end display setup--
88
89
90 /* --start browser output-- */
91 displayHtmlHeader( _("Printer Friendly"), '', FALSE );
92
93 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n" .
94 /* headers (we use table because translations are not all the same width) */
95 html_tag( 'table', '', 'center', '', 'cellspacing="0" cellpadding="0" border="0"' ) .
96 html_tag( 'tr',
97 html_tag( 'td', _("From").'&nbsp;', 'left' ,'','valign="top"') .
98 html_tag( 'td', htmlspecialchars($from), 'left' )
99 ) . "\n" .
100 html_tag( 'tr',
101 html_tag( 'td', _("Subject").'&nbsp;', 'left','','valign="top"' ) .
102 html_tag( 'td', htmlspecialchars($subject), 'left' )
103 ) . "\n" .
104 html_tag( 'tr',
105 html_tag( 'td', _("Date").'&nbsp;', 'left' ) .
106 html_tag( 'td', htmlspecialchars($date), 'left' )
107 ) . "\n" .
108 html_tag( 'tr',
109 html_tag( 'td', _("To").'&nbsp;', 'left','','valign="top"' ) .
110 html_tag( 'td', htmlspecialchars($to), 'left' )
111 ) . "\n";
112 if ( strlen($cc) > 0 ) { /* only show CC: if it's there... */
113 echo html_tag( 'tr',
114 html_tag( 'td', _("CC").'&nbsp;', 'left','','valign="top"' ) .
115 html_tag( 'td', htmlspecialchars($cc), 'left' )
116 );
117 }
118 /* body */
119 echo html_tag( 'tr',
120 html_tag( 'td', '<hr noshade size=1><br>' . "\n" . $body, 'left', '', 'colspan="2"' )
121 ) . "\n" .
122
123 '</table>' . "\n" .
124 '</body></html>';
125
126 /* --end browser output-- */
127
128
129 /* --start pf-specific functions-- */
130
131 /* $string = pf_clean_string($string, 9); */
132 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
133 global $data_dir, $username;
134
135 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
136 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
137
138 $leading_spaces = '';
139 while ( strlen($leading_spaces) < $num_leading_spaces )
140 $leading_spaces .= ' ';
141
142 $clean_string = '';
143 while ( strlen($unclean_string) > $wrap_at )
144 {
145 $this_line = substr($unclean_string, 0, $wrap_at);
146 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
147 {
148 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
149 $clean_string .= $leading_spaces;
150 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
151 }
152 else
153 {
154 $clean_string .= substr( $this_line, 0, strrpos( $this_line, ' ' ));
155 $clean_string .= "\n" . $leading_spaces;
156 $unclean_string = substr($unclean_string, (1+strrpos( $this_line, ' ' )));
157 }
158 }
159
160 $clean_string .= $unclean_string;
161
162 return $clean_string;
163 } /* end pf_clean_string() function */
164
165 /* --end pf-specific functions */
166
167 ?>