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