renaming file. using underscore instead of hyphen.
[squirrelmail.git] / src / printer_friendly_bottom.php
1 <?php
2
3 /**
4 * printer_friendly_bottom.php
5 *
6 * Copyright (c) 1999-2005 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 * @version $Id$
15 * @package squirrelmail
16 */
17
18 /**
19 * Path for SquirrelMail required files.
20 * @ignore
21 */
22 define('SM_PATH','../');
23
24 /* SquirrelMail required files. */
25 require_once(SM_PATH . 'include/validate.php');
26 require_once(SM_PATH . 'functions/imap.php');
27
28 /* get some of these globals */
29 sqgetGlobalVar('username', $username, SQ_SESSION);
30 sqgetGlobalVar('key', $key, SQ_COOKIE);
31 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
32
33 sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
34 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
35
36 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
37 $passed_ent_id = '';
38 }
39 /* end globals */
40
41 $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
42 $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox);
43 if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) {
44 $message = &$messages[$mbx_response['UIDVALIDITY']][$passed_id];
45 } else {
46 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
47 }
48 if ($passed_ent_id) {
49 $message = &$message->getEntity($passed_ent_id);
50 }
51
52 /* --start display setup-- */
53
54 $rfc822_header = $message->rfc822_header;
55 /* From and Date are usually fine as they are... */
56 $from = $rfc822_header->getAddr_s('from');
57 $date = getLongDateString($rfc822_header->date);
58 $subject = trim($rfc822_header->subject);
59
60 /* we can clean these up if the list is too long... */
61 $cc = $rfc822_header->getAddr_s('cc');
62 $to = $rfc822_header->getAddr_s('to');
63
64 if ($show_html_default == 1) {
65 $ent_ar = $message->findDisplayEntity(array());
66 } else {
67 $ent_ar = $message->findDisplayEntity(array(), array('text/plain'));
68 }
69 $body = '';
70 if ($ent_ar[0] != '') {
71 for ($i = 0; $i < count($ent_ar); $i++) {
72 $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE);
73 $body .= '<hr style="height: 1px;" />';
74 }
75 $hookResults = do_hook('message_body', $body);
76 $body = $hookResults[1];
77 } else {
78 $body = _("Message not printable");
79 }
80
81 /* now we clean up the display a bit... */
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 // clean up everything else...
90 $subject = pf_clean_string($subject, $num_leading_spaces);
91 $from = pf_clean_string($from, $num_leading_spaces);
92 $date = pf_clean_string($date, $num_leading_spaces);
93
94 // end cleanup
95
96 $to = decodeHeader($to);
97 $cc = decodeHeader($cc);
98 $from = decodeHeader($from);
99 $subject = decodeHeader($subject);
100
101 // --end display setup--
102
103
104 /* --start browser output-- */
105 displayHtmlHeader( $subject, '', FALSE );
106
107 echo '<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#000000">'."\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', '<b>'._("From").':</b>&nbsp;', 'left' ,'','valign="top"') .
112 html_tag( 'td', $from, 'left' )
113 ) . "\n" .
114 html_tag( 'tr',
115 html_tag( 'td', '<b>'._("Subject").':</b>&nbsp;', 'left','','valign="top"' ) .
116 html_tag( 'td', $subject, 'left' )
117 ) . "\n" .
118 html_tag( 'tr',
119 html_tag( 'td', '<b>'._("Date").':</b>&nbsp;', 'left' ) .
120 html_tag( 'td', htmlspecialchars($date), 'left' )
121 ) . "\n" .
122 html_tag( 'tr',
123 html_tag( 'td', '<b>'._("To").':</b>&nbsp;', 'left','','valign="top"' ) .
124 html_tag( 'td', $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', '<b>'._("Cc").':</b>&nbsp;', 'left','','valign="top"' ) .
129 html_tag( 'td', $cc, 'left' )
130 );
131 }
132 /* body */
133 echo html_tag( 'tr',
134 html_tag( 'td', '<hr style="height: 1px;" /><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 /**
146 * Function should clean layout of printed messages when user
147 * enables "Printer Friendly Clean Display" option.
148 * For example: $string = pf_clean_string($string, 9);
149 *
150 * @param string unclean_string
151 * @param integer num_leading_spaces
152 * @return string
153 * @access private
154 */
155 function pf_clean_string ( $unclean_string, $num_leading_spaces ) {
156 global $data_dir, $username;
157 $unclean_string = str_replace('&nbsp;',' ',$unclean_string);
158 $wrap_at = getPref($data_dir, $username, 'wrap_at', 86);
159 $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */
160
161 $leading_spaces = '';
162 while ( strlen($leading_spaces) < $num_leading_spaces )
163 $leading_spaces .= ' ';
164
165 $clean_string = '';
166 while ( strlen($unclean_string) > $wrap_at )
167 {
168 $this_line = substr($unclean_string, 0, $wrap_at);
169 if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */
170 {
171 $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" ));
172 $clean_string .= $leading_spaces;
173 $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" ));
174 }
175 else
176 {
177 $i = strrpos( $this_line, ' ');
178 $clean_string .= substr( $this_line, 0, $i);
179 $clean_string .= "\n" . $leading_spaces;
180 $unclean_string = substr($unclean_string, 1+$i);
181 }
182 }
183 $clean_string .= $unclean_string;
184
185 return $clean_string;
186 } /* end pf_clean_string() function */
187
188 /* --end pf-specific functions */
189 ?>