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