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