59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * read_body.php |
5 | * |
76911253 |
6 | * Copyright (c) 1999-2003 The SquirrelMail Project Team |
35586184 |
7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
8 | * |
9 | * This file is used for reading the msgs array and displaying |
10 | * the resulting emails in the right frame. |
11 | * |
12 | * $Id$ |
a07cd1a4 |
13 | */ |
35586184 |
14 | |
86725763 |
15 | /* Path for SquirrelMail required files. */ |
16 | define('SM_PATH','../'); |
17 | |
18 | /* SquirrelMail required files. */ |
08185f2a |
19 | require_once(SM_PATH . 'include/validate.php'); |
8650e9e1 |
20 | require_once(SM_PATH . 'functions/global.php'); |
86725763 |
21 | require_once(SM_PATH . 'functions/imap.php'); |
22 | require_once(SM_PATH . 'functions/mime.php'); |
23 | require_once(SM_PATH . 'functions/date.php'); |
24 | require_once(SM_PATH . 'functions/url_parser.php'); |
25 | require_once(SM_PATH . 'functions/html.php'); |
e95c04ec |
26 | require_once(SM_PATH . 'functions/global.php'); |
38c944cc |
27 | |
a07cd1a4 |
28 | /** |
1fca12b5 |
29 | * Given an IMAP message id number, this will look it up in the cached |
30 | * and sorted msgs array and return the index. Used for finding the next |
31 | * and previous messages. |
32 | * |
33 | * @return the index of the next valid message from the array |
34 | */ |
c615b1da |
35 | function findNextMessage($passed_id) { |
36 | global $msort, $msgs, $sort, |
cf710efe |
37 | $thread_sort_messages, $allow_server_sort, |
60a3e687 |
38 | $server_sort_array; |
2728fa19 |
39 | if (!is_array($server_sort_array)) { |
40 | $thread_sort_messages = 0; |
794d59c0 |
41 | $allow_server_sort = FALSE; |
2728fa19 |
42 | } |
a07cd1a4 |
43 | $result = -1; |
c615b1da |
44 | if ($thread_sort_messages || $allow_server_sort) { |
d9c1dccc |
45 | $count = count($server_sort_array) - 1; |
46 | foreach($server_sort_array as $key=>$value) { |
c615b1da |
47 | if ($passed_id == $value) { |
d9c1dccc |
48 | if ($key == $count) { |
60a3e687 |
49 | break; |
50 | } |
1fca12b5 |
51 | $result = $server_sort_array[$key + 1]; |
60a3e687 |
52 | break; |
789b4d79 |
53 | } |
60a3e687 |
54 | } |
d9c1dccc |
55 | } else { |
7e818af0 |
56 | if (is_array($msort)) { |
57 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
58 | if ($passed_id == $msgs[$key]['ID']) { |
59 | next($msort); |
60 | $key = key($msort); |
61 | if (isset($key)){ |
62 | $result = $msgs[$key]['ID']; |
63 | break; |
d9c1dccc |
64 | } |
1fca12b5 |
65 | } |
10f0ce72 |
66 | } |
67 | } |
10f0ce72 |
68 | } |
d9c1dccc |
69 | return $result; |
a07cd1a4 |
70 | } |
71 | |
a07cd1a4 |
72 | /** returns the index of the previous message from the array. */ |
c615b1da |
73 | function findPreviousMessage($numMessages, $passed_id) { |
74 | global $msort, $sort, $msgs, |
75 | $thread_sort_messages, |
60a3e687 |
76 | $allow_server_sort, $server_sort_array; |
a07cd1a4 |
77 | $result = -1; |
2728fa19 |
78 | if (!is_array($server_sort_array)) { |
79 | $thread_sort_messages = 0; |
794d59c0 |
80 | $allow_server_sort = FALSE; |
2728fa19 |
81 | } |
c615b1da |
82 | if ($thread_sort_messages || $allow_server_sort ) { |
d9c1dccc |
83 | foreach($server_sort_array as $key=>$value) { |
c615b1da |
84 | if ($passed_id == $value) { |
60a3e687 |
85 | if ($key == 0) { |
60a3e687 |
86 | break; |
87 | } |
d9c1dccc |
88 | $result = $server_sort_array[$key - 1]; |
60a3e687 |
89 | break; |
789b4d79 |
90 | } |
60a3e687 |
91 | } |
d9c1dccc |
92 | } else { |
7e818af0 |
93 | if (is_array($msort)) { |
94 | for (reset($msort); ($key = key($msort)), (isset($key)); next($msort)) { |
95 | if ($passed_id == $msgs[$key]['ID']) { |
96 | prev($msort); |
97 | $key = key($msort); |
98 | if (isset($key)) { |
99 | $result = $msgs[$key]['ID']; |
100 | break; |
d9c1dccc |
101 | } |
10f0ce72 |
102 | } |
103 | } |
10f0ce72 |
104 | } |
a07cd1a4 |
105 | } |
d9c1dccc |
106 | return $result; |
a07cd1a4 |
107 | } |
10f0ce72 |
108 | |
a07cd1a4 |
109 | /** |
1fca12b5 |
110 | * Displays a link to a page where the message is displayed more |
111 | * "printer friendly". |
112 | */ |
c615b1da |
113 | function printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color) { |
114 | global $javascript_on; |
a07cd1a4 |
115 | |
c615b1da |
116 | $params = '?passed_ent_id=' . $passed_ent_id . |
c2324b26 |
117 | '&mailbox=' . urlencode($mailbox) . |
118 | '&passed_id=' . $passed_id; |
10f0ce72 |
119 | |
a07cd1a4 |
120 | $print_text = _("View Printable Version"); |
10f0ce72 |
121 | |
c615b1da |
122 | $result = ''; |
a07cd1a4 |
123 | /* Output the link. */ |
124 | if ($javascript_on) { |
9f42bfc8 |
125 | $result = '<script language="javascript" type="text/javascript">' . "\n" . |
126 | '<!--' . "\n" . |
127 | " function printFormat() {\n" . |
128 | ' window.open("../src/printer_friendly_main.php' . |
129 | $params . '","Print","width=800,height=600");' . "\n". |
130 | " }\n" . |
131 | "// -->\n" . |
132 | "</script>\n" . |
133 | "<a href=\"javascript:printFormat();\">$print_text</a>\n"; |
a07cd1a4 |
134 | } else { |
c2324b26 |
135 | $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' . |
9f42bfc8 |
136 | "$params\">$print_text</a>\n"; |
a07cd1a4 |
137 | } |
d9c1dccc |
138 | return $result; |
a07cd1a4 |
139 | } |
140 | |
d9c1dccc |
141 | function ServerMDNSupport($read) { |
f69feefe |
142 | /* escaping $ doesn't work -> \x36 */ |
d9c1dccc |
143 | $ret = preg_match('/(\x36MDNSent|\\\*)/i', $read); |
144 | return $ret; |
57257333 |
145 | } |
146 | |
fc224f68 |
147 | function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) { |
e95c04ec |
148 | global $username, $attachment_dir, |
fc224f68 |
149 | $version, $attachments, $squirrelmail_language, $default_charset, |
d9c1dccc |
150 | $languages, $useSendmail, $domain, $sent_folder, |
151 | $popuser, $data_dir, $username; |
57257333 |
152 | |
e95c04ec |
153 | sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER); |
0b97a708 |
154 | |
38bca81c |
155 | $header = $message->rfc822_header; |
57257333 |
156 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
157 | |
fc224f68 |
158 | $rfc822_header = new Rfc822Header(); |
d9c1dccc |
159 | $content_type = new ContentType('multipart/report'); |
fc224f68 |
160 | $content_type->properties['report-type']='disposition-notification'; |
d9c1dccc |
161 | |
fc224f68 |
162 | set_my_charset(); |
163 | if ($default_charset) { |
d9c1dccc |
164 | $content_type->properties['charset']=$default_charset; |
fc224f68 |
165 | } |
166 | $rfc822_header->content_type = $content_type; |
167 | $rfc822_header->to[] = $header->dnt; |
9549758e |
168 | $rfc822_header->subject = _("Read:") . ' ' . decodeHeader($header->subject); |
fc224f68 |
169 | |
170 | |
171 | $reply_to = ''; |
172 | if (isset($identity) && $identity != 'default') { |
173 | $from_mail = getPref($data_dir, $username, |
d9c1dccc |
174 | 'email_address' . $identity); |
fc224f68 |
175 | $full_name = getPref($data_dir, $username, |
d9c1dccc |
176 | 'full_name' . $identity); |
fc224f68 |
177 | $from_addr = '"'.$full_name.'" <'.$from_mail.'>'; |
d9c1dccc |
178 | $reply_to = getPref($data_dir, $username, |
179 | 'reply_to' . $identity); |
fc224f68 |
180 | } else { |
181 | $from_mail = getPref($data_dir, $username, 'email_address'); |
182 | $full_name = getPref($data_dir, $username, 'full_name'); |
183 | $from_addr = '"'.$full_name.'" <'.$from_mail.'>'; |
d9c1dccc |
184 | $reply_to = getPref($data_dir, $username,'reply_to'); |
fc224f68 |
185 | } |
186 | if (!$from_addr) { |
187 | $from_addr = "$popuser@$domain"; |
188 | $from_mail = $from_addr; |
189 | } |
190 | $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); |
191 | if ($reply_to) { |
192 | $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); |
193 | } |
d9c1dccc |
194 | |
57257333 |
195 | // part 1 (RFC2298) |
57257333 |
196 | $senton = getLongDateString( $header->date ); |
197 | $to_array = $header->to; |
198 | $to = ''; |
199 | foreach ($to_array as $line) { |
af568a82 |
200 | $to .= ' '.$line->getAddress(); |
57257333 |
201 | } |
57257333 |
202 | $now = getLongDateString( time() ); |
78db1583 |
203 | set_my_charset(); |
46bb8da8 |
204 | $body = _("Your message") . "\r\n\r\n" . |
9549758e |
205 | "\t" . _("To:") . ' ' . decodeHeader($to) . "\r\n" . |
206 | "\t" . _("Subject:") . ' ' . decodeHeader($header->subject) . "\r\n" . |
46bb8da8 |
207 | "\t" . _("Sent:") . ' ' . $senton . "\r\n" . |
208 | "\r\n" . |
209 | sprintf( _("Was displayed on %s"), $now ); |
f69feefe |
210 | |
fc224f68 |
211 | $special_encoding = ''; |
212 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
213 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) { |
6fbd125b |
214 | $body = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $body); |
d9c1dccc |
215 | if (strtolower($default_charset) == 'iso-2022-jp') { |
216 | if (mb_detect_encoding($body) == 'ASCII') { |
217 | $special_encoding = '8bit'; |
218 | } else { |
219 | $body = mb_convert_encoding($body, 'JIS'); |
220 | $special_encoding = '7bit'; |
221 | } |
222 | } |
6fbd125b |
223 | } |
fc224f68 |
224 | $part1 = new Message(); |
225 | $part1->setBody($body); |
226 | $mime_header = new MessageHeader; |
227 | $mime_header->type0 = 'text'; |
228 | $mime_header->type1 = 'plain'; |
229 | if ($special_encoding) { |
230 | $mime_header->encoding = $special_encoding; |
d9c1dccc |
231 | } else { |
fc224f68 |
232 | $mime_header->encoding = 'us-ascii'; |
233 | } |
234 | if ($default_charset) { |
235 | $mime_header->parameters['charset'] = $default_charset; |
236 | } |
237 | $part1->mime_header = $mime_header; |
238 | |
57257333 |
239 | // part2 (RFC2298) |
d9c1dccc |
240 | $original_recipient = $to; |
57257333 |
241 | $original_message_id = $header->message_id; |
242 | |
fc224f68 |
243 | $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n"; |
57257333 |
244 | if ($original_recipient != '') { |
fc224f68 |
245 | $report .= "Original-Recipient : $original_recipient\r\n"; |
57257333 |
246 | } |
247 | $final_recipient = $sender; |
fc224f68 |
248 | $report .= "Final-Recipient: rfc822; $final_recipient\r\n" . |
57257333 |
249 | "Original-Message-ID : $original_message_id\r\n" . |
250 | "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; |
251 | |
fc224f68 |
252 | $part2 = new Message(); |
253 | $part2->setBody($report); |
254 | $mime_header = new MessageHeader; |
255 | $mime_header->type0 = 'message'; |
256 | $mime_header->type1 = 'disposition-notification'; |
257 | $mime_header->encoding = 'us-ascii'; |
258 | $part2->mime_header = $mime_header; |
259 | |
260 | $composeMessage = new Message(); |
261 | $composeMessage->rfc822_header = $rfc822_header; |
262 | $composeMessage->addEntity($part1); |
263 | $composeMessage->addEntity($part2); |
264 | |
265 | |
d9c1dccc |
266 | if ($useSendmail) { |
267 | require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); |
268 | global $sendmail_path; |
269 | $deliver = new Deliver_SendMail(); |
270 | $stream = $deliver->initStream($composeMessage,$sendmail_path); |
fc224f68 |
271 | } else { |
d9c1dccc |
272 | require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); |
273 | $deliver = new Deliver_SMTP(); |
47a29326 |
274 | global $smtpServerAddress, $smtpPort, $smtp_auth_mech, $pop_before_smtp; |
275 | if ($smtp_auth_mech == 'none') { |
276 | $user = ''; |
277 | $pass = ''; |
278 | } else { |
d9c1dccc |
279 | global $key, $onetimepad; |
280 | $user = $username; |
281 | $pass = OneTimePadDecrypt($key, $onetimepad); |
d9c1dccc |
282 | } |
283 | $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; |
284 | $stream = $deliver->initStream($composeMessage,$domain,0, |
70ce2218 |
285 | $smtpServerAddress, $smtpPort, $user, $pass, $authPop); |
d9c1dccc |
286 | } |
287 | $success = false; |
fc224f68 |
288 | if ($stream) { |
d9c1dccc |
289 | $length = $deliver->mail($composeMessage, $stream); |
290 | $success = $deliver->finalizeStream($stream); |
fc224f68 |
291 | } |
d9c1dccc |
292 | if (!$success) { |
00ac2f42 |
293 | $msg = $deliver->dlv_msg . '<br>' . |
294 | _("Server replied: ") . $deliver->dlv_ret_nr . ' '. |
295 | $deliver->dlv_server_msg; |
d9c1dccc |
296 | require_once(SM_PATH . 'functions/display_messages.php'); |
fc224f68 |
297 | plain_error_message($msg, $color); |
298 | } else { |
299 | unset ($deliver); |
d9c1dccc |
300 | if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) { |
301 | sqimap_append ($imapConnection, $sent_folder, $length); |
302 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
303 | $imap_deliver = new Deliver_IMAP(); |
304 | $imap_deliver->mail($composeMessage, $imapConnection); |
305 | sqimap_append_done ($imapConnection); |
306 | unset ($imap_deliver); |
307 | } |
308 | } |
309 | return $success; |
57257333 |
310 | } |
311 | |
d9c1dccc |
312 | function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id, $uid_support) { |
313 | $sg = $set?'+':'-'; |
314 | $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)'; |
0892e427 |
315 | $read = sqimap_run_command ($imapConnection, $cmd, true, $response, |
507d14ea |
316 | $readmessage, $uid_support); |
57257333 |
317 | } |
318 | |
319 | function ClearAttachments() { |
d9c1dccc |
320 | global $username, $attachments, $attachment_dir; |
321 | |
322 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
323 | |
324 | $rem_attachments = array(); |
6191bcb1 |
325 | if (isset($attachments)) { |
326 | foreach ($attachments as $info) { |
327 | if ($info['session'] == -1) { |
328 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
329 | if (file_exists($attached_file)) { |
330 | unlink($attached_file); |
331 | } |
332 | } else { |
333 | $rem_attachments[] = $info; |
334 | } |
335 | } |
d9c1dccc |
336 | } |
337 | $attachments = $rem_attachments; |
57257333 |
338 | } |
339 | |
4d0cd98b |
340 | function formatRecipientString($recipients, $item ) { |
d9c1dccc |
341 | global $show_more_cc, $show_more, $show_more_bcc, |
342 | $PHP_SELF; |
4d0cd98b |
343 | |
d9c1dccc |
344 | $string = ''; |
38c944cc |
345 | if ((is_array($recipients)) && (isset($recipients[0]))) { |
d9c1dccc |
346 | $show = false; |
38c944cc |
347 | |
348 | if ($item == 'to') { |
d9c1dccc |
349 | if ($show_more) { |
350 | $show = true; |
351 | $url = set_url_var($PHP_SELF, 'show_more',0); |
352 | } else { |
353 | $url = set_url_var($PHP_SELF, 'show_more',1); |
354 | } |
355 | } else if ($item == 'cc') { |
356 | if ($show_more_cc) { |
357 | $show = true; |
358 | $url = set_url_var($PHP_SELF, 'show_more_cc',0); |
359 | } else { |
360 | $url = set_url_var($PHP_SELF, 'show_more_cc',1); |
361 | } |
362 | } else if ($item == 'bcc') { |
363 | if ($show_more_bcc) { |
364 | $show = true; |
365 | $url = set_url_var($PHP_SELF, 'show_more_bcc',0); |
366 | } else { |
367 | $url = set_url_var($PHP_SELF, 'show_more_bcc',1); |
368 | } |
369 | } |
370 | |
371 | $cnt = count($recipients); |
372 | foreach($recipients as $r) { |
a91189d6 |
373 | $add = decodeHeader($r->getAddress(true)); |
d9c1dccc |
374 | if ($string) { |
375 | $string .= '<BR>' . $add; |
376 | } else { |
377 | $string = $add; |
378 | if ($cnt > 1) { |
38c944cc |
379 | $string .= ' (<A HREF="'.$url; |
d9c1dccc |
380 | if ($show) { |
381 | $string .= '">'._("less").'</A>)'; |
382 | } else { |
383 | $string .= '">'._("more").'</A>)'; |
384 | break; |
385 | } |
386 | } |
387 | } |
1fca12b5 |
388 | } |
4d0cd98b |
389 | } |
c615b1da |
390 | return $string; |
391 | } |
392 | |
af568a82 |
393 | function formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, |
394 | $color, $FirstTimeSee) { |
a94c1db1 |
395 | global $msn_user_support, $default_use_mdn, $default_use_priority, |
77836429 |
396 | $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on, |
397 | $squirrelmail_language; |
38bca81c |
398 | |
d9c1dccc |
399 | $header = $message->rfc822_header; |
400 | $env = array(); |
a91189d6 |
401 | $env[_("Subject")] = decodeHeader($header->subject); |
d9c1dccc |
402 | $from_name = $header->getAddr_s('from'); |
403 | if (!$from_name) { |
404 | $from_name = $header->getAddr_s('sender'); |
405 | if (!$from_name) { |
406 | $from_name = _("Unknown sender"); |
407 | } |
408 | } |
a91189d6 |
409 | $env[_("From")] = decodeHeader($from_name); |
d9c1dccc |
410 | $env[_("Date")] = getLongDateString($header->date); |
411 | $env[_("To")] = formatRecipientString($header->to, "to"); |
412 | $env[_("Cc")] = formatRecipientString($header->cc, "cc"); |
413 | $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc"); |
414 | if ($default_use_priority) { |
0e8006dc |
415 | $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority)); |
d9c1dccc |
416 | } |
417 | if ($show_xmailer_default) { |
a91189d6 |
418 | $env[_("Mailer")] = decodeHeader($header->xmailer); |
d9c1dccc |
419 | } |
420 | if ($default_use_mdn) { |
421 | if ($mdn_user_support) { |
422 | if ($header->dnt) { |
423 | if ($message->is_mdnsent) { |
424 | $env[_("Read receipt")] = _("send"); |
425 | } else { |
426 | $env[_("Read receipt")] = _("requested"); |
8e1d27aa |
427 | if (!(handleAsSent($mailbox) || |
d9c1dccc |
428 | $message->is_deleted || |
429 | $passed_ent_id)) { |
430 | $mdn_url = $PHP_SELF . '&sendreceipt=1'; |
431 | if ($FirstTimeSee && $javascript_on) { |
432 | $script = '<script language="JavaScript" type="text/javascript">' . "\n"; |
433 | $script .= '<!--'. "\n"; |
434 | $script .= 'if(window.confirm("' . |
435 | _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") . |
436 | '")) { '."\n" . |
437 | ' sendMDN()'. |
438 | '}' . "\n"; |
439 | $script .= '// -->'. "\n"; |
440 | $script .= '</script>'. "\n"; |
441 | echo $script; |
442 | } |
443 | $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' . |
444 | _("Send read receipt now") . ']</a>'; |
445 | } |
446 | } |
447 | } |
448 | } |
449 | } |
c615b1da |
450 | |
a94c1db1 |
451 | $s = '<TABLE WIDTH="100%" CELLPADDING="0" CELLSPACING="2" BORDER="0"'; |
0e02d604 |
452 | $s .= ' ALIGN="center" BGCOLOR="'.$color[0].'">'; |
d9c1dccc |
453 | foreach ($env as $key => $val) { |
454 | if ($val) { |
455 | $s .= '<TR>'; |
456 | $s .= html_tag('TD', '<B>' . $key . ': </B>', 'RIGHT', '', 'VALIGN="TOP" WIDTH="20%"') . "\n"; |
457 | $s .= html_tag('TD', $val, 'left', '', 'VALIGN="TOP" WIDTH="80%"') . "\n"; |
458 | $s .= '</TR>'; |
459 | } |
460 | } |
a94c1db1 |
461 | echo '<TABLE BGCOLOR="'.$color[9].'" WIDTH="100%" CELLPADDING="1"'. |
feb5ec1b |
462 | ' CELLSPACING="0" BORDER="0" ALIIGN="center">'."\n"; |
a94c1db1 |
463 | echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'. |
464 | $color[4].'"></TD></TR><TR><TD align=center>'."\n"; |
d9c1dccc |
465 | echo $s; |
00ac2f42 |
466 | do_hook('read_body_header'); |
d9c1dccc |
467 | formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color); |
468 | echo '</TABLE>'; |
a94c1db1 |
469 | echo '</TD></TR><TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'.$color[4].'"></TD></TR>'."\n"; |
feb5ec1b |
470 | echo '</TABLE>'; |
d9c1dccc |
471 | } |
c615b1da |
472 | |
7172cad7 |
473 | function formatMenubar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response) { |
a94c1db1 |
474 | global $base_uri, $draft_folder, $where, $what, $color, $sort, |
d62c4938 |
475 | $startMessage, $PHP_SELF, $save_as_draft, |
d9c1dccc |
476 | $enable_forward_as_attachment; |
c615b1da |
477 | |
d9c1dccc |
478 | $topbar_delimiter = ' | '; |
479 | $urlMailbox = urlencode($mailbox); |
a94c1db1 |
480 | $s = '<table width="100%" cellpadding="3" cellspacing="0" align="center"'. |
98fb28fd |
481 | ' border="0" bgcolor="'.$color[9].'"><tr>' . |
482 | html_tag( 'td', '', 'left', '', 'width="33%"' ) . '<small>'; |
e55c441a |
483 | |
d9c1dccc |
484 | $msgs_url = $base_uri . 'src/'; |
485 | if (isset($where) && isset($what)) { |
486 | $msgs_url .= 'search.php?where=' . urlencode($where) . |
487 | '&what=' . urlencode($what) . '&mailbox=' . $urlMailbox; |
488 | $msgs_str = _("Search results"); |
489 | } else { |
490 | $msgs_url .= 'right_main.php?sort=' . $sort . '&startMessage=' . |
491 | $startMessage . '&mailbox=' . $urlMailbox; |
492 | $msgs_str = _("Message List"); |
493 | } |
e55c441a |
494 | $s .= '<a href="' . $msgs_url . '">' . $msgs_str . '</a>'; |
d9c1dccc |
495 | |
496 | $delete_url = $base_uri . 'src/delete_message.php?mailbox=' . $urlMailbox . |
497 | '&message=' . $passed_id . '&'; |
498 | if (!(isset($passed_ent_id) && $passed_ent_id)) { |
499 | if ($where && $what) { |
500 | $delete_url .= 'where=' . urlencode($where) . '&what=' . urlencode($what); |
501 | } else { |
502 | $delete_url .= 'sort=' . $sort . '&startMessage=' . $startMessage; |
503 | } |
9f42bfc8 |
504 | $s .= $topbar_delimiter; |
e55c441a |
505 | $s .= '<a href="' . $delete_url . '">' . _("Delete") . '</a>'; |
d9c1dccc |
506 | } |
c615b1da |
507 | |
d62c4938 |
508 | $comp_uri = 'src/compose.php' . |
d9c1dccc |
509 | '?passed_id=' . $passed_id . |
510 | '&mailbox=' . $urlMailbox . |
511 | (isset($passed_ent_id)?'&passed_ent_id='.$passed_ent_id:''); |
2ffa3f57 |
512 | |
d9c1dccc |
513 | if (($mailbox == $draft_folder) && ($save_as_draft)) { |
514 | $comp_alt_uri = $comp_uri . '&action=draft'; |
515 | $comp_alt_string = _("Resume Draft"); |
8e1d27aa |
516 | } else if (handleAsSent($mailbox)) { |
d9c1dccc |
517 | $comp_alt_uri = $comp_uri . '&action=edit_as_new'; |
518 | $comp_alt_string = _("Edit Message as New"); |
519 | } |
520 | if (isset($comp_alt_uri)) { |
e55c441a |
521 | $s .= $topbar_delimiter; |
d62c4938 |
522 | $s .= makeComposeLink($comp_alt_uri, $comp_alt_string); |
d9c1dccc |
523 | } |
2ffa3f57 |
524 | |
e55c441a |
525 | $s .= '</small></td><td align="center" width="33%"><small>'; |
526 | |
d9c1dccc |
527 | if (!(isset($where) && isset($what)) && !$passed_ent_id) { |
528 | $prev = findPreviousMessage($mbx_response['EXISTS'], $passed_id); |
529 | $next = findNextMessage($passed_id); |
530 | if ($prev != -1) { |
531 | $uri = $base_uri . 'src/read_body.php?passed_id='.$prev. |
532 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
533 | '&startMessage='.$startMessage.'&show_more=0'; |
e55c441a |
534 | $s .= '<a href="'.$uri.'">'._("Previous").'</a>'; |
d9c1dccc |
535 | } else { |
e55c441a |
536 | $s .= _("Previous"); |
d9c1dccc |
537 | } |
e55c441a |
538 | $s .= $topbar_delimiter; |
d9c1dccc |
539 | if ($next != -1) { |
540 | $uri = $base_uri . 'src/read_body.php?passed_id='.$next. |
541 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
542 | '&startMessage='.$startMessage.'&show_more=0'; |
e55c441a |
543 | $s .= '<a href="'.$uri.'">'._("Next").'</a>'; |
d9c1dccc |
544 | } else { |
e55c441a |
545 | $s .= _("Next"); |
d9c1dccc |
546 | } |
547 | } else if (isset($passed_ent_id) && $passed_ent_id) { |
548 | /* code for navigating through attached message/rfc822 messages */ |
549 | $url = set_url_var($PHP_SELF, 'passed_ent_id',0); |
e55c441a |
550 | $s .= '<a href="'.$url.'">'._("View Message").'</a>'; |
70bdc740 |
551 | $entities = array(); |
552 | $entity_count = array(); |
553 | $c = 0; |
f2f03410 |
554 | |
70bdc740 |
555 | foreach($message->parent->entities as $ent) { |
9f42bfc8 |
556 | if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') { |
557 | $c++; |
558 | $entity_count[$c] = $ent->entity_id; |
559 | $entities[$ent->entity_id] = $c; |
560 | } |
70bdc740 |
561 | } |
562 | $prev_link = _("Previous"); |
563 | $next_link = _("Next"); |
564 | if($entities[$passed_ent_id] > 1) { |
565 | $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1]; |
566 | $prev_link = '<a href="' |
567 | . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id) |
568 | . '">' . $prev_link . '</a>'; |
569 | } |
570 | if($entities[$passed_ent_id] < $c) { |
571 | $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1]; |
572 | $next_link = '<a href="' |
573 | . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id) |
574 | . '">' . $next_link . '</a>'; |
575 | } |
e55c441a |
576 | $s .= $topbar_delimiter . $prev_link; |
d9c1dccc |
577 | $par_ent_id = $message->parent->entity_id; |
578 | if ($par_ent_id) { |
579 | $par_ent_id = substr($par_ent_id,0,-2); |
e55c441a |
580 | $s .= $topbar_delimiter; |
d9c1dccc |
581 | $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id); |
e55c441a |
582 | $s .= '<a href="'.$url.'">'._("Up").'</a>'; |
d9c1dccc |
583 | } |
e55c441a |
584 | $s .= $topbar_delimiter . $next_link; |
d9c1dccc |
585 | } |
c615b1da |
586 | |
98fb28fd |
587 | $s .= '</small></td>' . "\n" . |
588 | html_tag( 'td', '', 'right', '', 'width="33%" nowrap' ) . '<small>'; |
d9c1dccc |
589 | $comp_action_uri = $comp_uri . '&action=forward'; |
d62c4938 |
590 | $s .= makeComposeLink($comp_action_uri, _("Forward")); |
c615b1da |
591 | |
d9c1dccc |
592 | if ($enable_forward_as_attachment) { |
593 | $comp_action_uri = $comp_uri . '&action=forward_as_attachment'; |
e55c441a |
594 | $s .= $topbar_delimiter; |
d62c4938 |
595 | $s .= makeComposeLink($comp_action_uri, _("Forward as Attachment")); |
d9c1dccc |
596 | } |
a128c967 |
597 | |
a91189d6 |
598 | $comp_action_uri = $comp_uri . '&action=reply'; |
e55c441a |
599 | $s .= $topbar_delimiter; |
d62c4938 |
600 | $s .= makeComposeLink($comp_action_uri, _("Reply")); |
d9c1dccc |
601 | |
602 | $comp_action_uri = $comp_uri . '&action=reply_all'; |
9f42bfc8 |
603 | $s .= $topbar_delimiter; |
d62c4938 |
604 | $s .= makeComposeLink($comp_action_uri, _("Reply All")); |
e55c441a |
605 | $s .= '</small></td></tr></table>'; |
d62c4938 |
606 | do_hook('read_body_menu_top'); |
e55c441a |
607 | echo $s; |
d62c4938 |
608 | do_hook('read_body_menu_bottom'); |
c615b1da |
609 | } |
610 | |
611 | function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) { |
a94c1db1 |
612 | global $base_uri; |
fe369c70 |
613 | |
d9c1dccc |
614 | $urlMailbox = urlencode($mailbox); |
e95c04ec |
615 | sqgetGlobalVar('QUERY_STRING', $query_string, SQ_SERVER); |
616 | $url = $base_uri.'src/view_header.php?'.$query_string; |
d9c1dccc |
617 | |
a94c1db1 |
618 | $s = "<TR>\n" . |
98fb28fd |
619 | html_tag( 'td', '', 'right', '', 'VALIGN="MIDDLE" WIDTH="20%"' ) . '<B>' . _("Options") . ": </B></TD>\n" . |
620 | html_tag( 'td', '', 'left', '', 'VALIGN="MIDDLE" WIDTH="80%"' ) . '<SMALL>' . |
d9c1dccc |
621 | '<a href="'.$url.'">'._("View Full Header").'</a>'; |
622 | |
623 | /* Output the printer friendly link if we are in subtle mode. */ |
624 | $s .= ' | ' . |
625 | printer_friendly_link($mailbox, $passed_id, $passed_ent_id, $color); |
626 | echo $s; |
627 | do_hook("read_body_header_right"); |
628 | $s = "</SMALL></TD>\n" . |
629 | "</TR>\n"; |
630 | echo $s; |
a128c967 |
631 | |
4d0cd98b |
632 | } |
633 | |
6206f6c4 |
634 | /***************************/ |
2ffa3f57 |
635 | /* Main of read_body.php */ |
6206f6c4 |
636 | /***************************/ |
57257333 |
637 | |
0b97a708 |
638 | /* get the globals we may need */ |
639 | |
1e12d1ff |
640 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
e95c04ec |
641 | sqgetGlobalVar('username', $username, SQ_SESSION); |
642 | sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION); |
e95c04ec |
643 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
1e12d1ff |
644 | sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); |
645 | |
e95c04ec |
646 | sqgetGlobalVar('msgs', $msgs, SQ_SESSION); |
647 | sqgetGlobalVar('msort', $msort, SQ_SESSION); |
648 | sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION); |
649 | sqgetGlobalVar('server_sort_array', $server_sort_array, SQ_SESSION); |
650 | if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) { |
651 | $messages = array(); |
ce274df9 |
652 | } |
653 | |
e95c04ec |
654 | /** GET VARS */ |
655 | sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET); |
656 | sqgetGlobalVar('where', $where, SQ_GET); |
657 | sqgetGlobalVar('what', $what, SQ_GET); |
658 | if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) { |
659 | $show_more = (int) $temp; |
1b9f3c04 |
660 | } |
e95c04ec |
661 | if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) { |
662 | $show_more_cc = (int) $temp; |
0b97a708 |
663 | } |
e95c04ec |
664 | if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) { |
665 | $show_more_bcc = (int) $temp; |
0b97a708 |
666 | } |
e95c04ec |
667 | if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) { |
668 | $view_hdr = (int) $temp; |
0b97a708 |
669 | } |
e95c04ec |
670 | |
671 | /** POST VARS */ |
672 | sqgetGlobalVar('move_id', $move_id, SQ_POST); |
673 | |
674 | /** GET/POST VARS */ |
675 | sqgetGlobalVar('passed_ent_id', $passed_ent_id); |
676 | sqgetGlobalVar('mailbox', $mailbox); |
677 | |
678 | if ( sqgetGlobalVar('passed_id', $temp) ) { |
679 | $passed_id = (int) $temp; |
0b97a708 |
680 | } |
e95c04ec |
681 | if ( sqgetGlobalVar('sort', $temp) ) { |
682 | $sort = (int) $temp; |
0b97a708 |
683 | } |
e95c04ec |
684 | if ( sqgetGlobalVar('startMessage', $temp) ) { |
685 | $startMessage = (int) $temp; |
ce274df9 |
686 | } |
0b97a708 |
687 | |
ce274df9 |
688 | /* end of get globals */ |
38c944cc |
689 | global $uid_support, $sqimap_capabilities; |
690 | |
6206f6c4 |
691 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
9f42bfc8 |
692 | $mbx_response = sqimap_mailbox_select($imapConnection, $mailbox, false, false, true); |
38c944cc |
693 | |
38c944cc |
694 | |
695 | /** |
696 | * $message contains all information about the message |
697 | * including header and body |
698 | */ |
37d2a6ee |
699 | |
700 | $uidvalidity = $mbx_response['UIDVALIDITY']; |
9f42bfc8 |
701 | |
37d2a6ee |
702 | if (!isset($messages[$uidvalidity])) { |
703 | $messages[$uidvalidity] = array(); |
9f42bfc8 |
704 | } |
5200c026 |
705 | if (!isset($messages[$uidvalidity][$passed_id]) || !$uid_support) { |
706 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
fc224f68 |
707 | $FirstTimeSee = !$message->is_seen; |
708 | $message->is_seen = true; |
5200c026 |
709 | $messages[$uidvalidity][$passed_id] = $message; |
38c944cc |
710 | } else { |
fc224f68 |
711 | // $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
712 | $message = $messages[$uidvalidity][$passed_id]; |
713 | $FirstTimeSee = !$message->is_seen; |
5200c026 |
714 | } |
af568a82 |
715 | |
dd628162 |
716 | if (isset($passed_ent_id) && $passed_ent_id) { |
5200c026 |
717 | $message = $message->getEntity($passed_ent_id); |
ff9d4297 |
718 | if ($message->type0 != 'message' && $message->type1 != 'rfc822') { |
719 | $message = $message->parent; |
720 | } |
141a16b2 |
721 | $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, $uid_support); |
19d470aa |
722 | $rfc822_header = new Rfc822Header(); |
141a16b2 |
723 | $rfc822_header->parseHeader($read); |
724 | $message->rfc822_header = $rfc822_header; |
c615b1da |
725 | } else { |
726 | $passed_ent_id = 0; |
38c944cc |
727 | } |
5200c026 |
728 | $header = $message->header; |
57257333 |
729 | |
6c31f818 |
730 | do_hook('html_top'); |
57257333 |
731 | |
6206f6c4 |
732 | /****************************************/ |
733 | /* Block for handling incoming url vars */ |
734 | /****************************************/ |
5200c026 |
735 | |
5200c026 |
736 | if (isset($sendreceipt)) { |
737 | if ( !$message->is_mdnsent ) { |
738 | if (isset($identity) ) { |
739 | $final_recipient = getPref($data_dir, $username, 'email_address' . '0', '' ); |
740 | } else { |
741 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
742 | } |
743 | |
744 | $final_recipient = trim($final_recipient); |
745 | if ($final_recipient == '' ) { |
746 | $final_recipient = getPref($data_dir, $username, 'email_address', '' ); |
747 | } |
af568a82 |
748 | $supportMDN = ServerMDNSupport($mbx_response["PERMANENTFLAGS"]); |
fc224f68 |
749 | if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) { |
c615b1da |
750 | ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id, $uid_support); |
5200c026 |
751 | $message->is_mdnsent = true; |
6a108031 |
752 | $messages[$uidvalidity][$passed_id]=$message; |
5200c026 |
753 | } |
754 | ClearAttachments(); |
755 | } |
756 | } |
6206f6c4 |
757 | /***********************************************/ |
758 | /* End of block for handling incoming url vars */ |
759 | /***********************************************/ |
760 | |
38c944cc |
761 | $msgs[$passed_id]['FLAG_SEEN'] = true; |
9f42bfc8 |
762 | |
763 | $messagebody = ''; |
c4ad259b |
764 | do_hook('read_body_top'); |
765 | if ($show_html_default == 1) { |
766 | $ent_ar = $message->findDisplayEntity(array()); |
767 | } else { |
768 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
769 | } |
a128c967 |
770 | $cnt = count($ent_ar); |
771 | for ($i = 0; $i < $cnt; $i++) { |
6a108031 |
772 | $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox); |
a128c967 |
773 | if ($i != $cnt-1) { |
774 | $messagebody .= '<hr noshade size=1>'; |
775 | } |
38c944cc |
776 | } |
e55c441a |
777 | |
c615b1da |
778 | displayPageHeader($color, $mailbox); |
7172cad7 |
779 | formatMenuBar($mailbox, $passed_id, $passed_ent_id, $message, $mbx_response); |
af568a82 |
780 | formatEnvheader($mailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee); |
a94c1db1 |
781 | echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">'; |
6206f6c4 |
782 | echo ' <tr><td>'; |
a94c1db1 |
783 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">'; |
a128c967 |
784 | echo ' <tr><td>'; |
a94c1db1 |
785 | echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">'; |
6206f6c4 |
786 | echo ' <tr bgcolor="'.$color[4].'"><td>'; |
98fb28fd |
787 | // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">'; |
788 | echo html_tag( 'table' ,'' , 'left', '', 'cellpadding="1" cellspacing="5" border="0"' ); |
ce810ea7 |
789 | echo ' <tr>' . html_tag( 'td', '<br>'. $messagebody."\n", 'left') |
6c7b5d8c |
790 | . '</tr>'; |
6206f6c4 |
791 | echo ' </table>'; |
792 | echo ' </td></tr>'; |
793 | echo ' </table></td></tr>'; |
2ffa3f57 |
794 | echo ' </table>'; |
795 | echo ' </td></tr>'; |
a128c967 |
796 | |
d0a2476a |
797 | echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'. |
6c7b5d8c |
798 | $color[4].'"></TD></TR>'."\n"; |
d0a2476a |
799 | |
a128c967 |
800 | $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id); |
801 | if ($attachmentsdisplay) { |
8acd2fb5 |
802 | echo ' </table>'; |
6206f6c4 |
803 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
2ffa3f57 |
804 | echo ' <tr><td>'; |
d0a2476a |
805 | echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">'; |
98fb28fd |
806 | echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] ); |
6206f6c4 |
807 | echo ' <b>' . _("Attachments") . ':</b>'; |
808 | echo ' </td></tr>'; |
809 | echo ' <tr><td>'; |
810 | echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>'; |
811 | echo $attachmentsdisplay; |
812 | echo ' </td></tr></table>'; |
6c7b5d8c |
813 | echo ' </td></tr></table>'; |
6206f6c4 |
814 | echo ' </td></tr>'; |
6c7b5d8c |
815 | echo '<TR><TD HEIGHT="5" COLSPAN="2" BGCOLOR="'. |
816 | $color[4].'"></TD></TR>'; |
a128c967 |
817 | } |
c615b1da |
818 | echo '</table>'; |
a07cd1a4 |
819 | |
820 | /* show attached images inline -- if pref'fed so */ |
5be9f195 |
821 | if (($attachment_common_show_images) && |
a07cd1a4 |
822 | is_array($attachment_common_show_images_list)) { |
823 | foreach ($attachment_common_show_images_list as $img) { |
ce274df9 |
824 | $imgurl = SM_PATH . 'src/download.php' . |
57257333 |
825 | '?' . |
cd7b8833 |
826 | 'passed_id=' . urlencode($img['passed_id']) . |
3d570ba0 |
827 | '&mailbox=' . urlencode($mailbox) . |
ff9d4297 |
828 | '&ent_id=' . urlencode($img['ent_id']) . |
3d570ba0 |
829 | '&absolute_dl=true'; |
5be9f195 |
830 | |
b5058e9e |
831 | echo html_tag( 'table', "\n" . |
d9c1dccc |
832 | html_tag( 'tr', "\n" . |
833 | html_tag( 'td', '<img src="' . $imgurl . '">' ."\n", 'left' |
834 | ) |
835 | ) , |
b5058e9e |
836 | 'center', '', 'cellspacing=0 border="0" cellpadding="2"'); |
10f0ce72 |
837 | } |
a07cd1a4 |
838 | } |
839 | |
c615b1da |
840 | do_hook('read_body_bottom'); |
841 | do_hook('html_bottom'); |
a07cd1a4 |
842 | sqimap_logout($imapConnection); |
ce274df9 |
843 | /* sessions are written at the end of the script. it's better to register |
844 | them at the end so we avoid double session_register calls */ |
845 | sqsession_register($messages,'messages'); |
e55c441a |
846 | |
a07cd1a4 |
847 | ?> |
c615b1da |
848 | </body> |
849 | </html> |