f226cba7 |
1 | <?php |
2 | |
35586184 |
3 | /** |
4 | * printer_friendly_bottom.php |
5 | * |
35586184 |
6 | * with javascript on, it is the bottom frame of printer_friendly_main.php |
7 | * else, it is alone in a new window |
8 | * |
9 | * - this is the page that does all the work, really. |
10 | * |
4b5049de |
11 | * @copyright © 1999-2007 The SquirrelMail Project Team |
4b4abf93 |
12 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
30967a1e |
13 | * @version $Id$ |
8f6f9ba5 |
14 | * @package squirrelmail |
35586184 |
15 | */ |
16 | |
ebd2391c |
17 | /** This is the printer_friendly_bottom page */ |
18 | define('PAGE_NAME', 'printer_friendly_bottom'); |
19 | |
30967a1e |
20 | /** |
202bcbcc |
21 | * Include the SquirrelMail initialization file. |
30967a1e |
22 | */ |
202bcbcc |
23 | require('../include/init.php'); |
86725763 |
24 | |
25 | /* SquirrelMail required files. */ |
202bcbcc |
26 | require_once(SM_PATH . 'functions/imap_general.php'); |
27 | require_once(SM_PATH . 'functions/imap_messages.php'); |
28 | require_once(SM_PATH . 'functions/date.php'); |
29 | require_once(SM_PATH . 'functions/mime.php'); |
30 | require_once(SM_PATH . 'functions/url_parser.php'); |
f226cba7 |
31 | |
0b97a708 |
32 | /* get some of these globals */ |
f38b7cf0 |
33 | sqgetGlobalVar('passed_id', $passed_id, SQ_GET); |
34 | sqgetGlobalVar('mailbox', $mailbox, SQ_GET); |
4b6e1e59 |
35 | sqgetGlobalVar('messages', $messages, SQ_SESSION); |
d4538b25 |
36 | |
f38b7cf0 |
37 | if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) { |
d4538b25 |
38 | $passed_ent_id = ''; |
91e0dccc |
39 | } |
4c8986b4 |
40 | sqgetGlobalVar('show_html_default', $show_html_default, SQ_FORM); |
0b97a708 |
41 | /* end globals */ |
42 | |
906f7e9f |
43 | $imapConnection = sqimap_login($username, false, $imapServerAddress, $imapPort, 0); |
d4538b25 |
44 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox); |
45 | if (isset($messages[$mbx_response['UIDVALIDITY']][$passed_id])) { |
7f6171be |
46 | $message = $messages[$mbx_response['UIDVALIDITY']][$passed_id]; |
d4538b25 |
47 | } else { |
48 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
49 | } |
50 | if ($passed_ent_id) { |
7f6171be |
51 | $message = $message->getEntity($passed_ent_id); |
5caf2d0c |
52 | } |
32f4e318 |
53 | |
54 | /* --start display setup-- */ |
55 | |
91e0dccc |
56 | $rfc822_header = $message->rfc822_header; |
32f4e318 |
57 | /* From and Date are usually fine as they are... */ |
a91189d6 |
58 | $from = $rfc822_header->getAddr_s('from'); |
3aaa3214 |
59 | $date = getLongDateString($rfc822_header->date, $rfc822_header->date_unparsed); |
a91189d6 |
60 | $subject = trim($rfc822_header->subject); |
32f4e318 |
61 | |
62 | /* we can clean these up if the list is too long... */ |
a91189d6 |
63 | $cc = $rfc822_header->getAddr_s('cc'); |
64 | $to = $rfc822_header->getAddr_s('to'); |
32f4e318 |
65 | |
c8d6aef3 |
66 | if ($show_html_default == 1) { |
67 | $ent_ar = $message->findDisplayEntity(array()); |
68 | } else { |
69 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
70 | } |
18680db6 |
71 | $body = ''; |
72 | if ($ent_ar[0] != '') { |
73 | for ($i = 0; $i < count($ent_ar); $i++) { |
a2bfcbce |
74 | $body .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox, TRUE); |
be7a2943 |
75 | if ($i < count($ent_ar)-1) { |
76 | $body .= '<hr />'; |
77 | } |
18680db6 |
78 | } |
6e515418 |
79 | /* Note that $body is passed to this hook (and modified) by reference as of 1.5.2 */ |
80 | do_hook('message_body', $body); |
32f4e318 |
81 | } else { |
18680db6 |
82 | $body = _("Message not printable"); |
32f4e318 |
83 | } |
3bbf5974 |
84 | |
2b0f4faf |
85 | /* now we clean up the display a bit... */ |
91e0dccc |
86 | |
2b0f4faf |
87 | $num_leading_spaces = 9; // nine leading spaces for indentation |
f226cba7 |
88 | |
d3c4749f |
89 | // sometimes I see ',,' instead of ',' separating addresses *shrug* |
2b0f4faf |
90 | $cc = pf_clean_string(str_replace(',,', ',', $cc), $num_leading_spaces); |
91 | $to = pf_clean_string(str_replace(',,', ',', $to), $num_leading_spaces); |
f226cba7 |
92 | |
2b0f4faf |
93 | // clean up everything else... |
94 | $subject = pf_clean_string($subject, $num_leading_spaces); |
95 | $from = pf_clean_string($from, $num_leading_spaces); |
96 | $date = pf_clean_string($date, $num_leading_spaces); |
f226cba7 |
97 | |
2b0f4faf |
98 | // end cleanup |
18680db6 |
99 | |
a91189d6 |
100 | $to = decodeHeader($to); |
101 | $cc = decodeHeader($cc); |
102 | $from = decodeHeader($from); |
103 | $subject = decodeHeader($subject); |
104 | |
32f4e318 |
105 | // --end display setup-- |
f226cba7 |
106 | |
f226cba7 |
107 | |
32f4e318 |
108 | /* --start browser output-- */ |
be7a2943 |
109 | displayHtmlHeader($subject); |
f226cba7 |
110 | |
be7a2943 |
111 | $aHeaders = array(); |
112 | $aHeaders[ _("From") ] = $from; |
113 | $aHeaders[ _("Subject") ] = $subject; |
114 | $aHeaders[ _("Date") ] = htmlspecialchars($date); |
115 | $aHeaders[ _("To") ] = $to; |
116 | $aHeaders[ _("Cc") ] = $cc; |
5c4ff7bf |
117 | |
be7a2943 |
118 | $attachments_ar = buildAttachmentArray($message, $ent_ar, $mailbox, $passed_id); |
119 | |
120 | $oTemplate->assign('headers', $aHeaders); |
121 | $oTemplate->assign('message_body', $body); |
122 | $oTemplate->assign('attachments', $attachments_ar); |
1c663478 |
123 | |
be7a2943 |
124 | $oTemplate->display('printer_friendly_bottom.tpl'); |
5c4ff7bf |
125 | $oTemplate->display('footer.tpl'); |
f226cba7 |
126 | |
32f4e318 |
127 | /* --end browser output-- */ |
f226cba7 |
128 | |
f226cba7 |
129 | |
32f4e318 |
130 | /* --start pf-specific functions-- */ |
f226cba7 |
131 | |
b5cd24a8 |
132 | /** |
133 | * Function should clean layout of printed messages when user |
134 | * enables "Printer Friendly Clean Display" option. |
9dbdf00b |
135 | * For example: $string = pf_clean_string($string, 9); |
b5cd24a8 |
136 | * |
137 | * @param string unclean_string |
138 | * @param integer num_leading_spaces |
139 | * @return string |
91e0dccc |
140 | * @access private |
b5cd24a8 |
141 | */ |
f226cba7 |
142 | function pf_clean_string ( $unclean_string, $num_leading_spaces ) { |
143 | global $data_dir, $username; |
a91189d6 |
144 | $unclean_string = str_replace(' ',' ',$unclean_string); |
f6d2358f |
145 | $wrap_at = getPref($data_dir, $username, 'wrap_at', 86); |
32f4e318 |
146 | $wrap_at = $wrap_at - $num_leading_spaces; /* header stuff */ |
f226cba7 |
147 | |
148 | $leading_spaces = ''; |
149 | while ( strlen($leading_spaces) < $num_leading_spaces ) |
150 | $leading_spaces .= ' '; |
151 | |
152 | $clean_string = ''; |
153 | while ( strlen($unclean_string) > $wrap_at ) |
154 | { |
155 | $this_line = substr($unclean_string, 0, $wrap_at); |
32f4e318 |
156 | if ( strrpos( $this_line, "\n" ) ) /* this should NEVER happen with anything but the $body */ |
f226cba7 |
157 | { |
158 | $clean_string .= substr( $this_line, 0, strrpos( $this_line, "\n" )); |
159 | $clean_string .= $leading_spaces; |
160 | $unclean_string = substr($unclean_string, strrpos( $this_line, "\n" )); |
161 | } |
162 | else |
163 | { |
134e4174 |
164 | $i = strrpos( $this_line, ' '); |
165 | $clean_string .= substr( $this_line, 0, $i); |
166 | $clean_string .= "\n" . $leading_spaces; |
167 | $unclean_string = substr($unclean_string, 1+$i); |
168 | } |
f226cba7 |
169 | } |
170 | $clean_string .= $unclean_string; |
171 | |
172 | return $clean_string; |
32f4e318 |
173 | } /* end pf_clean_string() function */ |