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