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