reordered for easier code
[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".
41b94d65 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,
399 $use_signature, $composesession;
48985d59 400
41b94d65 401 $send_to = $send_to_cc = $send_to_bcc = $subject = $mailprio = $body = '';
e7f1a81d 402
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);
451 switch ($action) {
452 case ('draft'):
453 $use_signature = FALSE;
454 $send_to = $orig_header->getAddr_s('to');
455 $send_to_cc = $orig_header->getAddr_s('cc');
456 $send_to_bcc = $orig_header->getAddr_s('bcc');
457 $subject = $orig_header->subject;
458
459 $body_ary = explode("\n", $body);
460 $cnt = count($body_ary) ;
461 $body = '';
462 for ($i=0; $i < $cnt; $i++) {
463 if (!ereg("^[>\\s]*$", $body_ary[$i])) {
464 sqWordWrap($body_ary[$i], $editor_size );
465 $body .= $body_ary[$i] . "\n";
dc197c8a 466 }
41b94d65 467 unset($body_ary[$i]);
468 }
469 sqUnWordWrap($body);
470 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
471 break;
472 case ('edit_as_new'):
473 $send_to = $orig_header->getAddr_s('to');
474 $send_to_cc = $orig_header->getAddr_s('cc');
475 $send_to_bcc = $orig_header->getAddr_s('bcc');
476 $subject = $orig_header->subject;
477 $mailprio = $orig_header->priority;
478 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
479 sqUnWordWrap($body);
480 break;
481 case ('forward'):
482 $send_to = '';
483 $orig_from = $orig_header->from->getAddress();
484 $subject = $orig_header->subject;
485 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
486 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
487 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
488 $subject = '[Fwd: ' . $subject . ']';
489 }
490 $body = getforwardHeader($orig_header) . $body;
491 sqUnWordWrap($body);
492 getAttachments($message, $session, $passed_id, $entities, $imapConnection);
493 break;
494 case ('reply' || 'reply_all'):
495 $send_to = $orig_header->reply_to;
496 if ($send_to) {
497 $send_to = $send_to->getAddress();
498 } else {
499 $send_to = $orig_header->from->getAddress();
500 }
501 $orig_from = $orig_header->from->getAddress();
502 $subject = $orig_header->subject;
503 $subject = str_replace('"', "'", $subject);
504 $subject = trim($subject);
505 if (substr(strtolower($subject), 0, 3) != 're:') {
506 $subject = 'Re: ' . $subject;
507 }
508 if ($action == 'reply_all') {
509 $send_to_cc = replyAllString($orig_header);
510 }
511 /* this corrects some wrapping/quoting problems on replies */
512 $rewrap_body = explode("\n", $body);
513 $body = getReplyCitation($orig_header->from->personal);
514 $cnt = count($rewrap_body);
515 for ($i=0;$i<$cnt;$i++) {
3f606b3f 516 sqWordWrap($rewrap_body[$i], ($editor_size - 2));
517 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
518 $gt = $matches[1];
41b94d65 519 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
734f4ee6 520 } else {
41b94d65 521 $body .= '> ' . $rewrap_body[$i] . "\n";
522 }
523 unset($rewrap_body[$i]);
524 }
525 break;
526 default:
527 break;
528 }
529 }
530 $ret = array(
531 'send_to' => $send_to,
532 'send_to_cc' => $send_to_cc,
533 'send_to_bcc' => $send_to_bcc,
534 'subject' => $subject,
535 'mailprio' => $mailprio,
536 'body' => $body
537 );
538
539 return ($ret);
48985d59 540} /* function newMail() */
541
78509c54 542
41b94d65 543function getAttachments($message, $session, $passed_id, $entities, $imapConnection) {
544 global $attachments, $attachment_dir, $username;
545
48985d59 546 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
41b94d65 547 if (!count($message->entities) ||
548 ($message->type0 == 'message' && $message->type1 == 'rfc822')) {
549 if ( !in_array($message->entity_id, $entities) && $message->entity_id) {
550 if ($message->type0 == 'message' && $message->type1 == 'rfc822') {
551 $filename = decodeHeader($message->header->subject.'.eml');
552 if ($filename == "") {
553 $filename = "untitled-".$message->entity_id.'.eml';
554 }
555 } else {
556 $filename = decodeHeader($message->header->filename);
557 if ($filename == "") {
558 $filename = "untitled-".$message->entity_id;
559 }
48985d59 560 }
48985d59 561 $localfilename = GenerateRandomString(32, '', 7);
562 $full_localfilename = "$hashed_attachment_dir/$localfilename";
563 while (file_exists($full_localfilename)) {
564 $localfilename = GenerateRandomString(32, '', 7);
565 $full_localfilename = "$hashed_attachment_dir/$localfilename";
566 }
0a17f9dd 567
48985d59 568 $newAttachment = array();
569 $newAttachment['localfilename'] = $localfilename;
570 $newAttachment['remotefilename'] = $filename;
41b94d65 571 $newAttachment['type'] = strtolower($message->type0 .
572 '/' . $message->type1);
da95c4b6 573 $newAttachment['id'] = strtolower($message->header->id);
574 $newAttachment['session'] = $session;
48985d59 575
576 /* Write Attachment to file */
577 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
578 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
41b94d65 579 $passed_id, $message->entity_id),
48985d59 580 $message->header->encoding));
581 fclose ($fp);
582
583 $attachments[] = $newAttachment;
584 }
734f4ee6 585 } else {
48985d59 586 for ($i = 0; $i < count($message->entities); $i++) {
41b94d65 587 getAttachments($message->entities[$i], $session, $passed_id, $entities, $imapConnection);
48985d59 588 }
589 }
590 return;
591}
592
41b94d65 593function showInputForm ($session, $values=false) {
594 global $send_to, $send_to_cc, $body,
48985d59 595 $passed_body, $color, $use_signature, $signature, $prefix_sig,
596 $editor_size, $attachments, $subject, $newmail,
41b94d65 597 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
48985d59 598 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
599 $username, $data_dir, $identity, $draft_id, $delete_draft,
9c3e6cd4 600 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
41b94d65 601 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action;
48985d59 602
3b487216 603 $subject = decodeHeader($subject, false);
41b94d65 604 if ($values) {
605 $send_to = $values['send_to'];
606 $send_to_cc = $values['send_to_cc'];
607 $send_to_bcc = $values['send_to_bcc'];
608 $subject = $values['subject'];
609 $mailprio = $values['mailprio'];
610 $body = $values['body'];
611 }
612
48985d59 613 if ($use_javascript_addr_book) {
614 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
615 'function open_abook() { ' . "\n" .
616 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
617 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
618 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
619 ' nwin.opener = document.windows;' . "\n" .
620 "}\n" .
621 '// --></SCRIPT>' . "\n\n";
622 }
623
41b94d65 624 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
625 'ENCTYPE="multipart/form-data"';
48985d59 626 do_hook("compose_form");
e02775fe 627
57257333 628
48985d59 629 echo ">\n";
630
41b94d65 631 if ($action == 'draft') {
632 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
48985d59 633 }
634 if (isset($delete_draft)) {
635 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
636 }
da95c4b6 637 if (isset($session)) {
638 echo '<input type="hidden" name="session" value="' . "$session" . "\">\n";
639 }
640
9c3e6cd4 641 if ($saved_draft == 'yes') {
642 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
643 }
644 if ($mail_sent == 'yes') {
645 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
646 }
41b94d65 647 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
9c3e6cd4 648 if ($compose_new_win == '1') {
41b94d65 649 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n";
650 echo ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
9c3e6cd4 651 }
78a35fcd 652 if ($location_of_buttons == 'top') {
653 showComposeButtonRow();
654 }
48985d59 655
715225af 656 $idents = getPref($data_dir, $username, 'identities', 0);
657 if ($idents > 1) {
41b94d65 658 echo ' <TR>' . "\n" .
659 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
660 "\n" .
661 _("From:") .
662 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
48985d59 663 '<select name=identity>' . "\n" .
664 '<option value=default>' .
665 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
666 $em = getPref($data_dir, $username, 'email_address');
667 if ($em != '') {
248bfebb 668 echo htmlspecialchars(' <' . $em . '>') . "\n";
48985d59 669 }
670 for ($i = 1; $i < $idents; $i ++) {
248bfebb 671 echo '<option value="' . $i . '"';
48985d59 672 if (isset($identity) && $identity == $i) {
78a35fcd 673 echo ' SELECTED';
48985d59 674 }
675 echo '>' . htmlspecialchars(getPref($data_dir, $username,
676 'full_name' . $i));
248bfebb 677 $em = getPref($data_dir, $username, 'email_address' . $i);
48985d59 678 if ($em != '') {
78a35fcd 679 echo htmlspecialchars(' <' . $em . '>') . "\n";
48985d59 680 }
9f599fe3 681 echo '</option>';
48985d59 682 }
683 echo '</select>' . "\n" .
41b94d65 684 ' </TD>' . "\n" .
685 ' </TR>' . "\n";
686 }
687 echo ' <TR>' . "\n" .
688 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
689 _("To:") .
690 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
691 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
692 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
693 ' </TD>' . "\n" .
694 ' </TR>' . "\n" .
695 ' <TR>' . "\n" .
696 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
697 _("CC:") .
698 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
699 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
700 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
701 ' </TD>' . "\n" .
702 ' </TR>' . "\n" .
703 ' <TR>' . "\n" .
704 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
705 _("BCC:") .
706 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
707 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
708 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
709 '</TD></TR>' . "\n" .
710 ' <TR>' . "\n" .
711 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
712 _("Subject:") .
713 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
714 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
715 htmlspecialchars($subject) . '">';
716 echo '</td></tr>' . "\n\n";
48985d59 717
78a35fcd 718 if ($location_of_buttons == 'between') {
719 showComposeButtonRow();
720 }
fdc83c55 721 if ($compose_new_win == '1') {
41b94d65 722 echo ' <TR>' . "\n" .
723 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
724 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
725 $editor_size . '" WRAP="VIRTUAL">';
fdc83c55 726 }
727 else {
41b94d65 728 echo ' <TR>' . "\n" .
729 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
730 ' &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS="' .
731 $editor_size . '" WRAP="VIRTUAL">';
fdc83c55 732 }
48985d59 733 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
3b17e952 734 if ($sig_first == '1') {
735 echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
736 echo "\n\n".htmlspecialchars($body);
737 }
738 else {
739 echo "\n\n".htmlspecialchars($body);
740 echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
741 }
742 }
743 else {
744 echo htmlspecialchars($body);
48985d59 745 }
41b94d65 746 echo '</TEXTAREA><BR>' . "\n" .
747 ' </TD>' . "\n" .
748 ' </TR>' . "\n";
48985d59 749
750 if ($location_of_buttons == 'bottom') {
751 showComposeButtonRow();
752 } else {
41b94d65 753 echo ' <TR><TD COLSPAN=2 ALIGN=LEFT>';
754 echo ' &nbsp; <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
48985d59 755 }
46bb8da8 756
48985d59 757 /* This code is for attachments */
41b94d65 758 echo ' <TR>' . "\n" .
759 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
760 _("Attach:") .
761 ' </TD>' . "\n" .
762 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
763 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
764 ' &nbsp;&nbsp;<input type="submit" name="attach"' .
765 ' value="' . _("Add") .'">' . "\n" .
766 ' </TD>' . "\n" .
767 ' </TR>' . "\n";
768
769 if (count($attachments)) {
770 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
771 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
772 '&nbsp;' .
773 '</td><td align=left bgcolor="' . $color[0] . '">';
774 foreach ($attachments as $key => $info) {
775 if ($info['session'] == $session) {
776 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
777 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
778 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
779 show_readable_size( filesize( $attached_file ) ) . ")<br>\n";
780 }
781 }
782
783 echo '<input type="submit" name="do_delete" value="' .
784 _("Delete selected attachments") . "\">\n" .
785 '</td></tr>';
786 }
787 /* End of attachment code */
07687736 788 if ($compose_new_win == '1') {
41b94d65 789 echo '</TABLE>'."\n";
07687736 790 }
41b94d65 791 echo '</TABLE>' . "\n";
792 if ($action = 'reply' || $action = 'reply_all') {
793 echo '<input type=hidden name=reply_id value=' . $passed_id . ">\n";
48985d59 794 }
795 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
796 "\">\n" .
797 '</FORM>';
9f599fe3 798 do_hook('compose_bottom');
48985d59 799 echo '</BODY></HTML>' . "\n";
800}
801
802
70c4fd84 803function showComposeButtonRow() {
78a35fcd 804 global $use_javascript_addr_book, $save_as_draft,
70c4fd84 805 $default_use_priority, $mailprio, $default_use_mdn,
b2a7e5bc 806 $request_mdn, $request_dr,
70c4fd84 807 $data_dir, $username;
808
41b94d65 809 echo " <TR><TD>\n</TD><TD>\n";
ae25968c 810 if ($default_use_priority) {
811 if(!isset($mailprio)) {
812 $mailprio = "3";
70c4fd84 813 }
814 echo _("Priority") .': <select name="mailprio">'.
815 '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'.
816 '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'.
817 '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'.
818 "</select>";
ae25968c 819 }
820 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
821 if ($default_use_mdn) {
70c4fd84 822 if ($mdn_user_support) {
823 echo "\n\t". _("Receipt") .': '.
b2a7e5bc 824 '<input type="checkbox" name="request_mdn" value=1'.
825 ($request_mdn=='1'?' checked':'') .'>'. _("On read").
826 ' <input type="checkbox" name="request_dr" value=1'.
827 ($request_dr=='1'?' checked':'') .'>'. _("On Delivery");
70c4fd84 828 }
ae25968c 829 }
48985d59 830
41b94d65 831 echo " </td></tr>\n <TR><td>\n </td><td>\n";
01265fba 832 echo "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
78a35fcd 833 if ($use_javascript_addr_book) {
46bb8da8 834 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
835 " <input type=button value=\\\""._("Addresses").
836 "\\\" onclick='javascript:open_abook();'>\");".
837 " // --></SCRIPT><NOSCRIPT>\n".
838 " <input type=submit name=\"html_addr_search\" value=\"".
839 _("Addresses")."\">".
840 " </NOSCRIPT>\n";
734f4ee6 841 } else {
78a35fcd 842 echo " <input type=submit name=\"html_addr_search\" value=\"".
843 _("Addresses")."\">";
844 }
845 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
48985d59 846
78a35fcd 847 if ($save_as_draft) {
848 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
849 }
0a17f9dd 850
78a35fcd 851 do_hook('compose_button_row');
441f2d33 852
41b94d65 853 echo " </TD></TR>\n\n";
78a35fcd 854}
b278172f 855
70c4fd84 856function checkInput ($show) {
78a35fcd 857 /*
858 * I implemented the $show variable because the error messages
859 * were getting sent before the page header. So, I check once
860 * using $show=false, and then when i'm ready to display the error
861 * message, show=true
862 */
863 global $body, $send_to, $subject, $color;
864
865 if ($send_to == "") {
866 if ($show) {
0ad7dbda 867 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
78a35fcd 868 }
869 return false;
870 }
871 return true;
872} /* function checkInput() */
df15de21 873
3806fa52 874
00793a25 875/* True if FAILURE */
da95c4b6 876function saveAttachedFiles($session) {
4c9d2242 877 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
878
879 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
880 $localfilename = GenerateRandomString(32, '', 7);
881 $full_localfilename = "$hashed_attachment_dir/$localfilename";
882 while (file_exists($full_localfilename)) {
883 $localfilename = GenerateRandomString(32, '', 7);
884 $full_localfilename = "$hashed_attachment_dir/$localfilename";
885 }
886
887 if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
ceca62d3 888 if (function_exists("move_uploaded_file")) {
889 if (!@move_uploaded_file($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
056ddad7 890 return true;
ceca62d3 891 }
892 } else {
893
894 if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
895 return true;
896 }
897 }
898
4c9d2242 899 }
9487c2ff 900
41b94d65 901
902
4c9d2242 903 $newAttachment['localfilename'] = $localfilename;
904 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
905 $newAttachment['type'] = strtolower($HTTP_POST_FILES['attachfile']['type']);
da95c4b6 906 $newAttachment['session'] = $session;
8ef72f33 907
4c9d2242 908 if ($newAttachment['type'] == "") {
8ef72f33 909 $newAttachment['type'] = 'application/octet-stream';
056ddad7 910 }
9487c2ff 911
4c9d2242 912 $attachments[] = $newAttachment;
913}
914
4c9d2242 915
da95c4b6 916function ClearAttachments($session)
4c9d2242 917{
918 global $username, $attachments, $attachment_dir;
919 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
920
da95c4b6 921 $rem_attachments = array();
8712abea 922 if (is_array($attachments)) {
923 foreach ($attachments as $info) {
924 if ($info['session'] == $session) {
925 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
926 if (file_exists($attached_file)) {
927 unlink($attached_file);
928 }
929 }
930 else {
931 $rem_attachments[] = $info;
932 }
933 }
da95c4b6 934 }
935 $attachments = $rem_attachments;
4c9d2242 936}
937
da95c4b6 938
4c9d2242 939function getReplyCitation($orig_from)
940{
941 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
942
943 /* First, return an empty string when no citation style selected. */
944 if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
945 return '';
946 }
947
4c9d2242 948 /* Make sure our final value isn't an empty string. */
949 if ($orig_from == '') {
950 return '';
951 }
952
953 /* Otherwise, try to select the desired citation style. */
954 switch ($reply_citation_style) {
955 case 'author_said':
956 $start = '';
957 $end = ' ' . _("said") . ':';
958 break;
959 case 'quote_who':
960 $start = '<' . _("quote") . ' ' . _("who") . '="';
961 $end = '">';
962 break;
963 case 'user-defined':
1ecabe54 964 $start = $reply_citation_start . ' ';
4c9d2242 965 $end = $reply_citation_end;
966 break;
967 default:
968 return '';
969 }
970
971 /* Build and return the citation string. */
972 return ($start . $orig_from . $end . "\n");
973}
974
5e9e90fd 975?>