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