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