Quotes detection in motd
[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;
dc197c8a 393 $body = '';
48985d59 394 if ($ent_num) {
dc197c8a 395 $ent_ar = preg_split('/_/',$ent_num);
396 foreach($ent_ar as $ent_num) {
397 $message = getEntity($message, $ent_num);
398 if ($message->header->type0 == 'text' ||
399 $message->header->type1 == 'message') {
400 $bodypart = decodeBody(
401 mime_fetch_body($imapConnection, $id, $ent_num),
402 $message->header->encoding);
403 if ($message->header->type1 == 'html') {
404 $bodypart = strip_tags($bodypart);
405 }
406 $body .= $bodypart;
407 }
408 }
409 } else if ($message->header->type0 == 'text' ||
410 $message->header->type1 == 'message') {
411 $body .= decodeBody(
412 mime_fetch_body($imapConnection, $id, 1),
413 $message->header->encoding);
414 if ($message->header->type1 == 'html') {
415 $body = strip_tags($body);
416 }
417
418 }
f82d9be2 419
3f606b3f 420 sqUnWordWrap($body);
421
422 /* this corrects some wrapping/quoting problems on replies */
423 if ($reply_id) {
424 $rewrap_body = explode("\n", $body);
425 for ($i=0;$i<count($rewrap_body);$i++) {
426 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
427 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
428 $gt = $matches[1];
429 $rewrap_body[$i] = str_replace("\n", "\n$gt ", $rewrap_body[$i]);
430 }
431 $rewrap_body[$i] .= "\n";
432 }
433 $body = implode("", $rewrap_body);
434 }
435
48985d59 436 $body_ary = explode("\n", $body);
437 $i = count($body_ary) - 1;
438 while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
fb6ce88e 439 unset($body_ary[$i]);
440 $i --;
48985d59 441 }
442 $body = '';
443 for ($i=0; isset($body_ary[$i]); $i++) {
444 if ($reply_id) {
3f606b3f 445 if (preg_match("/^(>){1,}/", $body_ary[$i])) {
01aab860 446 $body_ary[$i] = '>' . $body_ary[$i];
734f4ee6 447 } else {
01aab860 448 $body_ary[$i] = '> ' . $body_ary[$i];
449 }
450 }
3f606b3f 451 if ($draft_id) {
452 sqWordWrap($body_ary[$i], $editor_size );
a951522b 453 }
01aab860 454 $body .= $body_ary[$i] . "\n";
f923b93d 455 unset($body_ary[$i]);
48985d59 456 }
457 if ($forward_id) {
458 $bodyTop = '-------- ' . _("Original Message") . " --------\n" .
459 _("Subject") . ': ' . $orig_header->subject . "\n" .
460 _("From") . ': ' . $orig_header->from . "\n" .
78a35fcd 461 _("Date") . ': ' .
462 getLongDateString( $orig_header->date ). "\n" .
48985d59 463 _("To") . ': ' . $orig_header->to[0] . "\n";
78a35fcd 464 if (count($orig_header->to) > 1) {
465 for ($x=1; $x < count($orig_header->to); $x++) {
466 $bodyTop .= ' ' . $orig_header->to[$x] . "\n";
467 }
468 }
a0bc3274 469 if (isset($forward_cc) && $forward_cc) {
470 $bodyTop .= _("Cc") . ': ' . $orig_header->cc[0] . "\n";
471 if (count($orig_header->cc) > 1) {
472 for ($x = 1; $x < count($orig_header->cc); $x++) {
473 $bodyTop .= ' ' . $orig_header->cc[$x] . "\n";
474 }
475 }
476 }
78a35fcd 477 $bodyTop .= "\n";
478 $body = $bodyTop . $body;
479 }
480 elseif ($reply_id) {
3b487216 481 $orig_from = decodeHeader($orig_header->from, false);
78a35fcd 482 $body = getReplyCitation($orig_from) . $body;
483 }
9487c2ff 484
78a35fcd 485 return;
48985d59 486 }
429f8906 487
48985d59 488 if (!$send_to) {
78a35fcd 489 $send_to = sqimap_find_email($send_to);
48985d59 490 }
29d08a52 491
48985d59 492 /* This formats a CC string if they hit "reply all" */
493 if ($send_to_cc != '') {
494 $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc);
0f8a1ce9 495 $send_to_cc = str_replace(';', ',', $send_to_cc);
48985d59 496 $sendcc = explode(',', $send_to_cc);
497 $send_to_cc = '';
9487c2ff 498
48985d59 499 for ($i = 0; $i < count($sendcc); $i++) {
df15de21 500 $sendcc[$i] = trim($sendcc[$i]);
48985d59 501 if ($sendcc[$i] == '') {
502 continue;
503 }
9487c2ff 504
a53e5469 505 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
48985d59 506 $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']);
507 $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']);
9487c2ff 508
df15de21 509 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
510 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
48985d59 511 (trim($sendcc[$i]) != '')) {
512 $send_to_cc .= trim($sendcc[$i]) . ', ';
df15de21 513 }
48985d59 514 }
515 $send_to_cc = trim($send_to_cc);
516 if (substr($send_to_cc, -1) == ',') {
df15de21 517 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
48985d59 518 }
519 }
520} /* function newMail() */
521
78509c54 522
da95c4b6 523function getAttachments($message, $session) {
48985d59 524 global $mailbox, $attachments, $attachment_dir, $imapConnection,
d7f8e6e6 525 $ent_num, $forward_id, $draft_id, $username, $passed_id;
e707c74a 526
48985d59 527 if (isset($draft_id)) {
78a35fcd 528 $id = $draft_id;
d7f8e6e6 529 } else if (isset($forward_id)) {
78a35fcd 530 $id = $forward_id;
d7f8e6e6 531 } else {
532 $id = $passed_id;
48985d59 533 }
f972eb46 534
48985d59 535 if (!$message) {
536 sqimap_mailbox_select($imapConnection, $mailbox);
537 $message = sqimap_get_message($imapConnection, $id, $mailbox);
538 }
9487c2ff 539
48985d59 540 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
541 if (count($message->entities) == 0) {
542 if ($message->header->entity_id != $ent_num) {
543 $filename = decodeHeader($message->header->filename);
5100704d 544
48985d59 545 if ($filename == "") {
546 $filename = "untitled-".$message->header->entity_id;
547 }
9487c2ff 548
48985d59 549 $localfilename = GenerateRandomString(32, '', 7);
550 $full_localfilename = "$hashed_attachment_dir/$localfilename";
551 while (file_exists($full_localfilename)) {
552 $localfilename = GenerateRandomString(32, '', 7);
553 $full_localfilename = "$hashed_attachment_dir/$localfilename";
554 }
0a17f9dd 555
48985d59 556 $newAttachment = array();
557 $newAttachment['localfilename'] = $localfilename;
558 $newAttachment['remotefilename'] = $filename;
559 $newAttachment['type'] = strtolower($message->header->type0 .
78a35fcd 560 '/' . $message->header->type1);
da95c4b6 561 $newAttachment['id'] = strtolower($message->header->id);
562 $newAttachment['session'] = $session;
48985d59 563
564 /* Write Attachment to file */
565 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
566 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
567 $id, $message->header->entity_id),
568 $message->header->encoding));
569 fclose ($fp);
570
571 $attachments[] = $newAttachment;
572 }
734f4ee6 573 } else {
48985d59 574 for ($i = 0; $i < count($message->entities); $i++) {
da95c4b6 575 getAttachments($message->entities[$i], $session);
48985d59 576 }
577 }
578 return;
579}
580
da95c4b6 581function showInputForm ($session) {
48985d59 582 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
583 $passed_body, $color, $use_signature, $signature, $prefix_sig,
584 $editor_size, $attachments, $subject, $newmail,
585 $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
586 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
587 $username, $data_dir, $identity, $draft_id, $delete_draft,
9c3e6cd4 588 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
52b3ed56 589 $saved_draft, $mail_sent, $sig_first, $edit_as_new;
48985d59 590
c480566c 591 $file_uploads = ini_get('file_uploads');
3b487216 592 $subject = decodeHeader($subject, false);
593 $reply_subj = decodeHeader($reply_subj, false);
594 $forward_subj = decodeHeader($forward_subj, false);
48985d59 595
596 if ($use_javascript_addr_book) {
597 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
598 'function open_abook() { ' . "\n" .
599 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
600 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
601 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
602 ' nwin.opener = document.windows;' . "\n" .
603 "}\n" .
604 '// --></SCRIPT>' . "\n\n";
605 }
606
c480566c 607 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ';
608 if ($file_uploads) {
609 echo 'ENCTYPE="multipart/form-data"';
610 }
48985d59 611 do_hook("compose_form");
e02775fe 612
57257333 613
48985d59 614 echo ">\n";
615
52b3ed56 616 if (isset($draft_id) && !$edit_as_new) {
48985d59 617 echo '<input type="hidden" name="delete_draft" value="' . $draft_id . "\">\n";
618 }
619 if (isset($delete_draft)) {
620 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
621 }
da95c4b6 622 if (isset($session)) {
623 echo '<input type="hidden" name="session" value="' . "$session" . "\">\n";
624 }
625
9c3e6cd4 626 if ($saved_draft == 'yes') {
627 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
628 }
629 if ($mail_sent == 'yes') {
630 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
631 }
48985d59 632 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
9c3e6cd4 633 if ($compose_new_win == '1') {
07687736 634 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
113e5e9d 635 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
9c3e6cd4 636 }
78a35fcd 637 if ($location_of_buttons == 'top') {
638 showComposeButtonRow();
639 }
48985d59 640
715225af 641 $idents = getPref($data_dir, $username, 'identities', 0);
642 if ($idents > 1) {
48985d59 643 echo ' <TR>' . "\n" .
644 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
645 "\n" .
646 _("From:") .
647 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
648 '<select name=identity>' . "\n" .
649 '<option value=default>' .
650 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
651 $em = getPref($data_dir, $username, 'email_address');
652 if ($em != '') {
248bfebb 653 echo htmlspecialchars(' <' . $em . '>') . "\n";
48985d59 654 }
655 for ($i = 1; $i < $idents; $i ++) {
248bfebb 656 echo '<option value="' . $i . '"';
48985d59 657 if (isset($identity) && $identity == $i) {
78a35fcd 658 echo ' SELECTED';
48985d59 659 }
660 echo '>' . htmlspecialchars(getPref($data_dir, $username,
661 'full_name' . $i));
248bfebb 662 $em = getPref($data_dir, $username, 'email_address' . $i);
48985d59 663 if ($em != '') {
78a35fcd 664 echo htmlspecialchars(' <' . $em . '>') . "\n";
48985d59 665 }
9f599fe3 666 echo '</option>';
48985d59 667 }
668 echo '</select>' . "\n" .
669 ' </TD>' . "\n" .
670 ' </TR>' . "\n";
671 }
672 echo ' <TR>' . "\n" .
673 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
674 _("To:") .
675 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
676 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
677 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
678 ' </TD>' . "\n" .
679 ' </TR>' . "\n" .
680 ' <TR>' . "\n" .
681 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
682 _("CC:") .
683 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
684 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
685 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
686 ' </TD>' . "\n" .
687 ' </TR>' . "\n" .
688 ' <TR>' . "\n" .
689 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
690 _("BCC:") .
691 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
692 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
693 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
694 '</TD></TR>' . "\n" .
695 ' <TR>' . "\n" .
696 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
697 _("Subject:") .
698 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
699 if ($reply_subj) {
700 $reply_subj = str_replace('"', "'", $reply_subj);
701 $reply_subj = trim($reply_subj);
78a35fcd 702 if (substr(strtolower($reply_subj), 0, 3) != 're:') {
48985d59 703 $reply_subj = 'Re: ' . $reply_subj;
78a35fcd 704 }
48985d59 705 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
706 htmlspecialchars($reply_subj) . '">';
78a35fcd 707 }
708 elseif ($forward_subj) {
48985d59 709 $forward_subj = trim($forward_subj);
710 if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
711 (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
712 (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) {
713 $forward_subj = '[Fwd: ' . $forward_subj . ']';
714 }
715 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
716 htmlspecialchars($forward_subj) . '">';
734f4ee6 717 } else {
e707c74a 718 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
48985d59 719 htmlspecialchars($subject) . '">';
720 }
721 echo '</td></tr>' . "\n\n";
722
78a35fcd 723 if ($location_of_buttons == 'between') {
724 showComposeButtonRow();
725 }
fdc83c55 726 if ($compose_new_win == '1') {
727 echo ' <TR>' . "\n" .
728 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
729 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
730 $editor_size . '" WRAP="VIRTUAL">';
731 }
732 else {
733 echo ' <TR>' . "\n" .
734 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
735 ' &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS="' .
736 $editor_size . '" WRAP="VIRTUAL">';
737 }
48985d59 738 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
3b17e952 739 if ($sig_first == '1') {
740 echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
741 echo "\n\n".htmlspecialchars($body);
742 }
743 else {
744 echo "\n\n".htmlspecialchars($body);
745 echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
746 }
747 }
748 else {
749 echo htmlspecialchars($body);
48985d59 750 }
751 echo '</TEXTAREA><BR>' . "\n" .
752 ' </TD>' . "\n" .
753 ' </TR>' . "\n";
754
755 if ($location_of_buttons == 'bottom') {
756 showComposeButtonRow();
757 } else {
9f599fe3 758 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
9f599fe3 759 echo ' &nbsp; <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
48985d59 760 }
46bb8da8 761
48985d59 762 /* This code is for attachments */
c480566c 763 if ($file_uploads) {
764 echo ' <TR>' . "\n" .
765 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
766 _("Attach:") .
767 ' </TD>' . "\n" .
768 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
769 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
770 ' &nbsp;&nbsp;<input type="submit" name="attach"' .
771 ' value="' . _("Add") .'">' . "\n" .
772 ' </TD>' . "\n" .
773 ' </TR>' . "\n";
774
775 if (count($attachments)) {
776 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
777 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
778 '&nbsp;' .
779 '</td><td align=left bgcolor="' . $color[0] . '">';
780 foreach ($attachments as $key => $info) {
781 if ($info['session'] == $session) {
782 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
783 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
784 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
785 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
786 }
787 }
9f599fe3 788
c480566c 789 echo '<input type="submit" name="do_delete" value="' .
790 _("Delete selected attachments") . "\">\n" .
791 '</td></tr>';
792 }
793 /* End of attachment code */
794 }
07687736 795 if ($compose_new_win == '1') {
796 echo '</TABLE>'."\n";
797 }
48985d59 798 echo '</TABLE>' . "\n";
799 if ($reply_id) {
800 echo '<input type=hidden name=reply_id value=' . $reply_id . ">\n";
801 }
802 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
803 "\">\n" .
804 '</FORM>';
9f599fe3 805 do_hook('compose_bottom');
48985d59 806 echo '</BODY></HTML>' . "\n";
807}
808
809
70c4fd84 810function showComposeButtonRow() {
78a35fcd 811 global $use_javascript_addr_book, $save_as_draft,
70c4fd84 812 $default_use_priority, $mailprio, $default_use_mdn,
b2a7e5bc 813 $request_mdn, $request_dr,
70c4fd84 814 $data_dir, $username;
815
ae25968c 816 echo " <TR><TD>\n</TD><TD>\n";
817 if ($default_use_priority) {
818 if(!isset($mailprio)) {
819 $mailprio = "3";
70c4fd84 820 }
821 echo _("Priority") .': <select name="mailprio">'.
822 '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'.
823 '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'.
824 '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'.
825 "</select>";
ae25968c 826 }
827 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
828 if ($default_use_mdn) {
70c4fd84 829 if ($mdn_user_support) {
830 echo "\n\t". _("Receipt") .': '.
b2a7e5bc 831 '<input type="checkbox" name="request_mdn" value=1'.
832 ($request_mdn=='1'?' checked':'') .'>'. _("On read").
833 ' <input type="checkbox" name="request_dr" value=1'.
834 ($request_dr=='1'?' checked':'') .'>'. _("On Delivery");
70c4fd84 835 }
ae25968c 836 }
48985d59 837
960a624f 838 echo " </td></tr>\n <TR><td>\n </td><td>\n";
01265fba 839 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
78a35fcd 840 if ($use_javascript_addr_book) {
46bb8da8 841 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
842 " <input type=button value=\\\""._("Addresses").
843 "\\\" onclick='javascript:open_abook();'>\");".
844 " // --></SCRIPT><NOSCRIPT>\n".
845 " <input type=submit name=\"html_addr_search\" value=\"".
846 _("Addresses")."\">".
847 " </NOSCRIPT>\n";
734f4ee6 848 } else {
78a35fcd 849 echo " <input type=submit name=\"html_addr_search\" value=\"".
850 _("Addresses")."\">";
851 }
852 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
48985d59 853
78a35fcd 854 if ($save_as_draft) {
855 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
856 }
0a17f9dd 857
78a35fcd 858 do_hook('compose_button_row');
441f2d33 859
46bb8da8 860 echo " </TD></TR>\n\n";
78a35fcd 861}
b278172f 862
70c4fd84 863function checkInput ($show) {
78a35fcd 864 /*
865 * I implemented the $show variable because the error messages
866 * were getting sent before the page header. So, I check once
867 * using $show=false, and then when i'm ready to display the error
868 * message, show=true
869 */
870 global $body, $send_to, $subject, $color;
871
872 if ($send_to == "") {
873 if ($show) {
0ad7dbda 874 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
78a35fcd 875 }
876 return false;
877 }
878 return true;
879} /* function checkInput() */
df15de21 880
3806fa52 881
00793a25 882/* True if FAILURE */
da95c4b6 883function saveAttachedFiles($session) {
4c9d2242 884 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
885
886 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
887 $localfilename = GenerateRandomString(32, '', 7);
888 $full_localfilename = "$hashed_attachment_dir/$localfilename";
889 while (file_exists($full_localfilename)) {
890 $localfilename = GenerateRandomString(32, '', 7);
891 $full_localfilename = "$hashed_attachment_dir/$localfilename";
892 }
893
894 if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
895 if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
056ddad7 896 return true;
4c9d2242 897 }
898 }
9487c2ff 899
4c9d2242 900 $newAttachment['localfilename'] = $localfilename;
901 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
902 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
da95c4b6 903 $newAttachment['session'] = $session;
8ef72f33 904
4c9d2242 905 if ($newAttachment['type'] == "") {
8ef72f33 906 $newAttachment['type'] = 'application/octet-stream';
056ddad7 907 }
9487c2ff 908
4c9d2242 909 $attachments[] = $newAttachment;
910}
911
4c9d2242 912
da95c4b6 913function ClearAttachments($session)
4c9d2242 914{
915 global $username, $attachments, $attachment_dir;
916 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
917
da95c4b6 918 $rem_attachments = array();
8712abea 919 if (is_array($attachments)) {
920 foreach ($attachments as $info) {
921 if ($info['session'] == $session) {
922 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
923 if (file_exists($attached_file)) {
924 unlink($attached_file);
925 }
926 }
927 else {
928 $rem_attachments[] = $info;
929 }
930 }
da95c4b6 931 }
932 $attachments = $rem_attachments;
4c9d2242 933}
934
da95c4b6 935
4c9d2242 936function getReplyCitation($orig_from)
937{
938 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
939
940 /* First, return an empty string when no citation style selected. */
941 if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
942 return '';
943 }
944
945 /* Decode the users name. */
946 $parpos = strpos($orig_from, '(');
947 if ($parpos === false) {
948 $orig_from = trim(substr($orig_from, 0, strpos($orig_from, '<')));
949 $orig_from = str_replace('"', '', $orig_from);
950 $orig_from = str_replace("'", '', $orig_from);
734f4ee6 951 } else {
4c9d2242 952 $end_parpos = strrpos($orig_from, ')');
953 $end_parpos -= ($end_parpos === false ? $end_parpos : $parpos + 1);
954 $orig_from = trim(substr($orig_from, $parpos + 1, $end_parpos));
955 }
956
957 /* Make sure our final value isn't an empty string. */
958 if ($orig_from == '') {
959 return '';
960 }
961
962 /* Otherwise, try to select the desired citation style. */
963 switch ($reply_citation_style) {
964 case 'author_said':
965 $start = '';
966 $end = ' ' . _("said") . ':';
967 break;
968 case 'quote_who':
969 $start = '<' . _("quote") . ' ' . _("who") . '="';
970 $end = '">';
971 break;
972 case 'user-defined':
1ecabe54 973 $start = $reply_citation_start . ' ';
4c9d2242 974 $end = $reply_citation_end;
975 break;
976 default:
977 return '';
978 }
979
980 /* Build and return the citation string. */
981 return ($start . $orig_from . $end . "\n");
982}
983
5e9e90fd 984?>