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