fix for modified header: $filename = header->getParameter('filename')
[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/plugin.php');
26 require_once('../functions/display_messages.php');
27 /* --------------------- Specific Functions ------------------------------ */
28
29 function replyAllString($header) {
30 global $include_self_reply_all, $username, $data_dir;
31 $excl_arr = array();
32 /**
33 * 1) Remove the addresses we'll be sending the message 'to'
34 */
35 $url_replytoall_avoid_addrs = '';
36 if (isset($header->replyto)) {
37 $excl_ar = $header->getAddr_a('replyto');
38 }
39 /**
40 * 2) Remove our identities from the CC list (they still can be in the
41 * TO list) only if $include_self_reply_all is turned off
42 */
43 if (!$include_self_reply_all) {
44 $email_address = trim(getPref($data_dir, $username, 'email_address'));
45 $excl_ar[$email_address] = '';
46
47 $idents = getPref($data_dir, $username, 'identities');
48 if ($idents != '' && $idents > 1) {
49 for ($i = 1; $i < $idents; $i ++) {
50 $cur_email_address = getPref($data_dir, $username,
51 'email_address' . $i);
52 $cur_email_address = strtolower($cur_email_address);
53 $excl_ar[$cur_email_address] = '';
54 }
55 }
56 }
57
58 /**
59 * 3) get the addresses.
60 */
61 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
62
63 /**
64 * 4) generate the string.
65 */
66 $url_replytoallcc = '';
67 foreach( $url_replytoall_ar as $email => $personal) {
68 if ($personal) {
69 $url_replytoallcc .= ", \"$personal\" <$email>";
70 } else {
71 $url_replytoallcc .= ', '. $email;
72 }
73 }
74 $url_replytoallcc = substr($url_replytoallcc,2);
75 return $url_replytoallcc;
76 }
77
78 function getforwardHeader($orig_header) {
79 $display = array(
80 _("Subject") => strlen(_("Subject")),
81 _("From") => strlen(_("From")),
82 _("Date") => strlen(_("Date")),
83 _("To") => strlen(_("To")),
84 _("Cc") => strlen(_("Cc"))
85 );
86 $maxsize = max($display);
87 $indent = str_pad('',$maxsize+2);
88 foreach($display as $key => $val) {
89 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
90 }
91 $bodyTop = str_pad(' '._("Original Message").' ',78, '-',STR_PAD_BOTH);
92 $bodyTop .= "\n". $display[_("Subject")] . $orig_header->subject . "\n" .
93 $display[_("From")] . $orig_header->getAddr_s('from',"\n$indent") . "\n" .
94 $display[_("Date")] . getLongDateString( $orig_header->date ). "\n" .
95 $display[_("To")] . $orig_header->getAddr_s('to',"\n$indent") ."\n";
96 if ($orig_header->cc != array() && $orig_header->cc !='') {
97 $bodyTop .= $display[_("Cc")] . $orig_header->getAddr_s('cc',"\n$indent") . "\n";
98 }
99 $bodyTop .= str_pad('',78, '-');
100 $bodyTop .= "\n";
101 return $bodyTop;
102 }
103 /* ----------------------------------------------------------------------- */
104
105 /*
106 * If the session is expired during a post this restores the compose session
107 * vars.
108 */
109 //$session_expired = false;
110 if (session_is_registered('session_expired_post')) {
111 global $session_expired_post, $session_expired;
112 /*
113 * extra check for username so we don't display previous post data from
114 * another user during this session.
115 */
116 if ($session_expired_post['username'] != $username) {
117 session_unregister('session_expired_post');
118 session_unregister('session_expired');
119 } else {
120 foreach ($session_expired_post as $postvar => $val) {
121 if (isset($val)) {
122 $$postvar = $val;
123 } else {
124 $$postvar = '';
125 }
126 }
127 if (isset($send)) {
128 unset($send);
129 }
130 $session_expired = true;
131 }
132 session_unregister('session_expired_post');
133 session_unregister('session_expired');
134 if (!isset($mailbox)) {
135 $mailbox = '';
136 }
137 if ($compose_new_win == '1') {
138 compose_Header($color, $mailbox);
139 } else {
140 displayPageHeader($color, $mailbox);
141 }
142 showInputForm($session, false);
143 exit();
144 }
145
146 if (!isset($attachments)) {
147 $attachments = array();
148 session_register('attachments');
149 }
150
151 if (!isset($composesession)) {
152 $composesession = 0;
153 session_register('composesession');
154 }
155
156 if (!isset($session) || (isset($newmessage) && $newmessage)) {
157 $session = "$composesession" +1;
158 $composesession = $session;
159 }
160
161 if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) {
162 $mailbox = 'INBOX';
163 }
164
165 if (isset($draft)) {
166 include_once ('../src/draft_actions.php');
167 if (! isset($passed_id)) {
168 $passed_id = 0;
169 }
170 if (! isset($MDN)) {
171 $MDN = 'False';
172 }
173 if (! isset($mailprio)) {
174 $mailprio = '';
175 }
176 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $passed_id, $mailprio, $session)) {
177 showInputForm($session);
178 exit();
179 } else {
180 $draft_message = _("Draft Email Saved");
181 /* If this is a resumed draft, then delete the original */
182 if(isset($delete_draft)) {
183 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
184 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
185 exit();
186 }
187 else {
188 if ($compose_new_win == '1') {
189 Header("Location: compose.php?saved_draft=yes&session=$composesession");
190 exit();
191 }
192 else {
193 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
194 "&startMessage=1&note=".urlencode($draft_message));
195 exit();
196 }
197 }
198 }
199 }
200
201 if (isset($send)) {
202 if (isset($HTTP_POST_FILES['attachfile']) &&
203 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
204 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
205 $AttachFailure = saveAttachedFiles($session);
206 }
207 if (checkInput(false) && !isset($AttachFailure)) {
208 $urlMailbox = urlencode (trim($mailbox));
209 if (! isset($passed_id)) {
210 $passed_id = 0;
211 }
212 /*
213 * Set $default_charset to correspond with the user's selection
214 * of language interface.
215 */
216 set_my_charset();
217
218 /*
219 * This is to change all newlines to \n
220 * We'll change them to \r\n later (in the sendMessage function)
221 */
222 $body = str_replace("\r\n", "\n", $body);
223 $body = str_replace("\r", "\n", $body);
224
225 /*
226 * Rewrap $body so that no line is bigger than $editor_size
227 * This should only really kick in the sqWordWrap function
228 * if the browser doesn't support "VIRTUAL" as the wrap type.
229 */
230 $body = explode("\n", $body);
231 $newBody = '';
232 foreach ($body as $line) {
233 if( $line <> '-- ' ) {
234 $line = rtrim($line);
235 }
236 if (strlen($line) <= $editor_size + 1) {
237 $newBody .= $line . "\n";
238 } else {
239 sqWordWrap($line, $editor_size);
240 $newBody .= $line . "\n";
241 }
242 }
243 $body = $newBody;
244
245 do_hook('compose_send');
246
247 $MDN = False; // we are not sending a mdn response
248 if (! isset($mailprio)) {
249 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
250 $subject, $body, $passed_id, $MDN, '', $session);
251 } else {
252 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
253 $subject, $body, $passed_id, $MDN, $mailprio, $session);
254 }
255 if (! $Result) {
256 showInputForm($session);
257 exit();
258 }
259 if ( isset($delete_draft)) {
260 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
261 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
262 exit();
263 }
264 if ($compose_new_win == '1') {
265 Header("Location: compose.php?mail_sent=yes");
266 }
267 else {
268 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
269 "&startMessage=1");
270 }
271 } else {
272 /*
273 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
274 * $imapPort, 0);
275 */
276 if ($compose_new_win == '1') {
277 compose_Header($color, $mailbox);
278 }
279 else {
280 displayPageHeader($color, $mailbox);
281 }
282 if (isset($AttachFailure)) {
283 plain_error_message(_("Could not move/copy file. File not attached"),
284 $color);
285 }
286 checkInput(true);
287 showInputForm($session);
288 /* sqimap_logout($imapConnection); */
289 }
290 } elseif (isset($html_addr_search_done)) {
291 if ($compose_new_win == '1') {
292 compose_Header($color, $mailbox);
293 }
294 else {
295 displayPageHeader($color, $mailbox);
296 }
297
298 if (isset($send_to_search) && is_array($send_to_search)) {
299 foreach ($send_to_search as $k => $v) {
300 if (substr($k, 0, 1) == 'T') {
301 if ($send_to) {
302 $send_to .= ', ';
303 }
304 $send_to .= $v;
305 }
306 elseif (substr($k, 0, 1) == 'C') {
307 if ($send_to_cc) {
308 $send_to_cc .= ', ';
309 }
310 $send_to_cc .= $v;
311 }
312 elseif (substr($k, 0, 1) == 'B') {
313 if ($send_to_bcc) {
314 $send_to_bcc .= ', ';
315 }
316 $send_to_bcc .= $v;
317 }
318 }
319 }
320 showInputForm($session);
321 } elseif (isset($html_addr_search)) {
322 if (isset($HTTP_POST_FILES['attachfile']) &&
323 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
324 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none') {
325 if (saveAttachedFiles($session)) {
326 plain_error_message(_("Could not move/copy file. File not attached"), $color);
327 }
328 }
329 /*
330 * I am using an include so as to elminiate an extra unnecessary
331 * click. If you can think of a better way, please implement it.
332 */
333 include_once('./addrbook_search_html.php');
334 } elseif (isset($attach)) {
335 if (saveAttachedFiles($session)) {
336 plain_error_message(_("Could not move/copy file. File not attached"), $color);
337 }
338 if ($compose_new_win == '1') {
339 compose_Header($color, $mailbox);
340 }
341 else {
342 displayPageHeader($color, $mailbox);
343 }
344 showInputForm($session);
345 }
346 elseif (isset($sigappend)) {
347 $idents = getPref($data_dir, $username, 'identities', 0);
348 if ($idents > 1) {
349 if ($identity == 'default') {
350 $no = 'g';
351 } else {
352 $no = $identity;
353 }
354 $signature = getSig($data_dir, $username, $no);
355 }
356 $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature;
357 if ($compose_new_win == '1') {
358 compose_Header($color, $mailbox);
359 } else {
360 displayPageHeader($color, $mailbox);
361 }
362 showInputForm($session);
363 } elseif (isset($do_delete)) {
364 if ($compose_new_win == '1') {
365 compose_Header($color, $mailbox);
366 }
367 else {
368 displayPageHeader($color, $mailbox);
369 }
370
371 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
372 if (isset($delete) && is_array($delete)) {
373 foreach($delete as $index) {
374 $attached_file = $hashed_attachment_dir . '/'
375 . $attachments[$index]['localfilename'];
376 unlink ($attached_file);
377 unset ($attachments[$index]);
378 }
379 setPref($data_dir, $username, 'attachments', serialize($attachments));
380 }
381
382 showInputForm($session);
383 } else {
384 /*
385 * This handles the default case as well as the error case
386 * (they had the same code) --> if (isset($smtpErrors))
387 */
388
389 if ($compose_new_win == '1') {
390 compose_Header($color, $mailbox);
391 } else {
392 displayPageHeader($color, $mailbox);
393 }
394
395 $newmail = true;
396
397 if (!isset($passed_ent_id)) $passed_ent_id = '';
398 if (!isset($passed_id)) $passed_id = '';
399 if (!isset($mailbox)) $mailbox = '';
400 if (!isset($action)) $action = '';
401
402 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
403
404 /* in case the origin is not read_body.php */
405 if (isset($send_to)) {
406 $values['send_to'] = $send_to;
407 }
408 if (isset($send_to_cc)) {
409 $values['send_to_cc'] = $send_to_cc;
410 }
411 if (isset($send_to_bcc)) {
412 $values['send_to_bcc'] = $send_to_bcc;
413 }
414 showInputForm($session, $values);
415 }
416
417 exit();
418
419 /**************** Only function definitions go below *************/
420
421
422 /* This function is used when not sending or adding attachments */
423 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
424 global $editor_size, $default_use_priority,
425 $use_signature, $composesession, $data_dir, $username,
426 $username, $key, $imapServerAddress, $imapPort;
427
428 $send_to = $send_to_cc = $send_to_bcc = $subject = $body = $identity = '';
429 $mailprio = 3;
430
431 if ($passed_id) {
432 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
433 $imapPort, 0);
434
435 sqimap_mailbox_select($imapConnection, $mailbox);
436 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
437 $body = '';
438 if ($passed_ent_id) {
439 /* redefine the messsage in case of message/rfc822 */
440 $message = $message->getEntity($passed_ent_id);
441 /* message is an entity which contains the envelope and type0=message
442 * and type1=rfc822. The actual entities are childs from
443 * $message->entities[0]. That's where the encoding and is located
444 */
445
446 $entities = $message->entities[0]->findDisplayEntity
447 (array(), $alt_order = array('text/plain'));
448 if (!count($entities)) {
449 $entities = $message->entities[0]->findDisplayEntity
450 (array(), $alt_order = array('text/plain','html/plain'));
451 }
452 $orig_header = $message->rfc822_header; /* here is the envelope located */
453 /* redefine the message for picking up the attachments */
454 $message = $message->entities[0];
455
456 } else {
457 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
458 if (!count($entities)) {
459 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
460 }
461 $orig_header = $message->rfc822_header;
462 }
463 $encoding = $message->header->encoding;
464 $type0 = $message->type0;
465 $type1 = $message->type1;
466
467 foreach ($entities as $ent) {
468 $bodypart = decodeBody(
469 mime_fetch_body($imapConnection, $passed_id, $ent),
470 $encoding);
471 if ($type1 == 'html') {
472 $bodypart = strip_tags($bodypart);
473 }
474 $body .= $bodypart;
475 }
476 if ($default_use_priority) {
477 $mailprio = substr($orig_header->priority,0,1);
478 if (!$mailprio) {
479 $mailprio = 3;
480 }
481 } else {
482 $mailprio = '';
483 }
484 ClearAttachments($session);
485
486 $identity = '';
487 $idents = getPref($data_dir, $username, 'identities');
488 $from_o = $orig_header->from;
489 if (is_object($from_o)) {
490 $orig_from = $from_o->getAddress();
491 } else {
492 $orig_from = '';
493 }
494 if (!empty($idents) && $idents > 1) {
495 for ($i = 1; $i < $idents; $i++) {
496 $enc_from_name = '"'.
497 getPref($data_dir,
498 $username,
499 'full_name' . $i) .
500 '" <' . getPref($data_dir, $username,
501 'email_address' . $i) . '>';
502 if ($enc_from_name == $orig_from) {
503 $identity = $i;
504 break;
505 }
506 }
507 }
508
509 switch ($action) {
510 case ('draft'):
511 $use_signature = FALSE;
512 $send_to = $orig_header->getAddr_s('to');
513 $send_to_cc = $orig_header->getAddr_s('cc');
514 $send_to_bcc = $orig_header->getAddr_s('bcc');
515 $subject = $orig_header->subject;
516
517 $body_ary = explode("\n", $body);
518 $cnt = count($body_ary) ;
519 $body = '';
520 for ($i=0; $i < $cnt; $i++) {
521 if (!ereg("^[>\\s]*$", $body_ary[$i])) {
522 sqWordWrap($body_ary[$i], $editor_size );
523 $body .= $body_ary[$i] . "\n";
524 }
525 unset($body_ary[$i]);
526 }
527 sqUnWordWrap($body);
528 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
529 break;
530 case ('edit_as_new'):
531 $send_to = $orig_header->getAddr_s('to');
532 $send_to_cc = $orig_header->getAddr_s('cc');
533 $send_to_bcc = $orig_header->getAddr_s('bcc');
534 $subject = $orig_header->subject;
535 $mailprio = $orig_header->priority;
536 $orig_from = '';
537 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
538 sqUnWordWrap($body);
539 break;
540 case ('forward'):
541 $send_to = '';
542 $subject = $orig_header->subject;
543 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
544 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
545 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
546 $subject = '[Fwd: ' . $subject . ']';
547 }
548 $body = getforwardHeader($orig_header) . $body;
549 sqUnWordWrap($body);
550 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
551 break;
552 case ('reply_all'):
553 $send_to_cc = replyAllString($orig_header);
554 case ('reply'):
555 $send_to = $orig_header->reply_to;
556 if (is_object($send_to)) {
557 $send_to = $send_to->getAddr_s('reply_to');
558 } else {
559 $send_to = $orig_header->getAddr_s('from');
560 }
561 $subject = $orig_header->subject;
562 $subject = str_replace('"', "'", $subject);
563 $subject = trim($subject);
564 if (substr(strtolower($subject), 0, 3) != 're:') {
565 $subject = 'Re: ' . $subject;
566 }
567 /* this corrects some wrapping/quoting problems on replies */
568 $rewrap_body = explode("\n", $body);
569 $body = getReplyCitation($orig_header->from->personal);
570 $cnt = count($rewrap_body);
571 for ($i=0;$i<$cnt;$i++) {
572 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
573 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
574 $gt = $matches[1];
575 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
576 } else {
577 $body .= '> ' . $rewrap_body[$i] . "\n";
578 }
579 unset($rewrap_body[$i]);
580 }
581 break;
582 default:
583 break;
584 }
585 sqimap_logout($imapConnection);
586 }
587 $ret = array(
588 'send_to' => $send_to,
589 'send_to_cc' => $send_to_cc,
590 'send_to_bcc' => $send_to_bcc,
591 'subject' => $subject,
592 'mailprio' => $mailprio,
593 'body' => $body,
594 'identity' => $identity
595 );
596
597 return ($ret);
598 } /* function newMail() */
599
600
601 function getAttachments($message, $session, $passed_id, $entities, $imapConnection) {
602 global $attachments, $attachment_dir, $username, $data_dir;
603
604 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
605 if (!count($message->entities) ||
606 ($message->type0 == 'message' && $message->type1 == 'rfc822')) {
607 if ( !in_array($message->entity_id, $entities) && $message->entity_id) {
608 if ($message->type0 == 'message' && $message->type1 == 'rfc822') {
609 $filename = decodeHeader($message->rfc822_header->subject.'.eml');
610 if ($filename == "") {
611 $filename = "untitled-".$message->entity_id.'.eml';
612 }
613 } else {
614 $filename = decodeHeader($message->header->getParameter('filename'));
615 if ($filename == "") {
616 $filename = "untitled-".$message->entity_id;
617 }
618 }
619 $localfilename = GenerateRandomString(32, '', 7);
620 $full_localfilename = "$hashed_attachment_dir/$localfilename";
621 while (file_exists($full_localfilename)) {
622 $localfilename = GenerateRandomString(32, '', 7);
623 $full_localfilename = "$hashed_attachment_dir/$localfilename";
624 }
625
626 $newAttachment = array();
627 $newAttachment['localfilename'] = $localfilename;
628 $newAttachment['remotefilename'] = $filename;
629 $newAttachment['type'] = strtolower($message->type0 .
630 '/' . $message->type1);
631 $newAttachment['id'] = strtolower($message->header->id);
632 $newAttachment['session'] = $session;
633
634 /* Write Attachment to file */
635 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
636 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
637 $passed_id, $message->entity_id),
638 $message->header->encoding));
639 fclose ($fp);
640
641 $attachments[] = $newAttachment;
642 setPref($data_dir, $username, 'attachments', $attachments);
643 }
644 } else {
645 for ($i = 0; $i < count($message->entities); $i++) {
646 getAttachments($message->entities[$i], $session, $passed_id, $entities, $imapConnection);
647 }
648 }
649 return;
650 }
651
652 function showInputForm ($session, $values=false) {
653 global $send_to, $send_to_cc, $body,
654 $passed_body, $color, $use_signature, $signature, $prefix_sig,
655 $editor_size, $attachments, $subject, $newmail,
656 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
657 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
658 $username, $data_dir, $identity, $draft_id, $delete_draft,
659 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
660 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
661 $username;
662
663 $subject = decodeHeader($subject, false);
664 if ($values) {
665 $send_to = $values['send_to'];
666 $send_to_cc = $values['send_to_cc'];
667 $send_to_bcc = $values['send_to_bcc'];
668 $subject = $values['subject'];
669 $mailprio = $values['mailprio'];
670 $body = $values['body'];
671 $identity = $values['identity'];
672 }
673
674 if ($use_javascript_addr_book) {
675 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
676 'function open_abook() { ' . "\n" .
677 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
678 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
679 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
680 ' nwin.opener = document.windows;' . "\n" .
681 "}\n" .
682 '// --></SCRIPT>' . "\n\n";
683 }
684
685 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
686 'ENCTYPE="multipart/form-data"';
687 do_hook("compose_form");
688
689
690 echo ">\n";
691
692 if ($action == 'draft') {
693 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
694 }
695 if (isset($delete_draft)) {
696 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
697 }
698 if (isset($session)) {
699 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
700 }
701
702
703 if ($saved_draft == 'yes') {
704 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
705 }
706 if ($mail_sent == 'yes') {
707 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
708 }
709 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
710 if ($compose_new_win == '1') {
711 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
712 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
713 }
714 if ($location_of_buttons == 'top') {
715 showComposeButtonRow();
716 }
717
718 $idents = getPref($data_dir, $username, 'identities', 0);
719 if ($idents > 1) {
720 echo ' <TR>' . "\n" .
721 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
722 "\n" .
723 _("From:") .
724 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
725 '<select name=identity>' . "\n" .
726 '<option value=default>' .
727 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
728 $em = getPref($data_dir, $username, 'email_address');
729 if ($em != '') {
730 echo htmlspecialchars(' <' . $em . '>') . "\n";
731 }
732 for ($i = 1; $i < $idents; $i ++) {
733 echo '<option value="' . $i . '"';
734 if (isset($identity) && $identity == $i) {
735 echo ' SELECTED';
736 }
737 echo '>' . htmlspecialchars(getPref($data_dir, $username,
738 'full_name' . $i));
739 $em = getPref($data_dir, $username, 'email_address' . $i);
740 if ($em != '') {
741 echo htmlspecialchars(' <' . $em . '>') . "\n";
742 }
743 echo '</option>';
744 }
745 echo '</select>' . "\n" .
746 ' </TD>' . "\n" .
747 ' </TR>' . "\n";
748 }
749 echo ' <TR>' . "\n" .
750 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
751 _("To:") .
752 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
753 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
754 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
755 ' </TD>' . "\n" .
756 ' </TR>' . "\n" .
757 ' <TR>' . "\n" .
758 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
759 _("CC:") .
760 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
761 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
762 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
763 ' </TD>' . "\n" .
764 ' </TR>' . "\n" .
765 ' <TR>' . "\n" .
766 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
767 _("BCC:") .
768 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
769 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
770 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
771 '</TD></TR>' . "\n" .
772 ' <TR>' . "\n" .
773 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
774 _("Subject:") .
775 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
776 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
777 htmlspecialchars($subject) . '">';
778 echo '</td></tr>' . "\n\n";
779
780 if ($location_of_buttons == 'between') {
781 showComposeButtonRow();
782 }
783 if ($compose_new_win == '1') {
784 echo ' <TR>' . "\n" .
785 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
786 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
787 $editor_size . '" WRAP="VIRTUAL">';
788 }
789 else {
790 echo ' <TR>' . "\n" .
791 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
792 ' &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS="' .
793 $editor_size . '" WRAP="VIRTUAL">';
794 }
795 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
796 if ($sig_first == '1') {
797 echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
798 echo "\n\n".htmlspecialchars($body);
799 }
800 else {
801 echo "\n\n".htmlspecialchars($body);
802 echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
803 }
804 }
805 else {
806 echo htmlspecialchars($body);
807 }
808 echo '</TEXTAREA><BR>' . "\n" .
809 ' </TD>' . "\n" .
810 ' </TR>' . "\n";
811
812 if ($location_of_buttons == 'bottom') {
813 showComposeButtonRow();
814 } else {
815 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
816 echo ' &nbsp; <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
817 }
818
819 /* This code is for attachments */
820 echo ' <TR>' . "\n" .
821 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
822 _("Attach:") .
823 ' </TD>' . "\n" .
824 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
825 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
826 ' &nbsp;&nbsp;<input type="submit" name="attach"' .
827 ' value="' . _("Add") .'">' . "\n" .
828 ' </TD>' . "\n" .
829 ' </TR>' . "\n";
830
831 if (count($attachments)) {
832 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
833 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
834 '&nbsp;' .
835 '</td><td align=left bgcolor="' . $color[0] . '">';
836 foreach ($attachments as $key => $info) {
837 if ($info['session'] == $session) {
838 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
839 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
840 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
841 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
842 }
843 }
844
845 echo '<input type="submit" name="do_delete" value="' .
846 _("Delete selected attachments") . "\">\n" .
847 '</td></tr>';
848 }
849 /* End of attachment code */
850 if ($compose_new_win == '1') {
851 echo '</TABLE>'."\n";
852 }
853 echo '</TABLE>' . "\n";
854
855 echo '<input type="hidden" name="username" value="'. $username . "\">\n";
856 echo '<input type=hidden name=action value=' . $action . ">\n";
857 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
858 "\">\n" .
859 '</FORM>';
860 do_hook('compose_bottom');
861 echo '</BODY></HTML>' . "\n";
862 }
863
864
865 function showComposeButtonRow() {
866 global $use_javascript_addr_book, $save_as_draft,
867 $default_use_priority, $mailprio, $default_use_mdn,
868 $request_mdn, $request_dr,
869 $data_dir, $username;
870
871 echo " <TR><TD>\n</TD><TD>\n";
872 if ($default_use_priority) {
873 if(!isset($mailprio)) {
874 $mailprio = "3";
875 }
876 echo _("Priority") .': <select name="mailprio">'.
877 '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'.
878 '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'.
879 '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'.
880 "</select>";
881 }
882 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
883 if ($default_use_mdn) {
884 if ($mdn_user_support) {
885 echo "\n\t". _("Receipt") .': '.
886 '<input type="checkbox" name="request_mdn" value=1'.
887 ($request_mdn=='1'?' checked':'') .'>'. _("On read").
888 ' <input type="checkbox" name="request_dr" value=1'.
889 ($request_dr=='1'?' checked':'') .'>'. _("On Delivery");
890 }
891 }
892
893 echo " </td></tr>\n <TR><td>\n </td><td>\n";
894 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
895 if ($use_javascript_addr_book) {
896 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
897 " <input type=button value=\\\""._("Addresses").
898 "\\\" onclick='javascript:open_abook();'>\");".
899 " // --></SCRIPT><NOSCRIPT>\n".
900 " <input type=submit name=\"html_addr_search\" value=\"".
901 _("Addresses")."\">".
902 " </NOSCRIPT>\n";
903 } else {
904 echo " <input type=submit name=\"html_addr_search\" value=\"".
905 _("Addresses")."\">";
906 }
907 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
908
909 if ($save_as_draft) {
910 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
911 }
912
913 do_hook('compose_button_row');
914
915 echo " </TD></TR>\n\n";
916 }
917
918 function checkInput ($show) {
919 /*
920 * I implemented the $show variable because the error messages
921 * were getting sent before the page header. So, I check once
922 * using $show=false, and then when i'm ready to display the error
923 * message, show=true
924 */
925 global $body, $send_to, $subject, $color;
926
927 if ($send_to == "") {
928 if ($show) {
929 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
930 }
931 return false;
932 }
933 return true;
934 } /* function checkInput() */
935
936
937 /* True if FAILURE */
938 function saveAttachedFiles($session) {
939 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username,
940 $data_dir;
941
942 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
943 $localfilename = GenerateRandomString(32, '', 7);
944 $full_localfilename = "$hashed_attachment_dir/$localfilename";
945 while (file_exists($full_localfilename)) {
946 $localfilename = GenerateRandomString(32, '', 7);
947 $full_localfilename = "$hashed_attachment_dir/$localfilename";
948 }
949
950 if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
951 if (function_exists("move_uploaded_file")) {
952 if (!@move_uploaded_file($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
953 return true;
954 }
955 } else {
956 if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
957 return true;
958 }
959 }
960
961 }
962 $newAttachment['localfilename'] = $localfilename;
963 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
964 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
965 $newAttachment['session'] = $session;
966
967 if ($newAttachment['type'] == "") {
968 $newAttachment['type'] = 'application/octet-stream';
969 }
970 $attachments[] = $newAttachment;
971 setPref($data_dir, $username, 'attachments', serialize($attachments));
972 }
973
974
975 function ClearAttachments($session)
976 {
977 global $username, $attachments, $attachment_dir, $data_dir;
978 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
979
980 $rem_attachments = array();
981 if (is_array($attachments)) {
982 foreach ($attachments as $info) {
983 if ($info['session'] == $session) {
984 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
985 if (file_exists($attached_file)) {
986 unlink($attached_file);
987 }
988 }
989 else {
990 $rem_attachments[] = $info;
991 }
992 }
993 }
994 $attachments = $rem_attachments;
995 setPref($data_dir, $username, 'attachments', serialize($attachments));
996 }
997
998
999 function getReplyCitation($orig_from)
1000 {
1001 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
1002
1003 /* First, return an empty string when no citation style selected. */
1004 if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
1005 return '';
1006 }
1007
1008 /* Make sure our final value isn't an empty string. */
1009 if ($orig_from == '') {
1010 return '';
1011 }
1012
1013 /* Otherwise, try to select the desired citation style. */
1014 switch ($reply_citation_style) {
1015 case 'author_said':
1016 $start = '';
1017 $end = ' ' . _("said") . ':';
1018 break;
1019 case 'quote_who':
1020 $start = '<' . _("quote") . ' ' . _("who") . '="';
1021 $end = '">';
1022 break;
1023 case 'user-defined':
1024 $start = $reply_citation_start . ' ';
1025 $end = $reply_citation_end;
1026 break;
1027 default:
1028 return '';
1029 }
1030
1031 /* Build and return the citation string. */
1032 return ($start . $orig_from . $end . "\n");
1033 }
1034
1035 ?>