Sync search results display with new mailbox_display
[squirrelmail.git] / src / compose.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * compose.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 code sends a mail.
10 *
11 * There are 4 modes of operation:
12 * - Start new mail
13 * - Add an attachment
14 * - Send mail
15 * - Save As Draft
16 *
17 * $Id$
8f6f9ba5 18 * @package squirrelmail
35586184 19 */
f7fb20fe 20
8f6f9ba5 21/** Path for SquirrelMail required files. */
86725763 22define('SM_PATH','../');
23
24/* SquirrelMail required files. */
08185f2a 25require_once(SM_PATH . 'include/validate.php');
953fa718 26require_once(SM_PATH . 'functions/global.php');
86725763 27require_once(SM_PATH . 'functions/imap.php');
28require_once(SM_PATH . 'functions/date.php');
29require_once(SM_PATH . 'functions/mime.php');
86725763 30require_once(SM_PATH . 'functions/plugin.php');
31require_once(SM_PATH . 'functions/display_messages.php');
32require_once(SM_PATH . 'class/deliver/Deliver.class.php');
24192f77 33require_once(SM_PATH . 'functions/addressbook.php');
1e2a6ff6 34require_once(SM_PATH . 'functions/identity.php');
91f2085b 35
0b97a708 36/* --------------------- Get globals ------------------------------------- */
953fa718 37/** COOKIE VARS */
38sqgetGlobalVar('key', $key, SQ_COOKIE);
0b97a708 39
953fa718 40/** SESSION VARS */
41sqgetGlobalVar('username', $username, SQ_SESSION);
42sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION);
43sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION);
44sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION);
45
46sqgetGlobalVar('composesession', $composesession, SQ_SESSION);
47sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION);
48
49/** SESSION/POST/GET VARS */
6f09fb70 50sqgetGlobalVar('smaction',$action);
b455793d 51sqgetGlobalVar('session',$session);
52sqgetGlobalVar('mailbox',$mailbox);
1e2a6ff6 53if(!sqgetGlobalVar('identity',$identity)) {
54 $identity=0;
55}
b455793d 56sqgetGlobalVar('send_to',$send_to);
57sqgetGlobalVar('send_to_cc',$send_to_cc);
58sqgetGlobalVar('send_to_bcc',$send_to_bcc);
59sqgetGlobalVar('subject',$subject);
60sqgetGlobalVar('body',$body);
61sqgetGlobalVar('mailprio',$mailprio);
62sqgetGlobalVar('request_mdn',$request_mdn);
63sqgetGlobalVar('request_dr',$request_dr);
64sqgetGlobalVar('html_addr_search',$html_addr_search);
65sqgetGlobalVar('mail_sent',$mail_sent);
66sqgetGlobalVar('passed_id',$passed_id);
67sqgetGlobalVar('passed_ent_id',$passed_ent_id);
68sqgetGlobalVar('send',$send);
0b97a708 69
b455793d 70sqgetGlobalVar('attach',$attach);
12a0ed01 71
b455793d 72sqgetGlobalVar('draft',$draft);
73sqgetGlobalVar('draft_id',$draft_id);
74sqgetGlobalVar('ent_num',$ent_num);
75sqgetGlobalVar('saved_draft',$saved_draft);
76sqgetGlobalVar('delete_draft',$delete_draft);
7772382e 77sqgetGlobalVar('startMessage',$startMessage);
953fa718 78
79/** POST VARS */
80sqgetGlobalVar('sigappend', $sigappend, SQ_POST);
81sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST);
82sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST);
83sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST);
84sqgetGlobalVar('do_delete', $do_delete, SQ_POST);
85sqgetGlobalVar('delete', $delete, SQ_POST);
b0314f04 86sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST);
953fa718 87if ( sqgetGlobalVar('return', $temp, SQ_POST) ) {
88 $html_addr_search_done = 'Use Addresses';
89}
90
91/** GET VARS */
92sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET);
0b97a708 93
3461167c 94/* Location (For HTTP 1.1 Header("Location: ...") redirects) */
95$location = get_location();
1e2a6ff6 96/* Identities (fetch only once) */
97$idents = get_identities();
3461167c 98
09044055 99/* --------------------- Specific Functions ------------------------------ */
0b97a708 100
41b94d65 101function replyAllString($header) {
1e2a6ff6 102 global $include_self_reply_all, $idents;
98e47335 103 $excl_ar = array();
41b94d65 104 /**
105 * 1) Remove the addresses we'll be sending the message 'to'
106 */
107 $url_replytoall_avoid_addrs = '';
108 if (isset($header->replyto)) {
109 $excl_ar = $header->getAddr_a('replyto');
110 }
111 /**
112 * 2) Remove our identities from the CC list (they still can be in the
113 * TO list) only if $include_self_reply_all is turned off
114 */
115 if (!$include_self_reply_all) {
1e2a6ff6 116 foreach($idents as $id) {
117 $excl_ar[strtolower(trim($id['email_address']))] = '';
118 }
41b94d65 119 }
120
1c044820 121 /**
41b94d65 122 * 3) get the addresses.
123 */
124 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
125
1c044820 126 /**
41b94d65 127 * 4) generate the string.
128 */
129 $url_replytoallcc = '';
130 foreach( $url_replytoall_ar as $email => $personal) {
131 if ($personal) {
aa39839d 132 // if personal name contains address separator then surround
133 // the personal name with double quotes.
134 if (strpos($personal,',') !== false) {
135 $personal = '"'.$personal.'"';
136 }
0b6aacc9 137 $url_replytoallcc .= ", $personal <$email>";
41b94d65 138 } else {
1c044820 139 $url_replytoallcc .= ', '. $email;
41b94d65 140 }
141 }
142 $url_replytoallcc = substr($url_replytoallcc,2);
1c044820 143
41b94d65 144 return $url_replytoallcc;
09044055 145}
146
12a0ed01 147function getReplyCitation($orig_from) {
148 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
790ad2f5 149 $orig_from = decodeHeader($orig_from->getAddress(false),false,false,true);
12a0ed01 150// $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false);
151 /* First, return an empty string when no citation style selected. */
152 if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
153 return '';
154 }
155
156 /* Make sure our final value isn't an empty string. */
157 if ($orig_from == '') {
158 return '';
159 }
160
161 /* Otherwise, try to select the desired citation style. */
162 switch ($reply_citation_style) {
163 case 'author_said':
164 $start = '';
165 $end = ' ' . _("said") . ':';
166 break;
167 case 'quote_who':
168 $start = '<' . _("quote") . ' ' . _("who") . '="';
169 $end = '">';
170 break;
171 case 'user-defined':
1c044820 172 $start = $reply_citation_start .
12a0ed01 173 ($reply_citation_start == '' ? '' : ' ');
174 $end = $reply_citation_end;
175 break;
176 default:
177 return '';
178 }
179
180 /* Build and return the citation string. */
181 return ($start . $orig_from . $end . "\n");
182}
183
41b94d65 184function getforwardHeader($orig_header) {
19c6f7a7 185 global $editor_size;
186
a61878d0 187 $display = array( _("Subject") => strlen(_("Subject")),
1c044820 188 _("From") => strlen(_("From")),
189 _("Date") => strlen(_("Date")),
190 _("To") => strlen(_("To")),
a61878d0 191 _("Cc") => strlen(_("Cc")) );
a45887d7 192 $maxsize = max($display);
193 $indent = str_pad('',$maxsize+2);
194 foreach($display as $key => $val) {
195 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
a91189d6 196 }
790ad2f5 197 $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true);
a91189d6 198 $from = str_replace('&nbsp;',' ',$from);
790ad2f5 199 $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true);
a91189d6 200 $to = str_replace('&nbsp;',' ',$to);
790ad2f5 201 $subject = decodeHeader($orig_header->subject,false,false,true);
a91189d6 202 $subject = str_replace('&nbsp;',' ',$subject);
a61878d0 203 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) .
7e4850ff 204 "\n". $display[_("Subject")] . $subject . "\n" .
a91189d6 205 $display[_("From")] . $from . "\n" .
206 $display[_("Date")] . getLongDateString( $orig_header->date ). "\n" .
207 $display[_("To")] . $to . "\n";
208 if ($orig_header->cc != array() && $orig_header->cc !='') {
790ad2f5 209 $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true);
1c044820 210 $cc = str_replace('&nbsp;',' ',$cc);
a91189d6 211 $bodyTop .= $display[_("Cc")] .$cc . "\n";
41b94d65 212 }
a61878d0 213 $bodyTop .= str_pad('', $editor_size -2 , '-') .
a91189d6 214 "\n\n";
41b94d65 215 return $bodyTop;
216}
09044055 217/* ----------------------------------------------------------------------- */
218
44560457 219/*
1c044820 220 * If the session is expired during a post this restores the compose session
44560457 221 * vars.
222 */
5da08ef7 223if (sqsession_is_registered('session_expired_post')) {
953fa718 224 sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION);
1c044820 225 /*
40934000 226 * extra check for username so we don't display previous post data from
227 * another user during this session.
228 */
229 if ($session_expired_post['username'] != $username) {
0ec1a14b 230 unset($session_expired_post);
0b97a708 231 sqsession_unregister('session_expired_post');
0ec1a14b 232 session_write_close();
40934000 233 } else {
234 foreach ($session_expired_post as $postvar => $val) {
235 if (isset($val)) {
236 $$postvar = $val;
237 } else {
238 $$postvar = '';
239 }
240 }
0ec1a14b 241 $compose_messages = unserialize(urldecode($restoremessages));
242 sqsession_register($compose_messages,'compose_messages');
243 sqsession_register($composesession,'composesession');
40934000 244 if (isset($send)) {
245 unset($send);
246 }
247 $session_expired = true;
248 }
5da08ef7 249 unset($session_expired_post);
0b97a708 250 sqsession_unregister('session_expired_post');
5da08ef7 251 session_write_close();
40934000 252 if (!isset($mailbox)) {
253 $mailbox = '';
254 }
255 if ($compose_new_win == '1') {
256 compose_Header($color, $mailbox);
257 } else {
258 displayPageHeader($color, $mailbox);
259 }
260 showInputForm($session, false);
261 exit();
44560457 262}
da95c4b6 263if (!isset($composesession)) {
264 $composesession = 0;
a43e4b90 265 sqsession_register(0,'composesession');
da95c4b6 266}
267
d7f8e6e6 268if (!isset($session) || (isset($newmessage) && $newmessage)) {
0b97a708 269 sqsession_unregister('composesession');
1c044820 270 $session = "$composesession" +1;
91f2085b 271 $composesession = $session;
a43e4b90 272 sqsession_register($composesession,'composesession');
1c044820 273}
a43e4b90 274if (!isset($compose_messages)) {
275 $compose_messages = array();
276}
40934000 277if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) {
278/* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
5628fdde 279 $composeMessage = new Message();
a43e4b90 280 $rfc822_header = new Rfc822Header();
281 $composeMessage->rfc822_header = $rfc822_header;
282 $composeMessage->reply_rfc822_header = '';
283 $compose_messages[$session] = $composeMessage;
1c044820 284 sqsession_register($compose_messages,'compose_messages');
5628fdde 285} else {
286 $composeMessage=$compose_messages[$session];
a43e4b90 287}
a43e4b90 288
00793a25 289if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) {
290 $mailbox = 'INBOX';
291}
292
4dfb9db7 293if ($draft) {
294 /*
295 * Set $default_charset to correspond with the user's selection
296 * of language interface.
297 */
298 set_my_charset();
299 $composeMessage=$compose_messages[$session];
b7ff469f 300 if (! deliverMessage($composeMessage, true)) {
da95c4b6 301 showInputForm($session);
00793a25 302 exit();
734f4ee6 303 } else {
5da08ef7 304 unset($compose_messages[$session]);
00793a25 305 $draft_message = _("Draft Email Saved");
306 /* If this is a resumed draft, then delete the original */
307 if(isset($delete_draft)) {
3461167c 308 Header("Location: $location/delete_message.php?mailbox=" . urlencode($draft_folder) .
fae72101 309 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
00793a25 310 exit();
7058a2a9 311 }
9c3e6cd4 312 else {
313 if ($compose_new_win == '1') {
3461167c 314 Header("Location: $location/compose.php?saved_draft=yes&session=$composesession");
a61878d0 315 exit();
9c3e6cd4 316 }
317 else {
3461167c 318 Header("Location: $location/right_main.php?mailbox=$draft_folder&sort=$sort".
a61878d0 319 "&startMessage=1&note=".urlencode($draft_message));
320 exit();
9c3e6cd4 321 }
00793a25 322 }
323 }
324}
325
4dfb9db7 326if ($send) {
0b97a708 327 if (isset($_FILES['attachfile']) &&
328 $_FILES['attachfile']['tmp_name'] &&
329 $_FILES['attachfile']['tmp_name'] != 'none') {
da95c4b6 330 $AttachFailure = saveAttachedFiles($session);
00793a25 331 }
332 if (checkInput(false) && !isset($AttachFailure)) {
a91189d6 333 if ($mailbox == "All Folders") {
334 /* We entered compose via the search results page */
335 $mailbox="INBOX"; /* Send 'em to INBOX, that's safe enough */
336 }
00793a25 337 $urlMailbox = urlencode (trim($mailbox));
3f6b1b6f 338 if (! isset($passed_id)) {
339 $passed_id = 0;
00793a25 340 }
341 /*
342 * Set $default_charset to correspond with the user's selection
7058a2a9 343 * of language interface.
00793a25 344 */
345 set_my_charset();
00793a25 346 /*
347 * This is to change all newlines to \n
7058a2a9 348 * We'll change them to \r\n later (in the sendMessage function)
00793a25 349 */
350 $body = str_replace("\r\n", "\n", $body);
351 $body = str_replace("\r", "\n", $body);
352
353 /*
354 * Rewrap $body so that no line is bigger than $editor_size
355 * This should only really kick in the sqWordWrap function
f302d704 356 * if the browser doesn't support "VIRTUAL" as the wrap type.
00793a25 357 */
358 $body = explode("\n", $body);
359 $newBody = '';
360 foreach ($body as $line) {
361 if( $line <> '-- ' ) {
362 $line = rtrim($line);
363 }
364 if (strlen($line) <= $editor_size + 1) {
365 $newBody .= $line . "\n";
734f4ee6 366 } else {
e0858036 367 sqWordWrap($line, $editor_size);
368 $newBody .= $line . "\n";
1c044820 369
00793a25 370 }
1c044820 371
00793a25 372 }
373 $body = $newBody;
1c044820 374
a43e4b90 375 $composeMessage=$compose_messages[$session];
d5181a1d 376
a91189d6 377 $Result = deliverMessage($composeMessage);
00793a25 378 if (! $Result) {
da95c4b6 379 showInputForm($session);
00793a25 380 exit();
381 }
dd4a44cd 382 unset($compose_messages[$session]);
00793a25 383 if ( isset($delete_draft)) {
3461167c 384 Header("Location: $location/delete_message.php?mailbox=" . urlencode( $draft_folder ).
fae72101 385 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
00793a25 386 exit();
387 }
9c3e6cd4 388 if ($compose_new_win == '1') {
0ec1a14b 389
3461167c 390 Header("Location: $location/compose.php?mail_sent=yes");
9c3e6cd4 391 }
392 else {
3461167c 393 Header("Location: $location/right_main.php?mailbox=$urlMailbox&sort=$sort".
2ffeb7c5 394 "&startMessage=$startMessage&mail_sent=yes");
9c3e6cd4 395 }
734f4ee6 396 } else {
9c3e6cd4 397 if ($compose_new_win == '1') {
398 compose_Header($color, $mailbox);
399 }
400 else {
401 displayPageHeader($color, $mailbox);
402 }
00793a25 403 if (isset($AttachFailure)) {
404 plain_error_message(_("Could not move/copy file. File not attached"),
405 $color);
406 }
00793a25 407 checkInput(true);
da95c4b6 408 showInputForm($session);
00793a25 409 /* sqimap_logout($imapConnection); */
410 }
e02775fe 411} elseif (isset($html_addr_search_done)) {
9c3e6cd4 412 if ($compose_new_win == '1') {
413 compose_Header($color, $mailbox);
414 }
415 else {
416 displayPageHeader($color, $mailbox);
417 }
00793a25 418
419 if (isset($send_to_search) && is_array($send_to_search)) {
420 foreach ($send_to_search as $k => $v) {
421 if (substr($k, 0, 1) == 'T') {
422 if ($send_to) {
423 $send_to .= ', ';
424 }
425 $send_to .= $v;
426 }
427 elseif (substr($k, 0, 1) == 'C') {
428 if ($send_to_cc) {
429 $send_to_cc .= ', ';
430 }
431 $send_to_cc .= $v;
432 }
433 elseif (substr($k, 0, 1) == 'B') {
434 if ($send_to_bcc) {
435 $send_to_bcc .= ', ';
436 }
437 $send_to_bcc .= $v;
438 }
439 }
440 }
da95c4b6 441 showInputForm($session);
e02775fe 442} elseif (isset($html_addr_search)) {
0b97a708 443 if (isset($_FILES['attachfile']) &&
444 $_FILES['attachfile']['tmp_name'] &&
445 $_FILES['attachfile']['tmp_name'] != 'none') {
446 if(saveAttachedFiles($session)) {
00793a25 447 plain_error_message(_("Could not move/copy file. File not attached"), $color);
448 }
449 }
450 /*
451 * I am using an include so as to elminiate an extra unnecessary
452 * click. If you can think of a better way, please implement it.
453 */
454 include_once('./addrbook_search_html.php');
e02775fe 455} elseif (isset($attach)) {
da95c4b6 456 if (saveAttachedFiles($session)) {
00793a25 457 plain_error_message(_("Could not move/copy file. File not attached"), $color);
458 }
9c3e6cd4 459 if ($compose_new_win == '1') {
460 compose_Header($color, $mailbox);
461 }
462 else {
463 displayPageHeader($color, $mailbox);
464 }
da95c4b6 465 showInputForm($session);
01265fba 466}
467elseif (isset($sigappend)) {
1e2a6ff6 468 $signature = $idents[$identity]['signature'];
469
01265fba 470 $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature;
471 if ($compose_new_win == '1') {
472 compose_Header($color, $mailbox);
473 } else {
474 displayPageHeader($color, $mailbox);
475 }
da95c4b6 476 showInputForm($session);
e02775fe 477} elseif (isset($do_delete)) {
9c3e6cd4 478 if ($compose_new_win == '1') {
479 compose_Header($color, $mailbox);
480 }
481 else {
482 displayPageHeader($color, $mailbox);
483 }
00793a25 484
00793a25 485 if (isset($delete) && is_array($delete)) {
a43e4b90 486 $composeMessage = $compose_messages[$session];
00793a25 487 foreach($delete as $index) {
a91189d6 488 $attached_file = $composeMessage->entities[$index]->att_local_name;
a61878d0 489 unlink ($attached_file);
a91189d6 490 unset ($composeMessage->entities[$index]);
491 }
492 $new_entities = array();
493 foreach ($composeMessage->entities as $entity) {
494 $new_entities[] = $entity;
00793a25 495 }
a91189d6 496 $composeMessage->entities = $new_entities;
497 $compose_messages[$session] = $composeMessage;
498 sqsession_register($compose_messages, 'compose_messages');
00793a25 499 }
da95c4b6 500 showInputForm($session);
734f4ee6 501} else {
00793a25 502 /*
503 * This handles the default case as well as the error case
1c044820 504 * (they had the same code) --> if (isset($smtpErrors))
00793a25 505 */
44560457 506
507 if ($compose_new_win == '1') {
508 compose_Header($color, $mailbox);
509 } else {
510 displayPageHeader($color, $mailbox);
511 }
00793a25 512
513 $newmail = true;
514
a61878d0 515 if (!isset($passed_ent_id)) {
516 $passed_ent_id = '';
517 }
518 if (!isset($passed_id)) {
1c044820 519 $passed_id = '';
a61878d0 520 }
521 if (!isset($mailbox)) {
522 $mailbox = '';
1c044820 523 }
a61878d0 524 if (!isset($action)) {
525 $action = '';
526 }
1c044820 527
44560457 528 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
b9928adc 529
530 /* in case the origin is not read_body.php */
531 if (isset($send_to)) {
532 $values['send_to'] = $send_to;
533 }
534 if (isset($send_to_cc)) {
44560457 535 $values['send_to_cc'] = $send_to_cc;
b9928adc 536 }
537 if (isset($send_to_bcc)) {
44560457 538 $values['send_to_bcc'] = $send_to_bcc;
b9928adc 539 }
2a2f2185 540 if (isset($subject)) {
541 $values['subject'] = $subject;
542 }
41b94d65 543 showInputForm($session, $values);
00793a25 544}
545
546exit();
547
00793a25 548/**************** Only function definitions go below *************/
549
92c6f757 550function getforwardSubject($subject)
551{
552 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
553 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
554 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
555 $subject = '[Fwd: ' . $subject . ']';
556 }
557 return $subject;
558}
00793a25 559
48985d59 560/* This function is used when not sending or adding attachments */
44560457 561function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
1e2a6ff6 562 global $editor_size, $default_use_priority, $body, $idents,
44560457 563 $use_signature, $composesession, $data_dir, $username,
a43e4b90 564 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
a91189d6 565 $composeMessage;
4e519821 566 global $languages, $squirrelmail_language, $default_charset;
e7f1a81d 567
91f2085b 568 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
bdb92db3 569 $mailprio = 3;
44560457 570
41b94d65 571 if ($passed_id) {
44560457 572 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
a61878d0 573 $imapPort, 0);
574
48985d59 575 sqimap_mailbox_select($imapConnection, $mailbox);
41b94d65 576 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
1c044820 577
a61878d0 578 $body = '';
579 if ($passed_ent_id) {
580 /* redefine the messsage in case of message/rfc822 */
581 $message = $message->getEntity($passed_ent_id);
582 /* message is an entity which contains the envelope and type0=message
583 * and type1=rfc822. The actual entities are childs from
584 * $message->entities[0]. That's where the encoding and is located
585 */
586
587 $entities = $message->entities[0]->findDisplayEntity
588 (array(), $alt_order = array('text/plain'));
589 if (!count($entities)) {
590 $entities = $message->entities[0]->findDisplayEntity
591 (array(), $alt_order = array('text/plain','html/plain'));
592 }
593 $orig_header = $message->rfc822_header; /* here is the envelope located */
594 /* redefine the message for picking up the attachments */
595 $message = $message->entities[0];
596
597 } else {
598 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
599 if (!count($entities)) {
600 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
601 }
602 $orig_header = $message->rfc822_header;
603 }
1c044820 604
41b94d65 605 $encoding = $message->header->encoding;
a61878d0 606 $type0 = $message->type0;
607 $type1 = $message->type1;
41b94d65 608 foreach ($entities as $ent) {
a61878d0 609 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
610 $body_part_entity = $message->getEntity($ent);
611 $bodypart = decodeBody($unencoded_bodypart,
612 $body_part_entity->header->encoding);
613 if ($type1 == 'html') {
5b755d9f 614 $bodypart = str_replace("\n", ' ', $bodypart);
615 $bodypart = preg_replace(array('/<p>/i','/<br\s*(\/)*>/i'), "\n", $bodypart);
616 $bodypart = str_replace(array('&nbsp;','&gt;','&lt;'),array(' ','>','<'),$bodypart);
a61878d0 617 $bodypart = strip_tags($bodypart);
5b755d9f 618
a61878d0 619 }
e842b215 620 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
621 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
622 if (mb_detect_encoding($bodypart) != 'ASCII') {
623 $bodypart = $languages[$squirrelmail_language]['XTRA_CODE']('decode', $bodypart);
624 }
625 }
4e519821 626
beca818e 627 if (isset($body_part_entity->header->parameters['charset'])) {
628 $actual = $body_part_entity->header->parameters['charset'];
629 } else {
630 $actual = 'us-ascii';
631 }
632
4e519821 633 if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){
634 $bodypart = charset_decode($actual,$bodypart);
635 }
636
a61878d0 637 $body .= $bodypart;
638 }
639 if ($default_use_priority) {
640 $mailprio = substr($orig_header->priority,0,1);
641 if (!$mailprio) {
642 $mailprio = 3;
643 }
644 } else {
645 $mailprio = '';
646 }
a43e4b90 647 //ClearAttachments($session);
bdb92db3 648
649 $identity = '';
a45887d7 650 $from_o = $orig_header->from;
bdb92db3 651 if (is_object($from_o)) {
652 $orig_from = $from_o->getAddress();
653 } else {
654 $orig_from = '';
a61878d0 655 }
1e2a6ff6 656
a91189d6 657 $identities = array();
1e2a6ff6 658 if (count($idents) > 1) {
659 foreach($idents as $nr=>$data) {
660 $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>';
661 if($enc_from_name == $orig_from) {
662 $identity = $nr;
a61878d0 663 break;
664 }
a91189d6 665 $identities[] = $enc_from_name;
666 }
1e2a6ff6 667
a91189d6 668 $identity_match = $orig_header->findAddress($identities);
669 if ($identity_match) {
670 $identity = $identity_match;
a61878d0 671 }
f55b5203 672 // we need identiy here fore draft case #845290
673 // echo $identity."leer";
bdb92db3 674 }
a61878d0 675
676 switch ($action) {
677 case ('draft'):
678 $use_signature = FALSE;
0a06275a 679 $composeMessage->rfc822_header = $orig_header;
790ad2f5 680 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true,true);
681 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true,true);
682 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true,true);
a656569f 683 $send_from = $orig_header->getAddr_s('from');
684 $send_from_parts = new AddressStructure();
685 $send_from_parts = $orig_header->parseAddress($send_from);
686 $send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host;
687 $identities = get_identities();
688 if (count($identities) > 0) {
689 foreach($identities as $iddata) {
690 if ($send_from_add == $iddata['email_address']) {
691 $identity = $iddata['index'];
692 break;
693 }
694 }
695 }
790ad2f5 696 $subject = decodeHeader($orig_header->subject,false,true,true);
0a06275a 697// /* remember the references and in-reply-to headers in case of an reply */
426e0b72 698 $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references;
699 $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to;
a61878d0 700 $body_ary = explode("\n", $body);
701 $cnt = count($body_ary) ;
702 $body = '';
703 for ($i=0; $i < $cnt; $i++) {
704 if (!ereg("^[>\\s]*$", $body_ary[$i]) || !$body_ary[$i]) {
705 sqWordWrap($body_ary[$i], $editor_size );
706 $body .= $body_ary[$i] . "\n";
707 }
708 unset($body_ary[$i]);
709 }
710 sqUnWordWrap($body);
a43e4b90 711 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
a61878d0 712 break;
a45887d7 713 case ('edit_as_new'):
790ad2f5 714 $send_to = decodeHeader($orig_header->getAddr_s('to'),false,true,true);
715 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,true,true);
716 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,true,true);
717 $subject = decodeHeader($orig_header->subject,false,true,true);
a61878d0 718 $mailprio = $orig_header->priority;
719 $orig_from = '';
a43e4b90 720 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
a61878d0 721 sqUnWordWrap($body);
722 break;
723 case ('forward'):
724 $send_to = '';
790ad2f5 725 $subject = getforwardSubject(decodeHeader($orig_header->subject,false,true,true));
a61878d0 726 $body = getforwardHeader($orig_header) . $body;
727 sqUnWordWrap($body);
a43e4b90 728 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
a91189d6 729 $body = "\n" . $body;
a61878d0 730 break;
731 case ('forward_as_attachment'):
790ad2f5 732 $subject = getforwardSubject(decodeHeader($orig_header->subject,false,true,true));
a43e4b90 733 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
a61878d0 734 $body = '';
735 break;
a45887d7 736 case ('reply_all'):
b268e66b 737 if(isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) {
738 $send_to = $orig_header->getAddr_s('mail_followup_to');
a91189d6 739 } else {
b268e66b 740 $send_to_cc = replyAllString($orig_header);
790ad2f5 741 $send_to_cc = decodeHeader($send_to_cc,false,true,true);
b268e66b 742 }
743 case ('reply'):
744 // skip this if send_to was already set right above here
745 if(!$send_to) {
746 $send_to = $orig_header->reply_to;
747 if (is_array($send_to) && count($send_to)) {
748 $send_to = $orig_header->getAddr_s('reply_to');
749 } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */
750 $send_to = $orig_header->getAddr_s('reply_to');
751 } else {
752 $send_to = $orig_header->getAddr_s('from');
753 }
a61878d0 754 }
790ad2f5 755 $send_to = decodeHeader($send_to,false,true,true);
756 $subject = decodeHeader($orig_header->subject,false,true,true);
a61878d0 757 $subject = str_replace('"', "'", $subject);
758 $subject = trim($subject);
759 if (substr(strtolower($subject), 0, 3) != 're:') {
760 $subject = 'Re: ' . $subject;
761 }
762 /* this corrects some wrapping/quoting problems on replies */
763 $rewrap_body = explode("\n", $body);
12a0ed01 764 $from = (is_array($orig_header->from)) ? $orig_header->from[0] : $orig_header->from;
dd4a44cd 765 sqUnWordWrap($body); // unwrap and then reset it?!
12a0ed01 766 $body = '';
dd4a44cd 767 $strip_sigs = getPref($data_dir, $username, 'strip_sigs');
768 foreach ($rewrap_body as $line) {
769 if ($strip_sigs && substr($line,0,3) == '-- ') {
770 break;
771 }
772 sqWordWrap($line, ($editor_size));
773 if (preg_match("/^(>+)/", $line, $matches)) {
a61878d0 774 $gt = $matches[1];
dd4a44cd 775 $body .= '>' . str_replace("\n", "\n>$gt ", rtrim($line)) ."\n";
a61878d0 776 } else {
dd4a44cd 777 $body .= '> ' . str_replace("\n", "\n> ", rtrim($line)) . "\n";
a61878d0 778 }
a61878d0 779 }
12a0ed01 780 $body = getReplyCitation($from) . $body;
a43e4b90 781 $composeMessage->reply_rfc822_header = $orig_header;
12a0ed01 782
a61878d0 783 break;
12a0ed01 784 default:
a61878d0 785 break;
41b94d65 786 }
a91189d6 787 $compose_messages[$session] = $composeMessage;
788 sqsession_register($compose_messages, 'compose_messages');
5da08ef7 789 session_write_close();
a61878d0 790 sqimap_logout($imapConnection);
41b94d65 791 }
a61878d0 792 $ret = array( 'send_to' => $send_to,
793 'send_to_cc' => $send_to_cc,
794 'send_to_bcc' => $send_to_bcc,
795 'subject' => $subject,
796 'mailprio' => $mailprio,
797 'body' => $body,
798 'identity' => $identity );
799
41b94d65 800 return ($ret);
48985d59 801} /* function newMail() */
802
a43e4b90 803function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
59edcad6 804 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
48985d59 805 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1c044820 806 if (!count($message->entities) ||
41b94d65 807 ($message->type0 == 'message' && $message->type1 == 'rfc822')) {
808 if ( !in_array($message->entity_id, $entities) && $message->entity_id) {
a91189d6 809 switch ($message->type0) {
810 case 'message':
181538ac 811 if ($message->type1 == 'rfc822') {
92c6f757 812 $filename = $message->rfc822_header->subject;
181538ac 813 if ($filename == "") {
92c6f757 814 $filename = "untitled-".$message->entity_id;
181538ac 815 }
92c6f757 816 $filename .= '.msg';
181538ac 817 } else {
818 $filename = $message->getFilename();
819 }
a91189d6 820 break;
821 default:
181538ac 822 if (!$message->mime_header) { /* temporary hack */
823 $message->mime_header = $message->header;
824 }
a91189d6 825 $filename = $message->getFilename();
826 break;
827 }
5a1f1da3 828 $filename = str_replace('&nbsp;', ' ', decodeHeader($filename));
1c044820 829 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
a91189d6 830 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
a43e4b90 831 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
832 }
a43e4b90 833 $localfilename = GenerateRandomString(32, '', 7);
834 $full_localfilename = "$hashed_attachment_dir/$localfilename";
835 while (file_exists($full_localfilename)) {
836 $localfilename = GenerateRandomString(32, '', 7);
837 $full_localfilename = "$hashed_attachment_dir/$localfilename";
838 }
a91189d6 839 $message->att_local_name = $full_localfilename;
181538ac 840
1c044820 841 $composeMessage->initAttachment($message->type0.'/'.$message->type1,$filename,
181538ac 842 $full_localfilename);
1c044820 843
a43e4b90 844 /* Write Attachment to file */
845 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
846 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
847 $passed_id, $message->entity_id),
848 $message->header->encoding));
849 fclose ($fp);
48985d59 850 }
734f4ee6 851 } else {
a43e4b90 852 for ($i=0, $entCount=count($message->entities); $i<$entCount;$i++) {
853 $composeMessage=getAttachments($message->entities[$i], $composeMessage, $passed_id, $entities, $imapConnection);
48985d59 854 }
855 }
a43e4b90 856 return $composeMessage;
48985d59 857}
858
1c044820 859function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
756406df 860 $passed_ent_id='', $imapConnection) {
a6ec592e 861 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
862 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
756406df 863 if (!$passed_ent_id) {
1c044820 864 $body_a = sqimap_run_command($imapConnection,
a61878d0 865 'FETCH '.$passed_id.' RFC822',
1c044820 866 TRUE, $response, $readmessage,
a61878d0 867 $uid_support);
756406df 868 } else {
1c044820 869 $body_a = sqimap_run_command($imapConnection,
a61878d0 870 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
871 TRUE, $response, $readmessage, $uid_support);
872 $message = $message->parent;
756406df 873 }
d0519c03 874 if ($response == 'OK') {
a61878d0 875 $subject = encodeHeader($message->rfc822_header->subject);
876 array_shift($body_a);
1c044820 877 array_pop($body_a);
a61878d0 878 $body = implode('', $body_a) . "\r\n";
1c044820 879
a61878d0 880 $localfilename = GenerateRandomString(32, 'FILE', 7);
881 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1c044820 882
883 $fp = fopen($full_localfilename, 'w');
a61878d0 884 fwrite ($fp, $body);
885 fclose($fp);
5a1f1da3 886 $composeMessage->initAttachment('message/rfc822',$subject.'.msg',
a91189d6 887 $full_localfilename);
a43e4b90 888 }
889 return $composeMessage;
a6ec592e 890}
891
41b94d65 892function showInputForm ($session, $values=false) {
4a1788b3 893 global $send_to, $send_to_cc, $body, $startMessage,
48985d59 894 $passed_body, $color, $use_signature, $signature, $prefix_sig,
895 $editor_size, $attachments, $subject, $newmail,
41b94d65 896 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
48985d59 897 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
1e2a6ff6 898 $username, $data_dir, $identity, $idents, $draft_id, $delete_draft,
9c3e6cd4 899 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
1c044820 900 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
ab4700c3 901 $username, $compose_messages, $composesession, $default_charset;
a43e4b90 902
903 $composeMessage = $compose_messages[$session];
48985d59 904
41b94d65 905 if ($values) {
906 $send_to = $values['send_to'];
907 $send_to_cc = $values['send_to_cc'];
908 $send_to_bcc = $values['send_to_bcc'];
1c044820 909 $subject = $values['subject'];
41b94d65 910 $mailprio = $values['mailprio'];
911 $body = $values['body'];
d3c13a51 912 $identity = (int) $values['identity'];
676bb189 913 } else {
914 $send_to = decodeHeader($send_to);
915 $send_to_cc = decodeHeader($send_to_cc);
916 $send_to_bcc = decodeHeader($send_to_bcc);
41b94d65 917 }
1c044820 918
48985d59 919 if ($use_javascript_addr_book) {
181538ac 920 echo "\n". '<SCRIPT LANGUAGE=JavaScript>'."\n<!--\n" .
48985d59 921 'function open_abook() { ' . "\n" .
922 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
923 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
924 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
925 ' nwin.opener = document.windows;' . "\n" .
926 "}\n" .
181538ac 927 "// -->\n</SCRIPT>\n\n";
48985d59 928 }
929
4a1788b3 930 echo "\n" . '<form name="compose" action="compose.php" method="post" ' .
931 'enctype="multipart/form-data"';
932 do_hook('compose_form');
1c044820 933
48985d59 934 echo ">\n";
935
4a1788b3 936 echo '<input type="hidden" name="startMessage" value="' . $startMessage . "\">\n";
937
41b94d65 938 if ($action == 'draft') {
939 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
48985d59 940 }
941 if (isset($delete_draft)) {
942 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
943 }
da95c4b6 944 if (isset($session)) {
44560457 945 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
da95c4b6 946 }
1c044820 947
08bad2b1 948 if (isset($passed_id)) {
949 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
950 }
44560457 951
9c3e6cd4 952 if ($saved_draft == 'yes') {
953 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
954 }
955 if ($mail_sent == 'yes') {
5a3071fc 956 echo '<BR><CENTER><B>'. _("Your Message has been sent.").'</CENTER></B>';
9c3e6cd4 957 }
4a1788b3 958 echo '<table align="center" cellspacing="0" border="0">' . "\n";
9c3e6cd4 959 if ($compose_new_win == '1') {
a94c1db1 960 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
98fb28fd 961 ' <TR><TD></TD>'. html_tag( 'td', '', 'right' ) . '<INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
9c3e6cd4 962 }
78a35fcd 963 if ($location_of_buttons == 'top') {
964 showComposeButtonRow();
965 }
48985d59 966
0f257091 967 /* display select list for identities */
1e2a6ff6 968 if (count($idents) > 1) {
0f257091 969 echo ' <tr>' . "\n" .
970 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
971 _("From:") . '</td>' . "\n" .
972 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
1e2a6ff6 973 ' <select name="identity">' . "\n" ;
974 foreach($idents as $id=>$data) {
975 echo '<option value="'.$id.'"';
976 if($id == $identity) {
0f257091 977 echo ' selected';
48985d59 978 }
1e2a6ff6 979 echo '>'.htmlspecialchars($data['full_name'].' <'.$data['email_address'].'>').
980 "</option>\n";
48985d59 981 }
1e2a6ff6 982
48985d59 983 echo '</select>' . "\n" .
0f257091 984 ' </td>' . "\n" .
985 ' </tr>' . "\n";
41b94d65 986 }
0f257091 987 echo ' <tr>' . "\n" .
988 html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) .
0ec1a14b 989 _("To:") . '</TD>' . "\n" .
0f257091 990 html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) .
991 ' <input type="text" name="send_to" value="' .
992 $send_to . '" size="60" /><br />' . "\n" .
993 ' </td>' . "\n" .
994 ' </tr>' . "\n" .
995 ' <tr>' . "\n" .
98fb28fd 996 html_tag( 'td', '', 'right', $color[4] ) .
0f257091 997 _("CC:") . '</td>' . "\n" .
98fb28fd 998 html_tag( 'td', '', 'left', $color[4] ) .
0f257091 999 ' <input type="text" name="send_to_cc" size="60" value="' .
1000 $send_to_cc . '" /><br />' . "\n" .
1001 ' </td>' . "\n" .
1002 ' </tr>' . "\n" .
1003 ' <tr>' . "\n" .
98fb28fd 1004 html_tag( 'td', '', 'right', $color[4] ) .
0f257091 1005 _("BCC:") . '</td>' . "\n" .
98fb28fd 1006 html_tag( 'td', '', 'left', $color[4] ) .
0f257091 1007 ' <input type="text" name="send_to_bcc" value="' .
1008 $send_to_bcc . '" size="60" /><br />' . "\n" .
1009 ' </td>' . "\n" .
1010 ' </tr>' . "\n" .
1011 ' <tr>' . "\n" .
98fb28fd 1012 html_tag( 'td', '', 'right', $color[4] ) .
0f257091 1013 _("Subject:") . '</td>' . "\n" .
98fb28fd 1014 html_tag( 'td', '', 'left', $color[4] ) . "\n";
0f257091 1015 echo ' <input type="text" name="subject" size="60" value="' .
1016 $subject . '" />' . "\n" .
1017 ' </td>' . "\n" .
1018 ' </tr>' . "\n\n";
48985d59 1019
78a35fcd 1020 if ($location_of_buttons == 'between') {
1021 showComposeButtonRow();
1022 }
4dfb9db7 1023
0f257091 1024 /* why this distinction? */
fdc83c55 1025 if ($compose_new_win == '1') {
a94c1db1 1026 echo ' <TR>' . "\n" .
1027 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
756a96a4 1028 ' <TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
0ec1a14b 1029 $editor_size . '" WRAP="VIRTUAL">';
fdc83c55 1030 }
1031 else {
a94c1db1 1032 echo ' <TR>' . "\n" .
1033 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
756a96a4 1034 ' &nbsp;&nbsp;<TEXTAREA NAME=body ID=body ROWS=20 COLS="' .
0ec1a14b 1035 $editor_size . '" WRAP="VIRTUAL">';
fdc83c55 1036 }
0f257091 1037
48985d59 1038 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
1e2a6ff6 1039 $signature = $idents[$identity]['signature'];
d3c13a51 1040
3b17e952 1041 if ($sig_first == '1') {
ab4700c3 1042 if ($default_charset == 'iso-2022-jp') {
83be314a 1043 echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1044 } else {
0a06275a 1045 echo "\n\n".($prefix_sig==true? "-- \n":'').decodeHeader($signature,false,false);
83be314a 1046 }
0a06275a 1047 echo "\n\n".decodeHeader($body,false,false);
3b17e952 1048 }
1049 else {
0a06275a 1050 echo "\n\n".decodeHeader($body,false,false);
ab4700c3 1051 if ($default_charset == 'iso-2022-jp') {
83be314a 1052 echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
1053 }else{
0a06275a 1054 echo "\n\n".($prefix_sig==true? "-- \n":'').decodeHeader($signature,false,false);
3b17e952 1055 }
1056 }
83be314a 1057 }
3b17e952 1058 else {
0a06275a 1059 echo decodeHeader($body,false,false);
48985d59 1060 }
0f257091 1061 echo '</textarea><br />' . "\n" .
1062 ' </td>' . "\n" .
1063 ' </tr>' . "\n";
48985d59 1064
12a0ed01 1065
48985d59 1066 if ($location_of_buttons == 'bottom') {
1067 showComposeButtonRow();
1068 } else {
0f257091 1069 echo ' <tr>' . "\n" .
1070 html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" .
1071 ' <input type="submit" name="send" value="' . _("Send") . '" />' . "\n" .
1072 ' &nbsp;&nbsp;&nbsp;&nbsp;<br /><br />' . "\n" .
1073 ' </td>' . "\n" .
1074 ' </tr>' . "\n";
48985d59 1075 }
46bb8da8 1076
48985d59 1077 /* This code is for attachments */
a91189d6 1078 if ((bool) ini_get('file_uploads')) {
0a2c3218 1079
1080 /* Calculate the max size for an uploaded file.
1081 * This is advisory for the user because we can't actually prevent
1082 * people to upload too large files. */
1083 $sizes = array();
1084 /* php.ini vars which influence the max for uploads */
1085 $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize');
1086 foreach($configvars as $var) {
1087 /* skip 0 or empty values */
1088 if( $size = getByteSize(ini_get($var)) ) {
1089 $sizes[] = $size;
1090 }
1091 }
1092
1093 if(count($sizes) > 0) {
1094 $maxsize = '(max.&nbsp;' . show_readable_size( min( $sizes ) ) . ')';
1095 } else {
1096 $maxsize = '';
1097 }
181538ac 1098 echo '<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="'.min( $sizes ).'">';
0a2c3218 1099 echo ' <tr>' . "\n" .
1100 ' <td colspan="2">' . "\n" .
a94c1db1 1101 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.
0ec1a14b 1102 ' border="0" bgcolor="'.$color[9].'">' . "\n" .
0a2c3218 1103 ' <tr>' . "\n" .
1104 ' <td>' . "\n" .
a94c1db1 1105 ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'.
0ec1a14b 1106 ' border="0">' . "\n" .
0a2c3218 1107 ' <tr>' . "\n" .
1108 html_tag( 'td', '', 'right', '', 'valign="middle"' ) .
1109 _("Attach:") . '</td>' . "\n" .
1110 html_tag( 'td', '', 'left', '', 'valign="middle"' ) .
1111 ' <input name="attachfile" size="48" type="file" />' . "\n" .
0ec1a14b 1112 ' &nbsp;&nbsp;<input type="submit" name="attach"' .
1113 ' value="' . _("Add") .'">' . "\n" .
0a2c3218 1114 $maxsize .
1115 ' </td>' . "\n" .
1116 ' </tr>' . "\n";
1c044820 1117
41b94d65 1118
91f2085b 1119 $s_a = array();
4dfb9db7 1120 if ($composeMessage->entities) {
1121 foreach ($composeMessage->entities as $key => $attachment) {
a43e4b90 1122 $attached_file = $attachment->att_local_name;
1c044820 1123 if ($attachment->att_local_name || $attachment->body_part) {
a91189d6 1124 $attached_filename = decodeHeader($attachment->mime_header->getParameter('name'));
1125 $type = $attachment->mime_header->type0.'/'.
1126 $attachment->mime_header->type1;
1c044820 1127
a91189d6 1128 $s_a[] = '<table bgcolor="'.$color[0].
1129 '" border="0"><tr><td><input type="checkbox" name="delete[]" value="' .
1c044820 1130 $key . "\"></td><td>\n" . $attached_filename .
a91189d6 1131 '</td><td>-</td><td> ' . $type . '</td><td>('.
1132 show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n";
a43e4b90 1133 }
4dfb9db7 1134 }
91f2085b 1135 }
1136 if (count($s_a)) {
a94c1db1 1137 foreach ($s_a as $s) {
98fb28fd 1138 echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>';
1c044820 1139 }
91f2085b 1140 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1141 _("Delete selected attachments") . "\">\n" .
1142 '</td></tr>';
1143 }
0ec1a14b 1144 echo ' </table>' . "\n" .
1145 ' </td>' . "\n" .
1146 ' </tr>' . "\n" .
1147 ' </TABLE>' . "\n" .
1148 ' </TD>' . "\n" .
1149 ' </TR>' . "\n";
a91189d6 1150 } // End of file_uploads if-block
41b94d65 1151 /* End of attachment code */
07687736 1152 if ($compose_new_win == '1') {
41b94d65 1153 echo '</TABLE>'."\n";
07687736 1154 }
a64f47e7 1155
a61878d0 1156 echo '</TABLE>' . "\n" .
1c044820 1157 '<input type="hidden" name="username" value="'. $username . "\">\n" .
6f09fb70 1158 '<input type=hidden name=smaction value="' . $action . "\">\n" .
a61878d0 1159 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
4dfb9db7 1160 "\">\n";
1c044820 1161 /*
1162 store the complete ComposeMessages array in a hidden input value
0ec1a14b 1163 so we can restore them in case of a session timeout.
5da08ef7 1164 */
953fa718 1165 sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER);
5da08ef7 1166 echo '<input type=hidden name=restoremessages value="' . urlencode(serialize($compose_messages)) . "\">\n";
1167 echo '<input type=hidden name=composesession value="' . $composesession . "\">\n";
953fa718 1168 echo '<input type=hidden name=querystring value="' . $queryString . "\">\n";
4dfb9db7 1169 echo '</FORM>';
a64f47e7 1170 if (!(bool) ini_get('file_uploads')) {
1171 /* File uploads are off, so we didn't show that part of the form.
1172 To avoid bogus bug reports, tell the user why. */
1173 echo 'Because PHP file uploads are turned off, you can not attach files ';
1174 echo "to this message. Please see your system administrator for details.\r\n";
1175 }
1176
9f599fe3 1177 do_hook('compose_bottom');
dcc1cc82 1178 echo '</BODY></HTML>' . "\n";
48985d59 1179}
1180
1181
70c4fd84 1182function showComposeButtonRow() {
78a35fcd 1183 global $use_javascript_addr_book, $save_as_draft,
a61878d0 1184 $default_use_priority, $mailprio, $default_use_mdn,
1185 $request_mdn, $request_dr,
1186 $data_dir, $username;
70c4fd84 1187
0ec1a14b 1188 echo ' <TR>' . "\n" .
1189 ' <TD></TD>' . "\n" .
1190 ' <TD>' . "\n";
ae25968c 1191 if ($default_use_priority) {
1192 if(!isset($mailprio)) {
1193 $mailprio = "3";
70c4fd84 1194 }
0ec1a14b 1195 echo ' ' . _("Priority") .': <select name="mailprio">'.
70c4fd84 1196 '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'.
1197 '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'.
1198 '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'.
0ec1a14b 1199 '</select>' . "\n";
ae25968c 1200 }
1201 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1202 if ($default_use_mdn) {
70c4fd84 1203 if ($mdn_user_support) {
0ec1a14b 1204 echo ' ' . _("Receipt") .': '.
b2a7e5bc 1205 '<input type="checkbox" name="request_mdn" value=1'.
a61878d0 1206 ($request_mdn=='1'?' checked':'') .'>'. _("On Read").
b2a7e5bc 1207 ' <input type="checkbox" name="request_dr" value=1'.
a61878d0 1208 ($request_dr=='1'?' checked':'') .'>'. _("On Delivery");
70c4fd84 1209 }
ae25968c 1210 }
48985d59 1211
0ec1a14b 1212 echo ' </TD>' . "\n" .
1213 ' </TR>' . "\n" .
1214 ' <TR>' . "\n" .
1215 ' <TD></TD>' . "\n" .
1216 ' <TD>' . "\n" .
1217 ' <INPUT TYPE=SUBMIT NAME="sigappend" VALUE="' . _("Signature") . '">' . "\n";
78a35fcd 1218 if ($use_javascript_addr_book) {
0ec1a14b 1219 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1220 " <input type=button value=\\\""._("Addresses").
1221 "\\\" onclick='javascript:open_abook();'>\");".
1222 " // --></SCRIPT><NOSCRIPT>\n".
1223 " <input type=submit name=\"html_addr_search\" value=\"".
46bb8da8 1224 _("Addresses")."\">".
0ec1a14b 1225 " </NOSCRIPT>\n";
734f4ee6 1226 } else {
0ec1a14b 1227 echo ' <input type=submit name="html_addr_search" value="'.
1228 _("Addresses").'">' . "\n";
78a35fcd 1229 }
48985d59 1230
78a35fcd 1231 if ($save_as_draft) {
0ec1a14b 1232 echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
78a35fcd 1233 }
0a17f9dd 1234
0ec1a14b 1235 echo ' <INPUT TYPE=submit NAME=send VALUE="'. _("Send") . '">' . "\n";
78a35fcd 1236 do_hook('compose_button_row');
441f2d33 1237
0ec1a14b 1238 echo ' </TD>' . "\n" .
1239 ' </TR>' . "\n\n";
78a35fcd 1240}
b278172f 1241
70c4fd84 1242function checkInput ($show) {
78a35fcd 1243 /*
1244 * I implemented the $show variable because the error messages
1245 * were getting sent before the page header. So, I check once
1246 * using $show=false, and then when i'm ready to display the error
1247 * message, show=true
1248 */
6bf2a88f 1249 global $body, $send_to, $send_to_bcc, $subject, $color;
78a35fcd 1250
6bf2a88f 1251 if ($send_to == '' && $send_to_bcc == '') {
78a35fcd 1252 if ($show) {
0ad7dbda 1253 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
78a35fcd 1254 }
1255 return false;
1256 }
1257 return true;
1258} /* function checkInput() */
df15de21 1259
3806fa52 1260
00793a25 1261/* True if FAILURE */
da95c4b6 1262function saveAttachedFiles($session) {
0b97a708 1263 global $_FILES, $attachment_dir, $attachments, $username,
a43e4b90 1264 $data_dir, $compose_messages;
4c9d2242 1265
45cdd1b5 1266 /* get out of here if no file was attached at all */
1267 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1268 return true;
1269 }
1270
4c9d2242 1271 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1272 $localfilename = GenerateRandomString(32, '', 7);
1273 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1274 while (file_exists($full_localfilename)) {
1275 $localfilename = GenerateRandomString(32, '', 7);
1276 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1277 }
1278
e6675f9a 1279 // FIXME: we SHOULD prefer move_uploaded_file over rename because
1280 // m_u_f works better with restricted PHP installes (safe_mode, open_basedir)
1281 if (!@rename($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1282 if (!@move_uploaded_file($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
a91189d6 1283 return true;
1284 }
a61878d0 1285 }
a43e4b90 1286 $message = $compose_messages[$session];
0b97a708 1287 $type = strtolower($_FILES['attachfile']['type']);
1288 $name = $_FILES['attachfile']['name'];
a43e4b90 1289 $message->initAttachment($type, $name, $full_localfilename);
1290 $compose_messages[$session] = $message;
b0314f04 1291 sqsession_register($compose_messages , 'compose_messages');
4c9d2242 1292}
1293
a43e4b90 1294function ClearAttachments($composeMessage) {
b48d3c53 1295 if ($composeMessage->att_local_name) {
1296 $attached_file = $composeMessage->att_local_name;
a43e4b90 1297 if (file_exists($attached_file)) {
1298 unlink($attached_file);
8712abea 1299 }
da95c4b6 1300 }
a43e4b90 1301 for ($i=0, $entCount=count($composeMessage->entities);$i< $entCount; ++$i) {
1302 ClearAttachments($composeMessage->entities[$i]);
1303 }
4c9d2242 1304}
1305
0a2c3218 1306/* parse values like 8M and 2k into bytes */
1307function getByteSize($ini_size) {
1308
4d30dc83 1309 if(!$ini_size) {
1310 return FALSE;
1311 }
da95c4b6 1312
0a2c3218 1313 $ini_size = trim($ini_size);
1314
5b9716de 1315 // if there's some kind of letter at the end of the string we need to multiply.
1316 if(!is_numeric(substr($ini_size, -1))) {
1317
1318 switch(strtoupper(substr($ini_size, -1))) {
1319 case 'G':
1320 $bytesize = 1073741824;
1321 break;
1322 case 'M':
1323 $bytesize = 1048576;
1324 break;
1325 case 'K':
1326 $bytesize = 1024;
1327 break;
1328 }
1329
4d30dc83 1330 return ($bytesize * (int)substr($ini_size, 0, -1));
0a2c3218 1331 }
1c044820 1332
4d30dc83 1333 return $ini_size;
0a2c3218 1334}
a43e4b90 1335
4c9d2242 1336
a43e4b90 1337/* temporary function to make use of the deliver class.
1338 In the future the responsable backend should be automaticly loaded
1339 and conf.pl should show a list of available backends.
1340 The message also should be constructed by the message class.
1341*/
1342
b7ff469f 1343function deliverMessage($composeMessage, $draft=false) {
a43e4b90 1344 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1e2a6ff6 1345 $username, $popuser, $usernamedata, $identity, $idents, $data_dir,
a91189d6 1346 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
20152d80 1347 $domain, $action, $default_move_to_sent, $move_to_sent;
a43e4b90 1348 global $imapServerAddress, $imapPort, $sent_folder, $key;
1349
b0a3a738 1350 /* some browsers replace <space> by nonbreaking spaces &nbsp;
1351 by replacing them back to spaces addressparsing works */
1352 /* FIXME: How to handle in case of other charsets where "\240"
1353 is not a non breaking space ??? */
790ad2f5 1354 /* THEFIX: browsers don't replace space with nbsp. SM replaces
1355 space with nbsp when decodes headers. If problem still happens,
1356 use cleanup_nbsp() */
1c044820 1357
790ad2f5 1358// $send_to = str_replace("\240",' ',$send_to);
1359// $send_to_cc = str_replace("\240",' ',$send_to_cc);
1360// $send_to_bcc = str_replace("\240",' ',$send_to_bcc);
b0a3a738 1361
a43e4b90 1362 $rfc822_header = $composeMessage->rfc822_header;
24192f77 1363
1364 $abook = addressbook_init(false, true);
24192f77 1365 $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup'));
1366 $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup'));
1367 $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup'));
a43e4b90 1368 $rfc822_header->priority = $mailprio;
1369 $rfc822_header->subject = $subject;
1370 $special_encoding='';
1371 if (strtolower($default_charset) == 'iso-2022-jp') {
1372 if (mb_detect_encoding($body) == 'ASCII') {
a91189d6 1373 $special_encoding = '8bit';
a43e4b90 1374 } else {
1375 $body = mb_convert_encoding($body, 'JIS');
1376 $special_encoding = '7bit';
1377 }
1378 }
1379 $composeMessage->setBody($body);
1380
1381 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1382 $popuser = $usernamedata[1];
1383 $domain = $usernamedata[2];
1384 unset($usernamedata);
1385 } else {
1386 $popuser = $username;
1387 }
1388 $reply_to = '';
1e2a6ff6 1389 $from_mail = $idents[$identity]['email_address'];
1390 $full_name = $idents[$identity]['full_name'];
1391 $reply_to = $idents[$identity]['reply_to'];
045714fd 1392 if (!$from_mail) {
1393 $from_mail = "$popuser@$domain";
045714fd 1394 }
1395 $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true);
1396 if ($full_name) {
9783f396 1397 $from = $rfc822_header->from[0];
a91189d6 1398 if (!$from->host) $from->host = $domain;
12a0ed01 1399 $full_name_encoded = encodeHeader($full_name);
1400 if ($full_name_encoded != $full_name) {
1401 $from_addr = $full_name_encoded .' <'.$from->mailbox.'@'.$from->host.'>';
1402 } else {
1403 $from_addr = '"'.$full_name .'" <'.$from->mailbox.'@'.$from->host.'>';
1404 }
045714fd 1405 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
a43e4b90 1406 }
a43e4b90 1407 if ($reply_to) {
1408 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
1409 }
1410 /* Receipt: On Read */
1411 if (isset($request_mdn) && $request_mdn) {
1412 $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true);
1413 }
1414 /* Receipt: On Delivery */
1415 if (isset($request_dr) && $request_dr) {
1c044820 1416 $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail;
a43e4b90 1417 }
1418 /* multipart messages */
1419 if (count($composeMessage->entities)) {
1420 $message_body = new Message();
a91189d6 1421 $message_body->body_part = $composeMessage->body_part;
1422 $composeMessage->body_part = '';
1423 $mime_header = new MessageHeader;
1424 $mime_header->type0 = 'text';
1425 $mime_header->type1 = 'plain';
1426 if ($special_encoding) {
1427 $mime_header->encoding = $special_encoding;
1c044820 1428 } else {
12a0ed01 1429 $mime_header->encoding = '8bit';
a91189d6 1430 }
1431 if ($default_charset) {
1432 $mime_header->parameters['charset'] = $default_charset;
1433 }
1c044820 1434 $message_body->mime_header = $mime_header;
a43e4b90 1435 array_unshift($composeMessage->entities, $message_body);
a91189d6 1436 $content_type = new ContentType('multipart/mixed');
a43e4b90 1437 } else {
1e2026df 1438 $content_type = new ContentType('text/plain');
1439 if ($special_encoding) {
1440 $rfc822_header->encoding = $special_encoding;
1c044820 1441 } else {
1e2026df 1442 $rfc822_header->encoding = '8bit';
1c044820 1443 }
426e0b72 1444 if ($default_charset) {
1445 $content_type->properties['charset']=$default_charset;
1446 }
181538ac 1447 }
1c044820 1448
a43e4b90 1449 $rfc822_header->content_type = $content_type;
1450 $composeMessage->rfc822_header = $rfc822_header;
181538ac 1451
1c044820 1452 /* Here you can modify the message structure just before we hand
5618924b 1453 it over to deliver */
5255585d 1454 $hookReturn = do_hook('compose_send', $composeMessage);
1455 /* Get any changes made by plugins to $composeMessage. */
1456 if ( is_object($hookReturn[1]) ) {
1457 $composeMessage = $hookReturn[1];
1458 }
a43e4b90 1459
b48d3c53 1460 if (!$useSendmail && !$draft) {
a91189d6 1461 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
1462 $deliver = new Deliver_SMTP();
1463 global $smtpServerAddress, $smtpPort, $pop_before_smtp, $smtp_auth_mech;
1464
a91189d6 1465 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
9bd3b1e6 1466 get_smtp_user($user, $pass);
a91189d6 1467 $stream = $deliver->initStream($composeMessage,$domain,0,
1468 $smtpServerAddress, $smtpPort, $user, $pass, $authPop);
b48d3c53 1469 } elseif (!$draft) {
86725763 1470 require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
b48d3c53 1471 global $sendmail_path;
1472 $deliver = new Deliver_SendMail();
1473 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1474 } elseif ($draft) {
1475 global $draft_folder;
86725763 1476 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
b48d3c53 1477 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1478 $imapPort, 0);
1479 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
4dfb9db7 1480 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
a91189d6 1481 $imap_deliver = new Deliver_IMAP();
1482 $length = $imap_deliver->mail($composeMessage);
1c044820 1483 sqimap_append ($imap_stream, $draft_folder, $length);
4dfb9db7 1484 $imap_deliver->mail($composeMessage, $imap_stream);
a91189d6 1485 sqimap_append_done ($imap_stream, $draft_folder);
1486 sqimap_logout($imap_stream);
1487 unset ($imap_deliver);
1488 return $length;
4dfb9db7 1489 } else {
a91189d6 1490 $msg = '<br>Error: '._("Draft folder")." $draft_folder" . ' does not exist.';
1491 plain_error_message($msg, $color);
1492 return false;
1493 }
a43e4b90 1494 }
1495 $succes = false;
1496 if ($stream) {
a91189d6 1497 $length = $deliver->mail($composeMessage, $stream);
1498 $succes = $deliver->finalizeStream($stream);
a43e4b90 1499 }
1500 if (!$succes) {
00ac2f42 1501 $msg = $deliver->dlv_msg . '<br>' .
1502 _("Server replied: ") . $deliver->dlv_ret_nr . ' '.
1503 $deliver->dlv_server_msg;
a43e4b90 1504 plain_error_message($msg, $color);
1505 } else {
1506 unset ($deliver);
20152d80 1507 $move_to_sent = getPref($data_dir,$username,'move_to_sent');
1508 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
e4a1f097 1509
1510 /* Move to sent code */
1511 if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) {
1512 $svr_allow_sent = true;
1513 } else {
1514 $svr_allow_sent = false;
1515 }
1516
1c044820 1517 if (isset($sent_folder) && (($sent_folder != '') || ($sent_folder != 'none'))
e4a1f097 1518 && sqimap_mailbox_exists( $imap_stream, $sent_folder)) {
1519 $fld_sent = true;
1520 } else {
1521 $fld_sent = false;
1522 }
1523
1524 if ((isset($move_to_sent) && ($move_to_sent != 0)) || (!isset($move_to_sent))) {
1525 $lcl_allow_sent = true;
1526 } else {
1527 $lcl_allow_sent = false;
1528 }
1529
1530 if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) || ($fld_sent && $lcl_allow_sent)) {
1531 sqimap_append ($imap_stream, $sent_folder, $length);
a91189d6 1532 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
1533 $imap_deliver = new Deliver_IMAP();
1534 $imap_deliver->mail($composeMessage, $imap_stream);
e4a1f097 1535 sqimap_append_done ($imap_stream, $sent_folder);
a91189d6 1536 unset ($imap_deliver);
1537 }
1538 global $passed_id, $mailbox, $action;
1539 ClearAttachments($composeMessage);
1540 if ($action == 'reply' || $action == 'reply_all') {
1541 sqimap_mailbox_select ($imap_stream, $mailbox);
fbdc7315 1542 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', false);
a91189d6 1543 }
1c044820 1544 sqimap_logout($imap_stream);
a43e4b90 1545 }
1546 return $succes;
1547}
1548
756a96a4 1549?>