59177427 |
1 | <?php |
134e4174 |
2 | |
35586184 |
3 | /** |
4 | * read_body.php |
5 | * |
35586184 |
6 | * This file is used for reading the msgs array and displaying |
7 | * the resulting emails in the right frame. |
8 | * |
47ccfad4 |
9 | * @copyright © 1999-2006 The SquirrelMail Project Team |
4b4abf93 |
10 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
30967a1e |
11 | * @version $Id$ |
8f6f9ba5 |
12 | * @package squirrelmail |
a07cd1a4 |
13 | */ |
35586184 |
14 | |
30967a1e |
15 | /** |
16 | * Path for SquirrelMail required files. |
17 | * @ignore |
18 | */ |
86725763 |
19 | define('SM_PATH','../'); |
20 | |
21 | /* SquirrelMail required files. */ |
5c4ff7bf |
22 | include_once(SM_PATH . 'include/validate.php'); |
23 | //require_once(SM_PATH . 'functions/global.php'); |
86725763 |
24 | require_once(SM_PATH . 'functions/imap.php'); |
25 | require_once(SM_PATH . 'functions/mime.php'); |
26 | require_once(SM_PATH . 'functions/date.php'); |
27 | require_once(SM_PATH . 'functions/url_parser.php'); |
28 | require_once(SM_PATH . 'functions/html.php'); |
5c4ff7bf |
29 | //require_once(SM_PATH . 'functions/global.php'); |
6d021521 |
30 | require_once(SM_PATH . 'functions/identity.php'); |
91c27aee |
31 | include_once(SM_PATH . 'functions/arrays.php'); |
c3731db5 |
32 | include_once(SM_PATH . 'functions/mailbox_display.php'); |
38c944cc |
33 | |
a07cd1a4 |
34 | /** |
1fca12b5 |
35 | * Given an IMAP message id number, this will look it up in the cached |
1e150c97 |
36 | * and sorted msgs array and return the index of the next message |
1fca12b5 |
37 | * |
1e150c97 |
38 | * @param int $passed_id The current message UID |
1fca12b5 |
39 | * @return the index of the next valid message from the array |
40 | */ |
e0e30169 |
41 | function findNextMessage($uidset,$passed_id='backwards') { |
324ac3c5 |
42 | if (!is_array($uidset)) { |
43 | return -1; |
44 | } |
e0e30169 |
45 | if ($passed_id=='backwards' || !is_array($uidset)) { // check for backwards compattibilty gpg plugin |
46 | $passed_id = $uidset; |
e0e30169 |
47 | } |
91c27aee |
48 | $result = sqm_array_get_value_by_offset($uidset,$passed_id,1); |
49 | if ($result === false) { |
50 | return -1; |
51 | } else { |
52 | return $result; |
10f0ce72 |
53 | } |
a07cd1a4 |
54 | } |
55 | |
1e150c97 |
56 | /** |
57 | * Given an IMAP message id number, this will look it up in the cached |
58 | * and sorted msgs array and return the index of the previous message |
59 | * |
60 | * @param int $passed_id The current message UID |
61 | * @return the index of the next valid message from the array |
62 | */ |
e0e30169 |
63 | |
64 | function findPreviousMessage($uidset, $passed_id) { |
324ac3c5 |
65 | if (!is_array($uidset)) { |
66 | return -1; |
e0e30169 |
67 | } |
91c27aee |
68 | $result = sqm_array_get_value_by_offset($uidset,$passed_id,-1); |
69 | if ($result === false) { |
70 | return -1; |
71 | } else { |
72 | return $result; |
a07cd1a4 |
73 | } |
a07cd1a4 |
74 | } |
10f0ce72 |
75 | |
a07cd1a4 |
76 | /** |
1fca12b5 |
77 | * Displays a link to a page where the message is displayed more |
78 | * "printer friendly". |
1e150c97 |
79 | * @param string $mailbox Name of current mailbox |
4669e892 |
80 | * @param int $passed_id |
1fca12b5 |
81 | */ |
1e150c97 |
82 | function printer_friendly_link($mailbox, $passed_id, $passed_ent_id) { |
4c8986b4 |
83 | global $javascript_on, $show_html_default; |
a07cd1a4 |
84 | |
e2da1d80 |
85 | /* hackydiehack */ |
86 | if( !sqgetGlobalVar('view_unsafe_images', $view_unsafe_images, SQ_GET) ) { |
87 | $view_unsafe_images = false; |
88 | } else { |
89 | $view_unsafe_images = true; |
90 | } |
164584f0 |
91 | $params = '?passed_ent_id=' . urlencode($passed_ent_id) . |
c2324b26 |
92 | '&mailbox=' . urlencode($mailbox) . |
4c8986b4 |
93 | '&passed_id=' . urlencode($passed_id) . |
94 | '&view_unsafe_images='. (bool) $view_unsafe_images . |
95 | '&show_html_default=' . $show_html_default; |
10f0ce72 |
96 | |
a07cd1a4 |
97 | $print_text = _("View Printable Version"); |
10f0ce72 |
98 | |
c615b1da |
99 | $result = ''; |
a07cd1a4 |
100 | /* Output the link. */ |
101 | if ($javascript_on) { |
2c92ea9d |
102 | $result = '<script type="text/javascript">' . "\n" . |
9f42bfc8 |
103 | '<!--' . "\n" . |
104 | " function printFormat() {\n" . |
105 | ' window.open("../src/printer_friendly_main.php' . |
106 | $params . '","Print","width=800,height=600");' . "\n". |
107 | " }\n" . |
108 | "// -->\n" . |
109 | "</script>\n" . |
110 | "<a href=\"javascript:printFormat();\">$print_text</a>\n"; |
a07cd1a4 |
111 | } else { |
c2324b26 |
112 | $result = '<a target="_blank" href="../src/printer_friendly_bottom.php' . |
9f42bfc8 |
113 | "$params\">$print_text</a>\n"; |
a07cd1a4 |
114 | } |
d9c1dccc |
115 | return $result; |
a07cd1a4 |
116 | } |
117 | |
7277191e |
118 | function view_as_html_link($mailbox, $passed_id, $passed_ent_id, $message) { |
119 | global $base_uri, $show_html_default; |
120 | |
121 | $has_html = false; |
122 | if ($message->header->type0 == 'message' && $message->header->type1 == 'rfc822') { |
123 | $type0 = $message->rfc822_header->content_type->type0; |
124 | $type1 = $message->rfc822_header->content_type->type1; |
125 | } else { |
126 | $type0 = $message->header->type0; |
127 | $type1 = $message->header->type1; |
128 | } |
129 | if($type0 == 'multipart' && |
130 | ($type1 == 'alternative' || $type1 == 'mixed' || $type1 == 'related')) { |
131 | if ($message->findDisplayEntity(array(), array('text/html'), true)) { |
132 | $has_html = true; |
133 | } |
134 | } |
135 | /* |
136 | * Normal single part message so check its type. |
137 | */ |
138 | else { |
139 | if($type0 == 'text' && $type1 == 'html') { |
140 | $has_html = true; |
141 | } |
142 | } |
143 | if($has_html == true) { |
144 | $vars = array('passed_ent_id', 'show_more', 'show_more_cc', 'override_type0', 'override_type1', 'startMessage'); |
145 | |
146 | $new_link = $base_uri . 'src/read_body.php?passed_id=' . urlencode($passed_id) . |
147 | '&passed_ent_id=' . urlencode($passed_ent_id) . |
148 | '&mailbox=' . urlencode($mailbox); |
149 | foreach($vars as $var) { |
150 | if(sqgetGlobalVar($var, $temp)) { |
151 | $new_link .= '&' . $var . '=' . urlencode($temp); |
152 | } |
153 | } |
154 | |
155 | if($show_html_default == 1) { |
156 | $new_link .= '&show_html_default=0'; |
157 | $link = _("View as plain text"); |
158 | } else { |
159 | $new_link .= '&show_html_default=1'; |
160 | $link = _("View as HTML"); |
161 | } |
162 | return ' | <a href="' . $new_link . '">' . $link . '</a>'; |
163 | } |
164 | return ''; |
165 | } |
166 | |
4669e892 |
167 | function ServerMDNSupport($aFlags) { |
168 | /* escaping $ doesn't work -> \x36 */ |
c075fcfe |
169 | return ( in_array('$mdnsent',$aFlags,true) || |
170 | in_array('\\*',$aFlags,true) ) ; |
57257333 |
171 | } |
172 | |
fc224f68 |
173 | function SendMDN ( $mailbox, $passed_id, $sender, $message, $imapConnection) { |
8d8da447 |
174 | global $username, $attachment_dir, $popuser, $username, $color, |
ce68b76b |
175 | $version, $squirrelmail_language, $default_charset, |
176 | $languages, $useSendmail, $domain, $sent_folder; |
57257333 |
177 | |
e95c04ec |
178 | sqgetGlobalVar('SERVER_NAME', $SERVER_NAME, SQ_SERVER); |
0b97a708 |
179 | |
38bca81c |
180 | $header = $message->rfc822_header; |
57257333 |
181 | |
fc224f68 |
182 | $rfc822_header = new Rfc822Header(); |
d9c1dccc |
183 | $content_type = new ContentType('multipart/report'); |
fc224f68 |
184 | $content_type->properties['report-type']='disposition-notification'; |
d9c1dccc |
185 | |
fc224f68 |
186 | set_my_charset(); |
187 | if ($default_charset) { |
d9c1dccc |
188 | $content_type->properties['charset']=$default_charset; |
fc224f68 |
189 | } |
190 | $rfc822_header->content_type = $content_type; |
191 | $rfc822_header->to[] = $header->dnt; |
a20855e4 |
192 | $rfc822_header->subject = _("Read:") . ' ' . encodeHeader($header->subject); |
fc224f68 |
193 | |
27a1d10a |
194 | // Patch #793504 Return Receipt Failing with <@> from Tim Craig (burny_md) |
195 | // This merely comes from compose.php and only happens when there is no |
196 | // email_addr specified in user's identity (which is the startup config) |
197 | if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) { |
198 | $popuser = $usernamedata[1]; |
199 | $domain = $usernamedata[2]; |
200 | unset($usernamedata); |
201 | } else { |
202 | $popuser = $username; |
203 | } |
fc224f68 |
204 | |
205 | $reply_to = ''; |
6d021521 |
206 | $ident = get_identities(); |
207 | if(!isset($identity)) $identity = 0; |
208 | $full_name = $ident[$identity]['full_name']; |
209 | $from_mail = $ident[$identity]['email_address']; |
210 | $from_addr = '"'.$full_name.'" <'.$from_mail.'>'; |
211 | $reply_to = $ident[$identity]['reply_to']; |
212 | |
27a1d10a |
213 | if (!$from_mail) { |
214 | $from_mail = "$popuser@$domain"; |
215 | $from_addr = $from_mail; |
fc224f68 |
216 | } |
217 | $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); |
218 | if ($reply_to) { |
219 | $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); |
220 | } |
d9c1dccc |
221 | |
57257333 |
222 | // part 1 (RFC2298) |
57257333 |
223 | $senton = getLongDateString( $header->date ); |
224 | $to_array = $header->to; |
225 | $to = ''; |
226 | foreach ($to_array as $line) { |
af568a82 |
227 | $to .= ' '.$line->getAddress(); |
57257333 |
228 | } |
57257333 |
229 | $now = getLongDateString( time() ); |
78db1583 |
230 | set_my_charset(); |
46bb8da8 |
231 | $body = _("Your message") . "\r\n\r\n" . |
48027e89 |
232 | "\t" . _("To") . ': ' . decodeHeader($to,false,false) . "\r\n" . |
233 | "\t" . _("Subject") . ': ' . decodeHeader($header->subject,false,false) . "\r\n" . |
234 | "\t" . _("Sent") . ': ' . $senton . "\r\n" . |
46bb8da8 |
235 | "\r\n" . |
236 | sprintf( _("Was displayed on %s"), $now ); |
f69feefe |
237 | |
fc224f68 |
238 | $special_encoding = ''; |
4669e892 |
239 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
f4bb5d22 |
240 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) { |
241 | $body = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $body); |
d9c1dccc |
242 | if (strtolower($default_charset) == 'iso-2022-jp') { |
243 | if (mb_detect_encoding($body) == 'ASCII') { |
244 | $special_encoding = '8bit'; |
245 | } else { |
246 | $body = mb_convert_encoding($body, 'JIS'); |
247 | $special_encoding = '7bit'; |
248 | } |
249 | } |
21461ca4 |
250 | } elseif (sq_is8bit($body)) { |
251 | $special_encoding = '8bit'; |
6fbd125b |
252 | } |
fc224f68 |
253 | $part1 = new Message(); |
254 | $part1->setBody($body); |
255 | $mime_header = new MessageHeader; |
256 | $mime_header->type0 = 'text'; |
257 | $mime_header->type1 = 'plain'; |
258 | if ($special_encoding) { |
259 | $mime_header->encoding = $special_encoding; |
d9c1dccc |
260 | } else { |
fc224f68 |
261 | $mime_header->encoding = 'us-ascii'; |
262 | } |
263 | if ($default_charset) { |
264 | $mime_header->parameters['charset'] = $default_charset; |
265 | } |
266 | $part1->mime_header = $mime_header; |
267 | |
57257333 |
268 | // part2 (RFC2298) |
d9c1dccc |
269 | $original_recipient = $to; |
57257333 |
270 | $original_message_id = $header->message_id; |
271 | |
fc224f68 |
272 | $report = "Reporting-UA : $SERVER_NAME ; SquirrelMail (version $version) \r\n"; |
57257333 |
273 | if ($original_recipient != '') { |
fc224f68 |
274 | $report .= "Original-Recipient : $original_recipient\r\n"; |
57257333 |
275 | } |
276 | $final_recipient = $sender; |
fc224f68 |
277 | $report .= "Final-Recipient: rfc822; $final_recipient\r\n" . |
57257333 |
278 | "Original-Message-ID : $original_message_id\r\n" . |
279 | "Disposition: manual-action/MDN-sent-manually; displayed\r\n"; |
280 | |
fc224f68 |
281 | $part2 = new Message(); |
282 | $part2->setBody($report); |
283 | $mime_header = new MessageHeader; |
284 | $mime_header->type0 = 'message'; |
285 | $mime_header->type1 = 'disposition-notification'; |
286 | $mime_header->encoding = 'us-ascii'; |
287 | $part2->mime_header = $mime_header; |
288 | |
289 | $composeMessage = new Message(); |
290 | $composeMessage->rfc822_header = $rfc822_header; |
291 | $composeMessage->addEntity($part1); |
292 | $composeMessage->addEntity($part2); |
293 | |
294 | |
d9c1dccc |
295 | if ($useSendmail) { |
296 | require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); |
297 | global $sendmail_path; |
298 | $deliver = new Deliver_SendMail(); |
299 | $stream = $deliver->initStream($composeMessage,$sendmail_path); |
fc224f68 |
300 | } else { |
d9c1dccc |
301 | require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); |
302 | $deliver = new Deliver_SMTP(); |
ce68b76b |
303 | global $smtpServerAddress, $smtpPort, $pop_before_smtp; |
d9c1dccc |
304 | $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; |
9bd3b1e6 |
305 | get_smtp_user($user, $pass); |
d9c1dccc |
306 | $stream = $deliver->initStream($composeMessage,$domain,0, |
70ce2218 |
307 | $smtpServerAddress, $smtpPort, $user, $pass, $authPop); |
d9c1dccc |
308 | } |
309 | $success = false; |
fc224f68 |
310 | if ($stream) { |
d9c1dccc |
311 | $length = $deliver->mail($composeMessage, $stream); |
312 | $success = $deliver->finalizeStream($stream); |
fc224f68 |
313 | } |
d9c1dccc |
314 | if (!$success) { |
a15f9d93 |
315 | $msg = $deliver->dlv_msg; |
316 | if (! empty($deliver->dlv_server_msg)) { |
317 | $msg.= '<br />' . |
0cc4fb0d |
318 | _("Server replied:") . ' ' . $deliver->dlv_ret_nr . ' ' . |
a15f9d93 |
319 | nl2br(htmlspecialchars($deliver->dlv_server_msg)); |
320 | } |
d9c1dccc |
321 | require_once(SM_PATH . 'functions/display_messages.php'); |
fc224f68 |
322 | plain_error_message($msg, $color); |
323 | } else { |
324 | unset ($deliver); |
d9c1dccc |
325 | if (sqimap_mailbox_exists ($imapConnection, $sent_folder)) { |
326 | sqimap_append ($imapConnection, $sent_folder, $length); |
327 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
328 | $imap_deliver = new Deliver_IMAP(); |
329 | $imap_deliver->mail($composeMessage, $imapConnection); |
330 | sqimap_append_done ($imapConnection); |
331 | unset ($imap_deliver); |
332 | } |
333 | } |
334 | return $success; |
57257333 |
335 | } |
336 | |
6201339c |
337 | function ToggleMDNflag ($set ,$imapConnection, $mailbox, $passed_id) { |
d9c1dccc |
338 | $sg = $set?'+':'-'; |
339 | $cmd = 'STORE ' . $passed_id . ' ' . $sg . 'FLAGS ($MDNSent)'; |
4669e892 |
340 | $read = sqimap_run_command ($imapConnection, $cmd, true, $response, |
6201339c |
341 | $readmessage, TRUE); |
57257333 |
342 | } |
343 | |
4d0cd98b |
344 | function formatRecipientString($recipients, $item ) { |
d9c1dccc |
345 | global $show_more_cc, $show_more, $show_more_bcc, |
346 | $PHP_SELF; |
4d0cd98b |
347 | |
d9c1dccc |
348 | $string = ''; |
38c944cc |
349 | if ((is_array($recipients)) && (isset($recipients[0]))) { |
d9c1dccc |
350 | $show = false; |
38c944cc |
351 | |
352 | if ($item == 'to') { |
d9c1dccc |
353 | if ($show_more) { |
354 | $show = true; |
355 | $url = set_url_var($PHP_SELF, 'show_more',0); |
356 | } else { |
357 | $url = set_url_var($PHP_SELF, 'show_more',1); |
358 | } |
359 | } else if ($item == 'cc') { |
360 | if ($show_more_cc) { |
361 | $show = true; |
362 | $url = set_url_var($PHP_SELF, 'show_more_cc',0); |
363 | } else { |
364 | $url = set_url_var($PHP_SELF, 'show_more_cc',1); |
365 | } |
366 | } else if ($item == 'bcc') { |
367 | if ($show_more_bcc) { |
368 | $show = true; |
369 | $url = set_url_var($PHP_SELF, 'show_more_bcc',0); |
370 | } else { |
371 | $url = set_url_var($PHP_SELF, 'show_more_bcc',1); |
372 | } |
373 | } |
374 | |
375 | $cnt = count($recipients); |
376 | foreach($recipients as $r) { |
a91189d6 |
377 | $add = decodeHeader($r->getAddress(true)); |
d9c1dccc |
378 | if ($string) { |
3c621ba1 |
379 | $string .= '<br />' . $add; |
d9c1dccc |
380 | } else { |
381 | $string = $add; |
382 | if ($cnt > 1) { |
3c621ba1 |
383 | $string .= ' (<a href="'.$url; |
d9c1dccc |
384 | if ($show) { |
3c621ba1 |
385 | $string .= '">'._("less").'</a>)'; |
d9c1dccc |
386 | } else { |
3c621ba1 |
387 | $string .= '">'._("more").'</a>)'; |
d9c1dccc |
388 | break; |
389 | } |
390 | } |
391 | } |
1fca12b5 |
392 | } |
4d0cd98b |
393 | } |
c615b1da |
394 | return $string; |
395 | } |
396 | |
e0e30169 |
397 | function formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, |
af568a82 |
398 | $color, $FirstTimeSee) { |
ce68b76b |
399 | global $default_use_mdn, $default_use_priority, |
77836429 |
400 | $show_xmailer_default, $mdn_user_support, $PHP_SELF, $javascript_on, |
134e4174 |
401 | $squirrelmail_language; |
38bca81c |
402 | |
134e4174 |
403 | $mailbox = $aMailbox['NAME']; |
e0e30169 |
404 | |
d9c1dccc |
405 | $header = $message->rfc822_header; |
406 | $env = array(); |
bdb9ce72 |
407 | $env[_("Subject")] = str_replace(" "," ",decodeHeader($header->subject)); |
7893c8a5 |
408 | |
d9c1dccc |
409 | $from_name = $header->getAddr_s('from'); |
d6b6d221 |
410 | if (!$from_name) |
d9c1dccc |
411 | $from_name = $header->getAddr_s('sender'); |
d6b6d221 |
412 | if (!$from_name) |
413 | $env[_("From")] = _("Unknown sender"); |
414 | else |
415 | $env[_("From")] = decodeHeader($from_name); |
d9c1dccc |
416 | $env[_("Date")] = getLongDateString($header->date); |
417 | $env[_("To")] = formatRecipientString($header->to, "to"); |
418 | $env[_("Cc")] = formatRecipientString($header->cc, "cc"); |
419 | $env[_("Bcc")] = formatRecipientString($header->bcc, "bcc"); |
420 | if ($default_use_priority) { |
0e8006dc |
421 | $env[_("Priority")] = htmlspecialchars(getPriorityStr($header->priority)); |
d9c1dccc |
422 | } |
423 | if ($show_xmailer_default) { |
a91189d6 |
424 | $env[_("Mailer")] = decodeHeader($header->xmailer); |
d9c1dccc |
425 | } |
426 | if ($default_use_mdn) { |
427 | if ($mdn_user_support) { |
428 | if ($header->dnt) { |
429 | if ($message->is_mdnsent) { |
509ce88e |
430 | $env[_("Read receipt")] = _("sent"); |
d9c1dccc |
431 | } else { |
4669e892 |
432 | $env[_("Read receipt")] = _("requested"); |
433 | if (!(handleAsSent($mailbox) || |
d9c1dccc |
434 | $message->is_deleted || |
435 | $passed_ent_id)) { |
436 | $mdn_url = $PHP_SELF . '&sendreceipt=1'; |
437 | if ($FirstTimeSee && $javascript_on) { |
2c92ea9d |
438 | $script = '<script type="text/javascript">' . "\n"; |
d9c1dccc |
439 | $script .= '<!--'. "\n"; |
440 | $script .= 'if(window.confirm("' . |
441 | _("The message sender has requested a response to indicate that you have read this message. Would you like to send a receipt?") . |
442 | '")) { '."\n" . |
443 | ' sendMDN()'. |
444 | '}' . "\n"; |
445 | $script .= '// -->'. "\n"; |
446 | $script .= '</script>'. "\n"; |
447 | echo $script; |
448 | } |
449 | $env[_("Read receipt")] .= ' <a href="' . $mdn_url . '">[' . |
450 | _("Send read receipt now") . ']</a>'; |
451 | } |
452 | } |
453 | } |
454 | } |
455 | } |
c615b1da |
456 | |
3c621ba1 |
457 | $s = '<table width="100%" cellpadding="0" cellspacing="2" border="0"'; |
458 | $s .= ' align="center" bgcolor="'.$color[0].'">'; |
d9c1dccc |
459 | foreach ($env as $key => $val) { |
460 | if ($val) { |
3c621ba1 |
461 | $s .= '<tr>'; |
462 | $s .= html_tag('td', '<b>' . $key . ': </b>', 'right', '', 'valign="top" width="20%"') . "\n"; |
463 | $s .= html_tag('td', $val, 'left', '', 'valign="top" width="80%"') . "\n"; |
464 | $s .= '</tr>'; |
d9c1dccc |
465 | } |
466 | } |
3c621ba1 |
467 | echo '<table bgcolor="'.$color[9].'" width="100%" cellpadding="1"'. |
468 | ' cellspacing="0" border="0" align="center">'."\n"; |
469 | echo '<tr><td height="5" colspan="2" bgcolor="'. |
470 | $color[4].'"></td></tr><tr><td align="center">'."\n"; |
d9c1dccc |
471 | echo $s; |
00ac2f42 |
472 | do_hook('read_body_header'); |
d9c1dccc |
473 | formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color); |
3c621ba1 |
474 | echo '</table>'; |
475 | echo '</td></tr><tr><td height="5" colspan="2" bgcolor="'.$color[4].'"></td></tr>'."\n"; |
476 | echo '</table>'; |
d9c1dccc |
477 | } |
c615b1da |
478 | |
1e150c97 |
479 | /** |
4669e892 |
480 | * Format message toolbar |
481 | * |
1e150c97 |
482 | * @param string $mailbox Name of current mailbox |
483 | * @param int $passed_id UID of current message |
484 | * @param int $passed_ent_id Id of entity within message |
485 | * @param object $message Current message object |
486 | * @param object $mbx_response |
487 | */ |
324ac3c5 |
488 | function formatMenubar($aMailbox, $passed_id, $passed_ent_id, $message, $removedVar, $nav_on_top = TRUE) { |
a94c1db1 |
489 | global $base_uri, $draft_folder, $where, $what, $color, $sort, |
4669e892 |
490 | $startMessage, $PHP_SELF, $save_as_draft, |
1e150c97 |
491 | $enable_forward_as_attachment, $imapConnection, $lastTargetMailbox, |
ce68b76b |
492 | $username, $delete_prev_next_display, |
91c27aee |
493 | $compose_new_win, $javascript_on, $compose_width, $compose_height; |
c615b1da |
494 | |
e0e30169 |
495 | //FIXME cleanup argument list, use $aMailbox where possible |
496 | $mailbox = $aMailbox['NAME']; |
497 | |
d9c1dccc |
498 | $topbar_delimiter = ' | '; |
1e150c97 |
499 | $double_delimiter = ' '; |
d9c1dccc |
500 | $urlMailbox = urlencode($mailbox); |
c615b1da |
501 | |
1e150c97 |
502 | $msgs_url = $base_uri . 'src/'; |
2ffa3f57 |
503 | |
1e150c97 |
504 | // BEGIN NAV ROW - PREV/NEXT, DEL PREV/NEXT, LINKS TO INDEX, etc. |
45c1ed84 |
505 | $nav_row = '<tr><td align="left" colspan="2" style="border: 1px solid '.$color[9].';"><small>'; |
e55c441a |
506 | |
1e150c97 |
507 | // Create Prev & Next links |
508 | // Handle nested entities first (i.e. Mime Attach parts) |
509 | if (isset($passed_ent_id) && $passed_ent_id) { |
510 | // code for navigating through attached message/rfc822 messages |
d9c1dccc |
511 | $url = set_url_var($PHP_SELF, 'passed_ent_id',0); |
70bdc740 |
512 | $entities = array(); |
513 | $entity_count = array(); |
514 | $c = 0; |
f2f03410 |
515 | |
70bdc740 |
516 | foreach($message->parent->entities as $ent) { |
9f42bfc8 |
517 | if ($ent->type0 == 'message' && $ent->type1 == 'rfc822') { |
518 | $c++; |
519 | $entity_count[$c] = $ent->entity_id; |
520 | $entities[$ent->entity_id] = $c; |
521 | } |
70bdc740 |
522 | } |
1e150c97 |
523 | |
70bdc740 |
524 | $prev_link = _("Previous"); |
91c27aee |
525 | if(isset($entities[$passed_ent_id]) && $entities[$passed_ent_id] > 1) { |
70bdc740 |
526 | $prev_ent_id = $entity_count[$entities[$passed_ent_id] - 1]; |
527 | $prev_link = '<a href="' |
528 | . set_url_var($PHP_SELF, 'passed_ent_id', $prev_ent_id) |
529 | . '">' . $prev_link . '</a>'; |
530 | } |
1e150c97 |
531 | |
532 | $next_link = _("Next"); |
91c27aee |
533 | if(isset($entities[$passed_ent_id]) && $entities[$passed_ent_id] < $c) { |
70bdc740 |
534 | $next_ent_id = $entity_count[$entities[$passed_ent_id] + 1]; |
535 | $next_link = '<a href="' |
536 | . set_url_var($PHP_SELF, 'passed_ent_id', $next_ent_id) |
537 | . '">' . $next_link . '</a>'; |
538 | } |
1e150c97 |
539 | |
d9c1dccc |
540 | $par_ent_id = $message->parent->entity_id; |
1e150c97 |
541 | $up_link = ''; |
d9c1dccc |
542 | if ($par_ent_id) { |
543 | $par_ent_id = substr($par_ent_id,0,-2); |
1e150c97 |
544 | if ( $par_ent_id != 0 ) { |
545 | $up_link = $topbar_delimiter; |
546 | $url = set_url_var($PHP_SELF, 'passed_ent_id',$par_ent_id); |
547 | $up_link .= '<a href="'.$url.'">'._("Up").'</a>'; |
548 | } |
549 | } |
550 | |
551 | $nav_row .= $prev_link . $up_link . $topbar_delimiter . $next_link; |
abafb676 |
552 | $nav_row .= $double_delimiter . '[<a href="'.$url.'">'._("View Message").'</a>]'; |
1e150c97 |
553 | |
554 | // Prev/Next links for regular messages |
324ac3c5 |
555 | } else if ( true ) { //!(isset($where) && isset($what)) ) { |
324ac3c5 |
556 | $prev = findPreviousMessage($aMailbox['UIDSET'][$what], $passed_id); |
557 | $next = findNextMessage($aMailbox['UIDSET'][$what],$passed_id); |
1e150c97 |
558 | |
559 | $prev_link = _("Previous"); |
560 | if ($prev >= 0) { |
561 | $uri = $base_uri . 'src/read_body.php?passed_id='.$prev. |
562 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
324ac3c5 |
563 | "&where=$where&what=$what" . |
1e150c97 |
564 | '&startMessage='.$startMessage.'&show_more=0'; |
565 | $prev_link = '<a href="'.$uri.'">'.$prev_link.'</a>'; |
d9c1dccc |
566 | } |
1e150c97 |
567 | |
568 | $next_link = _("Next"); |
569 | if ($next >= 0) { |
570 | $uri = $base_uri . 'src/read_body.php?passed_id='.$next. |
571 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
324ac3c5 |
572 | "&where=$where&what=$what" . |
1e150c97 |
573 | '&startMessage='.$startMessage.'&show_more=0'; |
574 | $next_link = '<a href="'.$uri.'">'.$next_link.'</a>'; |
575 | } |
576 | |
1e150c97 |
577 | // Only bother with Delete & Prev and Delete & Next IF |
6201339c |
578 | // top display is enabled. |
4669e892 |
579 | if ( $delete_prev_next_display == 1 && |
324ac3c5 |
580 | in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) { |
45c1ed84 |
581 | $del_prev_link = _("Delete & Prev"); |
1e150c97 |
582 | if ($prev >= 0) { |
583 | $uri = $base_uri . 'src/read_body.php?passed_id='.$prev. |
584 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
585 | '&startMessage='.$startMessage.'&show_more=0'. |
324ac3c5 |
586 | "&where=$where&what=$what" . |
1e150c97 |
587 | '&delete_id='.$passed_id; |
4669e892 |
588 | $del_prev_link = '<a href="'.$uri.'">'.$del_prev_link.'</a>'; |
1e150c97 |
589 | } |
590 | |
45c1ed84 |
591 | $del_next_link = _("Delete & Next"); |
1e150c97 |
592 | if ($next >= 0) { |
593 | $uri = $base_uri . 'src/read_body.php?passed_id='.$next. |
594 | '&mailbox='.$urlMailbox.'&sort='.$sort. |
595 | '&startMessage='.$startMessage.'&show_more=0'. |
324ac3c5 |
596 | "&where=$where&what=$what" . |
1e150c97 |
597 | '&delete_id='.$passed_id; |
45c1ed84 |
598 | $del_next_link = '<a href="'.$uri.'">'.$del_next_link.'</a>'; |
1e150c97 |
599 | } |
1e150c97 |
600 | } |
45c1ed84 |
601 | |
abafb676 |
602 | $nav_row .= '['.$prev_link.$topbar_delimiter.$next_link.']'; |
603 | if ( isset($del_prev_link) && isset($del_next_link) ) |
604 | $nav_row .= $double_delimiter.'['.$del_prev_link.$topbar_delimiter.$del_next_link.']'; |
1e150c97 |
605 | } |
606 | |
607 | // Start with Search Results or Message List link. |
324ac3c5 |
608 | $msgs_url .= "$where?where=read_body.php&what=$what&mailbox=" . $urlMailbox. |
609 | "&startMessage=$startMessage"; |
610 | if ($where == 'search.php') { |
1e150c97 |
611 | $msgs_str = _("Search Results"); |
612 | } else { |
1e150c97 |
613 | $msgs_str = _("Message List"); |
614 | } |
615 | $nav_row .= $double_delimiter . |
abafb676 |
616 | '[<a href="' . $msgs_url . '">' . $msgs_str . '</a>]'; |
1e150c97 |
617 | |
618 | $nav_row .= '</small></td></tr>'; |
619 | |
620 | |
621 | // BEGIN MENU ROW - DELETE/REPLY/FORWARD/MOVE/etc. |
ad2ee09d |
622 | $menu_row = '<tr bgcolor="'.$color[0].'"><td><small>'; |
98a9cc03 |
623 | $comp_uri = $base_uri.'src/compose.php' . |
624 | '?passed_id=' . $passed_id . |
625 | '&mailbox=' . $urlMailbox . |
626 | '&startMessage=' . $startMessage . |
627 | (isset($passed_ent_id) ? '&passed_ent_id='.$passed_ent_id : ''); |
4669e892 |
628 | |
629 | // Start form for reply/reply all/forward.. |
1a531551 |
630 | $target = ''; |
631 | $on_click=''; |
ee66175d |
632 | $method='method="post" '; |
6190378c |
633 | $onsubmit=''; |
1a531551 |
634 | if ($compose_new_win == '1') { |
91c27aee |
635 | if (!preg_match("/^[0-9]{3,4}$/", $compose_width)) { |
636 | $compose_width = '640'; |
637 | } |
638 | if (!preg_match("/^[0-9]{3,4}$/", $compose_height)) { |
639 | $compose_height = '550'; |
640 | } |
1a531551 |
641 | if ( $javascript_on ) { |
91c27aee |
642 | $on_click=' onclick="comp_in_new_form(\''.$comp_uri.'\', this, this.form,'. $compose_width .',' . $compose_height .')"'; |
1a531551 |
643 | $comp_uri = 'javascript:void(0)'; |
ee66175d |
644 | $method='method="get" '; |
6190378c |
645 | $onsubmit = 'onsubmit="return false" '; |
1a531551 |
646 | } else { |
647 | $target = 'target="_blank"'; |
1a531551 |
648 | } |
649 | } |
650 | |
6190378c |
651 | $menu_row .= "\n".'<form name="composeForm" action="'.$comp_uri.'" ' |
652 | . $method.$target.$onsubmit.' style="display: inline">'."\n"; |
98a9cc03 |
653 | |
1e150c97 |
654 | // If Draft folder - create Resume link |
655 | if (($mailbox == $draft_folder) && ($save_as_draft)) { |
1a531551 |
656 | $new_button = 'smaction_draft'; |
1e150c97 |
657 | $comp_alt_string = _("Resume Draft"); |
658 | } else if (handleAsSent($mailbox)) { |
659 | // If in Sent folder, edit as new |
1a531551 |
660 | $new_button = 'smaction_edit_new'; |
1e150c97 |
661 | $comp_alt_string = _("Edit Message as New"); |
662 | } |
1e150c97 |
663 | // Show Alt URI for Draft/Sent |
98a9cc03 |
664 | if (isset($comp_alt_string)) |
e1728a7a |
665 | $menu_row .= getButton('submit', $new_button, $comp_alt_string, $on_click) . "\n"; |
1e150c97 |
666 | |
e1728a7a |
667 | $menu_row .= getButton('submit', 'smaction_reply', _("Reply"), $on_click) . "\n"; |
668 | $menu_row .= getButton('submit', 'smaction_reply_all', _("Reply All"), $on_click) ."\n"; |
669 | $menu_row .= getButton('submit', 'smaction_forward', _("Forward"), $on_click); |
98a9cc03 |
670 | if ($enable_forward_as_attachment) |
ff0969a0 |
671 | $menu_row .= '<input type="checkbox" name="smaction_attache" />' . _("As Attachment") .' '."\n"; |
1e150c97 |
672 | |
51eb014b |
673 | $menu_row .= '</form> '; |
c615b1da |
674 | |
324ac3c5 |
675 | if ( in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) { |
676 | // Form for deletion. Form is handled by the originating display in $where. This is right_main.php or search.php |
677 | $delete_url = $base_uri . "src/$where"; |
25e57ed2 |
678 | $menu_row .= '<form name="deleteMessageForm" action="'.$delete_url.'" method="post" style="display: inline">'; |
a128c967 |
679 | |
4669e892 |
680 | if (!(isset($passed_ent_id) && $passed_ent_id)) { |
324ac3c5 |
681 | $menu_row .= addHidden('mailbox', $aMailbox['NAME']); |
682 | $menu_row .= addHidden('msg[0]', $passed_id); |
7fcab811 |
683 | $menu_row .= addHidden('startMessage', $startMessage); |
e1728a7a |
684 | $menu_row .= getButton('submit', 'delete', _("Delete")); |
ff0969a0 |
685 | $menu_row .= '<input type="checkbox" name="bypass_trash" />' . _("Bypass Trash"); |
324ac3c5 |
686 | } else { |
e1728a7a |
687 | $menu_row .= getButton('submit', 'delete', _("Delete"), '', FALSE) . "\n"; // delete button is disabled |
abafb676 |
688 | } |
abafb676 |
689 | |
4669e892 |
690 | $menu_row .= '</form>'; |
691 | } |
abafb676 |
692 | |
1e150c97 |
693 | // Add top move link |
694 | $menu_row .= '</small></td><td align="right">'; |
4669e892 |
695 | if ( !(isset($passed_ent_id) && $passed_ent_id) && |
324ac3c5 |
696 | in_array('\\deleted', $aMailbox['PERMANENTFLAGS'],true) ) { |
b2811304 |
697 | |
25e57ed2 |
698 | $menu_row .= '<form name="moveMessageForm" action="'.$base_uri.'src/'.$where.'?'.'" method="post" style="display: inline">'. |
64c9e87e |
699 | '<small>'. |
324ac3c5 |
700 | |
701 | addHidden('mailbox',$aMailbox['NAME']) . |
702 | addHidden('msg[0]', $passed_id) . _("Move to:") . |
1e150c97 |
703 | '<select name="targetMailbox" style="padding: 0px; margin: 0px">'; |
b2811304 |
704 | |
1e150c97 |
705 | if (isset($lastTargetMailbox) && !empty($lastTargetMailbox)) { |
706 | $menu_row .= sqimap_mailbox_option_list($imapConnection, array(strtolower($lastTargetMailbox))); |
707 | } else { |
708 | $menu_row .= sqimap_mailbox_option_list($imapConnection); |
709 | } |
b2811304 |
710 | $menu_row .= '</select> '; |
711 | |
e1728a7a |
712 | $menu_row .= getButton('submit', 'moveButton',_("Move")) . "\n" . '</form>'; |
1e150c97 |
713 | } |
714 | $menu_row .= '</td></tr>'; |
d9c1dccc |
715 | |
1e150c97 |
716 | // echo rows, with hooks |
764971df |
717 | $ret = do_hook_function('read_body_menu_top', array($nav_row, $menu_row)); |
988e24f6 |
718 | if (is_array($ret)) { |
719 | if (isset($ret[0]) && !empty($ret[0])) { |
720 | $nav_row = $ret[0]; |
721 | } |
722 | if (isset($ret[1]) && !empty($ret[1])) { |
723 | $menu_row = $ret[1]; |
724 | } |
764971df |
725 | } |
1e150c97 |
726 | echo '<table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">'; |
727 | echo $nav_on_top ? $nav_row . $menu_row : $menu_row . $nav_row; |
728 | echo '</table>'."\n"; |
d62c4938 |
729 | do_hook('read_body_menu_bottom'); |
c615b1da |
730 | } |
731 | |
732 | function formatToolbar($mailbox, $passed_id, $passed_ent_id, $message, $color) { |
40a34e57 |
733 | global $base_uri, $where, $what, $download_and_unsafe_link; |
4669e892 |
734 | |
d9c1dccc |
735 | $urlMailbox = urlencode($mailbox); |
78909469 |
736 | $urlPassed_id = urlencode($passed_id); |
737 | $urlPassed_ent_id = urlencode($passed_ent_id); |
4669e892 |
738 | |
78909469 |
739 | $query_string = 'mailbox=' . $urlMailbox . '&passed_id=' . $urlPassed_id . '&passed_ent_id=' . $urlPassed_ent_id; |
4669e892 |
740 | |
78909469 |
741 | if (!empty($where)) { |
742 | $query_string .= '&where=' . urlencode($where); |
743 | } |
744 | |
745 | if (!empty($what)) { |
746 | $query_string .= '&what=' . urlencode($what); |
747 | } |
748 | |
e95c04ec |
749 | $url = $base_uri.'src/view_header.php?'.$query_string; |
d9c1dccc |
750 | |
3c621ba1 |
751 | $s = "<tr>\n" . |
752 | html_tag( 'td', '', 'right', '', 'valign="middle" width="20%"' ) . '<b>' . _("Options") . ": </b></td>\n" . |
753 | html_tag( 'td', '', 'left', '', 'valign="middle" width="80%"' ) . '<small>' . |
d9c1dccc |
754 | '<a href="'.$url.'">'._("View Full Header").'</a>'; |
755 | |
756 | /* Output the printer friendly link if we are in subtle mode. */ |
757 | $s .= ' | ' . |
1e150c97 |
758 | printer_friendly_link($mailbox, $passed_id, $passed_ent_id); |
d9c1dccc |
759 | echo $s; |
7277191e |
760 | echo view_as_html_link($mailbox, $passed_id, $passed_ent_id, $message); |
40a34e57 |
761 | |
762 | /* Output the download and/or unsafe images link/-s, if any. */ |
763 | if ($download_and_unsafe_link) { |
764 | echo $download_and_unsafe_link; |
765 | } |
766 | |
d9c1dccc |
767 | do_hook("read_body_header_right"); |
3c621ba1 |
768 | $s = "</small></td>\n" . |
769 | "</tr>\n"; |
d9c1dccc |
770 | echo $s; |
a128c967 |
771 | |
4d0cd98b |
772 | } |
773 | |
91c27aee |
774 | /** |
775 | * Creates button |
776 | * |
777 | * @deprecated see form functions available in 1.5.1 and 1.4.3. |
778 | * @param string $type |
779 | * @param string $name |
780 | * @param string $value |
781 | * @param string $js |
782 | * @param bool $enabled |
783 | */ |
784 | function getButton($type, $name, $value, $js = '', $enabled = TRUE) { |
785 | $disabled = ( $enabled ? '' : 'disabled ' ); |
786 | $js = ( $js ? $js.' ' : '' ); |
787 | return '<input '.$disabled.$js. |
788 | 'type="'.$type. |
789 | '" name="'.$name. |
790 | '" value="'.$value . |
791 | '" style="padding: 0px; margin: 0px" />'; |
792 | } |
793 | |
794 | |
6206f6c4 |
795 | /***************************/ |
2ffa3f57 |
796 | /* Main of read_body.php */ |
6206f6c4 |
797 | /***************************/ |
57257333 |
798 | |
0b97a708 |
799 | /* get the globals we may need */ |
800 | |
1e12d1ff |
801 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
e95c04ec |
802 | sqgetGlobalVar('username', $username, SQ_SESSION); |
803 | sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION); |
e95c04ec |
804 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
1e12d1ff |
805 | sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); |
e95c04ec |
806 | sqgetGlobalVar('lastTargetMailbox', $lastTargetMailbox, SQ_SESSION); |
e95c04ec |
807 | if (!sqgetGlobalVar('messages', $messages, SQ_SESSION) ) { |
808 | $messages = array(); |
ce274df9 |
809 | } |
810 | |
e95c04ec |
811 | /** GET VARS */ |
812 | sqgetGlobalVar('sendreceipt', $sendreceipt, SQ_GET); |
324ac3c5 |
813 | if (!sqgetGlobalVar('where', $where, SQ_GET) ) { |
814 | $where = 'right_main.php'; |
815 | } |
d0b119a5 |
816 | /* |
817 | * Used as entry key to the list of uid's cached in the mailbox cache |
818 | * we use the cached uid's to get the next and prev message. |
819 | */ |
324ac3c5 |
820 | if (!sqgetGlobalVar('what', $what, SQ_GET) ){ |
821 | $what = 0; |
822 | } |
e95c04ec |
823 | if ( sqgetGlobalVar('show_more', $temp, SQ_GET) ) { |
824 | $show_more = (int) $temp; |
1b9f3c04 |
825 | } |
e95c04ec |
826 | if ( sqgetGlobalVar('show_more_cc', $temp, SQ_GET) ) { |
827 | $show_more_cc = (int) $temp; |
0b97a708 |
828 | } |
e95c04ec |
829 | if ( sqgetGlobalVar('show_more_bcc', $temp, SQ_GET) ) { |
830 | $show_more_bcc = (int) $temp; |
0b97a708 |
831 | } |
e95c04ec |
832 | if ( sqgetGlobalVar('view_hdr', $temp, SQ_GET) ) { |
833 | $view_hdr = (int) $temp; |
0b97a708 |
834 | } |
e95c04ec |
835 | |
91c27aee |
836 | if ( sqgetGlobalVar('account', $temp, SQ_GET) ) { |
837 | $iAccount = (int) $temp; |
838 | } else { |
839 | $iAccount = 0; |
840 | } |
841 | |
e95c04ec |
842 | /** GET/POST VARS */ |
843 | sqgetGlobalVar('passed_ent_id', $passed_ent_id); |
844 | sqgetGlobalVar('mailbox', $mailbox); |
845 | |
846 | if ( sqgetGlobalVar('passed_id', $temp) ) { |
847 | $passed_id = (int) $temp; |
0b97a708 |
848 | } |
e95c04ec |
849 | if ( sqgetGlobalVar('sort', $temp) ) { |
850 | $sort = (int) $temp; |
0b97a708 |
851 | } |
e95c04ec |
852 | if ( sqgetGlobalVar('startMessage', $temp) ) { |
853 | $startMessage = (int) $temp; |
324ac3c5 |
854 | } else { |
855 | $startMessage = 1; |
ce274df9 |
856 | } |
7277191e |
857 | if(sqgetGlobalVar('show_html_default', $temp)) { |
858 | $show_html_default = (int) $temp; |
859 | } |
860 | |
861 | if(sqgetGlobalVar('view_unsafe_images', $temp)) { |
862 | $view_unsafe_images = (int) $temp; |
863 | if($view_unsafe_images == 1) { |
864 | $show_html_default = 1; |
865 | } |
866 | } else { |
867 | $view_unsafe_images = 0; |
868 | } |
324ac3c5 |
869 | /** |
870 | * Retrieve mailbox cache |
871 | */ |
872 | sqgetGlobalVar('mailbox_cache',$mailbox_cache,SQ_SESSION); |
0b97a708 |
873 | |
ce274df9 |
874 | /* end of get globals */ |
6201339c |
875 | global $sqimap_capabilities, $lastTargetMailbox; |
38c944cc |
876 | |
6206f6c4 |
877 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
91c27aee |
878 | $aMailbox = sqm_api_mailbox_select($imapConnection, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array()); |
879 | |
c3731db5 |
880 | |
91c27aee |
881 | /** |
c3731db5 |
882 | Start code to set the columns to fetch in case of hitting the next/prev link |
883 | The reason for this is the fact that the cache can be invalidated which means that the headers |
884 | to fetch aren't there anymore. Before they got calculated when the messagelist was shown. |
885 | |
886 | Todo, better central handling of setting the mailbox options so we do not need to do the stuff below |
887 | */ |
888 | |
889 | /** |
890 | * Replace From => To in case it concerns a draft or sent folder |
891 | */ |
199ff86a |
892 | $aColumns = array(); |
c3731db5 |
893 | if (($mailbox == $sent_folder || $mailbox == $draft_folder) && |
894 | !in_array(SQM_COL_TO,$index_order)) { |
895 | $aNewOrder = array(); // nice var name ;) |
896 | foreach($index_order as $iCol) { |
897 | if ($iCol == SQM_COL_FROM) { |
898 | $iCol = SQM_COL_TO; |
899 | } |
199ff86a |
900 | $aColumns[$iCol] = array(); |
c3731db5 |
901 | } |
c3731db5 |
902 | } else { |
199ff86a |
903 | foreach ($index_order as $iCol) { |
904 | $aColumns[$iCol] = array(); |
905 | } |
c3731db5 |
906 | } |
907 | |
908 | $aProps = array( |
909 | 'columns' => $aColumns, // columns bound settings |
910 | 'config' => array( |
911 | 'highlight_list' => $message_highlight_list, // row highlighting rules |
912 | 'trash_folder' => $trash_folder, |
913 | 'sent_folder' => $sent_folder, |
914 | 'draft_folder' => $draft_folder)); |
915 | |
916 | calcFetchColumns($aMailbox,$aProps); |
917 | |
918 | /** |
919 | End code to set the columns to fetch in case of hitting the next/prev link |
920 | */ |
921 | |
922 | |
923 | |
924 | /** |
925 | * Check if cache is still valid, $what contains the key |
926 | * which gives us acces to the array with uid's. At this moment |
927 | * 0 is used for a normal message list and search uses 1 as key. This can be |
928 | * changed / extended in the future. |
929 | * If on a select of a mailbox we detect that the cache should be invalidated due to |
930 | * the delete of messages or due to new messages we empty the list with uid's and |
931 | * that's what we detect below. |
932 | */ |
91c27aee |
933 | if (!is_array($aMailbox['UIDSET'][$what])) { |
d0b119a5 |
934 | fetchMessageHeaders($imapConnection, $aMailbox); |
91c27aee |
935 | } |
38c944cc |
936 | |
d0b119a5 |
937 | $iSetIndex = $aMailbox['SETINDEX']; |
938 | $aMailbox['CURRENT_MSG'][$iSetIndex] = $passed_id; |
939 | |
324ac3c5 |
940 | /** |
941 | * Update the seen state |
942 | * and ignore in_array('\\seen',$aMailbox['PERMANENTFLAGS'],true) |
943 | */ |
944 | if (isset($aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'])) { |
945 | $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS']['\\seen'] = true; |
e0e30169 |
946 | } |
e0e30169 |
947 | |
1e150c97 |
948 | /** |
949 | * Process Delete from delete-move-next |
950 | * but only if delete_id was set |
951 | */ |
952 | if ( sqgetGlobalVar('delete_id', $delete_id, SQ_GET) ) { |
324ac3c5 |
953 | handleMessageListForm($imapConnection,$aMailbox,$sButton='setDeleted', array($delete_id)); |
1e150c97 |
954 | } |
955 | |
38c944cc |
956 | /** |
957 | * $message contains all information about the message |
958 | * including header and body |
959 | */ |
37d2a6ee |
960 | |
324ac3c5 |
961 | if (isset($aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'])) { |
962 | $message = $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT']; |
963 | $FirstTimeSee = !$message->is_seen; |
38c944cc |
964 | } else { |
324ac3c5 |
965 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
966 | $FirstTimeSee = !$message->is_seen; |
967 | $message->is_seen = true; |
968 | $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message; |
5200c026 |
969 | } |
af568a82 |
970 | |
dd628162 |
971 | if (isset($passed_ent_id) && $passed_ent_id) { |
324ac3c5 |
972 | $message = $message->getEntity($passed_ent_id); |
973 | if ($message->type0 != 'message' && $message->type1 != 'rfc822') { |
974 | $message = $message->parent; |
975 | } |
976 | $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[$passed_ent_id.HEADER]", true, $response, $msg, TRUE); |
977 | $rfc822_header = new Rfc822Header(); |
978 | $rfc822_header->parseHeader($read); |
979 | $message->rfc822_header = $rfc822_header; |
91c27aee |
980 | } else if ($message->type0 == 'message' && $message->type1 == 'rfc822' && isset($message->entities[0])) { |
981 | $read = sqimap_run_command ($imapConnection, "FETCH $passed_id BODY[1.HEADER]", true, $response, $msg, TRUE); |
982 | $rfc822_header = new Rfc822Header(); |
983 | $rfc822_header->parseHeader($read); |
984 | $message->rfc822_header = $rfc822_header; |
c615b1da |
985 | } else { |
324ac3c5 |
986 | $passed_ent_id = 0; |
38c944cc |
987 | } |
5200c026 |
988 | $header = $message->header; |
57257333 |
989 | |
57257333 |
990 | |
6206f6c4 |
991 | /****************************************/ |
992 | /* Block for handling incoming url vars */ |
993 | /****************************************/ |
5200c026 |
994 | |
5200c026 |
995 | if (isset($sendreceipt)) { |
996 | if ( !$message->is_mdnsent ) { |
27a1d10a |
997 | $final_recipient = ''; |
134e4174 |
998 | if ((isset($identity)) && ($identity != 0)) //Main identity |
27a1d10a |
999 | $final_recipient = trim(getPref($data_dir, $username, 'email_address' . $identity, '' )); |
1000 | if ($final_recipient == '' ) |
1001 | $final_recipient = trim(getPref($data_dir, $username, 'email_address', '' )); |
324ac3c5 |
1002 | $supportMDN = ServerMDNSupport($aMailbox["PERMANENTFLAGS"]); |
fc224f68 |
1003 | if ( SendMDN( $mailbox, $passed_id, $final_recipient, $message, $imapConnection ) > 0 && $supportMDN ) { |
6201339c |
1004 | ToggleMDNflag( true, $imapConnection, $mailbox, $passed_id); |
5200c026 |
1005 | $message->is_mdnsent = true; |
1012f961 |
1006 | $aMailbox['MSG_HEADERS'][$passed_id]['MESSAGE_OBJECT'] = $message; |
5200c026 |
1007 | } |
5200c026 |
1008 | } |
1009 | } |
6206f6c4 |
1010 | /***********************************************/ |
1011 | /* End of block for handling incoming url vars */ |
1012 | /***********************************************/ |
1013 | |
9f42bfc8 |
1014 | $messagebody = ''; |
c4ad259b |
1015 | do_hook('read_body_top'); |
1016 | if ($show_html_default == 1) { |
1017 | $ent_ar = $message->findDisplayEntity(array()); |
1018 | } else { |
1019 | $ent_ar = $message->findDisplayEntity(array(), array('text/plain')); |
1020 | } |
a128c967 |
1021 | $cnt = count($ent_ar); |
1022 | for ($i = 0; $i < $cnt; $i++) { |
6a108031 |
1023 | $messagebody .= formatBody($imapConnection, $message, $color, $wrap_at, $ent_ar[$i], $passed_id, $mailbox); |
a128c967 |
1024 | if ($i != $cnt-1) { |
83ae18bc |
1025 | $messagebody .= '<hr style="height: 1px;" />'; |
a128c967 |
1026 | } |
38c944cc |
1027 | } |
e55c441a |
1028 | |
b89ceca6 |
1029 | displayPageHeader($color, $mailbox,'',''); |
324ac3c5 |
1030 | formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message,false); |
e0e30169 |
1031 | formatEnvheader($aMailbox, $passed_id, $passed_ent_id, $message, $color, $FirstTimeSee); |
a94c1db1 |
1032 | echo '<table width="100%" cellpadding="0" cellspacing="0" align="center" border="0">'; |
6206f6c4 |
1033 | echo ' <tr><td>'; |
a94c1db1 |
1034 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center" border="0" bgcolor="'.$color[9].'">'; |
a128c967 |
1035 | echo ' <tr><td>'; |
a94c1db1 |
1036 | echo ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">'; |
6206f6c4 |
1037 | echo ' <tr bgcolor="'.$color[4].'"><td>'; |
98fb28fd |
1038 | // echo ' <table cellpadding="1" cellspacing="5" align="left" border="0">'; |
605ce385 |
1039 | echo html_tag( 'table' ,'' , 'left', '', 'width="100%" cellpadding="1" cellspacing="5" border="0"' ); |
3c621ba1 |
1040 | echo ' <tr>' . html_tag( 'td', '<br />'. $messagebody."\n", 'left') |
6c7b5d8c |
1041 | . '</tr>'; |
6206f6c4 |
1042 | echo ' </table>'; |
4669e892 |
1043 | echo ' </td></tr>'; |
6206f6c4 |
1044 | echo ' </table></td></tr>'; |
2ffa3f57 |
1045 | echo ' </table>'; |
1046 | echo ' </td></tr>'; |
a128c967 |
1047 | |
3c621ba1 |
1048 | echo '<tr><td height="5" colspan="2" bgcolor="'. |
1049 | $color[4].'"></td></tr>'."\n"; |
d0a2476a |
1050 | |
a128c967 |
1051 | $attachmentsdisplay = formatAttachments($message,$ent_ar,$mailbox, $passed_id); |
1052 | if ($attachmentsdisplay) { |
8acd2fb5 |
1053 | echo ' </table>'; |
6206f6c4 |
1054 | echo ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">'; |
2ffa3f57 |
1055 | echo ' <tr><td>'; |
d0a2476a |
1056 | echo ' <table width="100%" cellpadding="0" cellspacing="0" align="center" border="0" bgcolor="'.$color[4].'">'; |
4669e892 |
1057 | echo ' <tr>' . html_tag( 'td', '', 'left', $color[9] ); |
6206f6c4 |
1058 | echo ' <b>' . _("Attachments") . ':</b>'; |
1059 | echo ' </td></tr>'; |
1060 | echo ' <tr><td>'; |
1061 | echo ' <table width="100%" cellpadding="2" cellspacing="2" align="center"'.' border="0" bgcolor="'.$color[0].'"><tr><td>'; |
1062 | echo $attachmentsdisplay; |
1063 | echo ' </td></tr></table>'; |
6c7b5d8c |
1064 | echo ' </td></tr></table>'; |
6206f6c4 |
1065 | echo ' </td></tr>'; |
3c621ba1 |
1066 | echo '<tr><td height="5" colspan="2" bgcolor="'. |
1067 | $color[4].'"></td></tr>'; |
a128c967 |
1068 | } |
c615b1da |
1069 | echo '</table>'; |
a07cd1a4 |
1070 | |
1071 | /* show attached images inline -- if pref'fed so */ |
5be9f195 |
1072 | if (($attachment_common_show_images) && |
a07cd1a4 |
1073 | is_array($attachment_common_show_images_list)) { |
1074 | foreach ($attachment_common_show_images_list as $img) { |
ce274df9 |
1075 | $imgurl = SM_PATH . 'src/download.php' . |
57257333 |
1076 | '?' . |
cd7b8833 |
1077 | 'passed_id=' . urlencode($img['passed_id']) . |
3d570ba0 |
1078 | '&mailbox=' . urlencode($mailbox) . |
ff9d4297 |
1079 | '&ent_id=' . urlencode($img['ent_id']) . |
3d570ba0 |
1080 | '&absolute_dl=true'; |
5be9f195 |
1081 | |
b5058e9e |
1082 | echo html_tag( 'table', "\n" . |
d9c1dccc |
1083 | html_tag( 'tr', "\n" . |
3c621ba1 |
1084 | html_tag( 'td', '<img src="' . $imgurl . '" />' ."\n", 'left' |
d9c1dccc |
1085 | ) |
1086 | ) , |
3c621ba1 |
1087 | 'center', '', 'cellspacing="0" border="0" cellpadding="2"'); |
10f0ce72 |
1088 | } |
a07cd1a4 |
1089 | } |
1090 | |
324ac3c5 |
1091 | formatMenuBar($aMailbox, $passed_id, $passed_ent_id, $message, false, FALSE); |
1e150c97 |
1092 | |
c615b1da |
1093 | do_hook('read_body_bottom'); |
a07cd1a4 |
1094 | sqimap_logout($imapConnection); |
91c27aee |
1095 | |
1096 | /** |
1097 | * Write mailbox with updated seen flag information back to cache. |
1098 | */ |
1099 | $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox; |
324ac3c5 |
1100 | sqsession_register($mailbox_cache,'mailbox_cache'); |
5c4ff7bf |
1101 | $oTemplate->display('footer.tpl'); |
7277191e |
1102 | ?> |