Fix SRC directory being moved on Windows systems: check whether a file was really...
[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 /* Path for SquirrelMail required files. */
21 define('SM_PATH','../');
22
23 /* SquirrelMail required files. */
24 require_once(SM_PATH . 'include/validate.php');
25 require_once(SM_PATH . 'functions/imap.php');
26 require_once(SM_PATH . 'functions/date.php');
27 require_once(SM_PATH . 'functions/mime.php');
28 //require_once(SM_PATH . 'functions/smtp.php');
29 require_once(SM_PATH . 'functions/plugin.php');
30 require_once(SM_PATH . 'functions/display_messages.php');
31 require_once(SM_PATH . 'class/deliver/Deliver.class.php');
32
33 /* --------------------- Get globals ------------------------------------- */
34 $username = $_SESSION['username'];
35 $onetimepad = $_SESSION['onetimepad'];
36 $base_uri = $_SESSION['base_uri'];
37 $delimiter = $_SESSION['delimiter'];
38
39 if (isset($_POST['return'])) {
40 $html_addr_search_done = 'Use Addresses';
41 }
42 if ( isset($_SESSION['composesession']) ) {
43 $composesession = $_SESSION['composesession'];
44 }
45 sqextractGlobalVar('action');
46 sqextractGlobalVar('session');
47 sqextractGlobalVar('mailbox');
48 sqextractGlobalVar('identity');
49 sqextractGlobalVar('send_to');
50 sqextractGlobalVar('send_to_cc');
51 sqextractGlobalVar('send_to_bcc');
52 sqextractGlobalVar('subject');
53 sqextractGlobalVar('body');
54 sqextractGlobalVar('mailprio');
55 sqextractGlobalVar('request_mdn');
56 sqextractGlobalVar('request_dr');
57 sqextractGlobalVar('html_addr_search');
58 sqextractGlobalVar('mail_sent');
59 sqextractGlobalVar('passed_id');
60 sqextractGlobalVar('passed_ent_id');
61
62 if ( isset($_POST['sigappend']) ) {
63 $sigappend = $_POST['sigappend'];
64 }
65 /* From addressbook search */
66 if ( isset($_POST['from_htmladdr_search']) ) {
67 $from_htmladdr_search = $_POST['from_htmladdr_search'];
68 }
69 if ( isset($_POST['addr_search_done']) ) {
70 $html_addr_search_done = $_POST['addr_search_done'];
71 }
72 if ( isset($_POST['send_to_search']) ) {
73 $send_to_search = &$_POST['send_to_search'];
74 }
75
76 /* Attachments */
77 sqextractGlobalVar('attach');
78 if ( isset($_POST['do_delete']) ) {
79 $do_delete = $_POST['do_delete'];
80 }
81 if ( isset($_POST['delete']) ) {
82 $delete = &$_POST['delete'];
83 }
84 if ( isset($_POST['attachments']) ) {
85 $attachments = &$_POST['attachments'];
86 }
87 elseif ( isset($_SESSION['attachments'])) {
88 $attachments = &$_SESSION['attachments'];
89 }
90
91 /* Forward message as attachment */
92 if ( isset($_GET['attachedmessages']) ) {
93 $attachedmessages = $_GET['attachedmessages'];
94 }
95
96 /* Drafts */
97 sqextractGlobalVar('draft');
98 sqextractGlobalVar('draft_id');
99 sqextractGlobalVar('ent_num');
100 sqextractGlobalVar('saved_draft');
101 sqextractGlobalVar('delete_draft');
102
103 $key = $_COOKIE['key'];
104
105 /* --------------------- Specific Functions ------------------------------ */
106
107 function replyAllString($header) {
108 global $include_self_reply_all, $username, $data_dir;
109 $excl_arr = array();
110 /**
111 * 1) Remove the addresses we'll be sending the message 'to'
112 */
113 $url_replytoall_avoid_addrs = '';
114 if (isset($header->replyto)) {
115 $excl_ar = $header->getAddr_a('replyto');
116 }
117 /**
118 * 2) Remove our identities from the CC list (they still can be in the
119 * TO list) only if $include_self_reply_all is turned off
120 */
121 if (!$include_self_reply_all) {
122 $email_address = trim(getPref($data_dir, $username, 'email_address'));
123 $excl_ar[$email_address] = '';
124
125 $idents = getPref($data_dir, $username, 'identities');
126 if ($idents != '' && $idents > 1) {
127 for ($i = 1; $i < $idents; $i ++) {
128 $cur_email_address = getPref($data_dir, $username,
129 'email_address' . $i);
130 $cur_email_address = strtolower($cur_email_address);
131 $excl_ar[$cur_email_address] = '';
132 }
133 }
134 }
135
136 /**
137 * 3) get the addresses.
138 */
139 $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar);
140
141 /**
142 * 4) generate the string.
143 */
144 $url_replytoallcc = '';
145 foreach( $url_replytoall_ar as $email => $personal) {
146 if ($personal) {
147 $url_replytoallcc .= ", \"$personal\" <$email>";
148 } else {
149 $url_replytoallcc .= ', '. $email;
150 }
151 }
152 $url_replytoallcc = substr($url_replytoallcc,2);
153 return $url_replytoallcc;
154 }
155
156 function getforwardHeader($orig_header) {
157 global $editor_size;
158
159 $display = array( _("Subject") => strlen(_("Subject")),
160 _("From") => strlen(_("From")),
161 _("Date") => strlen(_("Date")),
162 _("To") => strlen(_("To")),
163 _("Cc") => strlen(_("Cc")) );
164 $maxsize = max($display);
165 $indent = str_pad('',$maxsize+2);
166 foreach($display as $key => $val) {
167 $display[$key] = $key .': '. str_pad('', $maxsize - $val);
168 }
169 $bodyTop = str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH) .
170 "\n". $display[_("Subject")] .
171 decodeHeader($orig_header->subject) . "\n" .
172 $display[_("From")] .
173 decodeHeader($orig_header->getAddr_s('from',"\n$indent")) . "\n" .
174 $display[_("Date")] .
175 getLongDateString( $orig_header->date ). "\n" .
176 $display[_("To")] .
177 decodeHeader($orig_header->getAddr_s('to',"\n$indent")) ."\n";
178 if ($orig_header->cc != array() && $orig_header->cc !='') {
179 $bodyTop .= $display[_("Cc")] . decodeHeader($orig_header->getAddr_s('cc',"\n$indent")) . "\n";
180 }
181 $bodyTop .= str_pad('', $editor_size -2 , '-') .
182 "\n";
183 return $bodyTop;
184 }
185 /* ----------------------------------------------------------------------- */
186
187 /* OLD: should be adapted to composeMessage */
188
189 /*
190 * If the session is expired during a post this restores the compose session
191 * vars.
192 */
193 //$session_expired = false;
194 if (session_is_registered('session_expired_post')) {
195 global $session_expired_post, $session_expired;
196 /*
197 * extra check for username so we don't display previous post data from
198 * another user during this session.
199 */
200 if ($session_expired_post['username'] != $username) {
201 sqsession_unregister('session_expired_post');
202 sqsession_unregister('session_expired');
203 } else {
204 foreach ($session_expired_post as $postvar => $val) {
205 if (isset($val)) {
206 $$postvar = $val;
207 } else {
208 $$postvar = '';
209 }
210 }
211 if (isset($send)) {
212 unset($send);
213 }
214 $session_expired = true;
215 }
216 sqsession_unregister('session_expired_post');
217 sqsession_unregister('session_expired');
218 if (!isset($mailbox)) {
219 $mailbox = '';
220 }
221 if ($compose_new_win == '1') {
222 compose_Header($color, $mailbox);
223 } else {
224 displayPageHeader($color, $mailbox);
225 }
226 showInputForm($session, false);
227 exit();
228 }
229
230 if (!isset($composesession)) {
231 $composesession = 0;
232 sqsession_register(0,'composesession');
233 }
234
235 if (!isset($session) || (isset($newmessage) && $newmessage)) {
236 sqsession_unregister('composesession');
237 $session = "$composesession" +1;
238 $composesession = $session;
239 sqsession_register($composesession,'composesession');
240 }
241
242 if (!isset($compose_messages)) {
243 $compose_messages = array();
244 }
245 if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) {
246 /* if (!array_key_exists($session, $compose_messages)) { /* We can only do this in PHP >= 4.1 */
247 $composeMessage = new Message();
248 $rfc822_header = new Rfc822Header();
249 $composeMessage->rfc822_header = $rfc822_header;
250 $composeMessage->reply_rfc822_header = '';
251 $compose_messages[$session] = $composeMessage;
252 sqsession_register($compose_messages,'compose_messages');
253 } else {
254 $composeMessage=$compose_messages[$session];
255 }
256
257 if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) {
258 $mailbox = 'INBOX';
259 }
260
261 if (isset($draft)) {
262 /*
263 * Set $default_charset to correspond with the user's selection
264 * of language interface.
265 */
266 set_my_charset();
267 $composeMessage=$compose_messages[$session];
268 $Result = sendMessage($composeMessage, true);
269
270 if (! sendMessage($composeMessage, true)) {
271 showInputForm($session);
272 exit();
273 } else {
274 $draft_message = _("Draft Email Saved");
275 /* If this is a resumed draft, then delete the original */
276 if(isset($delete_draft)) {
277 Header("Location: delete_message.php?mailbox=" . urlencode($draft_folder) .
278 "&message=$delete_draft&sort=$sort&startMessage=1&saved_draft=yes");
279 exit();
280 }
281 else {
282 if ($compose_new_win == '1') {
283 Header("Location: compose.php?saved_draft=yes&session=$composesession");
284 exit();
285 }
286 else {
287 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort".
288 "&startMessage=1&note=".urlencode($draft_message));
289 exit();
290 }
291 }
292 }
293 }
294
295 if (isset($send)) {
296 if (isset($_FILES['attachfile']) &&
297 $_FILES['attachfile']['tmp_name'] &&
298 $_FILES['attachfile']['tmp_name'] != 'none') {
299 $AttachFailure = saveAttachedFiles($session);
300 }
301 if (checkInput(false) && !isset($AttachFailure)) {
302 $urlMailbox = urlencode (trim($mailbox));
303 if (! isset($passed_id)) {
304 $passed_id = 0;
305 }
306 /*
307 * Set $default_charset to correspond with the user's selection
308 * of language interface.
309 */
310 set_my_charset();
311 /*
312 * This is to change all newlines to \n
313 * We'll change them to \r\n later (in the sendMessage function)
314 */
315 $body = str_replace("\r\n", "\n", $body);
316 $body = str_replace("\r", "\n", $body);
317
318 /*
319 * Rewrap $body so that no line is bigger than $editor_size
320 * This should only really kick in the sqWordWrap function
321 * if the browser doesn't support "VIRTUAL" as the wrap type.
322 */
323 $body = explode("\n", $body);
324 $newBody = '';
325 foreach ($body as $line) {
326 if( $line <> '-- ' ) {
327 $line = rtrim($line);
328 }
329 if (strlen($line) <= $editor_size + 1) {
330 $newBody .= $line . "\n";
331 } else {
332 sqWordWrap($line, $editor_size);
333 $newBody .= $line . "\n";
334 }
335 }
336 $body = $newBody;
337 do_hook('compose_send');
338 $composeMessage=$compose_messages[$session];
339 $Result = sendMessage($composeMessage);
340 if (! $Result) {
341 showInputForm($session);
342 exit();
343 }
344 if ( isset($delete_draft)) {
345 Header("Location: delete_message.php?mailbox=" . urlencode( $draft_folder ).
346 "&message=$delete_draft&sort=$sort&startMessage=1&mail_sent=yes");
347 exit();
348 }
349 if ($compose_new_win == '1') {
350 Header("Location: compose.php?mail_sent=yes");
351 }
352 else {
353 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort".
354 "&startMessage=1");
355 }
356 } else {
357 /*
358 *$imapConnection = sqimap_login($username, $key, $imapServerAddress,
359 * $imapPort, 0);
360 */
361 if ($compose_new_win == '1') {
362 compose_Header($color, $mailbox);
363 }
364 else {
365 displayPageHeader($color, $mailbox);
366 }
367 if (isset($AttachFailure)) {
368 plain_error_message(_("Could not move/copy file. File not attached"),
369 $color);
370 }
371 checkInput(true);
372 showInputForm($session);
373 /* sqimap_logout($imapConnection); */
374 }
375 } elseif (isset($html_addr_search_done)) {
376 if ($compose_new_win == '1') {
377 compose_Header($color, $mailbox);
378 }
379 else {
380 displayPageHeader($color, $mailbox);
381 }
382
383 if (isset($send_to_search) && is_array($send_to_search)) {
384 foreach ($send_to_search as $k => $v) {
385 if (substr($k, 0, 1) == 'T') {
386 if ($send_to) {
387 $send_to .= ', ';
388 }
389 $send_to .= $v;
390 }
391 elseif (substr($k, 0, 1) == 'C') {
392 if ($send_to_cc) {
393 $send_to_cc .= ', ';
394 }
395 $send_to_cc .= $v;
396 }
397 elseif (substr($k, 0, 1) == 'B') {
398 if ($send_to_bcc) {
399 $send_to_bcc .= ', ';
400 }
401 $send_to_bcc .= $v;
402 }
403 }
404 }
405 showInputForm($session);
406 } elseif (isset($html_addr_search)) {
407 if (isset($_FILES['attachfile']) &&
408 $_FILES['attachfile']['tmp_name'] &&
409 $_FILES['attachfile']['tmp_name'] != 'none') {
410 if(saveAttachedFiles($session)) {
411 plain_error_message(_("Could not move/copy file. File not attached"), $color);
412 }
413 }
414 /*
415 * I am using an include so as to elminiate an extra unnecessary
416 * click. If you can think of a better way, please implement it.
417 */
418 include_once('./addrbook_search_html.php');
419 } elseif (isset($attach)) {
420 if (saveAttachedFiles($session)) {
421 plain_error_message(_("Could not move/copy file. File not attached"), $color);
422 }
423 if ($compose_new_win == '1') {
424 compose_Header($color, $mailbox);
425 }
426 else {
427 displayPageHeader($color, $mailbox);
428 }
429 showInputForm($session);
430 }
431 elseif (isset($sigappend)) {
432 $idents = getPref($data_dir, $username, 'identities', 0);
433 if ($idents > 1) {
434 if ($identity == 'default') {
435 $no = 'g';
436 } else {
437 $no = $identity;
438 }
439 $signature = getSig($data_dir, $username, $no);
440 }
441 $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature;
442 if ($compose_new_win == '1') {
443 compose_Header($color, $mailbox);
444 } else {
445 displayPageHeader($color, $mailbox);
446 }
447 showInputForm($session);
448 } elseif (isset($do_delete)) {
449 if ($compose_new_win == '1') {
450 compose_Header($color, $mailbox);
451 }
452 else {
453 displayPageHeader($color, $mailbox);
454 }
455
456 if (isset($delete) && is_array($delete)) {
457 $composeMessage = $compose_messages[$session];
458 foreach($delete as $index) {
459 $attached_file = $composeMessage->entities[$index]->att_local_name;
460 unlink ($attached_file);
461 unset ($composeMessage->entities[$index]);
462 }
463 $new_entities = array();
464 foreach ($composeMessage->entities as $entity) {
465 $new_entities[] = $entity;
466 }
467 $composeMessage->entities = $new_entities;
468 $compose_messages[$session] = $composeMessage;
469 sqsession_register($compose_messages, 'compose_messages');
470 // setPref($data_dir, $username, 'attachments', serialize($attachments));
471 }
472 showInputForm($session);
473 } else {
474 /*
475 * This handles the default case as well as the error case
476 * (they had the same code) --> if (isset($smtpErrors))
477 */
478
479 if ($compose_new_win == '1') {
480 compose_Header($color, $mailbox);
481 } else {
482 displayPageHeader($color, $mailbox);
483 }
484
485 $newmail = true;
486
487 if (!isset($passed_ent_id)) {
488 $passed_ent_id = '';
489 }
490 if (!isset($passed_id)) {
491 $passed_id = '';
492 }
493 if (!isset($mailbox)) {
494 $mailbox = '';
495 }
496 if (!isset($action)) {
497 $action = '';
498 }
499
500 $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session);
501
502 /* in case the origin is not read_body.php */
503 if (isset($send_to)) {
504 $values['send_to'] = $send_to;
505 }
506 if (isset($send_to_cc)) {
507 $values['send_to_cc'] = $send_to_cc;
508 }
509 if (isset($send_to_bcc)) {
510 $values['send_to_bcc'] = $send_to_bcc;
511 }
512 showInputForm($session, $values);
513 }
514
515 exit();
516
517 /**************** Only function definitions go below *************/
518
519
520 /* This function is used when not sending or adding attachments */
521 function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') {
522 global $editor_size, $default_use_priority, $body,
523 $use_signature, $composesession, $data_dir, $username,
524 $username, $key, $imapServerAddress, $imapPort, $compose_messages,
525 $composeMessage;
526
527 $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = '';
528 $mailprio = 3;
529
530 if ($passed_id) {
531 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
532 $imapPort, 0);
533
534 sqimap_mailbox_select($imapConnection, $mailbox);
535 $message = sqimap_get_message($imapConnection, $passed_id, $mailbox);
536
537 $body = '';
538 if ($passed_ent_id) {
539 /* redefine the messsage in case of message/rfc822 */
540 $message = $message->getEntity($passed_ent_id);
541 /* message is an entity which contains the envelope and type0=message
542 * and type1=rfc822. The actual entities are childs from
543 * $message->entities[0]. That's where the encoding and is located
544 */
545
546 $entities = $message->entities[0]->findDisplayEntity
547 (array(), $alt_order = array('text/plain'));
548 if (!count($entities)) {
549 $entities = $message->entities[0]->findDisplayEntity
550 (array(), $alt_order = array('text/plain','html/plain'));
551 }
552 $orig_header = $message->rfc822_header; /* here is the envelope located */
553 /* redefine the message for picking up the attachments */
554 $message = $message->entities[0];
555
556 } else {
557 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain'));
558 if (!count($entities)) {
559 $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain'));
560 }
561 $orig_header = $message->rfc822_header;
562 }
563
564 $encoding = $message->header->encoding;
565 $type0 = $message->type0;
566 $type1 = $message->type1;
567 foreach ($entities as $ent) {
568 $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent);
569 $body_part_entity = $message->getEntity($ent);
570 $bodypart = decodeBody($unencoded_bodypart,
571 $body_part_entity->header->encoding);
572 if ($type1 == 'html') {
573 $bodypart = strip_tags($bodypart);
574 }
575 $body .= $bodypart;
576 }
577 if ($default_use_priority) {
578 $mailprio = substr($orig_header->priority,0,1);
579 if (!$mailprio) {
580 $mailprio = 3;
581 }
582 } else {
583 $mailprio = '';
584 }
585 //ClearAttachments($session);
586
587 $identity = '';
588 $idents = getPref($data_dir, $username, 'identities');
589 $from_o = $orig_header->from;
590 if (is_object($from_o)) {
591 $orig_from = $from_o->getAddress();
592 } else {
593 $orig_from = '';
594 }
595 if (!empty($idents) && $idents > 1) {
596 for ($i = 1; $i < $idents; $i++) {
597 $enc_from_name = '"'.
598 getPref($data_dir,
599 $username,
600 'full_name' . $i) .
601 '" <' . getPref($data_dir, $username,
602 'email_address' . $i) . '>';
603 if ($enc_from_name == $orig_from) {
604 $identity = $i;
605 break;
606 }
607 }
608 }
609
610 switch ($action) {
611 case ('draft'):
612 $use_signature = FALSE;
613 $send_to = decodeHeader($orig_header->getAddr_s('to'));
614 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'));
615 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'));
616 $subject = decodeHeader($orig_header->subject);
617
618 $body_ary = explode("\n", $body);
619 $cnt = count($body_ary) ;
620 $body = '';
621 for ($i=0; $i < $cnt; $i++) {
622 if (!ereg("^[>\\s]*$", $body_ary[$i]) || !$body_ary[$i]) {
623 sqWordWrap($body_ary[$i], $editor_size );
624 $body .= $body_ary[$i] . "\n";
625 }
626 unset($body_ary[$i]);
627 }
628 sqUnWordWrap($body);
629 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
630 break;
631 case ('edit_as_new'):
632 $send_to = decodeHeader($orig_header->getAddr_s('to'));
633 $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'));
634 $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'));
635 $subject = decodeHeader($orig_header->subject);
636 $mailprio = $orig_header->priority;
637 $orig_from = '';
638 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
639 sqUnWordWrap($body);
640 break;
641 case ('forward'):
642 $send_to = '';
643 $subject = decodeHeader($orig_header->subject);
644 if ((substr(strtolower($subject), 0, 4) != 'fwd:') &&
645 (substr(strtolower($subject), 0, 5) != '[fwd:') &&
646 (substr(strtolower($subject), 0, 6) != '[ fwd:')) {
647 $subject = '[Fwd: ' . $subject . ']';
648 }
649 $body = getforwardHeader($orig_header) . $body;
650 sqUnWordWrap($body);
651 $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection);
652 break;
653 case ('forward_as_attachment'):
654 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection);
655 $body = '';
656 break;
657 case ('reply_all'):
658 $send_to_cc = replyAllString($orig_header);
659 case ('reply'):
660 $send_to = $orig_header->reply_to;
661 if (is_object($send_to)) {
662 $send_to = decodeHeader($send_to->getAddr_s('reply_to'));
663 } else {
664 $send_to = decodeHeader($orig_header->getAddr_s('from'));
665 }
666 $subject = decodeHeader($orig_header->subject);
667 $subject = str_replace('"', "'", $subject);
668 $subject = trim($subject);
669 if (substr(strtolower($subject), 0, 3) != 're:') {
670 $subject = 'Re: ' . $subject;
671 }
672 /* this corrects some wrapping/quoting problems on replies */
673 $rewrap_body = explode("\n", $body);
674
675 $body = getReplyCitation($orig_header->from->personal);
676 $cnt = count($rewrap_body);
677 for ($i=0;$i<$cnt;$i++) {
678 // sqWordWrap($rewrap_body[$i], ($editor_size - 2));
679 if (preg_match("/^(>+)/", $rewrap_body[$i], $matches)) {
680 $gt = $matches[1];
681 $body .= '>' . str_replace("\n", "\n$gt ", $rewrap_body[$i]) ."\n";
682 } else {
683 $body .= '> ' . $rewrap_body[$i] . "\n";
684 }
685 unset($rewrap_body[$i]);
686 }
687 $composeMessage->reply_rfc822_header = $orig_header;
688 break;
689 default:
690 break;
691 }
692 $compose_messages[$session] = $composeMessage;
693 sqsession_register($compose_messages, 'compose_messages');
694
695 sqimap_logout($imapConnection);
696 }
697 $ret = array( 'send_to' => $send_to,
698 'send_to_cc' => $send_to_cc,
699 'send_to_bcc' => $send_to_bcc,
700 'subject' => $subject,
701 'mailprio' => $mailprio,
702 'body' => $body,
703 'identity' => $identity );
704
705 return ($ret);
706 } /* function newMail() */
707
708 function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) {
709 global $attachment_dir, $username, $data_dir, $squirrelmail_language;
710 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
711 if (!count($message->entities) ||
712 ($message->type0 == 'message' && $message->type1 == 'rfc822')) {
713 if ( !in_array($message->entity_id, $entities) && $message->entity_id) {
714 switch ($message->type0) {
715 case 'message':
716 if ($message->type1 == 'rfc822') {
717 $filename = decodeHeader($message->rfc822_header->subject.'.eml');
718 if ($filename == "") {
719 $filename = "untitled-".$message->entity_id.'.eml';
720 }
721 } else {
722 $filename = decodeHeader($message->getFilename());
723 }
724 break;
725 default:
726 $filename = decodeHeader($message->getFilename());
727 break;
728 }
729 if (isset($languages[$squirrelmail_language]['XTRA_CODE']) &&
730 function_exists($languages[$squirrelmail_language]['XTRA_CODE'])) {
731 $filename = $languages[$squirrelmail_language]['XTRA_CODE']('encode', $filename);
732 }
733
734 $localfilename = GenerateRandomString(32, '', 7);
735 $full_localfilename = "$hashed_attachment_dir/$localfilename";
736 while (file_exists($full_localfilename)) {
737 $localfilename = GenerateRandomString(32, '', 7);
738 $full_localfilename = "$hashed_attachment_dir/$localfilename";
739 }
740 $message->att_local_name = $full_localfilename;
741 if (!$message->mime_header) { /* temporary hack */
742 $message->mime_header = $message->header;
743 }
744
745 $composeMessage->addEntity($message);
746
747 /* Write Attachment to file */
748 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb');
749 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
750 $passed_id, $message->entity_id),
751 $message->header->encoding));
752 fclose ($fp);
753 }
754 } else {
755 for ($i=0, $entCount=count($message->entities); $i<$entCount;$i++) {
756 $composeMessage=getAttachments($message->entities[$i], $composeMessage, $passed_id, $entities, $imapConnection);
757 }
758 }
759 // setPref($data_dir, $username, 'attachments', serialize($attachments));
760 return $composeMessage;
761 }
762
763 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
764 $passed_ent_id='', $imapConnection) {
765 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
766 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
767 if (!$passed_ent_id) {
768 $body_a = sqimap_run_command($imapConnection,
769 'FETCH '.$passed_id.' RFC822',
770 TRUE, $response, $readmessage,
771 $uid_support);
772 } else {
773 $body_a = sqimap_run_command($imapConnection,
774 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
775 TRUE, $response, $readmessage, $uid_support);
776 $message = $message->parent;
777 }
778 if ($response = 'OK') {
779 $subject = encodeHeader($message->rfc822_header->subject);
780 array_shift($body_a);
781 $body = implode('', $body_a) . "\r\n";
782
783 $localfilename = GenerateRandomString(32, 'FILE', 7);
784 $full_localfilename = "$hashed_attachment_dir/$localfilename";
785
786 $fp = fopen( $full_localfilename, 'w');
787 fwrite ($fp, $body);
788 fclose($fp);
789 $composeMessage->initAttachment('message/rfc822',$subject.'.eml',
790 $full_localfilename);
791 }
792 return $composeMessage;
793 }
794
795 function showInputForm ($session, $values=false) {
796 global $send_to, $send_to_cc, $body,
797 $passed_body, $color, $use_signature, $signature, $prefix_sig,
798 $editor_size, $attachments, $subject, $newmail,
799 $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox,
800 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
801 $username, $data_dir, $identity, $draft_id, $delete_draft,
802 $mailprio, $default_use_mdn, $mdn_user_support, $compose_new_win,
803 $saved_draft, $mail_sent, $sig_first, $edit_as_new, $action,
804 $username, $compose_messages;
805
806 $composeMessage = $compose_messages[$session];
807
808 $subject = decodeHeader($subject, false);
809 if ($values) {
810 $send_to = $values['send_to'];
811 $send_to_cc = $values['send_to_cc'];
812 $send_to_bcc = $values['send_to_bcc'];
813 $subject = $values['subject'];
814 $mailprio = $values['mailprio'];
815 $body = $values['body'];
816 $identity = $values['identity'];
817 }
818
819 if ($use_javascript_addr_book) {
820 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
821 'function open_abook() { ' . "\n" .
822 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
823 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
824 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
825 ' nwin.opener = document.windows;' . "\n" .
826 "}\n" .
827 '// --></SCRIPT>' . "\n\n";
828 }
829
830 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
831 'ENCTYPE="multipart/form-data"';
832 do_hook("compose_form");
833
834
835 echo ">\n";
836
837 if ($action == 'draft') {
838 echo '<input type="hidden" name="delete_draft" value="' . $passed_id . "\">\n";
839 }
840 if (isset($delete_draft)) {
841 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
842 }
843 if (isset($session)) {
844 echo '<input type="hidden" name="session" value="' . $session . "\">\n";
845 }
846
847 if (isset($passed_id)) {
848 echo '<input type="hidden" name="passed_id" value="' . $passed_id . "\">\n";
849 }
850
851 if ($saved_draft == 'yes') {
852 echo '<BR><CENTER><B>'. _("Draft Saved").'</CENTER></B>';
853 }
854 if ($mail_sent == 'yes') {
855 echo '<BR><CENTER><B>'. _("Your Message has been sent").'</CENTER></B>';
856 }
857 echo '<TABLE ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
858 if ($compose_new_win == '1') {
859 echo '<TABLE ALIGN=CENTER BGCOLOR="'.$color[0].'" WIDTH="100%" BORDER=0>'."\n" .
860 ' <TR><TD></TD><TD ALIGN="RIGHT"><INPUT TYPE="BUTTON" NAME="Close" onClick="return self.close()" VALUE='._("Close").'></TD></TR>'."\n";
861 }
862 if ($location_of_buttons == 'top') {
863 showComposeButtonRow();
864 }
865
866 $idents = getPref($data_dir, $username, 'identities', 0);
867 if ($idents > 1) {
868 echo ' <TR>' . "\n" .
869 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
870 "\n" .
871 _("From:") .
872 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
873 '<select name=identity>' . "\n" .
874 '<option value=default>' .
875 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
876 $em = getPref($data_dir, $username, 'email_address');
877 if ($em != '') {
878 echo htmlspecialchars(' <' . $em . '>') . "\n";
879 }
880 for ($i = 1; $i < $idents; $i ++) {
881 echo '<option value="' . $i . '"';
882 if (isset($identity) && $identity == $i) {
883 echo ' SELECTED';
884 }
885 echo '>' . htmlspecialchars(getPref($data_dir, $username,
886 'full_name' . $i));
887 $em = getPref($data_dir, $username, 'email_address' . $i);
888 if ($em != '') {
889 echo htmlspecialchars(' <' . $em . '>') . "\n";
890 }
891 echo '</option>';
892 }
893 echo '</select>' . "\n" .
894 ' </TD>' . "\n" .
895 ' </TR>' . "\n";
896 }
897 echo ' <TR>' . "\n" .
898 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
899 _("To:") .
900 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
901 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
902 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
903 ' </TD>' . "\n" .
904 ' </TR>' . "\n" .
905 ' <TR>' . "\n" .
906 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
907 _("CC:") .
908 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
909 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
910 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
911 ' </TD>' . "\n" .
912 ' </TR>' . "\n" .
913 ' <TR>' . "\n" .
914 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
915 _("BCC:") .
916 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
917 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
918 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
919 '</TD></TR>' . "\n" .
920 ' <TR>' . "\n" .
921 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
922 _("Subject:") .
923 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
924 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
925 htmlspecialchars($subject) . '">';
926 echo '</td></tr>' . "\n\n";
927
928 if ($location_of_buttons == 'between') {
929 showComposeButtonRow();
930 }
931 if ($compose_new_win == '1') {
932 echo ' <TR>' . "\n" .
933 ' <TD BGCOLOR="' . $color[0] . '" COLSPAN=2 ALIGN=CENTER>' . "\n" .
934 ' <TEXTAREA NAME=body ROWS=20 COLS="' .
935 $editor_size . '" WRAP="VIRTUAL">';
936 }
937 else {
938 echo ' <TR>' . "\n" .
939 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
940 ' &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS="' .
941 $editor_size . '" WRAP="VIRTUAL">';
942 }
943 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
944 if ($sig_first == '1') {
945 if ($charset == 'iso-2022-jp') {
946 echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
947 } else {
948 echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
949 }
950 echo "\n\n".htmlspecialchars($body);
951 }
952 else {
953 echo "\n\n".htmlspecialchars($body);
954 if ($charset == 'iso-2022-jp') {
955 echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP');
956 }else{
957 echo "\n\n".($prefix_sig==true? "-- \n":'').htmlspecialchars($signature);
958 }
959 }
960 }
961 else {
962 echo htmlspecialchars($body);
963 }
964 echo '</TEXTAREA><BR>' . "\n" .
965 ' </TD>' . "\n" .
966 ' </TR>' . "\n";
967
968 if ($location_of_buttons == 'bottom') {
969 showComposeButtonRow();
970 } else {
971 echo ' <TR><TD COLSPAN=2 ALIGN=RIGHT>' .
972 ' <INPUT TYPE=SUBMIT NAME=send VALUE="' . _("Send") . '">' .
973 ' &nbsp;&nbsp;&nbsp;&nbsp;<BR><BR>' .
974 ' </TD></TR>' . "\n";
975 }
976
977 /* This code is for attachments */
978 echo '<table width="100%" cellpadding="0" cellspacing="4" align="center" border="0">' .
979 ' <tr><td>' .
980 ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'.' border="0" bgcolor="'.$color[9].'">' .
981 ' <tr><td>' .
982 ' <table width="100%" cellpadding="3" cellspacing="0" align="center" border="0">' .
983 ' <TR>' . "\n" .
984 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
985 _("Attach:") .
986 ' </TD>' . "\n" .
987 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
988 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
989 ' &nbsp;&nbsp;<input type="submit" name="attach"' .
990 ' value="' . _("Add") .'">' . "\n" .
991 ' </TD>' . "\n" .
992 ' </TR>' . "\n";
993
994
995 $s_a = array();
996 foreach ($composeMessage->entities as $key => $attachment) {
997 $attached_file = $attachment->att_local_name;
998 if ($attachment->att_local_name || $attachment->body_part) {
999 $attached_filename = decodeHeader($attachment->mime_header->getParameter('name'));
1000 $type = $attachment->mime_header->type0.'/'.
1001 $attachment->mime_header->type1;
1002 $s_a[] = '<input type="checkbox" name="delete[]" value="' .
1003 $key . "\">\n" . $attached_filename . ' - ' . $type .
1004 ' ('.show_readable_size( filesize( $attached_file ) )
1005 . ')<br>'."\n";
1006 }
1007 }
1008 if (count($s_a)) {
1009 foreach ($s_a as $s) {
1010 echo '<tr><td align=left colspan="2" bgcolor="' . $color[0] . '">'.$s.'</td></tr>';
1011 }
1012 echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' .
1013 _("Delete selected attachments") . "\">\n" .
1014 '</td></tr>';
1015 }
1016 echo ' </table></td></tr>' .
1017 ' </table>' .
1018 ' </td></tr>';
1019
1020 /* End of attachment code */
1021 if ($compose_new_win == '1') {
1022 echo '</TABLE>'."\n";
1023 }
1024 echo '</TABLE>' . "\n" .
1025 '<input type="hidden" name="username" value="'. $username . "\">\n" .
1026 '<input type=hidden name=action value=' . $action . ">\n" .
1027 '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
1028 "\">\n" .
1029 '</FORM>';
1030 do_hook('compose_bottom');
1031 echo '</BODY></HTML>' . "\n";
1032 }
1033
1034
1035 function showComposeButtonRow() {
1036 global $use_javascript_addr_book, $save_as_draft,
1037 $default_use_priority, $mailprio, $default_use_mdn,
1038 $request_mdn, $request_dr,
1039 $data_dir, $username;
1040
1041 echo " <TR><TD>\n</TD><TD>\n";
1042 if ($default_use_priority) {
1043 if(!isset($mailprio)) {
1044 $mailprio = "3";
1045 }
1046 echo _("Priority") .': <select name="mailprio">'.
1047 '<option value="1"'.($mailprio=='1'?' selected':'').'>'. _("High") .'</option>'.
1048 '<option value="3"'.($mailprio=='3'?' selected':'').'>'. _("Normal") .'</option>'.
1049 '<option value="5"'.($mailprio=='5'?' selected':'').'>'. _("Low").'</option>'.
1050 "</select>";
1051 }
1052 $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn);
1053 if ($default_use_mdn) {
1054 if ($mdn_user_support) {
1055 echo "\n\t". _("Receipt") .': '.
1056 '<input type="checkbox" name="request_mdn" value=1'.
1057 ($request_mdn=='1'?' checked':'') .'>'. _("On Read").
1058 ' <input type="checkbox" name="request_dr" value=1'.
1059 ($request_dr=='1'?' checked':'') .'>'. _("On Delivery");
1060 }
1061 }
1062
1063 echo " </td></tr>\n <TR><td>\n </td><td>\n" .
1064 "\n <INPUT TYPE=SUBMIT NAME=\"sigappend\" VALUE=\"". _("Signature") . "\">\n";
1065 if ($use_javascript_addr_book) {
1066 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"".
1067 " <input type=button value=\\\""._("Addresses").
1068 "\\\" onclick='javascript:open_abook();'>\");".
1069 " // --></SCRIPT><NOSCRIPT>\n".
1070 " <input type=submit name=\"html_addr_search\" value=\"".
1071 _("Addresses")."\">".
1072 " </NOSCRIPT>\n";
1073 } else {
1074 echo " <input type=submit name=\"html_addr_search\" value=\"".
1075 _("Addresses")."\">";
1076 }
1077
1078 if ($save_as_draft) {
1079 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
1080 }
1081
1082 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
1083 do_hook('compose_button_row');
1084
1085 echo " </TD></TR>\n\n";
1086 }
1087
1088 function checkInput ($show) {
1089 /*
1090 * I implemented the $show variable because the error messages
1091 * were getting sent before the page header. So, I check once
1092 * using $show=false, and then when i'm ready to display the error
1093 * message, show=true
1094 */
1095 global $body, $send_to, $send_to_bcc, $subject, $color;
1096
1097 if ($send_to == '' && $send_to_bcc == '') {
1098 if ($show) {
1099 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
1100 }
1101 return false;
1102 }
1103 return true;
1104 } /* function checkInput() */
1105
1106
1107 /* True if FAILURE */
1108 function saveAttachedFiles($session) {
1109 global $_FILES, $attachment_dir, $attachments, $username,
1110 $data_dir, $compose_messages;
1111
1112 /* get out of here if no file was attached at all */
1113 if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) {
1114 return true;
1115 }
1116
1117 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
1118 $localfilename = GenerateRandomString(32, '', 7);
1119 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1120 while (file_exists($full_localfilename)) {
1121 $localfilename = GenerateRandomString(32, '', 7);
1122 $full_localfilename = "$hashed_attachment_dir/$localfilename";
1123 }
1124
1125 if (!@rename($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1126 if (function_exists("move_uploaded_file")) {
1127 if (!@move_uploaded_file($_FILES['attachfile']['tmp_name'],$full_localfilename)) {
1128 return true;
1129 }
1130 } else {
1131 if (!@copy($_FILES['attachfile']['tmp_name'], $full_localfilename)) {
1132 return true;
1133 }
1134 }
1135 }
1136 $message = $compose_messages[$session];
1137 $type = strtolower($_FILES['attachfile']['type']);
1138 $name = $_FILES['attachfile']['name'];
1139 $message->initAttachment($type, $name, $full_localfilename);
1140 $compose_messages[$session] = $message;
1141 }
1142
1143 function ClearAttachments($composeMessage) {
1144 if ($composeMessage->att_local_name) {
1145 $attached_file = $composeMessage->att_local_name;
1146 if (file_exists($attached_file)) {
1147 unlink($attached_file);
1148 }
1149 }
1150 for ($i=0, $entCount=count($composeMessage->entities);$i< $entCount; ++$i) {
1151 ClearAttachments($composeMessage->entities[$i]);
1152 }
1153 }
1154
1155
1156
1157 function getReplyCitation($orig_from) {
1158 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
1159
1160 /* First, return an empty string when no citation style selected. */
1161 if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
1162 return '';
1163 }
1164
1165 /* Make sure our final value isn't an empty string. */
1166 if ($orig_from == '') {
1167 return '';
1168 }
1169
1170 /* Otherwise, try to select the desired citation style. */
1171 switch ($reply_citation_style) {
1172 case 'author_said':
1173 $start = '';
1174 $end = ' ' . _("said") . ':';
1175 break;
1176 case 'quote_who':
1177 $start = '<' . _("quote") . ' ' . _("who") . '="';
1178 $end = '">';
1179 break;
1180 case 'user-defined':
1181 $start = $reply_citation_start .
1182 ($reply_citation_start == '' ? '' : ' ');
1183 $end = $reply_citation_end;
1184 break;
1185 default:
1186 return '';
1187 }
1188
1189 /* Build and return the citation string. */
1190 return ($start . $orig_from . $end . "\n");
1191 }
1192
1193 /* temporary function to make use of the deliver class.
1194 In the future the responsable backend should be automaticly loaded
1195 and conf.pl should show a list of available backends.
1196 The message also should be constructed by the message class.
1197 */
1198
1199 function sendMessage($composeMessage, $draft=false) {
1200 global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body,
1201 $username, $popuser, $usernamedata, $identity, $data_dir,
1202 $request_mdn, $request_dr, $default_charset, $color, $useSendmail,
1203 $domain, $action;
1204 global $imapServerAddress, $imapPort, $sent_folder, $key;
1205
1206 $rfc822_header = $composeMessage->rfc822_header;
1207 $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain);
1208 $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain);
1209 $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain);
1210 $rfc822_header->priority = $mailprio;
1211 $rfc822_header->subject = $subject;
1212 $special_encoding='';
1213 if (strtolower($default_charset) == 'iso-2022-jp') {
1214 if (mb_detect_encoding($body) == 'ASCII') {
1215 $special_encoding = '8bit';
1216 } else {
1217 $body = mb_convert_encoding($body, 'JIS');
1218 $special_encoding = '7bit';
1219 }
1220 }
1221 $composeMessage->setBody($body);
1222
1223 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
1224 $popuser = $usernamedata[1];
1225 $domain = $usernamedata[2];
1226 unset($usernamedata);
1227 } else {
1228 $popuser = $username;
1229 }
1230 $reply_to = '';
1231 if (isset($identity) && $identity != 'default') {
1232 $from_mail = getPref($data_dir, $username,'email_address' . $identity);
1233 $full_name = getPref($data_dir, $username,'full_name' . $identity);
1234 $reply_to = getPref($data_dir, $username,'reply_to' . $identity);
1235 } else {
1236 $from_mail = getPref($data_dir, $username, 'email_address');
1237 $full_name = getPref($data_dir, $username, 'full_name');
1238 $reply_to = getPref($data_dir, $username,'reply_to');
1239 }
1240 if (!$from_mail) {
1241 $from_mail = "$popuser@$domain";
1242 $full_name = '';
1243 }
1244 $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true);
1245 if ($full_name) {
1246 $from = $rfc822_header->from[0];
1247 if (!$from->host) $from->host = $domain;
1248 $from_addr = $full_name .' <'.$from->mailbox.'@'.$from->host.'>';
1249 $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true);
1250 }
1251 if ($reply_to) {
1252 $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true);
1253 }
1254 /* Receipt: On Read */
1255 if (isset($request_mdn) && $request_mdn) {
1256 $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true);
1257 }
1258 /* Receipt: On Delivery */
1259 if (isset($request_dr) && $request_dr) {
1260 $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail;
1261 }
1262 /* multipart messages */
1263 if (count($composeMessage->entities)) {
1264 $message_body = new Message();
1265 $message_body->body_part = $composeMessage->body_part;
1266 $composeMessage->body_part = '';
1267 $mime_header = new MessageHeader;
1268 $mime_header->type0 = 'text';
1269 $mime_header->type1 = 'plain';
1270 if ($special_encoding) {
1271 $mime_header->encoding = $special_encoding;
1272 } else {
1273 $mime_header->encoding = 'us-ascii';
1274 }
1275 if ($default_charset) {
1276 $mime_header->parameters['charset'] = $default_charset;
1277 }
1278 $message_body->mime_header = $mime_header;
1279 array_unshift($composeMessage->entities, $message_body);
1280 $content_type = new ContentType('multipart/mixed');
1281 } else {
1282 $content_type = new ContentType('text/plain');
1283 }
1284 if ($default_charset) {
1285 $content_type->properties['charset']=$default_charset;
1286 }
1287
1288 $rfc822_header->content_type = $content_type;
1289 $composeMessage->rfc822_header = $rfc822_header;
1290
1291 if (!$useSendmail && !$draft) {
1292 require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php');
1293 $deliver = new Deliver_SMTP();
1294 global $smtpServerAddress, $smtpPort, $use_authenticated_smtp, $pop_before_smtp;
1295 if ($use_authenticated_smtp) {
1296 global $key, $onetimepad;
1297 $user = $username;
1298 $pass = OneTimePadDecrypt($key, $onetimepad);
1299 } else {
1300 $user = '';
1301 $pass = '';
1302 }
1303 $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false;
1304 $stream = $deliver->initStream($composeMessage,$domain,0,
1305 $smtpServerAddress, $smtpPort, $authPop);
1306 } elseif (!$draft) {
1307 require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php');
1308 global $sendmail_path;
1309 $deliver = new Deliver_SendMail();
1310 $stream = $deliver->initStream($composeMessage,$sendmail_path);
1311 } elseif ($draft) {
1312 global $draft_folder;
1313 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
1314 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1315 $imapPort, 0);
1316 if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) {
1317 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
1318 $imap_deliver = new Deliver_IMAP();
1319 $length = $imap_deliver->mail($composeMessage);
1320 sqimap_append ($imap_stream, $draft_folder, $length);
1321 $imap_deliver->mail($composeMessage, $imap_stream);
1322 sqimap_append_done ($imap_stream);
1323 sqimap_logout($imap_stream);
1324 unset ($imap_deliver);
1325
1326 }
1327 return $length;
1328 }
1329 $succes = false;
1330 if ($stream) {
1331 $length = $deliver->mail($composeMessage, $stream);
1332 $succes = $deliver->finalizeStream($stream);
1333 }
1334 if (!$succes) {
1335 $msg = $deliver->dlv_msg . '<br>Server replied: '.$deliver->dlv_ret_nr;
1336 plain_error_message($msg, $color);
1337 } else {
1338 unset ($deliver);
1339 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
1340 $imapPort, 0);
1341 if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
1342 sqimap_append ($imap_stream, $sent_folder, $length);
1343 require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php');
1344 $imap_deliver = new Deliver_IMAP();
1345 $imap_deliver->mail($composeMessage, $imap_stream);
1346 sqimap_append_done ($imap_stream);
1347 unset ($imap_deliver);
1348 }
1349 global $passed_id, $mailbox, $action;
1350 ClearAttachments($composeMessage);
1351 if ($action == 'reply' || $action == 'reply_all') {
1352 sqimap_mailbox_select ($imap_stream, $mailbox);
1353 sqimap_messages_flag ($imap_stream, $passed_id, $passed_id, 'Answered', true);
1354 }
1355 sqimap_logout($imap_stream);
1356 }
1357 return $succes;
1358 }
1359
1360 ?>