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