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