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