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