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