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