[PHP-DEV] CVS update: php31/ext/imap From: rasmus (php-dev <email protected>)
Date: 08/24/98

Date: Monday August 24, 1998 @ 22:44
Author: rasmus

Update of /repository/php31/ext/imap
In directory asf:/export/home/rasmus/php31/ext/imap

Modified Files:
        imap.c imap.h
Log Message:
Bring 3.0 imap.c changes into 3.1 tree

Index: php31/ext/imap/imap.c
diff -c php31/ext/imap/imap.c:2.1 php31/ext/imap/imap.c:2.2
*** php31/ext/imap/imap.c:2.1 Fri Jul 3 12:24:27 1998
--- php31/ext/imap/imap.c Mon Aug 24 22:44:11 1998
***************
*** 1,6 ****
  /*
     +----------------------------------------------------------------------+
! | PHP HTML Embedded Scripting Language Version 3.0 |
     +----------------------------------------------------------------------+
     | Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
     +----------------------------------------------------------------------+
--- 1,6 ----
  /*
     +----------------------------------------------------------------------+
! | PHP HTML Embedded Scripting Language Version 3.1 |
     +----------------------------------------------------------------------+
     | Copyright (c) 1997,1998 PHP Development Team (See Credits file) |
     +----------------------------------------------------------------------+
***************
*** 23,53 ****
     | If you did not, or have any questions about PHP licensing, please |
     | contact core <email protected> |
     +----------------------------------------------------------------------+
! | Authors: |
! | |
     +----------------------------------------------------------------------+
   */
  
  #include "php.h"
  
! #if HAVE_IMAP
  
! #include "imap.h"
! #include "modules.h"
! #include "php3_list.h"
  
  #include <stdio.h>
  #include <ctype.h>
  #include <signal.h>
! #ifdef ERROR
! #undef ERROR
! #endif
  #include "mail.h"
  #include "rfc822.h"
! MAILSTREAM *mail_close_it (MAILSTREAM *stream);
  #if (WIN32|WINNT)
  #include "winsock.h"
- #define IMAP41
  #endif
  
  #ifdef IMAP41
--- 23,67 ----
     | If you did not, or have any questions about PHP licensing, please |
     | contact core <email protected> |
     +----------------------------------------------------------------------+
! | Authors: Rex Logan <veebert <email protected>> |
! | Mark Musone <musone <email protected>> |
! | Brian Wang <brian <email protected>> |
! | Kaj-Michael Lang <milang <email protected>> |
! | Antoni Pamies Olive <toni <email protected>> |
! | Rasmus Lerdorf <rasmus <email protected>> |
     +----------------------------------------------------------------------+
   */
+ /* $Id: imap.c,v 2.2 1998/08/25 02:44:11 rasmus Exp $ */
+
+ #define IMAP41
+
+ #ifdef ERROR
+ #undef ERROR
+ #endif
  
+ #if !(WIN32|WINNT)
+ #include "config.h"
+ #endif
  #include "php.h"
+ #include "internal_functions.h"
  
! #if COMPILE_DL
! #include "dl/phpdl.h"
! #endif
  
! #if HAVE_IMAP
  
+ #include <time.h>
  #include <stdio.h>
  #include <ctype.h>
  #include <signal.h>
! #include "php3_list.h"
! #include "imap.h"
  #include "mail.h"
  #include "rfc822.h"
! #include "modules.h"
  #if (WIN32|WINNT)
  #include "winsock.h"
  #endif
  
  #ifdef IMAP41
***************
*** 65,70 ****
--- 79,87 ----
  #define CONTENT_MSG_BODY contents.msg.body
  #define IMAPVER "Imap 4"
  #endif
+
+ #define PHP_EXPUNGE 32768
+
  /*
   * this array should be set up as:
   * {"PHPScriptFunctionName",dllFunctionName,1}
***************
*** 76,126 ****
  extern void rfc822_date(char *date);
  extern char *cpystr(const char *string);
  extern unsigned long find_rightmost_bit (unsigned long *valptr);
  
  
  function_entry imap_functions[] =
  {
! {"imap_open", php3_imap_open, NULL},
! {"imap_reopen", php3_imap_reopen, NULL},
! {"imap_num_msg", php3_imap_num_msg, NULL},
! {"imap_num_recent", php3_imap_num_recent, NULL},
! {"imap_headers", php3_imap_headers, NULL},
! {"imap_header", php3_imap_headerinfo, NULL},
! {"imap_headerinfo", php3_imap_headerinfo, NULL},
! {"imap_body", php3_imap_body, NULL},
! {"imap_fetchstructure", php3_imap_fetchstructure, NULL},
! {"imap_fetchbody", php3_imap_fetchbody, NULL},
! {"imap_expunge", php3_imap_expunge, NULL},
! {"imap_delete", php3_imap_delete, NULL},
! {"imap_undelete", php3_imap_undelete, NULL},
! {"imap_check", php3_imap_check, NULL},
! {"imap_close", php3_imap_close, NULL},
! {"imap_mail_copy", php3_imap_mail_copy, NULL},
! {"imap_mail_move", php3_imap_mail_move, NULL},
! {"imap_createmailbox", php3_imap_createmailbox, NULL},
! {"imap_renamemailbox", php3_imap_renamemailbox, NULL},
! {"imap_deletemailbox", php3_imap_deletemailbox, NULL},
! {"imap_listmailbox", php3_imap_list, NULL},
! {"imap_scanmailbox", php3_imap_listscan, NULL},
! {"imap_listsubscribed", php3_imap_lsub, NULL},
! {"imap_subscribe", php3_imap_subscribe, NULL},
! {"imap_unsubscribe", php3_imap_unsubscribe, NULL},
          {"imap_append", php3_imap_append, NULL},
          {"imap_ping", php3_imap_ping, NULL},
! {"imap_base64", php3_imap_base64, NULL},
          {"imap_qprint", php3_imap_qprint, NULL},
          {"imap_8bit", php3_imap_8bit, NULL},
! {NULL, NULL, NULL}
  };
  
  
! php3_module_entry imap_module_entry = {
! IMAPVER, imap_functions, imap_init, NULL, NULL, NULL, NULL, 0, 0, 0, NULL
  };
  
  
  #if COMPILE_DL
! DLEXPORT php3_module_entry *get_module(void) { return &imap_module_entry; }
  #endif
  
  /*
--- 93,170 ----
  extern void rfc822_date(char *date);
  extern char *cpystr(const char *string);
  extern unsigned long find_rightmost_bit (unsigned long *valptr);
+ extern void fs_give (void **block);
+ int add_assoc_object(pval *arg, char *key, pval tmp);
+ int add_next_index_object(pval *arg, pval tmp);
+ void imap_add_body( pval *arg, BODY *body );
  
+ typedef struct php3_imap_le_struct {
+ MAILSTREAM *imap_stream;
+ long flags;
+ } pils;
  
+ MAILSTREAM *mail_close_it (pils *imap_le_struct);
+
  function_entry imap_functions[] =
  {
! {"imap_open", php3_imap_open, NULL},
! {"imap_reopen", php3_imap_reopen, NULL},
! {"imap_num_msg", php3_imap_num_msg, NULL},
! {"imap_num_recent", php3_imap_num_recent, NULL},
! {"imap_headers", php3_imap_headers, NULL},
! {"imap_header", php3_imap_headerinfo, NULL},
! {"imap_headerinfo", php3_imap_headerinfo, NULL},
! {"imap_body", php3_imap_body, NULL},
! {"imap_fetchstructure", php3_imap_fetchstructure, NULL},
! {"imap_fetchbody", php3_imap_fetchbody, NULL},
! {"imap_expunge", php3_imap_expunge, NULL},
! {"imap_delete", php3_imap_delete, NULL},
! {"imap_undelete", php3_imap_undelete, NULL},
! {"imap_check", php3_imap_check, NULL},
! {"imap_close", php3_imap_close, NULL},
! {"imap_mail_copy", php3_imap_mail_copy, NULL},
! {"imap_mail_move", php3_imap_mail_move, NULL},
! {"imap_createmailbox", php3_imap_createmailbox, NULL},
! {"imap_renamemailbox", php3_imap_renamemailbox, NULL},
! {"imap_deletemailbox", php3_imap_deletemailbox, NULL},
! {"imap_listmailbox", php3_imap_list, NULL},
! {"imap_scanmailbox", php3_imap_listscan, NULL},
! {"imap_listsubscribed", php3_imap_lsub, NULL},
! {"imap_subscribe", php3_imap_subscribe, NULL},
! {"imap_unsubscribe", php3_imap_unsubscribe, NULL},
          {"imap_append", php3_imap_append, NULL},
          {"imap_ping", php3_imap_ping, NULL},
! {"imap_base64", php3_imap_base64, NULL},
          {"imap_qprint", php3_imap_qprint, NULL},
          {"imap_8bit", php3_imap_8bit, NULL},
! {"imap_binary", php3_imap_binary, NULL},
! {"imap_mailboxmsginfo", php3_imap_mailboxmsginfo, NULL},
! {"imap_rfc822_write_address", php3_imap_rfc822_write_address, NULL},
! {"imap_rfc822_parse_adrlist", php3_imap_rfc822_parse_adrlist, NULL},
! {"imap_setflag_full", php3_imap_setflag_full, NULL},
! {"imap_clearflag_full", php3_imap_clearflag_full, NULL},
! {"imap_sort", php3_imap_sort, NULL},
! {"imap_fetchheader", php3_imap_fetchheader, NULL},
! {"imap_fetchtext", php3_imap_body, NULL},
! {"imap_uid", php3_imap_uid, NULL},
! {"imap_msgno",php3_imap_msgno, NULL},
! {"imap_list", php3_imap_list, NULL},
! {"imap_scan", php3_imap_listscan, NULL},
! {"imap_lsub", php3_imap_lsub, NULL},
! {"imap_create", php3_imap_createmailbox, NULL},
! {"imap_rename", php3_imap_renamemailbox, NULL},
! {"imap_status", php3_imap_status, NULL},
! {NULL, NULL, NULL}
  };
  
  
! php3_module_entry php3_imap_module_entry = {
! IMAPVER, imap_functions, imap_init, NULL, NULL, NULL,imap_info, 0, 0, 0, NULL
  };
  
  
  #if COMPILE_DL
! DLEXPORT php3_module_entry *get_module(void) { return &php3_imap_module_entry; }
  #endif
  
  /*
***************
*** 133,144 ****
  char imap_password[80]="";
  STRINGLIST *imap_folders=NIL;
  STRINGLIST *imap_sfolders=NIL;
  
! MAILSTREAM *mail_close_it (MAILSTREAM *stream)
  {
! return mail_close_full ( stream,NIL);
  }
  
  int imap_init(INIT_FUNC_ARGS)
  {
  #if WIN32|WINNT
--- 177,221 ----
  char imap_password[80]="";
  STRINGLIST *imap_folders=NIL;
  STRINGLIST *imap_sfolders=NIL;
+ long status_flags;
+ unsigned long status_messages;
+ unsigned long status_recent;
+ unsigned long status_unseen;
+ unsigned long status_uidnext;
+ unsigned long status_uidvalidity;
+
+ MAILSTREAM *mail_close_it (pils *imap_le_struct)
+ {
+ MAILSTREAM *ret;
+ ret = mail_close_full (imap_le_struct->imap_stream,imap_le_struct->flags);
+ efree(imap_le_struct);
+ return ret;
+ }
+
+ inline int add_assoc_object(pval *arg, char *key, pval tmp)
+ {
+ return _php3_hash_update(arg->value.ht, key, strlen(key)+1, (void *) &tmp, sizeof(pval), NULL);
+ }
  
! inline int add_next_index_object(pval *arg, pval tmp)
  {
! return _php3_hash_next_index_insert( arg->value.ht, (void *) &tmp, sizeof(pval), NULL);
  }
  
+
+ void imap_info(void)
+ {
+ php3_printf("Imap Support enabled<br>");
+ php3_printf("<table>");
+ php3_printf("<tr><td>Imap c-client Version:</td>");
+ #ifdef IMAP41
+ php3_printf("<td>Imap 4.1</td>");
+ #else
+ php3_printf("<td>Imap 4.0</td>");
+ #endif
+ php3_printf("</tr></table>");
+ }
+
  int imap_init(INIT_FUNC_ARGS)
  {
  #if WIN32|WINNT
***************
*** 163,168 ****
--- 240,373 ----
  #endif
          mail_link (&dummydriver); /* link in the dummy driver */
          auth_link (&auth_log); /* link in the log authenticator */
+ /* lets allow NIL */
+
+ REGISTER_MAIN_LONG_CONSTANT("NIL", NIL, CONST_PERSISTENT | CONST_CS);
+
+
+ /* Open Options */
+
+ REGISTER_MAIN_LONG_CONSTANT("OP_DEBUG", OP_DEBUG, CONST_PERSISTENT | CONST_CS);
+ /* debug protocol negotiations */
+
+ REGISTER_MAIN_LONG_CONSTANT("OP_READONLY", OP_READONLY, CONST_PERSISTENT | CONST_CS);
+ /* read-only open */
+
+ REGISTER_MAIN_LONG_CONSTANT("OP_ANONYMOUS", OP_ANONYMOUS, CONST_PERSISTENT | CONST_CS);
+ /* anonymous open of newsgroup */
+
+ REGISTER_MAIN_LONG_CONSTANT("OP_SHORTCACHE", OP_SHORTCACHE, CONST_PERSISTENT | CONST_CS);
+
+ /* short (elt-only) caching */
+
+ REGISTER_MAIN_LONG_CONSTANT("OP_SILENT", OP_SILENT, CONST_PERSISTENT | CONST_CS);
+ /* don't pass up events (internal use) */
+ REGISTER_MAIN_LONG_CONSTANT("OP_PROTOTYPE", OP_PROTOTYPE, CONST_PERSISTENT | CONST_CS);
+ /* return driver prototype */
+ REGISTER_MAIN_LONG_CONSTANT("OP_HALFOPEN", OP_HALFOPEN, CONST_PERSISTENT | CONST_CS);
+ /* half-open (IMAP connect but no select) */
+
+ REGISTER_MAIN_LONG_CONSTANT("OP_EXPUNGE", OP_EXPUNGE, CONST_PERSISTENT | CONST_CS);
+ /* silently expunge recycle stream */
+
+ REGISTER_MAIN_LONG_CONSTANT("OP_SECURE", OP_SECURE, CONST_PERSISTENT | CONST_CS);
+ /* don't do non-secure authentication */
+
+ /*
+ PHP re-assigns CL_EXPUNGE a custom value that can be used as part of the imap_open() bitfield
+ because it seems like a good idea to be able to indicate that the mailbox should be
+ automatically expunged during imap_open in case the script get interrupted and it doesn't get
+ to the imap_close() where this option is normally placed. If the c-client library adds other
+ options and the value for this one conflicts, simply make PHP_EXPUNGE higher at the top of
+ this file
+ */
+ REGISTER_MAIN_LONG_CONSTANT("CL_EXPUNGE", PHP_EXPUNGE, CONST_PERSISTENT | CONST_CS);
+ /* expunge silently */
+
+
+ /* Fetch options */
+
+ REGISTER_MAIN_LONG_CONSTANT("FT_UID", FT_UID, CONST_PERSISTENT | CONST_CS);
+ /* argument is a UID */
+ REGISTER_MAIN_LONG_CONSTANT("FT_PEEK", FT_PEEK, CONST_PERSISTENT | CONST_CS);
+ /* peek at data */
+ REGISTER_MAIN_LONG_CONSTANT("FT_NOT", FT_NOT, CONST_PERSISTENT | CONST_CS);
+ /* NOT flag for header lines fetch */
+ REGISTER_MAIN_LONG_CONSTANT("FT_INTERNAL", FT_INTERNAL, CONST_PERSISTENT | CONST_CS);
+ /* text can be internal strings */
+ REGISTER_MAIN_LONG_CONSTANT("FT_PREFETCHTEXT", FT_PREFETCHTEXT, CONST_PERSISTENT | CONST_CS);
+ /* IMAP prefetch text when fetching header */
+
+
+ /* Flagging options */
+
+ REGISTER_MAIN_LONG_CONSTANT("ST_UID", ST_UID, CONST_PERSISTENT | CONST_CS);
+ /* argument is a UID sequence */
+ REGISTER_MAIN_LONG_CONSTANT("ST_SILENT", ST_SILENT, CONST_PERSISTENT | CONST_CS);
+ /* don't return results */
+ REGISTER_MAIN_LONG_CONSTANT("ST_SET", ST_SET, CONST_PERSISTENT | CONST_CS);
+ /* set vs. clear */
+
+ /* Copy options */
+
+ REGISTER_MAIN_LONG_CONSTANT("CP_UID", CP_UID, CONST_PERSISTENT | CONST_CS);
+ /* argument is a UID sequence */
+ REGISTER_MAIN_LONG_CONSTANT("CP_MOVE", CP_MOVE, CONST_PERSISTENT | CONST_CS);
+ /* delete from source after copying */
+
+
+ /* Search/sort options */
+
+ REGISTER_MAIN_LONG_CONSTANT("SE_UID", SE_UID, CONST_PERSISTENT | CONST_CS);
+ /* return UID */
+ REGISTER_MAIN_LONG_CONSTANT("SE_FREE", SE_FREE, CONST_PERSISTENT | CONST_CS);
+ /* free search program after finished */
+ REGISTER_MAIN_LONG_CONSTANT("SE_NOPREFETCH", SE_NOPREFETCH, CONST_PERSISTENT | CONST_CS);
+ /* no search prefetching */
+ REGISTER_MAIN_LONG_CONSTANT("SO_FREE", SO_FREE, CONST_PERSISTENT | CONST_CS);
+ /* free sort program after finished */
+ REGISTER_MAIN_LONG_CONSTANT("SO_NOSERVER", SO_NOSERVER, CONST_PERSISTENT | CONST_CS);
+ /* don't do server-based sort */
+
+ /* Status options */
+
+ REGISTER_MAIN_LONG_CONSTANT("SA_MESSAGES",SA_MESSAGES , CONST_PERSISTENT | CONST_CS);
+ /* number of messages */
+ REGISTER_MAIN_LONG_CONSTANT("SA_RECENT", SA_RECENT, CONST_PERSISTENT | CONST_CS);
+ /* number of recent messages */
+ REGISTER_MAIN_LONG_CONSTANT("SA_UNSEEN",SA_UNSEEN , CONST_PERSISTENT | CONST_CS);
+ /* number of unseen messages */
+ REGISTER_MAIN_LONG_CONSTANT("SA_UIDNEXT", SA_UIDNEXT, CONST_PERSISTENT | CONST_CS);
+ /* next UID to be assigned */
+ REGISTER_MAIN_LONG_CONSTANT("SA_UIDVALIDITY",SA_UIDVALIDITY , CONST_PERSISTENT | CONST_CS);
+ /* UID validity value */
+
+
+ /* Bits for mm_list() and mm_lsub() */
+
+ REGISTER_MAIN_LONG_CONSTANT("LATT_NOINFERIORS",LATT_NOINFERIORS , CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("LATT_NOSELECT", LATT_NOSELECT, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("LATT_MARKED", LATT_MARKED, CONST_PERSISTENT | CONST_CS);
+ REGISTER_MAIN_LONG_CONSTANT("LATT_UNMARKED",LATT_UNMARKED , CONST_PERSISTENT | CONST_CS);
+
+
+ /* Sort functions */
+
+ REGISTER_MAIN_LONG_CONSTANT("SORTDATE",SORTDATE , CONST_PERSISTENT | CONST_CS);
+ /* date */
+ REGISTER_MAIN_LONG_CONSTANT("SORTARRIVAL",SORTARRIVAL , CONST_PERSISTENT | CONST_CS);
+ /* arrival date */
+ REGISTER_MAIN_LONG_CONSTANT("SORTFROM",SORTFROM , CONST_PERSISTENT | CONST_CS);
+ /* from */
+ REGISTER_MAIN_LONG_CONSTANT("SORTSUBJECT",SORTSUBJECT , CONST_PERSISTENT | CONST_CS);
+ /* subject */
+ REGISTER_MAIN_LONG_CONSTANT("SORTTO",SORTTO , CONST_PERSISTENT | CONST_CS);
+ /* to */
+ REGISTER_MAIN_LONG_CONSTANT("SORTCC",SORTCC , CONST_PERSISTENT | CONST_CS);
+ /* cc */
+ REGISTER_MAIN_LONG_CONSTANT("SORTSIZE",SORTSIZE , CONST_PERSISTENT | CONST_CS);
+ /* size */
+
  
      le_imap = register_list_destructors(mail_close_it,NULL);
          return SUCCESS;
***************
*** 173,199 ****
          pval *mailbox;
          pval *user;
          pval *passwd;
          MAILSTREAM *imap_stream;
          int ind;
!
! if (getParameters(ht, 3, &mailbox,&user,&passwd) == SUCCESS) {
                  convert_to_string(mailbox);
                  convert_to_string(user);
                  convert_to_string(passwd);
                  strcpy(imap_user,user->value.str.val);
                  strcpy(imap_password,passwd->value.str.val);
-
                  imap_stream = NIL;
! imap_stream = mail_open(imap_stream,mailbox->value.str.val,NIL);
                  if (imap_stream == NIL){
                          php3_error(E_WARNING,"Couldn't open stream %s\n",mailbox->value.str.val);
                          RETURN_FALSE;
                  }
! ind = php3_list_insert(imap_stream, le_imap);
  
                  RETURN_LONG(ind);
- } else {
- WRONG_PARAM_COUNT;
          }
          return;
  }
--- 378,423 ----
          pval *mailbox;
          pval *user;
          pval *passwd;
+ pval *options;
          MAILSTREAM *imap_stream;
+ pils *imap_le_struct;
+ long flags=NIL;
+ long cl_flags=NIL;
+
          int ind;
! int myargc=ARG_COUNT(ht);
!
! if (myargc <3 || myargc >4 || getParameters(ht, myargc, &mailbox,&user,&passwd,&options) == FAILURE) {
! WRONG_PARAM_COUNT;
! } else {
                  convert_to_string(mailbox);
                  convert_to_string(user);
                  convert_to_string(passwd);
+ if(myargc ==4) {
+ convert_to_long(options);
+ flags = options->value.lval;
+ if(flags & PHP_EXPUNGE) {
+ cl_flags = CL_EXPUNGE;
+ flags ^= PHP_EXPUNGE;
+ }
+ }
                  strcpy(imap_user,user->value.str.val);
                  strcpy(imap_password,passwd->value.str.val);
                  imap_stream = NIL;
! imap_stream = mail_open(imap_stream,mailbox->value.str.val,flags);
!
                  if (imap_stream == NIL){
                          php3_error(E_WARNING,"Couldn't open stream %s\n",mailbox->value.str.val);
                          RETURN_FALSE;
                  }
! /* Note that if we ever come up with a persistent imap stream, the persistent version of this
! struct needs to be malloc'ed and not emalloc'ed */
! imap_le_struct = emalloc(sizeof(pils));
! imap_le_struct->imap_stream = imap_stream;
! imap_le_struct->flags = cl_flags;
! ind = php3_list_insert(imap_le_struct, le_imap);
  
                  RETURN_LONG(ind);
          }
          return;
  }
***************
*** 203,233 ****
  {
          pval *streamind;
          pval *mailbox;
! pval *user;
! pval *passwd;
          MAILSTREAM *imap_stream;
          int ind, ind_type;
  
! if (getParameters(ht, 4,&streamind, &mailbox,&user,&passwd) == FAILURE) {
          WRONG_PARAM_COUNT;
      }
  
          convert_to_long(streamind);
          ind = streamind->value.lval;
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
  
          convert_to_string(mailbox);
! convert_to_string(user);
! convert_to_string(passwd);
! strcpy(imap_user,user->value.str.val);
! strcpy(imap_password,passwd->value.str.val);
!
! imap_stream = mail_open(imap_stream,mailbox->value.str.val,NIL);
! if (imap_stream == NIL){
                  php3_error(E_WARNING,"Couldn't re-open stream\n");
                  RETURN_FALSE;
          }
--- 427,464 ----
  {
          pval *streamind;
          pval *mailbox;
! pval *options;
          MAILSTREAM *imap_stream;
+ pils *imap_le_struct;
          int ind, ind_type;
+ long flags=NIL;
+ long cl_flags=NIL;
+ int myargc=ARG_COUNT(ht);
  
! if (myargc<2 || myargc>3 || getParameters(ht,myargc,&streamind, &mailbox, &options) == FAILURE) {
          WRONG_PARAM_COUNT;
      }
  
          convert_to_long(streamind);
          ind = streamind->value.lval;
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
  
          convert_to_string(mailbox);
! if(myargc == 3) {
! convert_to_long(options);
! flags = options->value.lval;
! if(flags & PHP_EXPUNGE) {
! cl_flags = CL_EXPUNGE;
! flags ^= PHP_EXPUNGE;
! }
! imap_le_struct->flags = cl_flags;
! }
! imap_stream = mail_open(imap_le_struct->imap_stream, mailbox->value.str.val, flags);
! if (imap_stream == NIL) {
                  php3_error(E_WARNING,"Couldn't re-open stream\n");
                  RETURN_FALSE;
          }
***************
*** 236,270 ****
  
  void php3_imap_append(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind,*folder, *message;
! int ind, ind_type;
! MAILSTREAM *imap_stream;
!
! if ( ARG_COUNT(ht) != 3 || getParameters( ht, 3, &streamind, &folder, &message) == FAILURE) {
      WRONG_PARAM_COUNT;
! }
!
! convert_to_long(streamind);
! convert_to_string(folder);
! convert_to_string(message);
!
! ind = streamind->value.lval;
!
! imap_stream = ( MAILSTREAM *)php3_list_find( ind, &ind_type );
!
! if ( !imap_stream || ind_type != le_imap ) {
! php3_error(E_WARNING, "Unable to find stream pointer");
! RETURN_FALSE;
! }
! mail_append( imap_stream, folder->value.str.val, (STRING *)message->value.str.val );
! RETURN_TRUE;
  }
  
  void php3_imap_num_msg(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *streamind;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
  
          if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) {
                  WRONG_PARAM_COUNT;
--- 467,510 ----
  
  void php3_imap_append(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind,*folder, *message,*flags;
! int ind, ind_type;
! pils *imap_le_struct;
! STRING st;
! int myargc=ARG_COUNT(ht);
!
! if ( myargc < 3 || myargc > 4 || getParameters( ht, myargc, &streamind, &folder, &message,&flags) == FAILURE) {
      WRONG_PARAM_COUNT;
! }
!
! convert_to_long(streamind);
! convert_to_string(folder);
! convert_to_string(message);
! if (myargc == 4) convert_to_long(flags);
! ind = streamind->value.lval;
!
! imap_le_struct = (pils *)php3_list_find( ind, &ind_type );
!
! if ( !imap_le_struct || ind_type != le_imap ) {
! php3_error(E_WARNING, "Unable to find stream pointer");
! RETURN_FALSE;
! }
! INIT (&st,mail_string,(void *) message->value.str.val,message->value.str.len);
! if(mail_append_full(imap_le_struct->imap_stream, folder->value.str.val,myargc==4?flags->value.str.val:NIL,NIL,&st))
! {
! RETURN_TRUE;
! }
! else
! {
! RETURN_FALSE;
! }
  }
  
  void php3_imap_num_msg(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *streamind;
          int ind, ind_type;
! pils *imap_le_struct;
  
          if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) {
                  WRONG_PARAM_COUNT;
***************
*** 274,334 ****
  
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
  
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
  
! RETURN_LONG(imap_stream->nmsgs);
  }
  
  void php3_imap_ping(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind;
! int ind, ind_type;
! MAILSTREAM *imap_stream;
!
! if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) {
! WRONG_PARAM_COUNT;
! }
!
! convert_to_long( streamind );
! ind = streamind->value.lval;
!
! imap_stream = ( MAILSTREAM *)php3_list_find( ind, &ind_type );
! if ( !imap_stream || ind_type != le_imap ) {
! php3_error( E_WARNING, "Unable to find stream pointer" );
! RETURN_FALSE;
! }
! RETURN_LONG( mail_ping( imap_stream ) );
  }
  
  
  void php3_imap_num_recent(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind;
! int ind, ind_type;
! MAILSTREAM *imap_stream;
! if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) {
! WRONG_PARAM_COUNT;
! }
! convert_to_long(streamind);
! ind = streamind->value.lval;
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
! php3_error(E_WARNING, "Unable to find stream pointer");
! RETURN_FALSE;
! }
! RETURN_LONG(imap_stream->recent);
  }
  
  void php3_imap_expunge(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *streamind;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
  
          if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) {
                  WRONG_PARAM_COUNT;
--- 514,574 ----
  
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
  
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
  
! RETURN_LONG(imap_le_struct->imap_stream->nmsgs);
  }
  
  void php3_imap_ping(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind;
! int ind, ind_type;
! pils *imap_le_struct;
!
! if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) {
! WRONG_PARAM_COUNT;
! }
!
! convert_to_long( streamind );
! ind = streamind->value.lval;
!
! imap_le_struct = (pils *)php3_list_find( ind, &ind_type );
! if ( !imap_le_struct || ind_type != le_imap ) {
! php3_error( E_WARNING, "Unable to find stream pointer" );
! RETURN_FALSE;
! }
! RETURN_LONG( mail_ping( imap_le_struct->imap_stream ) );
  }
  
  
  void php3_imap_num_recent(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind;
! int ind, ind_type;
! pils *imap_le_struct;
! if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) {
! WRONG_PARAM_COUNT;
! }
! convert_to_long(streamind);
! ind = streamind->value.lval;
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
! php3_error(E_WARNING, "Unable to find stream pointer");
! RETURN_FALSE;
! }
! RETURN_LONG(imap_le_struct->imap_stream->recent);
  }
  
  void php3_imap_expunge(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *streamind;
          int ind, ind_type;
! pils *imap_le_struct;
  
          if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) {
                  WRONG_PARAM_COUNT;
***************
*** 338,351 ****
  
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
  
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
  
! mail_expunge (imap_stream);
  
          RETURN_TRUE;
  }
--- 578,591 ----
  
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
  
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
  
! mail_expunge (imap_le_struct->imap_stream);
  
          RETURN_TRUE;
  }
***************
*** 353,365 ****
  
  void php3_imap_close(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *ind;
  
! if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &ind) == FAILURE) {
                  WRONG_PARAM_COUNT;
          }
! convert_to_long(ind);
! php3_list_delete(ind->value.lval);
          RETURN_TRUE;
  }
  
--- 593,625 ----
  
  void php3_imap_close(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *options, *streamind;
! int ind, ind_type;
! pils *imap_le_struct=NULL;
! int myargcount=ARG_COUNT(ht);
! long flags = NIL;
  
! if (myargcount < 1 || myargcount > 2 || getParameters(ht, myargcount, &streamind, &options) == FAILURE) {
                  WRONG_PARAM_COUNT;
          }
! convert_to_long(streamind);
! ind = streamind->value.lval;
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct->imap_stream || ind_type != le_imap) {
! php3_error(E_WARNING, "Unable to find stream pointer");
! RETURN_FALSE;
! }
! if(myargcount==2) {
! convert_to_long(options);
! flags = options->value.lval;
! /* Do the translation from PHP's internal PHP_EXPUNGE define to c-client's CL_EXPUNGE */
! if(flags & PHP_EXPUNGE) {
! flags ^= PHP_EXPUNGE;
! flags |= CL_EXPUNGE;
! }
! imap_le_struct->flags = flags;
! }
! php3_list_delete(ind);
          RETURN_TRUE;
  }
  
***************
*** 368,385 ****
  {
          pval *streamind;
          int ind, ind_type;
          unsigned int msgno;
! MAILSTREAM *imap_stream;
          char tmp[MAILTMPLEN];
- char tmp2[MAILTMPLEN];
- char tmp3[MAILTMPLEN];
- char tmp4[MAILTMPLEN];
- char mysubject[MAILTMPLEN];
- char myfrom[MAILTMPLEN];
- /* unused vars, left here just in case needed for some reason
- char *t;
- unsigned long i;
- */
  
          if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) {
                  WRONG_PARAM_COUNT;
--- 628,638 ----
  {
          pval *streamind;
          int ind, ind_type;
+ unsigned long i;
+ char *t;
          unsigned int msgno;
! pils *imap_le_struct;
          char tmp[MAILTMPLEN];
  
          if (ARG_COUNT(ht) != 1 || getParameters(ht, 1, &streamind) == FAILURE) {
                  WRONG_PARAM_COUNT;
***************
*** 389,397 ****
  
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
  
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
--- 642,650 ----
  
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
  
! if (!imap_le_struct->imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
***************
*** 401,409 ****
                  RETURN_FALSE;
          }
  
! for (msgno = 1; msgno <= imap_stream->nmsgs; msgno++) {
! MESSAGECACHE * cache = mail_elt (imap_stream,msgno);
! mail_fetchstructure (imap_stream,msgno,NIL);
                  tmp[0] = cache->recent ? (cache->seen ? 'R': 'N') : ' ';
                  tmp[1] = (cache->recent | cache->seen) ? ' ' : 'U';
                  tmp[2] = cache->flagged ? 'F' : ' ';
--- 654,662 ----
                  RETURN_FALSE;
          }
  
! for (msgno = 1; msgno <= imap_le_struct->imap_stream->nmsgs; msgno++) {
! MESSAGECACHE * cache = mail_elt (imap_le_struct->imap_stream,msgno);
! mail_fetchstructure (imap_le_struct->imap_stream,msgno,NIL);
                  tmp[0] = cache->recent ? (cache->seen ? 'R': 'N') : ' ';
                  tmp[1] = (cache->recent | cache->seen) ? ' ' : 'U';
                  tmp[2] = cache->flagged ? 'F' : ' ';
***************
*** 413,439 ****
                  mail_date (tmp+11,cache);
                  tmp[17] = ' ';
                  tmp[18] = '\0';
! mail_fetchfrom (tmp2,imap_stream,msgno,(long) 30);
! sprintf(myfrom,"%-30s",tmp2);
! strcat(tmp,myfrom);
! strcat(tmp," ");
!
! /* Don't want user flags.
! if (i = cache->user_flags) {
                          strcat (tmp,"{");
                          while (i) {
! strcat (tmp,imap_stream->user_flags[find_rightmost_bit (&i)]);
                                  if (i) strcat (tmp," ");
                          }
                          strcat (tmp,"} ");
                  }
! */
!
! mail_fetchsubject(tmp3,imap_stream,msgno,(long)25);
! sprintf(mysubject,"%-25s",tmp3);
! strcat(tmp,mysubject);
! sprintf (tmp4," %ld",cache->rfc822_size);
! strcat(tmp,tmp4);
                  add_next_index_string(return_value,tmp,1);
          }
  
--- 666,683 ----
                  mail_date (tmp+11,cache);
                  tmp[17] = ' ';
                  tmp[18] = '\0';
! mail_fetchfrom (tmp+18,imap_le_struct->imap_stream,msgno,(long) 20);
! strcat (tmp," ");
! if ((i = cache->user_flags)) {
                          strcat (tmp,"{");
                          while (i) {
! strcat (tmp,imap_le_struct->imap_stream->user_flags[find_rightmost_bit (&i)]);
                                  if (i) strcat (tmp," ");
                          }
                          strcat (tmp,"} ");
                  }
! mail_fetchsubject(t=tmp+strlen(tmp),imap_le_struct->imap_stream,msgno,(long)25);
! sprintf (t+=strlen(t)," (%ld chars)",cache->rfc822_size);
                  add_next_index_string(return_value,tmp,1);
          }
  
***************
*** 441,491 ****
  
  void php3_imap_body(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind, * msgno;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
!
! if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&msgno) == FAILURE) {
                  WRONG_PARAM_COUNT;
          }
  
          convert_to_long(streamind);
          convert_to_long(msgno);
!
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! RETVAL_STRING(mail_fetchtext (imap_stream,msgno->value.lval),1);
  
  }
  
! void php3_imap_mail_copy(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind,*seq, *folder;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
  
! if (ARG_COUNT(ht)!=3
! || getParameters(ht,3,&streamind,&seq,&folder) == FAILURE) {
                  WRONG_PARAM_COUNT;
          }
  
          convert_to_long(streamind);
          convert_to_string(seq);
          convert_to_string(folder);
!
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! if ( mail_copy(imap_stream,seq->value.str.val,folder->value.str.val)==T ) {
          RETURN_TRUE;
          } else {
                  RETURN_FALSE;
--- 685,758 ----
  
  void php3_imap_body(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind, * msgno, *flags;
          int ind, ind_type;
! pils *imap_le_struct;
! int myargc=ARG_COUNT(ht);
! if (myargc <2 || myargc > 3 || getParameters(ht,myargc,&streamind,&msgno,&flags) == FAILURE) {
                  WRONG_PARAM_COUNT;
          }
  
          convert_to_long(streamind);
          convert_to_long(msgno);
! if(myargc == 3) convert_to_long(flags);
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! RETVAL_STRING(mail_fetchtext_full (imap_le_struct->imap_stream,msgno->value.lval,NIL,myargc == 3 ? flags->value.lval : NIL),1);
  
  }
  
! void php3_imap_fetchtext_full(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind, * msgno, *flags;
          int ind, ind_type;
! pils *imap_le_struct;
! int myargcount = ARG_COUNT(ht);
! if (myargcount >3 || myargcount <2 || getParameters(ht,myargcount,&streamind,&msgno,&flags) == FAILURE) {
! WRONG_PARAM_COUNT;
! }
  
! convert_to_long(streamind);
! convert_to_long(msgno);
! if (myargcount == 3) convert_to_long(flags);
! ind = streamind->value.lval;
!
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
! php3_error(E_WARNING, "Unable to find stream pointer");
! RETURN_FALSE;
! }
! RETVAL_STRING(mail_fetchtext_full (imap_le_struct->imap_stream,msgno->value.lval,NIL,myargcount==3?flags->value.lval:NIL),1);
! }
!
! void php3_imap_mail_copy(INTERNAL_FUNCTION_PARAMETERS)
! {
! pval *streamind,*seq, *folder, *options;
! int ind, ind_type;
! pils *imap_le_struct;
! int myargcount = ARG_COUNT(ht);
! if (myargcount > 4 || myargcount < 3
! || getParameters(ht,myargcount,&streamind,&seq,&folder,&options) == FAILURE) {
                  WRONG_PARAM_COUNT;
          }
  
          convert_to_long(streamind);
          convert_to_string(seq);
          convert_to_string(folder);
! if(myargcount == 4) convert_to_long(options);
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! if ( mail_copy_full(imap_le_struct->imap_stream,seq->value.str.val,folder->value.str.val,myargcount == 4 ? options->value.lval : NIL)==T ) {
          RETURN_TRUE;
          } else {
                  RETURN_FALSE;
***************
*** 496,502 ****
  {
          pval *streamind,*seq, *folder;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
  
          if (ARG_COUNT(ht)!=3
                  || getParameters(ht,3,&streamind,&seq,&folder) == FAILURE) {
--- 763,769 ----
  {
          pval *streamind,*seq, *folder;
          int ind, ind_type;
! pils *imap_le_struct;
  
          if (ARG_COUNT(ht)!=3
                  || getParameters(ht,3,&streamind,&seq,&folder) == FAILURE) {
***************
*** 509,520 ****
  
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! if ( mail_move(imap_stream,seq->value.str.val,folder->value.str.val)==T ) {
          RETURN_TRUE;
          } else {
                  RETURN_FALSE;
--- 776,787 ----
  
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! if ( mail_move(imap_le_struct->imap_stream,seq->value.str.val,folder->value.str.val)==T ) {
          RETURN_TRUE;
          } else {
                  RETURN_FALSE;
***************
*** 525,531 ****
  {
          pval *streamind, *folder;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
  
          if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&folder) == FAILURE) {
                  WRONG_PARAM_COUNT;
--- 792,798 ----
  {
          pval *streamind, *folder;
          int ind, ind_type;
! pils *imap_le_struct;
  
          if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&folder) == FAILURE) {
                  WRONG_PARAM_COUNT;
***************
*** 536,547 ****
  
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! if ( mail_create(imap_stream,folder->value.str.val)==T ) {
          RETURN_TRUE;
          } else {
                  RETURN_FALSE;
--- 803,814 ----
  
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! if ( mail_create(imap_le_struct->imap_stream,folder->value.str.val)==T ) {
          RETURN_TRUE;
          } else {
                  RETURN_FALSE;
***************
*** 552,558 ****
  {
          pval *streamind, *old, *new;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
  
          if (ARG_COUNT(ht)!=3 || getParameters(ht,3,&streamind,&old,&new)==FAILURE){
                  WRONG_PARAM_COUNT;
--- 819,825 ----
  {
          pval *streamind, *old, *new;
          int ind, ind_type;
! pils *imap_le_struct;
  
          if (ARG_COUNT(ht)!=3 || getParameters(ht,3,&streamind,&old,&new)==FAILURE){
                  WRONG_PARAM_COUNT;
***************
*** 564,575 ****
  
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! if ( mail_rename(imap_stream,old->value.str.val,new->value.str.val)==T ) {
          RETURN_TRUE;
          } else {
                  RETURN_FALSE;
--- 831,842 ----
  
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! if ( mail_rename(imap_le_struct->imap_stream,old->value.str.val,new->value.str.val)==T ) {
          RETURN_TRUE;
          } else {
                  RETURN_FALSE;
***************
*** 580,586 ****
  {
          pval *streamind, *folder;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
  
          if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&folder) == FAILURE) {
                  WRONG_PARAM_COUNT;
--- 847,853 ----
  {
          pval *streamind, *folder;
          int ind, ind_type;
! pils *imap_le_struct;
  
          if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&folder) == FAILURE) {
                  WRONG_PARAM_COUNT;
***************
*** 591,602 ****
  
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! if ( mail_delete(imap_stream,folder->value.str.val)==T ) {
          RETURN_TRUE;
          } else {
                  RETURN_FALSE;
--- 858,869 ----
  
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
! if ( mail_delete(imap_le_struct->imap_stream,folder->value.str.val)==T ) {
          RETURN_TRUE;
          } else {
                  RETURN_FALSE;
***************
*** 606,614 ****
  void php3_imap_list(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *streamind, *ref, *pat;
- /* int i; unused */
          int ind, ind_type;
! MAILSTREAM *imap_stream;
          STRINGLIST *cur=NIL;
  
          if (ARG_COUNT(ht)!=3
--- 873,880 ----
  void php3_imap_list(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *streamind, *ref, *pat;
          int ind, ind_type;
! pils *imap_le_struct;
          STRINGLIST *cur=NIL;
  
          if (ARG_COUNT(ht)!=3
***************
*** 622,634 ****
  
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
      imap_folders = NIL;
! mail_list(imap_stream,ref->value.str.val,pat->value.str.val);
          if (imap_folders == NIL) {
                  RETURN_FALSE;
          }
--- 888,900 ----
  
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
      imap_folders = NIL;
! mail_list(imap_le_struct->imap_stream,ref->value.str.val,pat->value.str.val);
          if (imap_folders == NIL) {
                  RETURN_FALSE;
          }
***************
*** 640,691 ****
      }
          mail_free_stringlist (&imap_folders);
  }
  void php3_imap_listscan(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind, *ref, *pat, *content;
! /* int i; unused */
! int ind, ind_type;
! MAILSTREAM *imap_stream;
! STRINGLIST *cur=NIL;
!
! if (ARG_COUNT(ht)!=3
! || getParameters(ht,4,&streamind,&ref,&pat,&content) == FAILURE) {
! WRONG_PARAM_COUNT;
! }
!
! convert_to_long(streamind);
! convert_to_string(ref);
! convert_to_string(pat);
! convert_to_string(content);
!
! ind = streamind->value.lval;
!
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
! php3_error(E_WARNING, "Unable to find stream pointer");
! RETURN_FALSE;
! }
! imap_folders = NIL;
! mail_scan(imap_stream,ref->value.str.val,pat->value.str.val,content->value.str.val);
! if (imap_folders == NIL) {
! RETURN_FALSE;
! }
! array_init(return_value);
! cur=imap_folders;
! while (cur != NIL ) {
! add_next_index_string(return_value,cur->LTEXT,1);
! cur=cur->next;
! }
! mail_free_stringlist (&imap_folders);
  }
  
  void php3_imap_check(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *streamind;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
          char date[50];
- /*char tmp[150]; unused */
  
          if (ARG_COUNT(ht)!=1 || getParameters(ht,1,&streamind) == FAILURE) {
                  WRONG_PARAM_COUNT;
--- 906,955 ----
      }
          mail_free_stringlist (&imap_folders);
  }
+
  void php3_imap_listscan(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind, *ref, *pat, *content;
! int ind, ind_type;
! pils *imap_le_struct;
! STRINGLIST *cur=NIL;
!
! if (ARG_COUNT(ht)!=3 || getParameters(ht,4,&streamind,&ref,&pat,&content) == FAILURE) {
! WRONG_PARAM_COUNT;
! }
!
! convert_to_long(streamind);
! convert_to_string(ref);
! convert_to_string(pat);
! convert_to_string(content);
!
! ind = streamind->value.lval;
!
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
! php3_error(E_WARNING, "Unable to find stream pointer");
! RETURN_FALSE;
! }
! imap_folders = NIL;
! mail_scan(imap_le_struct->imap_stream,ref->value.str.val,pat->value.str.val,content->value.str.val);
! if (imap_folders == NIL) {
! RETURN_FALSE;
! }
! array_init(return_value);
! cur=imap_folders;
! while (cur != NIL ) {
! add_next_index_string(return_value,cur->LTEXT,1);
! cur=cur->next;
! }
! mail_free_stringlist (&imap_folders);
  }
  
  void php3_imap_check(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *streamind;
          int ind, ind_type;
! pils *imap_le_struct;
          char date[50];
  
          if (ARG_COUNT(ht)!=1 || getParameters(ht,1,&streamind) == FAILURE) {
                  WRONG_PARAM_COUNT;
***************
*** 695,717 ****
  
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
  
! if (mail_ping (imap_stream) == NIL ) {
                  RETURN_FALSE;
      }
! if (imap_stream && imap_stream->mailbox) {
                  rfc822_date (date);
                  object_init(return_value);
                  add_property_string(return_value,"Date",date,1);
! add_property_string(return_value,"Driver",imap_stream->dtb->name,1);
! add_property_string(return_value,"Mailbox",imap_stream->mailbox,1);
! add_property_long(return_value,"Nmsgs",imap_stream->nmsgs);
! add_property_long(return_value,"Recent",imap_stream->recent);
          } else {
                  RETURN_FALSE;
          }
--- 959,981 ----
  
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
  
! if (mail_ping (imap_le_struct->imap_stream) == NIL ) {
                  RETURN_FALSE;
      }
! if (imap_le_struct->imap_stream && imap_le_struct->imap_stream->mailbox) {
                  rfc822_date (date);
                  object_init(return_value);
                  add_property_string(return_value,"Date",date,1);
! add_property_string(return_value,"Driver",imap_le_struct->imap_stream->dtb->name,1);
! add_property_string(return_value,"Mailbox",imap_le_struct->imap_stream->mailbox,1);
! add_property_long(return_value,"Nmsgs",imap_le_struct->imap_stream->nmsgs);
! add_property_long(return_value,"Recent",imap_le_struct->imap_stream->recent);
          } else {
                  RETURN_FALSE;
          }
***************
*** 722,728 ****
  {
          pval *streamind, * msgno;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
  
          if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&msgno) == FAILURE) {
                  WRONG_PARAM_COUNT;
--- 986,992 ----
  {
          pval *streamind, * msgno;
          int ind, ind_type;
! pils *imap_le_struct;
  
          if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&msgno) == FAILURE) {
                  WRONG_PARAM_COUNT;
***************
*** 733,754 ****
  
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
  
! mail_setflag(imap_stream,msgno->value.str.val,"\\DELETED");
          RETVAL_TRUE;
-
  }
  
  void php3_imap_undelete(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *streamind, * msgno;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
  
          if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&msgno) == FAILURE) {
                  WRONG_PARAM_COUNT;
--- 997,1017 ----
  
          ind = streamind->value.lval;
  
! imap_le_struct = (pils *)php3_list_find(ind, &ind_type);
! if (!imap_le_struct || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
  
! mail_setflag(imap_le_struct->imap_stream,msgno->value.str.val,"\\DELETED");
          RETVAL_TRUE;
  }
  
  void php3_imap_undelete(INTERNAL_FUNCTION_PARAMETERS)
  {
          pval *streamind, * msgno;
          int ind, ind_type;
! pils *imap_le_struct;
  
          if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&msgno) == FAILURE) {
                  WRONG_PARAM_COUNT;
***************
*** 759,839 ****
  
          ind = streamind->value.lval;
  
! imap_stream = ( MAILSTREAM *)php3_list_find(ind, &ind_type);
! if (!imap_stream || ind_type != le_imap) {
                  php3_error(E_WARNING, "Unable to find stream pointer");
                  RETURN_FALSE;
          }
  
! mail_clearflag (imap_stream,msgno->value.str.val,"\\DELETED");
          RETVAL_TRUE;
-
  }
  
  
  void php3_imap_headerinfo(INTERNAL_FUNCTION_PARAMETERS)
  {
! pval *streamind, * msgno;
          int ind, ind_type;
! MAILSTREAM *imap_stream;
! STRINGLIST *lines=NULL;
          MESSAGECACHE * cache;
          char dummy[2000];
! if (ARG_COUNT(ht)!=2 || getParameters(ht,2,&streamind,&msgno)==FAILURE) {
                  WRONG_PARAM_COUNT;
          }
   &