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