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