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