fixed a problem with preg_match when mailbox delimiter is "/"
[squirrelmail.git] / src / compose.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * compose.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 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$
18 */
f7fb20fe 19
35586184 20require_once('../src/validate.php');
21require_once('../functions/imap.php');
22require_once('../functions/date.php');
23require_once('../functions/mime.php');
24require_once('../functions/smtp.php');
25require_once('../functions/display_messages.php');
26require_once('../functions/plugin.php');
8467bf00 27
48985d59 28if (!isset($attachments)) {
29 $attachments = array();
30 session_register('attachments');
31}
32
da95c4b6 33if (!isset($composesession)) {
34 $composesession = 0;
35 session_register('composesession');
36}
37
38if (!isset($session)) {
39 $session = "$composesession" +1;
40 $composesession = $session;
41}
42
00793a25 43if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) {
44 $mailbox = 'INBOX';
45}
46
47if (isset($draft)) {
715225af 48 include_once ('../src/draft_actions.php');
113e5e9d 49 if (! isset($reply_id)) {
50 $reply_id = 0;
51 }
7058a2a9 52 if (! isset($MDN)) {
53 $MDN = 'False';
113e5e9d 54 }
e93c9514 55 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id, $MDN, $session)) {
da95c4b6 56 showInputForm($session);
00793a25 57 exit();
734f4ee6 58 } else {
00793a25 59 $draft_message = _("Draft Email Saved");
60 /* If this is a resumed draft, then delete the original */
61 if(isset($delete_draft)) {
7058a2a9 62 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
fae72101 63 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
00793a25 64 exit();
7058a2a9 65 }
9c3e6cd4 66 else {
67 if ($compose_new_win == '1') {
da95c4b6 68 Header("Location: compose.php?saved_draft=yes&session=$composesession");
9c3e6cd4 69 exit();
70 }
71 else {
fae72101 72 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
73 "&startMessage=1&note=$draft_message");
00793a25 74 exit();
9c3e6cd4 75 }
00793a25 76 }
77 }
78}
79
80if (isset($send)) {
81 if (isset($HTTP_POST_FILES['attachfile']) &&
82 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
83 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
da95c4b6 84 $AttachFailure = saveAttachedFiles($session);
00793a25 85 }
86 if (checkInput(false) && !isset($AttachFailure)) {
87 $urlMailbox = urlencode (trim($mailbox));
88 if (! isset($reply_id)) {
89 $reply_id = 0;
90 }
91 /*
92 * Set $default_charset to correspond with the user's selection
7058a2a9 93 * of language interface.
00793a25 94 */
95 set_my_charset();
96
97 /*
98 * This is to change all newlines to \n
7058a2a9 99 * We'll change them to \r\n later (in the sendMessage function)
00793a25 100 */
101 $body = str_replace("\r\n", "\n", $body);
102 $body = str_replace("\r", "\n", $body);
103
104 /*
105 * Rewrap $body so that no line is bigger than $editor_size
106 * This should only really kick in the sqWordWrap function
107 * if the browser doesn't support "HARD" as the wrap type
7058a2a9 108 * Or, in Opera's case, something goes wrong.
00793a25 109 */
110 $body = explode("\n", $body);
111 $newBody = '';
112 foreach ($body as $line) {
113 if( $line <> '-- ' ) {
114 $line = rtrim($line);
115 }
116 if (strlen($line) <= $editor_size + 1) {
117 $newBody .= $line . "\n";
734f4ee6 118 } else {
00793a25 119 sqWordWrap($line, $editor_size) . "\n";
120 $newBody .= $line;
121 }
122 }
123 $body = $newBody;
124
e02775fe 125 do_hook('compose_send');
126
57257333 127 $MDN = False; // we are not sending a mdn response
00793a25 128 if (! isset($mailprio)) {
129 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
da95c4b6 130 $subject, $body, $reply_id, $MDN, '', $session);
734f4ee6 131 } else {
00793a25 132 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
da95c4b6 133 $subject, $body, $reply_id, $MDN, $mailprio, $session);
00793a25 134 }
135 if (! $Result) {
da95c4b6 136 showInputForm($session);
00793a25 137 exit();
138 }
139 if ( isset($delete_draft)) {
7058a2a9 140 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
fae72101 141 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
00793a25 142 exit();
143 }
9c3e6cd4 144 if ($compose_new_win == '1') {
da95c4b6 145 Header("Location: compose.php?mail_sent=yes&session=$composesession");
9c3e6cd4 146 }
147 else {
fae72101 148 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
149 "&startMessage=1");
9c3e6cd4 150 }
734f4ee6 151 } else {
00793a25 152 /*
153 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
154 * $imapPort, 0);
155 */
9c3e6cd4 156 if ($compose_new_win == '1') {
157 compose_Header($color, $mailbox);
158 }
159 else {
160 displayPageHeader($color, $mailbox);
161 }
00793a25 162 if (isset($AttachFailure)) {
163 plain_error_message(_("Could not move/copy file. File not attached"),
164 $color);
165 }
166
167 checkInput(true);
da95c4b6 168 showInputForm($session);
00793a25 169 /* sqimap_logout($imapConnection); */
170 }
e02775fe 171} elseif (isset($html_addr_search_done)) {
9c3e6cd4 172 if ($compose_new_win == '1') {
173 compose_Header($color, $mailbox);
174 }
175 else {
176 displayPageHeader($color, $mailbox);
177 }
00793a25 178
179 if (isset($send_to_search) && is_array($send_to_search)) {
180 foreach ($send_to_search as $k => $v) {
181 if (substr($k, 0, 1) == 'T') {
182 if ($send_to) {
183 $send_to .= ', ';
184 }
185 $send_to .= $v;
186 }
187 elseif (substr($k, 0, 1) == 'C') {
188 if ($send_to_cc) {
189 $send_to_cc .= ', ';
190 }
191 $send_to_cc .= $v;
192 }
193 elseif (substr($k, 0, 1) == 'B') {
194 if ($send_to_bcc) {
195 $send_to_bcc .= ', ';
196 }
197 $send_to_bcc .= $v;
198 }
199 }
200 }
da95c4b6 201 showInputForm($session);
e02775fe 202} elseif (isset($html_addr_search)) {
00793a25 203 if (isset($HTTP_POST_FILES['attachfile']) &&
204 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
205 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
da95c4b6 206 if (saveAttachedFiles($session)) {
00793a25 207 plain_error_message(_("Could not move/copy file. File not attached"), $color);
208 }
209 }
210 /*
211 * I am using an include so as to elminiate an extra unnecessary
212 * click. If you can think of a better way, please implement it.
213 */
214 include_once('./addrbook_search_html.php');
e02775fe 215} elseif (isset($attach)) {
da95c4b6 216 if (saveAttachedFiles($session)) {
00793a25 217 plain_error_message(_("Could not move/copy file. File not attached"), $color);
218 }
9c3e6cd4 219 if ($compose_new_win == '1') {
220 compose_Header($color, $mailbox);
221 }
222 else {
223 displayPageHeader($color, $mailbox);
224 }
da95c4b6 225 showInputForm($session);
01265fba 226}
227elseif (isset($sigappend)) {
228 $idents = getPref($data_dir, $username, 'identities', 0);
229 if ($idents > 1) {
230 if ($identity == 'default') {
231 $no = 'g';
232 } else {
233 $no = $identity;
234 }
235 $signature = getSig($data_dir, $username, $no);
236 }
237 $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature;
238 if ($compose_new_win == '1') {
239 compose_Header($color, $mailbox);
240 } else {
241 displayPageHeader($color, $mailbox);
242 }
da95c4b6 243 showInputForm($session);
e02775fe 244} elseif (isset($do_delete)) {
9c3e6cd4 245 if ($compose_new_win == '1') {
246 compose_Header($color, $mailbox);
247 }
248 else {
249 displayPageHeader($color, $mailbox);
250 }
00793a25 251
252 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
253 if (isset($delete) && is_array($delete)) {
254 foreach($delete as $index) {
255 $attached_file = $hashed_attachment_dir . '/'
256 . $attachments[$index]['localfilename'];
da95c4b6 257 unlink ($attached_file);
258 unset ($attachments[$index]);
00793a25 259 }
260 }
261
da95c4b6 262 showInputForm($session);
263
264} elseif (isset($attachedmessages)) {
265
266 /*
267 * This handles the case if we attache message
268 */
269 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
270 $imapPort, 0);
271 if ($compose_new_win == '1') {
272 compose_Header($color, $mailbox);
273 }
274 else {
275 displayPageHeader($color, $mailbox);
276 }
277
278 $newmail = true;
279
280 newMail();
281 showInputForm($session);
282 sqimap_logout($imapConnection);
283
734f4ee6 284} else {
00793a25 285 /*
286 * This handles the default case as well as the error case
287 * (they had the same code) --> if (isset($smtpErrors))
288 */
289 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
290 $imapPort, 0);
9c3e6cd4 291 if ($compose_new_win == '1') {
292 compose_Header($color, $mailbox);
293 }
294 else {
295 displayPageHeader($color, $mailbox);
296 }
00793a25 297
298 $newmail = true;
299
da95c4b6 300 ClearAttachments($session);
00793a25 301
302 if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num) {
da95c4b6 303 getAttachments(0, $session);
00793a25 304 }
305
306 if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num) {
da95c4b6 307 getAttachments(0, $session);
00793a25 308 }
309
da95c4b6 310 newMail($session);
311 showInputForm($session);
00793a25 312 sqimap_logout($imapConnection);
313}
314
315exit();
316
317
318/**************** Only function definitions go below *************/
319
320
48985d59 321/* This function is used when not sending or adding attachments */
322function newMail () {
323 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
324 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size,
da95c4b6 325 $draft_id, $use_signature, $composesession;
48985d59 326
3b487216 327 $send_to = decodeHeader($send_to, false);
328 $send_to_cc = decodeHeader($send_to_cc, false);
329 $send_to_bcc = decodeHeader($send_to_bcc, false);
48985d59 330
331 if ($forward_id) {
332 $id = $forward_id;
333 } elseif ($reply_id) {
334 $id = $reply_id;
335 }
336
337 if ($draft_id){
338 $id = $draft_id;
339 $use_signature = FALSE;
340 }
341
342 if (isset($id)) {
343 sqimap_mailbox_select($imapConnection, $mailbox);
344 $message = sqimap_get_message($imapConnection, $id, $mailbox);
345 $orig_header = $message->header;
346 if ($ent_num) {
1195c340 347 $message = getEntity($message, $ent_num);
48985d59 348 }
349 if ($message->header->type0 == 'text' ||
350 $message->header->type1 == 'message') {
351 if ($ent_num) {
352 $body = decodeBody(
353 mime_fetch_body($imapConnection, $id, $ent_num),
354 $message->header->encoding);
355 } else {
356 $body = decodeBody(
357 mime_fetch_body($imapConnection, $id, 1),
358 $message->header->encoding);
359 }
734f4ee6 360 } else {
e707c74a 361 $body = '';
48985d59 362 }
9487c2ff 363
e707c74a 364 if ($message->header->type1 == 'html') {
429f8906 365 $body = strip_tags($body);
48985d59 366 }
f82d9be2 367
48985d59 368 sqUnWordWrap($body);
369 $body_ary = explode("\n", $body);
370 $i = count($body_ary) - 1;
371 while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
fb6ce88e 372 unset($body_ary[$i]);
373 $i --;
48985d59 374 }
375 $body = '';
376 for ($i=0; isset($body_ary[$i]); $i++) {
377 if ($reply_id) {
378 if (ereg('^[ >]+', $body_ary[$i])) {
01aab860 379 $body_ary[$i] = '>' . $body_ary[$i];
734f4ee6 380 } else {
01aab860 381 $body_ary[$i] = '> ' . $body_ary[$i];
382 }
383 }
a951522b 384 if (!$draft_id) {
78a35fcd 385 sqWordWrap($body_ary[$i], $editor_size - 1);
a951522b 386 }
01aab860 387 $body .= $body_ary[$i] . "\n";
f923b93d 388 unset($body_ary[$i]);
48985d59 389 }
390 if ($forward_id) {
391 $bodyTop = '-------- ' . _("Original Message") . " --------\n" .
392 _("Subject") . ': ' . $orig_header->subject . "\n" .
393 _("From") . ': ' . $orig_header->from . "\n" .
78a35fcd 394 _("Date") . ': ' .
395 getLongDateString( $orig_header->date ). "\n" .
48985d59 396 _("To") . ': ' . $orig_header->to[0] . "\n";
78a35fcd 397 if (count($orig_header->to) > 1) {
398 for ($x=1; $x < count($orig_header->to); $x++) {
399 $bodyTop .= ' ' . $orig_header->to[$x] . "\n";
400 }
401 }
402 $bodyTop .= "\n";
403 $body = $bodyTop . $body;
404 }
405 elseif ($reply_id) {
3b487216 406 $orig_from = decodeHeader($orig_header->from, false);
78a35fcd 407 $body = getReplyCitation($orig_from) . $body;
408 }
9487c2ff 409
78a35fcd 410 return;
48985d59 411 }
429f8906 412
48985d59 413 if (!$send_to) {
78a35fcd 414 $send_to = sqimap_find_email($send_to);
48985d59 415 }
29d08a52 416
48985d59 417 /* This formats a CC string if they hit "reply all" */
418 if ($send_to_cc != '') {
419 $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc);
0f8a1ce9 420 $send_to_cc = str_replace(';', ',', $send_to_cc);
48985d59 421 $sendcc = explode(',', $send_to_cc);
422 $send_to_cc = '';
9487c2ff 423
48985d59 424 for ($i = 0; $i < count($sendcc); $i++) {
df15de21 425 $sendcc[$i] = trim($sendcc[$i]);
48985d59 426 if ($sendcc[$i] == '') {
427 continue;
428 }
9487c2ff 429
a53e5469 430 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
48985d59 431 $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']);
432 $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']);
9487c2ff 433
df15de21 434 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
435 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
48985d59 436 (trim($sendcc[$i]) != '')) {
437 $send_to_cc .= trim($sendcc[$i]) . ', ';
df15de21 438 }
48985d59 439 }
440 $send_to_cc = trim($send_to_cc);
441 if (substr($send_to_cc, -1) == ',') {
df15de21 442 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
48985d59 443 }
444 }
445} /* function newMail() */
446
78509c54 447
da95c4b6 448function getAttachments($message, $session) {
48985d59 449 global $mailbox, $attachments, $attachment_dir, $imapConnection,
450 $ent_num, $forward_id, $draft_id, $username;
e707c74a 451
48985d59 452 if (isset($draft_id)) {
78a35fcd 453 $id = $draft_id;
734f4ee6 454 } else {
78a35fcd 455 $id = $forward_id;
48985d59 456 }
f972eb46 457
48985d59 458 if (!$message) {
459 sqimap_mailbox_select($imapConnection, $mailbox);
460 $message = sqimap_get_message($imapConnection, $id, $mailbox);
461 }
9487c2ff 462
48985d59 463 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
464 if (count($message->entities) == 0) {
465 if ($message->header->entity_id != $ent_num) {
466 $filename = decodeHeader($message->header->filename);
5100704d 467
48985d59 468 if ($filename == "") {
469 $filename = "untitled-".$message->header->entity_id;
470 }
9487c2ff 471
48985d59 472 $localfilename = GenerateRandomString(32, '', 7);
473 $full_localfilename = "$hashed_attachment_dir/$localfilename";
474 while (file_exists($full_localfilename)) {
475 $localfilename = GenerateRandomString(32, '', 7);
476 $full_localfilename = "$hashed_attachment_dir/$localfilename";
477 }
0a17f9dd 478
48985d59 479 $newAttachment = array();
480 $newAttachment['localfilename'] = $localfilename;
481 $newAttachment['remotefilename'] = $filename;
482 $newAttachment['type'] = strtolower($message->header->type0 .
78a35fcd 483 '/' . $message->header->type1);
da95c4b6 484 $newAttachment['id'] = strtolower($message->header->id);
485 $newAttachment['session'] = $session;
48985d59 486
487 /* Write Attachment to file */
488 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
489 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
490 $id, $message->header->entity_id),
491 $message->header->encoding));
492 fclose ($fp);
493
494 $attachments[] = $newAttachment;
495 }
734f4ee6 496 } else {
48985d59 497 for ($i = 0; $i < count($message->entities); $i++) {
da95c4b6 498 getAttachments($message->entities[$i], $session);
48985d59 499 }
500 }
501 return;
502}
503
da95c4b6 504function showInputForm ($session) {
48985d59 505 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
506 $passed_body, $color, $use_signature, $signature, $prefix_sig,
507 $editor_size, $attachments, $subject, $newmail,
508 $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
509 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
510 $username, $data_dir, $identity, $draft_id, $delete_draft,
9c3e6cd4 511 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
3b17e952 512 $saved_draft, $mail_sent, $sig_first;
48985d59 513
3b487216 514 $subject = decodeHeader($subject, false);
515 $reply_subj = decodeHeader($reply_subj, false);
516 $forward_subj = decodeHeader($forward_subj, false);
48985d59 517
518 if ($use_javascript_addr_book) {
519 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
520 'function open_abook() { ' . "\n" .
521 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
522 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
523 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
524 ' nwin.opener = document.windows;' . "\n" .
525 "}\n" .
526 '// --></SCRIPT>' . "\n\n";
527 }
528
529 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
530 'ENCTYPE="multipart/form-data"';
531 do_hook("compose_form");
e02775fe 532
57257333 533
48985d59 534 echo ">\n";
535
536 if (isset($draft_id)) {
537 echo '<input type="hidden" name="delete_draft" value="' . $draft_id . "\">\n";
538 }
539 if (isset($delete_draft)) {
540 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
541 }
da95c4b6 542 if (isset($session)) {
543 echo '<input type="hidden" name="session" value="' . "$session" . "\">\n";
544 }
545
9c3e6cd4 546 if ($saved_draft == 'yes') {
547 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
548 }
549 if ($mail_sent == 'yes') {
550 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
551 }
48985d59 552 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
9c3e6cd4 553 if ($compose_new_win == '1') {
113e5e9d 554 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
9c3e6cd4 555 }
78a35fcd 556 if ($location_of_buttons == 'top') {
557 showComposeButtonRow();
558 }
48985d59 559
715225af 560 $idents = getPref($data_dir, $username, 'identities', 0);
561 if ($idents > 1) {
48985d59 562 echo ' <TR>' . "\n" .
563 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
564 "\n" .
565 _("From:") .
566 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
567 '<select name=identity>' . "\n" .
568 '<option value=default>' .
569 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
570 $em = getPref($data_dir, $username, 'email_address');
571 if ($em != '') {
248bfebb 572 echo htmlspecialchars(' <' . $em . '>') . "\n";
48985d59 573 }
574 for ($i = 1; $i < $idents; $i ++) {
248bfebb 575 echo '<option value="' . $i . '"';
48985d59 576 if (isset($identity) && $identity == $i) {
78a35fcd 577 echo ' SELECTED';
48985d59 578 }
579 echo '>' . htmlspecialchars(getPref($data_dir, $username,
580 'full_name' . $i));
248bfebb 581 $em = getPref($data_dir, $username, 'email_address' . $i);
48985d59 582 if ($em != '') {
78a35fcd 583 echo htmlspecialchars(' <' . $em . '>') . "\n";
48985d59 584 }
9f599fe3 585 echo '</option>';
48985d59 586 }
587 echo '</select>' . "\n" .
588 ' </TD>' . "\n" .
589 ' </TR>' . "\n";
590 }
591 echo ' <TR>' . "\n" .
592 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
593 _("To:") .
594 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
595 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
596 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
597 ' </TD>' . "\n" .
598 ' </TR>' . "\n" .
599 ' <TR>' . "\n" .
600 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
601 _("CC:") .
602 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
603 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
604 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
605 ' </TD>' . "\n" .
606 ' </TR>' . "\n" .
607 ' <TR>' . "\n" .
608 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
609 _("BCC:") .
610 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
611 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
612 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
613 '</TD></TR>' . "\n" .
614 ' <TR>' . "\n" .
615 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
616 _("Subject:") .
617 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
618 if ($reply_subj) {
619 $reply_subj = str_replace('"', "'", $reply_subj);
620 $reply_subj = trim($reply_subj);
78a35fcd 621 if (substr(strtolower($reply_subj), 0, 3) != 're:') {
48985d59 622 $reply_subj = 'Re: ' . $reply_subj;
78a35fcd 623 }
48985d59 624 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
625 htmlspecialchars($reply_subj) . '">';
78a35fcd 626 }
627 elseif ($forward_subj) {
48985d59 628 $forward_subj = trim($forward_subj);
629 if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
630 (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
631 (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) {
632 $forward_subj = '[Fwd: ' . $forward_subj . ']';
633 }
634 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
635 htmlspecialchars($forward_subj) . '">';
734f4ee6 636 } else {
e707c74a 637 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
48985d59 638 htmlspecialchars($subject) . '">';
639 }
640 echo '</td></tr>' . "\n\n";
641
78a35fcd 642 if ($location_of_buttons == 'between') {
643 showComposeButtonRow();
644 }
48985d59 645
646 echo ' <TR>' . "\n" .
647 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
648 ' &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS="' .
3b17e952 649 $editor_size . '" WRAP=HARD>';
48985d59 650 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
3b17e952 651 if ($sig_first == '1') {
652 echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
653 echo "\n\n".htmlspecialchars($body);
654 }
655 else {
656 echo "\n\n".htmlspecialchars($body);
657 echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
658 }
659 }
660 else {
661 echo htmlspecialchars($body);
48985d59 662 }
663 echo '</TEXTAREA><BR>' . "\n" .
664 ' </TD>' . "\n" .
665 ' </TR>' . "\n";
666
667 if ($location_of_buttons == 'bottom') {
668 showComposeButtonRow();
669 } else {
9f599fe3 670 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
9f599fe3 671 echo ' &nbsp; <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
48985d59 672 }
46bb8da8 673
48985d59 674 /* This code is for attachments */
675 echo ' <TR>' . "\n" .
676 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
677 _("Attach:") .
678 ' </TD>' . "\n" .
679 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
680 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
681 ' &nbsp;&nbsp;<input type="submit" name="attach"' .
682 ' value="' . _("Add") .'">' . "\n" .
683 ' </TD>' . "\n" .
684 ' </TR>' . "\n";
9f599fe3 685
48985d59 686 if (count($attachments)) {
687 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
688 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
689 '&nbsp;' .
690 '</td><td align=left bgcolor="' . $color[0] . '">';
691 foreach ($attachments as $key => $info) {
da95c4b6 692 if ($info['session'] == $session) {
693 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
694 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
695 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
696 show_readable_size(filesize($attached_file)) . ")<br>\n";
697 }
48985d59 698 }
699
700 echo '<input type="submit" name="do_delete" value="' .
701 _("Delete selected attachments") . "\">\n" .
702 '</td></tr>';
703 }
704 /* End of attachment code */
705
706 echo '</TABLE>' . "\n";
707 if ($reply_id) {
708 echo '<input type=hidden name=reply_id value=' . $reply_id . ">\n";
709 }
710 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
711 "\">\n" .
712 '</FORM>';
9f599fe3 713 do_hook('compose_bottom');
48985d59 714 echo '</BODY></HTML>' . "\n";
715}
716
717
70c4fd84 718function showComposeButtonRow() {
78a35fcd 719 global $use_javascript_addr_book, $save_as_draft,
70c4fd84 720 $default_use_priority, $mailprio, $default_use_mdn,
721 $data_dir, $username;
722
ae25968c 723 echo " <TR><TD>\n</TD><TD>\n";
724 if ($default_use_priority) {
725 if(!isset($mailprio)) {
726 $mailprio = "3";
70c4fd84 727 }
728 echo _("Priority") .': <select name="mailprio">'.
729 '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'.
730 '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'.
731 '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'.
732 "</select>";
ae25968c 733 }
734 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
735 if ($default_use_mdn) {
70c4fd84 736 if ($mdn_user_support) {
737 echo "\n\t". _("Receipt") .': '.
738 '<input type="checkbox" name="request_mdn" value=1>'. _("On read").
739 ' <input type="checkbox" name="request_dr" value=1>'. _("On Delivery");
740 }
ae25968c 741 }
48985d59 742
78a35fcd 743 echo " <TR><td>\n </td><td>\n";
01265fba 744 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
78a35fcd 745 if ($use_javascript_addr_book) {
46bb8da8 746 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
747 " <input type=button value=\\\""._("Addresses").
748 "\\\" onclick='javascript:open_abook();'>\");".
749 " // --></SCRIPT><NOSCRIPT>\n".
750 " <input type=submit name=\"html_addr_search\" value=\"".
751 _("Addresses")."\">".
752 " </NOSCRIPT>\n";
734f4ee6 753 } else {
78a35fcd 754 echo " <input type=submit name=\"html_addr_search\" value=\"".
755 _("Addresses")."\">";
756 }
757 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
48985d59 758
78a35fcd 759 if ($save_as_draft) {
760 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
761 }
0a17f9dd 762
78a35fcd 763 do_hook('compose_button_row');
441f2d33 764
46bb8da8 765 echo " </TD></TR>\n\n";
78a35fcd 766}
b278172f 767
70c4fd84 768function checkInput ($show) {
78a35fcd 769 /*
770 * I implemented the $show variable because the error messages
771 * were getting sent before the page header. So, I check once
772 * using $show=false, and then when i'm ready to display the error
773 * message, show=true
774 */
775 global $body, $send_to, $subject, $color;
776
777 if ($send_to == "") {
778 if ($show) {
0ad7dbda 779 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
78a35fcd 780 }
781 return false;
782 }
783 return true;
784} /* function checkInput() */
df15de21 785
3806fa52 786
00793a25 787/* True if FAILURE */
da95c4b6 788function saveAttachedFiles($session) {
4c9d2242 789 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
790
791 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
792 $localfilename = GenerateRandomString(32, '', 7);
793 $full_localfilename = "$hashed_attachment_dir/$localfilename";
794 while (file_exists($full_localfilename)) {
795 $localfilename = GenerateRandomString(32, '', 7);
796 $full_localfilename = "$hashed_attachment_dir/$localfilename";
797 }
798
799 if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
800 if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
056ddad7 801 return true;
4c9d2242 802 }
803 }
9487c2ff 804
4c9d2242 805 $newAttachment['localfilename'] = $localfilename;
806 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
807 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
da95c4b6 808 $newAttachment['session'] = $session;
8ef72f33 809
4c9d2242 810 if ($newAttachment['type'] == "") {
8ef72f33 811 $newAttachment['type'] = 'application/octet-stream';
056ddad7 812 }
9487c2ff 813
4c9d2242 814 $attachments[] = $newAttachment;
815}
816
4c9d2242 817
da95c4b6 818function ClearAttachments($session)
4c9d2242 819{
820 global $username, $attachments, $attachment_dir;
821 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
822
da95c4b6 823 $rem_attachments = array();
4c9d2242 824 foreach ($attachments as $info) {
da95c4b6 825 if ($info['session'] == $session) {
826 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
827 if (file_exists($attached_file)) {
828 unlink($attached_file);
829 }
830 } else {
831 $rem_attachments[] = $info;
832 }
833 }
834 $attachments = $rem_attachments;
4c9d2242 835}
836
da95c4b6 837
4c9d2242 838function getReplyCitation($orig_from)
839{
840 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
841
842 /* First, return an empty string when no citation style selected. */
843 if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
844 return '';
845 }
846
847 /* Decode the users name. */
848 $parpos = strpos($orig_from, '(');
849 if ($parpos === false) {
850 $orig_from = trim(substr($orig_from, 0, strpos($orig_from, '<')));
851 $orig_from = str_replace('"', '', $orig_from);
852 $orig_from = str_replace("'", '', $orig_from);
734f4ee6 853 } else {
4c9d2242 854 $end_parpos = strrpos($orig_from, ')');
855 $end_parpos -= ($end_parpos === false ? $end_parpos : $parpos + 1);
856 $orig_from = trim(substr($orig_from, $parpos + 1, $end_parpos));
857 }
858
859 /* Make sure our final value isn't an empty string. */
860 if ($orig_from == '') {
861 return '';
862 }
863
864 /* Otherwise, try to select the desired citation style. */
865 switch ($reply_citation_style) {
866 case 'author_said':
867 $start = '';
868 $end = ' ' . _("said") . ':';
869 break;
870 case 'quote_who':
871 $start = '<' . _("quote") . ' ' . _("who") . '="';
872 $end = '">';
873 break;
874 case 'user-defined':
1ecabe54 875 $start = $reply_citation_start . ' ';
4c9d2242 876 $end = $reply_citation_end;
877 break;
878 default:
879 return '';
880 }
881
882 /* Build and return the citation string. */
883 return ($start . $orig_from . $end . "\n");
884}
885
5e9e90fd 886?>