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