diff options
-rw-r--r-- | ext/imap/php_imap.c | 779 | ||||
-rw-r--r-- | ext/imap/php_imap.h | 5 | ||||
-rw-r--r-- | ext/imap/php_imap.stub.php | 180 | ||||
-rw-r--r-- | ext/imap/php_imap_arginfo.h | 79 | ||||
-rw-r--r-- | ext/imap/tests/bug75774.phpt | 5 |
5 files changed, 469 insertions, 579 deletions
diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index dc7f3b087a..1d909d6065 100644 --- a/ext/imap/php_imap.c +++ b/ext/imap/php_imap.c @@ -34,6 +34,8 @@ #include "php.h" #include "php_ini.h" #include "php_streams.h" +#include "Zend/zend_exceptions.h" +#include "Zend/zend_interfaces.h" #include "ext/standard/php_string.h" #include "ext/standard/info.h" #include "ext/standard/file.h" @@ -138,19 +140,62 @@ ZEND_TSRMLS_CACHE_DEFINE() ZEND_GET_MODULE(imap) #endif -/* True globals, no need for thread safety */ -static int le_imap; +/* Imap class entry definition */ +static zend_class_entry *php_imap_ce = NULL; +static zend_object_handlers imap_object_handlers; -// TODO Promote to ValueError? -#define PHP_IMAP_CHECK_MSGNO(msgindex, arg_pos) \ - if (msgindex < 1) { \ - zend_argument_value_error(arg_pos, "must be greater than 0"); \ +typedef struct _php_imap_object { + MAILSTREAM *imap_stream; + long flags; + zend_object std; +} php_imap_object; + +static inline zend_object *imap_object_to_zend_object(php_imap_object *obj) { + return ((zend_object*)(obj + 1)) - 1; +} + +static inline php_imap_object *imap_object_from_zend_object(zend_object *zobj) { + return ((php_imap_object*)(zobj + 1)) - 1; +} + +static zend_object* imap_object_create(zend_class_entry* ce) { + php_imap_object *obj = zend_object_alloc(sizeof(php_imap_object), ce); + zend_object *zobj = imap_object_to_zend_object(obj); + obj->imap_stream = NULL; + obj->flags = 0; + zend_object_std_init(zobj, ce); + object_properties_init(zobj, ce); + zobj->handlers = &imap_object_handlers; + + return zobj; +} + +static void imap_object_destroy(zend_object *zobj) { + php_imap_object *obj = imap_object_from_zend_object(zobj); + + if (obj->imap_stream) { + /* Do not try to close prototype streams */ + if (!(obj->flags & OP_PROTOTYPE)) { + mail_close_full(obj->imap_stream, obj->flags); + } + } + + if (IMAPG(imap_user)) { + efree(IMAPG(imap_user)); + IMAPG(imap_user) = 0; + } + if (IMAPG(imap_password)) { + efree(IMAPG(imap_password)); + IMAPG(imap_password) = 0; + } +} + +#define GET_IMAP_STREAM(imap_conn_struct, zval_imap_obj) \ + imap_conn_struct = imap_object_from_zend_object(Z_OBJ_P(zval_imap_obj)); \ + if (!imap_conn_struct) { \ + zend_throw_exception(zend_ce_value_error, "IMAPConnection is already closed", 0); \ RETURN_THROWS(); \ - } \ - if (((unsigned) msgindex) > imap_le_struct->imap_stream->nmsgs) { \ - php_error_docref(NULL, E_WARNING, "Bad message number"); \ - RETURN_FALSE; \ - } \ + } #define PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgindex, arg_pos) \ if (msgindex < 1) { \ @@ -162,40 +207,28 @@ static int le_imap; if (func_flags & uid_flag) { \ /* This should be cached; if it causes an extra RTT to the IMAP server, */ \ /* then that's the price we pay for making sure we don't crash. */ \ - unsigned int msg_no_from_uid = mail_msgno(imap_le_struct->imap_stream, msgindex); \ + unsigned int msg_no_from_uid = mail_msgno(imap_conn_struct->imap_stream, msgindex); \ if (msg_no_from_uid == 0) { \ php_error_docref(NULL, E_WARNING, "UID does not exist"); \ RETURN_FALSE; \ } \ } else { \ - if (((unsigned) msgindex) > imap_le_struct->imap_stream->nmsgs) { \ + if (((unsigned) msgindex) > imap_conn_struct->imap_stream->nmsgs) { \ php_error_docref(NULL, E_WARNING, "Bad message number"); \ RETURN_FALSE; \ } \ } \ -/* {{{ mail_close_it */ -static void mail_close_it(zend_resource *rsrc) -{ - pils *imap_le_struct = (pils *)rsrc->ptr; - - /* Do not try to close prototype streams */ - if (!(imap_le_struct->flags & OP_PROTOTYPE)) { - mail_close_full(imap_le_struct->imap_stream, imap_le_struct->flags); - } - - if (IMAPG(imap_user)) { - efree(IMAPG(imap_user)); - IMAPG(imap_user) = 0; - } - if (IMAPG(imap_password)) { - efree(IMAPG(imap_password)); - IMAPG(imap_password) = 0; - } - - efree(imap_le_struct); -} -/* }}} */ +// TODO Promote to ValueError? +#define PHP_IMAP_CHECK_MSGNO(msgindex, arg_pos) \ + if (msgindex < 1) { \ + zend_argument_value_error(arg_pos, "must be greater than 0"); \ + RETURN_THROWS(); \ + } \ + if (((unsigned) msgindex) > imap_conn_struct->imap_stream->nmsgs) { \ + php_error_docref(NULL, E_WARNING, "Bad message number"); \ + RETURN_FALSE; \ + } \ /* {{{ php_imap_hash_add_object */ static zval *php_imap_hash_add_object(zval *arg, char *key, zval *tmp) @@ -406,6 +439,7 @@ static PHP_GINIT_FUNCTION(imap) /* {{{ PHP_MINIT_FUNCTION */ PHP_MINIT_FUNCTION(imap) { + zend_class_entry ce; unsigned long sa_all = SA_MESSAGES | SA_RECENT | SA_UNSEEN | SA_UIDNEXT | SA_UIDVALIDITY; REGISTER_INI_ENTRIES(); @@ -439,6 +473,19 @@ PHP_MINIT_FUNCTION(imap) ssl_onceonlyinit (); #endif + + INIT_CLASS_ENTRY(ce, "IMAPConnection", class_IMAPConnection_methods); + php_imap_ce = zend_register_internal_class(&ce); + php_imap_ce->ce_flags |= ZEND_ACC_FINAL | ZEND_ACC_NO_DYNAMIC_PROPERTIES; + php_imap_ce->create_object = imap_object_create; + php_imap_ce->serialize = zend_class_serialize_deny; + php_imap_ce->unserialize = zend_class_unserialize_deny; + + memcpy(&imap_object_handlers, &std_object_handlers, sizeof(zend_object_handlers)); + imap_object_handlers.offset = XtOffsetOf(php_imap_object, std); + imap_object_handlers.dtor_obj = imap_object_destroy; + imap_object_handlers.clone_obj = NULL; + /* lets allow NIL */ REGISTER_LONG_CONSTANT("NIL", NIL, CONST_PERSISTENT | CONST_CS); @@ -633,7 +680,6 @@ PHP_MINIT_FUNCTION(imap) mail_parameters (NIL, SET_SSHTIMEOUT, 0); } - le_imap = zend_register_list_destructors_ex(mail_close_it, NULL, "imap", module_number); return SUCCESS; } /* }}} */ @@ -728,7 +774,6 @@ PHP_FUNCTION(imap_open) zend_string *mailbox, *user, *passwd; zend_long retries = 0, flags = 0, cl_flags = 0; MAILSTREAM *imap_stream; - pils *imap_le_struct; HashTable *params = NULL; if (zend_parse_parameters(ZEND_NUM_ARGS(), "PSS|llh", &mailbox, &user, &passwd, &flags, &retries, ¶ms) == FAILURE) { @@ -831,31 +876,27 @@ PHP_FUNCTION(imap_open) RETURN_FALSE; } - imap_le_struct = emalloc(sizeof(pils)); - imap_le_struct->imap_stream = imap_stream; - imap_le_struct->flags = cl_flags; - - RETURN_RES(zend_register_resource(imap_le_struct, le_imap)); + object_init_ex(return_value, php_imap_ce); + imap_object_from_zend_object(Z_OBJ_P(return_value))->imap_stream = imap_stream; + imap_object_from_zend_object(Z_OBJ_P(return_value))->flags = cl_flags; } /* }}} */ /* {{{ Reopen an IMAP stream to a new mailbox */ PHP_FUNCTION(imap_reopen) { - zval *streamind; + zval *imap_conn_obj; zend_string *mailbox; zend_long options = 0, retries = 0; - pils *imap_le_struct; - long flags=NIL; - long cl_flags=NIL; + php_imap_object *imap_conn_struct; + long flags = 0; + long cl_flags = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS|ll", &streamind, &mailbox, &options, &retries) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS|ll", &imap_conn_obj, php_imap_ce, &mailbox, &options, &retries) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* TODO Verify these are the only options available as they are pulled from the php.net documentation */ if (options && ((options & ~(OP_READONLY | OP_ANONYMOUS | OP_HALFOPEN | OP_EXPUNGE | CL_EXPUNGE)) != 0)) { @@ -875,7 +916,7 @@ PHP_FUNCTION(imap_reopen) cl_flags = CL_EXPUNGE; flags ^= PHP_EXPUNGE; } - imap_le_struct->flags = cl_flags; + imap_conn_struct->flags = cl_flags; } #ifdef SET_MAXLOGINTRIALS if (retries) { @@ -887,9 +928,9 @@ PHP_FUNCTION(imap_reopen) RETURN_FALSE; } - imap_le_struct->imap_stream = mail_open(imap_le_struct->imap_stream, ZSTR_VAL(mailbox), flags); - if (imap_le_struct->imap_stream == NIL) { - zend_list_close(Z_RES_P(streamind)); + imap_conn_struct->imap_stream = mail_open(imap_conn_struct->imap_stream, ZSTR_VAL(mailbox), flags); + if (imap_conn_struct->imap_stream == NIL) { + /* IMAPConnection object will release it self. */ php_error_docref(NULL, E_WARNING, "Couldn't re-open stream"); RETURN_FALSE; } @@ -900,16 +941,15 @@ PHP_FUNCTION(imap_reopen) /* {{{ Append a new message to a specified mailbox */ PHP_FUNCTION(imap_append) { - zval *streamind; + zval *imap_conn_obj; zend_string *folder, *message, *internal_date = NULL, *flags = NULL; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; STRING st; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|S!S!", &streamind, &folder, &message, &flags, &internal_date) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS|S!S!", &imap_conn_obj, php_imap_ce, &folder, &message, &flags, &internal_date) == FAILURE) { RETURN_THROWS(); } - if (internal_date) { zend_string *regex = zend_string_init("/[0-3][0-9]-((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))-[0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [+-][0-9]{4}/", sizeof("/[0-3][0-9]-((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))-[0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [+-][0-9]{4}/") - 1, 0); pcre_cache_entry *pce; /* Compiled regex */ @@ -935,13 +975,11 @@ PHP_FUNCTION(imap_append) /* TODO Check if flags are valid (documentation is not present on php.net so need to check this first) */ - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); INIT (&st, mail_string, (void *) ZSTR_VAL(message), ZSTR_LEN(message)); - if (mail_append_full(imap_le_struct->imap_stream, ZSTR_VAL(folder), (flags ? ZSTR_VAL(flags) : NIL), (internal_date ? ZSTR_VAL(internal_date) : NIL), &st)) { + if (mail_append_full(imap_conn_struct->imap_stream, ZSTR_VAL(folder), (flags ? ZSTR_VAL(flags) : NIL), (internal_date ? ZSTR_VAL(internal_date) : NIL), &st)) { RETURN_TRUE; } else { RETURN_FALSE; @@ -952,54 +990,48 @@ PHP_FUNCTION(imap_append) /* {{{ Gives the number of messages in the current mailbox */ PHP_FUNCTION(imap_num_msg) { - zval *streamind; - pils *imap_le_struct; + zval *imap_conn_obj; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &streamind) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &imap_conn_obj, php_imap_ce) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); - RETURN_LONG(imap_le_struct->imap_stream->nmsgs); + RETURN_LONG(imap_conn_struct->imap_stream->nmsgs); } /* }}} */ /* {{{ Check if the IMAP stream is still active */ PHP_FUNCTION(imap_ping) { - zval *streamind; - pils *imap_le_struct; + zval *imap_conn_obj; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &streamind) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &imap_conn_obj, php_imap_ce) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); - RETURN_BOOL(mail_ping(imap_le_struct->imap_stream)); + RETURN_BOOL(mail_ping(imap_conn_struct->imap_stream)); } /* }}} */ /* {{{ Gives the number of recent messages in current mailbox */ PHP_FUNCTION(imap_num_recent) { - zval *streamind; - pils *imap_le_struct; + zval *imap_conn_obj; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &streamind) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &imap_conn_obj, php_imap_ce) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); - RETURN_LONG(imap_le_struct->imap_stream->recent); + RETURN_LONG(imap_conn_struct->imap_stream->recent); } /* }}} */ @@ -1007,24 +1039,22 @@ PHP_FUNCTION(imap_num_recent) /* {{{ Returns the quota set to the mailbox account qroot */ PHP_FUNCTION(imap_get_quota) { - zval *streamind; + zval *imap_conn_obj; zend_string *qroot; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS", &streamind, &qroot) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &imap_conn_obj, php_imap_ce, &qroot) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); array_init(return_value); IMAPG(quota_return) = &return_value; /* set the callback for the GET_QUOTA function */ mail_parameters(NIL, SET_QUOTA, (void *) mail_getquota); - if (!imap_getquota(imap_le_struct->imap_stream, ZSTR_VAL(qroot))) { + if (!imap_getquota(imap_conn_struct->imap_stream, ZSTR_VAL(qroot))) { php_error_docref(NULL, E_WARNING, "C-client imap_getquota failed"); zend_array_destroy(Z_ARR_P(return_value)); RETURN_FALSE; @@ -1035,24 +1065,22 @@ PHP_FUNCTION(imap_get_quota) /* {{{ Returns the quota set to the mailbox account mbox */ PHP_FUNCTION(imap_get_quotaroot) { - zval *streamind; + zval *imap_conn_obj; zend_string *mbox; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS", &streamind, &mbox) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &imap_conn_obj, php_imap_ce, &mbox) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); array_init(return_value); IMAPG(quota_return) = &return_value; /* set the callback for the GET_QUOTAROOT function */ mail_parameters(NIL, SET_QUOTA, (void *) mail_getquota); - if (!imap_getquotaroot(imap_le_struct->imap_stream, ZSTR_VAL(mbox))) { + if (!imap_getquotaroot(imap_conn_struct->imap_stream, ZSTR_VAL(mbox))) { php_error_docref(NULL, E_WARNING, "C-client imap_getquotaroot failed"); zend_array_destroy(Z_ARR_P(return_value)); RETURN_FALSE; @@ -1063,61 +1091,55 @@ PHP_FUNCTION(imap_get_quotaroot) /* {{{ Will set the quota for qroot mailbox */ PHP_FUNCTION(imap_set_quota) { - zval *streamind; + zval *imap_conn_obj; zend_string *qroot; zend_long mailbox_size; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; STRINGLIST limits; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSl", &streamind, &qroot, &mailbox_size) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSl", &imap_conn_obj, php_imap_ce, &qroot, &mailbox_size) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); limits.text.data = (unsigned char*)"STORAGE"; limits.text.size = mailbox_size; limits.next = NIL; - RETURN_BOOL(imap_setquota(imap_le_struct->imap_stream, ZSTR_VAL(qroot), &limits)); + RETURN_BOOL(imap_setquota(imap_conn_struct->imap_stream, ZSTR_VAL(qroot), &limits)); } /* }}} */ /* {{{ Sets the ACL for a given mailbox */ PHP_FUNCTION(imap_setacl) { - zval *streamind; + zval *imap_conn_obj; zend_string *mailbox, *id, *rights; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSSS", &streamind, &mailbox, &id, &rights) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSSS", &imap_conn_obj, php_imap_ce, &mailbox, &id, &rights) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); - RETURN_BOOL(imap_setacl(imap_le_struct->imap_stream, ZSTR_VAL(mailbox), ZSTR_VAL(id), ZSTR_VAL(rights))); + RETURN_BOOL(imap_setacl(imap_conn_struct->imap_stream, ZSTR_VAL(mailbox), ZSTR_VAL(id), ZSTR_VAL(rights))); } /* }}} */ /* {{{ Gets the ACL for a given mailbox */ PHP_FUNCTION(imap_getacl) { - zval *streamind; + zval *imap_conn_obj; zend_string *mailbox; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS", &streamind, &mailbox) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &imap_conn_obj, php_imap_ce, &mailbox) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* initializing the special array for the return values */ array_init(return_value); @@ -1126,7 +1148,7 @@ PHP_FUNCTION(imap_getacl) /* set the callback for the GET_ACL function */ mail_parameters(NIL, SET_ACL, (void *) mail_getacl); - if (!imap_getacl(imap_le_struct->imap_stream, ZSTR_VAL(mailbox))) { + if (!imap_getacl(imap_conn_struct->imap_stream, ZSTR_VAL(mailbox))) { php_error(E_WARNING, "c-client imap_getacl failed"); zend_array_destroy(Z_ARR_P(return_value)); RETURN_FALSE; @@ -1140,18 +1162,16 @@ PHP_FUNCTION(imap_getacl) /* {{{ Permanently delete all messages marked for deletion */ PHP_FUNCTION(imap_expunge) { - zval *streamind; - pils *imap_le_struct; + zval *imap_conn_obj; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &streamind) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &imap_conn_obj, php_imap_ce) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); - mail_expunge (imap_le_struct->imap_stream); + mail_expunge (imap_conn_struct->imap_stream); RETURN_TRUE; } @@ -1160,24 +1180,22 @@ PHP_FUNCTION(imap_expunge) /* {{{ This function garbage collects (purges) the cache of entries of a specific type. */ PHP_FUNCTION(imap_gc) { - zval *streamind; - pils *imap_le_struct; + zval *imap_conn_obj; + php_imap_object *imap_conn_struct; zend_long flags; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &streamind, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &imap_conn_obj, php_imap_ce, &flags) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); if (flags && ((flags & ~(GC_TEXTS | GC_ELT | GC_ENV)) != 0)) { zend_argument_value_error(2, "must be a bitmask of IMAP_GC_TEXTS, IMAP_GC_ELT, and IMAP_GC_ENV"); RETURN_THROWS(); } - mail_gc(imap_le_struct->imap_stream, flags); + mail_gc(imap_conn_struct->imap_stream, flags); // TODO Return void? RETURN_TRUE; @@ -1187,36 +1205,36 @@ PHP_FUNCTION(imap_gc) /* {{{ Close an IMAP stream */ PHP_FUNCTION(imap_close) { - zval *streamind; - pils *imap_le_struct=NULL; - zend_long options = 0, flags = NIL; + zval *imap_conn_obj; + php_imap_object *imap_conn_struct = NULL; + zend_long options = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &streamind, &options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l", &imap_conn_obj, php_imap_ce, &options) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); if (options) { - flags = options; - /* Check that flags is exactly equal to PHP_EXPUNGE or zero */ - if (flags && ((flags & ~PHP_EXPUNGE) != 0)) { + if (options && ((options & ~PHP_EXPUNGE) != 0)) { zend_argument_value_error(2, "must be CL_EXPUNGE or 0"); RETURN_THROWS(); } /* 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; + if (options & PHP_EXPUNGE) { + options ^= PHP_EXPUNGE; + options |= CL_EXPUNGE; } - imap_le_struct->flags = flags; + imap_conn_struct->flags = options; } - zend_list_close(Z_RES_P(streamind)); + /* Do not try to close prototype streams */ + if (!(imap_conn_struct->flags & OP_PROTOTYPE)) { + mail_close_full(imap_conn_struct->imap_stream, imap_conn_struct->flags); + imap_conn_struct->imap_stream = NULL; + } // TODO Return void? RETURN_TRUE; @@ -1226,27 +1244,25 @@ PHP_FUNCTION(imap_close) /* {{{ Returns headers for all messages in a mailbox */ PHP_FUNCTION(imap_headers) { - zval *streamind; - pils *imap_le_struct; + zval *imap_conn_obj; + php_imap_object *imap_conn_struct; unsigned long i; char *t; unsigned int msgno; char tmp[MAILTMPLEN]; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &streamind) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &imap_conn_obj, php_imap_ce) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* Initialize return array */ array_init(return_value); - 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); + for (msgno = 1; msgno <= imap_conn_struct->imap_stream->nmsgs; msgno++) { + MESSAGECACHE * cache = mail_elt (imap_conn_struct->imap_stream, msgno); + mail_fetchstructure(imap_conn_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' : ' '; @@ -1257,17 +1273,17 @@ PHP_FUNCTION(imap_headers) mail_date(tmp+11, cache); tmp[22] = ' '; tmp[23] = '\0'; - mail_fetchfrom(tmp+23, imap_le_struct->imap_stream, msgno, (long)20); + mail_fetchfrom(tmp+23, imap_conn_struct->imap_stream, msgno, (long)20); strcat(tmp, " "); if ((i = cache->user_flags)) { strcat(tmp, "{"); while (i) { - strlcat(tmp, imap_le_struct->imap_stream->user_flags[find_rightmost_bit (&i)], sizeof(tmp)); + strlcat(tmp, imap_conn_struct->imap_stream->user_flags[find_rightmost_bit (&i)], sizeof(tmp)); if (i) strlcat(tmp, " ", sizeof(tmp)); } strlcat(tmp, "} ", sizeof(tmp)); } - mail_fetchsubject(t = tmp + strlen(tmp), imap_le_struct->imap_stream, msgno, (long)25); + mail_fetchsubject(t = tmp + strlen(tmp), imap_conn_struct->imap_stream, msgno, (long)25); snprintf(t += strlen(t), sizeof(tmp) - strlen(tmp), " (%ld chars)", cache->rfc822_size); add_next_index_string(return_value, tmp); } @@ -1277,19 +1293,17 @@ PHP_FUNCTION(imap_headers) /* {{{ Read the message body */ PHP_FUNCTION(imap_body) { - zval *streamind; + zval *imap_conn_obj; zend_long msgno, flags = 0; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; char *body; unsigned long body_len = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &streamind, &msgno, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol|l", &imap_conn_obj, php_imap_ce, &msgno, &flags) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 2); @@ -1300,7 +1314,7 @@ PHP_FUNCTION(imap_body) PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS(msgno, 2, flags, FT_UID); - body = mail_fetchtext_full (imap_le_struct->imap_stream, msgno, &body_len, flags); + body = mail_fetchtext_full (imap_conn_struct->imap_stream, msgno, &body_len, flags); if (body_len == 0) { RETVAL_EMPTY_STRING(); } else { @@ -1313,25 +1327,23 @@ PHP_FUNCTION(imap_body) /* {{{ Copy specified message to a mailbox */ PHP_FUNCTION(imap_mail_copy) { - zval *streamind; + zval *imap_conn_obj; zend_long options = 0; zend_string *seq, *folder; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|l", &streamind, &seq, &folder, &options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS|l", &imap_conn_obj, php_imap_ce, &seq, &folder, &options) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); if (options && ((options & ~(CP_UID | CP_MOVE)) != 0)) { zend_argument_value_error(4, "must be a bitmask of CP_UID, and CP_MOVE"); RETURN_THROWS(); } - if (mail_copy_full(imap_le_struct->imap_stream, ZSTR_VAL(seq), ZSTR_VAL(folder), options) == T) { + if (mail_copy_full(imap_conn_struct->imap_stream, ZSTR_VAL(seq), ZSTR_VAL(folder), options) == T) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1343,18 +1355,16 @@ PHP_FUNCTION(imap_mail_copy) /* {{{ Move specified message to a mailbox */ PHP_FUNCTION(imap_mail_move) { - zval *streamind; + zval *imap_conn_obj; zend_string *seq, *folder; zend_long options = 0; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|l", &streamind, &seq, &folder, &options) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS|l", &imap_conn_obj, php_imap_ce, &seq, &folder, &options) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); if (options && ((options & ~CP_UID) != 0)) { zend_argument_value_error(4, "must be CP_UID or 0"); @@ -1364,7 +1374,7 @@ PHP_FUNCTION(imap_mail_move) /* Add CP_MOVE flag */ options = (options | CP_MOVE); - if (mail_copy_full(imap_le_struct->imap_stream, ZSTR_VAL(seq), ZSTR_VAL(folder), options) == T) { + if (mail_copy_full(imap_conn_struct->imap_stream, ZSTR_VAL(seq), ZSTR_VAL(folder), options) == T) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1375,19 +1385,17 @@ PHP_FUNCTION(imap_mail_move) /* {{{ Create a new mailbox */ PHP_FUNCTION(imap_createmailbox) { - zval *streamind; + zval *imap_conn_obj; zend_string *folder; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS", &streamind, &folder) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &imap_conn_obj, php_imap_ce, &folder) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); - if (mail_create(imap_le_struct->imap_stream, ZSTR_VAL(folder)) == T) { + if (mail_create(imap_conn_struct->imap_stream, ZSTR_VAL(folder)) == T) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1398,19 +1406,17 @@ PHP_FUNCTION(imap_createmailbox) /* {{{ Rename a mailbox */ PHP_FUNCTION(imap_renamemailbox) { - zval *streamind; + zval *imap_conn_obj; zend_string *old_mailbox, *new_mailbox; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS", &streamind, &old_mailbox, &new_mailbox) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS", &imap_conn_obj, php_imap_ce, &old_mailbox, &new_mailbox) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); - if (mail_rename(imap_le_struct->imap_stream, ZSTR_VAL(old_mailbox), ZSTR_VAL(new_mailbox)) == T) { + if (mail_rename(imap_conn_struct->imap_stream, ZSTR_VAL(old_mailbox), ZSTR_VAL(new_mailbox)) == T) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1421,19 +1427,17 @@ PHP_FUNCTION(imap_renamemailbox) /* {{{ Delete a mailbox */ PHP_FUNCTION(imap_deletemailbox) { - zval *streamind; + zval *imap_conn_obj; zend_string *folder; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS", &streamind, &folder) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &imap_conn_obj, php_imap_ce, &folder) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); - if (mail_delete(imap_le_struct->imap_stream, ZSTR_VAL(folder)) == T) { + if (mail_delete(imap_conn_struct->imap_stream, ZSTR_VAL(folder)) == T) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1444,24 +1448,22 @@ PHP_FUNCTION(imap_deletemailbox) /* {{{ Read the list of mailboxes */ PHP_FUNCTION(imap_list) { - zval *streamind; + zval *imap_conn_obj; zend_string *ref, *pat; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; STRINGLIST *cur=NIL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS", &streamind, &ref, &pat) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS", &imap_conn_obj, php_imap_ce, &ref, &pat) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* set flag for normal, old mailbox list */ IMAPG(folderlist_style) = FLIST_ARRAY; IMAPG(imap_folders) = IMAPG(imap_folders_tail) = NIL; - mail_list(imap_le_struct->imap_stream, ZSTR_VAL(ref), ZSTR_VAL(pat)); + mail_list(imap_conn_struct->imap_stream, ZSTR_VAL(ref), ZSTR_VAL(pat)); if (IMAPG(imap_folders) == NIL) { RETURN_FALSE; } @@ -1482,25 +1484,23 @@ PHP_FUNCTION(imap_list) /* Author: CJH */ PHP_FUNCTION(imap_getmailboxes) { - zval *streamind, mboxob; + zval *imap_conn_obj, mboxob; zend_string *ref, *pat; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; FOBJECTLIST *cur=NIL; char *delim=NIL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS", &streamind, &ref, &pat) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS", &imap_conn_obj, php_imap_ce, &ref, &pat) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* set flag for new, improved array of objects mailbox list */ IMAPG(folderlist_style) = FLIST_OBJECT; IMAPG(imap_folder_objects) = IMAPG(imap_folder_objects_tail) = NIL; - mail_list(imap_le_struct->imap_stream, ZSTR_VAL(ref), ZSTR_VAL(pat)); + mail_list(imap_conn_struct->imap_stream, ZSTR_VAL(ref), ZSTR_VAL(pat)); if (IMAPG(imap_folder_objects) == NIL) { RETURN_FALSE; } @@ -1531,21 +1531,19 @@ PHP_FUNCTION(imap_getmailboxes) /* {{{ Read list of mailboxes containing a certain string */ PHP_FUNCTION(imap_listscan) { - zval *streamind; + zval *imap_conn_obj; zend_string *ref, *pat, *content; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; STRINGLIST *cur=NIL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSSS", &streamind, &ref, &pat, &content) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSSS", &imap_conn_obj, php_imap_ce, &ref, &pat, &content) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); IMAPG(imap_folders) = NIL; - mail_scan(imap_le_struct->imap_stream, ZSTR_VAL(ref), ZSTR_VAL(pat), ZSTR_VAL(content)); + mail_scan(imap_conn_struct->imap_stream, ZSTR_VAL(ref), ZSTR_VAL(pat), ZSTR_VAL(content)); if (IMAPG(imap_folders) == NIL) { RETURN_FALSE; } @@ -1565,30 +1563,28 @@ PHP_FUNCTION(imap_listscan) /* {{{ Get mailbox properties */ PHP_FUNCTION(imap_check) { - zval *streamind; - pils *imap_le_struct; + zval *imap_conn_obj; + php_imap_object *imap_conn_struct; char date[100]; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &streamind) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &imap_conn_obj, php_imap_ce) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); - if (mail_ping (imap_le_struct->imap_stream) == NIL) { + if (mail_ping (imap_conn_struct->imap_stream) == NIL) { RETURN_FALSE; } - if (imap_le_struct->imap_stream && imap_le_struct->imap_stream->mailbox) { + if (imap_conn_struct->imap_stream && imap_conn_struct->imap_stream->mailbox) { rfc822_date(date); object_init(return_value); add_property_string(return_value, "Date", date); - add_property_string(return_value, "Driver", imap_le_struct->imap_stream->dtb->name); - add_property_string(return_value, "Mailbox", imap_le_struct->imap_stream->mailbox); - add_property_long(return_value, "Nmsgs", imap_le_struct->imap_stream->nmsgs); - add_property_long(return_value, "Recent", imap_le_struct->imap_stream->recent); + add_property_string(return_value, "Driver", imap_conn_struct->imap_stream->dtb->name); + add_property_string(return_value, "Mailbox", imap_conn_struct->imap_stream->mailbox); + add_property_long(return_value, "Nmsgs", imap_conn_struct->imap_stream->nmsgs); + add_property_long(return_value, "Recent", imap_conn_struct->imap_stream->recent); } else { RETURN_FALSE; } @@ -1598,18 +1594,16 @@ PHP_FUNCTION(imap_check) /* {{{ Mark a message for deletion */ PHP_FUNCTION(imap_delete) { - zval *streamind; - pils *imap_le_struct; + zval *imap_conn_obj; + php_imap_object *imap_conn_struct; zend_string *sequence; zend_long flags = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS|l", &streamind, &sequence, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS|l", &imap_conn_obj, php_imap_ce, &sequence, &flags) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); // TODO Check sequence validity? @@ -1618,7 +1612,9 @@ PHP_FUNCTION(imap_delete) RETURN_THROWS(); } - mail_setflag_full(imap_le_struct->imap_stream, ZSTR_VAL(sequence), "\\DELETED", flags); + mail_setflag_full(imap_conn_struct->imap_stream, ZSTR_VAL(sequence), "\\DELETED", flags); + + // TODO Return void? RETURN_TRUE; } /* }}} */ @@ -1626,45 +1622,41 @@ PHP_FUNCTION(imap_delete) /* {{{ Remove the delete flag from a message */ PHP_FUNCTION(imap_undelete) { - zval *streamind; + zval *imap_conn_obj; zend_string *sequence; zend_long flags = 0; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS|l", &streamind, &sequence, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS|l", &imap_conn_obj, php_imap_ce, &sequence, &flags) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* TODO Check if flags are valid (documentation is not present on php.net so need to check this first) */ - mail_clearflag_full(imap_le_struct->imap_stream, ZSTR_VAL(sequence), "\\DELETED", flags); + mail_clearflag_full(imap_conn_struct->imap_stream, ZSTR_VAL(sequence), "\\DELETED", flags); // TODO Return void? - RETVAL_TRUE; + RETURN_TRUE; } /* }}} */ /* {{{ Read the headers of the message */ PHP_FUNCTION(imap_headerinfo) { - zval *streamind; + zval *imap_conn_obj; zend_long msgno, fromlength = 0, subjectlength = 0; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; MESSAGECACHE *cache; ENVELOPE *en; char dummy[2000], fulladdress[MAILTMPLEN + 1]; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|ll", &streamind, &msgno, &fromlength, &subjectlength) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol|ll", &imap_conn_obj, php_imap_ce, &msgno, &fromlength, &subjectlength) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); PHP_IMAP_CHECK_MSGNO(msgno, 2); @@ -1678,13 +1670,13 @@ PHP_FUNCTION(imap_headerinfo) RETURN_THROWS(); } - if (mail_fetchstructure(imap_le_struct->imap_stream, msgno, NIL)) { - cache = mail_elt(imap_le_struct->imap_stream, msgno); + if (mail_fetchstructure(imap_conn_struct->imap_stream, msgno, NIL)) { + cache = mail_elt(imap_conn_struct->imap_stream, msgno); } else { RETURN_FALSE; } - en = mail_fetchenvelope(imap_le_struct->imap_stream, msgno); + en = mail_fetchenvelope(imap_conn_struct->imap_stream, msgno); /* call a function to parse all the text, so that we can use the same function to parse text from other sources */ @@ -1712,12 +1704,12 @@ PHP_FUNCTION(imap_headerinfo) if (en->from && fromlength) { fulladdress[0] = 0x00; - mail_fetchfrom(fulladdress, imap_le_struct->imap_stream, msgno, fromlength); + mail_fetchfrom(fulladdress, imap_conn_struct->imap_stream, msgno, fromlength); add_property_string(return_value, "fetchfrom", fulladdress); } if (en->subject && subjectlength) { fulladdress[0] = 0x00; - mail_fetchsubject(fulladdress, imap_le_struct->imap_stream, msgno, subjectlength); + mail_fetchsubject(fulladdress, imap_conn_struct->imap_stream, msgno, subjectlength); add_property_string(return_value, "fetchsubject", fulladdress); } } @@ -1750,25 +1742,23 @@ PHP_FUNCTION(imap_rfc822_parse_headers) /* {{{ Return a list of subscribed mailboxes */ PHP_FUNCTION(imap_lsub) { - zval *streamind; + zval *imap_conn_obj; zend_string *ref, *pat; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; STRINGLIST *cur=NIL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS", &streamind, &ref, &pat) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS", &imap_conn_obj, php_imap_ce, &ref, &pat) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* set flag for normal, old mailbox list */ IMAPG(folderlist_style) = FLIST_ARRAY; IMAPG(imap_sfolders) = NIL; ZEND_IGNORE_LEAKS_BEGIN(); - mail_lsub(imap_le_struct->imap_stream, ZSTR_VAL(ref), ZSTR_VAL(pat)); + mail_lsub(imap_conn_struct->imap_stream, ZSTR_VAL(ref), ZSTR_VAL(pat)); ZEND_IGNORE_LEAKS_END(); if (IMAPG(imap_sfolders) == NIL) { RETURN_FALSE; @@ -1789,26 +1779,24 @@ PHP_FUNCTION(imap_lsub) /* Author: CJH */ PHP_FUNCTION(imap_getsubscribed) { - zval *streamind, mboxob; + zval *imap_conn_obj, mboxob; zend_string *ref, *pat; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; FOBJECTLIST *cur=NIL; char *delim=NIL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS", &streamind, &ref, &pat) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS", &imap_conn_obj, php_imap_ce, &ref, &pat) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* set flag for new, improved array of objects list */ IMAPG(folderlist_style) = FLIST_OBJECT; IMAPG(imap_sfolder_objects) = IMAPG(imap_sfolder_objects_tail) = NIL; ZEND_IGNORE_LEAKS_BEGIN(); - mail_lsub(imap_le_struct->imap_stream, ZSTR_VAL(ref), ZSTR_VAL(pat)); + mail_lsub(imap_conn_struct->imap_stream, ZSTR_VAL(ref), ZSTR_VAL(pat)); ZEND_IGNORE_LEAKS_END(); if (IMAPG(imap_sfolder_objects) == NIL) { RETURN_FALSE; @@ -1840,19 +1828,17 @@ PHP_FUNCTION(imap_getsubscribed) /* {{{ Subscribe to a mailbox */ PHP_FUNCTION(imap_subscribe) { - zval *streamind; + zval *imap_conn_obj; zend_string *folder; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS", &streamind, &folder) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &imap_conn_obj, php_imap_ce, &folder) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); - if (mail_subscribe(imap_le_struct->imap_stream, ZSTR_VAL(folder)) == T) { + if (mail_subscribe(imap_conn_struct->imap_stream, ZSTR_VAL(folder)) == T) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1863,19 +1849,17 @@ PHP_FUNCTION(imap_subscribe) /* {{{ Unsubscribe from a mailbox */ PHP_FUNCTION(imap_unsubscribe) { - zval *streamind; + zval *imap_conn_obj; zend_string *folder; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS", &streamind, &folder) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS", &imap_conn_obj, php_imap_ce, &folder) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); - if (mail_unsubscribe(imap_le_struct->imap_stream, ZSTR_VAL(folder)) == T) { + if (mail_unsubscribe(imap_conn_struct->imap_stream, ZSTR_VAL(folder)) == T) { RETURN_TRUE; } else { RETURN_FALSE; @@ -1886,18 +1870,16 @@ PHP_FUNCTION(imap_unsubscribe) /* {{{ Read the full structure of a message */ PHP_FUNCTION(imap_fetchstructure) { - zval *streamind; + zval *imap_conn_obj; zend_long msgno, flags = 0; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; BODY *body; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &streamind, &msgno, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol|l", &imap_conn_obj, php_imap_ce, &msgno, &flags) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 2); @@ -1910,7 +1892,7 @@ PHP_FUNCTION(imap_fetchstructure) object_init(return_value); - mail_fetchstructure_full(imap_le_struct->imap_stream, msgno, &body , flags); + mail_fetchstructure_full(imap_conn_struct->imap_stream, msgno, &body , flags); if (!body) { php_error_docref(NULL, E_WARNING, "No body information available"); @@ -1924,20 +1906,18 @@ PHP_FUNCTION(imap_fetchstructure) /* {{{ Get a specific body section */ PHP_FUNCTION(imap_fetchbody) { - zval *streamind; + zval *imap_conn_obj; zend_long msgno, flags = 0; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; char *body; zend_string *sec; unsigned long len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlS|l", &streamind, &msgno, &sec, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OlS|l", &imap_conn_obj, php_imap_ce, &msgno, &sec, &flags) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 2); @@ -1948,7 +1928,7 @@ PHP_FUNCTION(imap_fetchbody) PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS(msgno, 2, flags, FT_UID); - body = mail_fetchbody_full(imap_le_struct->imap_stream, msgno, ZSTR_VAL(sec), &len, flags); + body = mail_fetchbody_full(imap_conn_struct->imap_stream, msgno, ZSTR_VAL(sec), &len, flags); if (!body) { php_error_docref(NULL, E_WARNING, "No body information available"); @@ -1963,20 +1943,18 @@ PHP_FUNCTION(imap_fetchbody) /* {{{ Get a specific body section's MIME headers */ PHP_FUNCTION(imap_fetchmime) { - zval *streamind; + zval *imap_conn_obj; zend_long msgno, flags = 0; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; char *body; zend_string *sec; unsigned long len; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlS|l", &streamind, &msgno, &sec, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OlS|l", &imap_conn_obj, php_imap_ce, &msgno, &sec, &flags) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 2); @@ -1987,7 +1965,7 @@ PHP_FUNCTION(imap_fetchmime) PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS(msgno, 2, flags, FT_UID); - body = mail_fetch_mime(imap_le_struct->imap_stream, msgno, ZSTR_VAL(sec), &len, flags); + body = mail_fetch_mime(imap_conn_struct->imap_stream, msgno, ZSTR_VAL(sec), &len, flags); if (!body) { php_error_docref(NULL, E_WARNING, "No body MIME information available"); @@ -2001,20 +1979,19 @@ PHP_FUNCTION(imap_fetchmime) /* {{{ Save a specific body section to a file */ PHP_FUNCTION(imap_savebody) { - zval *stream, *out; - pils *imap_le_struct = NULL; + zval *imap_conn_obj; + zval *out; + php_imap_object *imap_conn_struct = NULL; php_stream *writer = NULL; zend_string *section = NULL; int close_stream = 1; zend_long msgno, flags = 0; - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "rzl|Sl", &stream, &out, &msgno, §ion, &flags)) { + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "Ozl|Sl", &imap_conn_obj, php_imap_ce, &out, &msgno, §ion, &flags)) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(stream), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 3) @@ -2048,7 +2025,7 @@ PHP_FUNCTION(imap_savebody) IMAPG(gets_stream) = writer; mail_parameters(NIL, SET_GETS, (void *) php_mail_gets); - mail_fetchbody_full(imap_le_struct->imap_stream, msgno, section?ZSTR_VAL(section):"", NULL, flags); + mail_fetchbody_full(imap_conn_struct->imap_stream, msgno, section?ZSTR_VAL(section):"", NULL, flags); mail_parameters(NIL, SET_GETS, (void *) NULL); IMAPG(gets_stream) = NULL; @@ -2151,26 +2128,24 @@ PHP_FUNCTION(imap_binary) /* {{{ Returns info about the current mailbox */ PHP_FUNCTION(imap_mailboxmsginfo) { - zval *streamind; - pils *imap_le_struct; + zval *imap_conn_obj; + php_imap_object *imap_conn_struct; char date[100]; unsigned long msgno; zend_ulong unreadmsg = 0, deletedmsg = 0, msize = 0; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r", &streamind) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &imap_conn_obj, php_imap_ce) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* Initialize return object */ object_init(return_value); - 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); + for (msgno = 1; msgno <= imap_conn_struct->imap_stream->nmsgs; msgno++) { + MESSAGECACHE * cache = mail_elt (imap_conn_struct->imap_stream, msgno); + mail_fetchstructure (imap_conn_struct->imap_stream, msgno, NIL); if (!cache->seen || cache->recent) { unreadmsg++; @@ -2183,13 +2158,13 @@ PHP_FUNCTION(imap_mailboxmsginfo) } add_property_long(return_value, "Unread", unreadmsg); add_property_long(return_value, "Deleted", deletedmsg); - add_property_long(return_value, "Nmsgs", imap_le_struct->imap_stream->nmsgs); + add_property_long(return_value, "Nmsgs", imap_conn_struct->imap_stream->nmsgs); add_property_long(return_value, "Size", msize); rfc822_date(date); add_property_string(return_value, "Date", date); - add_property_string(return_value, "Driver", imap_le_struct->imap_stream->dtb->name); - add_property_string(return_value, "Mailbox", imap_le_struct->imap_stream->mailbox); - add_property_long(return_value, "Recent", imap_le_struct->imap_stream->recent); + add_property_string(return_value, "Driver", imap_conn_struct->imap_stream->dtb->name); + add_property_string(return_value, "Mailbox", imap_conn_struct->imap_stream->mailbox); + add_property_long(return_value, "Recent", imap_conn_struct->imap_stream->recent); } /* }}} */ @@ -2629,25 +2604,23 @@ PHP_FUNCTION(imap_mutf7_to_utf8) /* {{{ Sets flags on messages */ PHP_FUNCTION(imap_setflag_full) { - zval *streamind; + zval *imap_conn_obj; zend_string *sequence, *flag; zend_long flags = 0; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|l", &streamind, &sequence, &flag, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS|l", &imap_conn_obj, php_imap_ce, &sequence, &flag, &flags) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); if (flags && ((flags & ~ST_UID) != 0)) { zend_argument_value_error(4, "must be ST_UID or 0"); RETURN_THROWS(); } - mail_setflag_full(imap_le_struct->imap_stream, ZSTR_VAL(sequence), ZSTR_VAL(flag), (flags ? flags : NIL)); + mail_setflag_full(imap_conn_struct->imap_stream, ZSTR_VAL(sequence), ZSTR_VAL(flag), (flags ? flags : NIL)); RETURN_TRUE; } /* }}} */ @@ -2655,25 +2628,23 @@ PHP_FUNCTION(imap_setflag_full) /* {{{ Clears flags on messages */ PHP_FUNCTION(imap_clearflag_full) { - zval *streamind; + zval *imap_conn_obj; zend_string *sequence, *flag; zend_long flags = 0; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSS|l", &streamind, &sequence, &flag, &flags) ==FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSS|l", &imap_conn_obj, php_imap_ce, &sequence, &flag, &flags) ==FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); if (flags && ((flags & ~ST_UID) != 0)) { zend_argument_value_error(4, "must be ST_UID or 0"); RETURN_THROWS(); } - mail_clearflag_full(imap_le_struct->imap_stream, ZSTR_VAL(sequence), ZSTR_VAL(flag), flags); + mail_clearflag_full(imap_conn_struct->imap_stream, ZSTR_VAL(sequence), ZSTR_VAL(flag), flags); RETURN_TRUE; } /* }}} */ @@ -2681,23 +2652,21 @@ PHP_FUNCTION(imap_clearflag_full) /* {{{ Sort an array of message headers, optionally including only messages that meet specified criteria. */ PHP_FUNCTION(imap_sort) { - zval *streamind; + zval *imap_conn_obj; zend_string *criteria = NULL, *charset = NULL; zend_long sort, flags = 0; zend_bool rev; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; unsigned long *slst, *sl; char *search_criteria; SORTPGM *mypgm=NIL; SEARCHPGM *spg=NIL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlb|lS!S!", &streamind, &sort, &rev, &flags, &criteria, &charset) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Olb|lS!S!", &imap_conn_obj, php_imap_ce, &sort, &rev, &flags, &criteria, &charset) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); if (!(sort == SORTDATE || sort == SORTARRIVAL || sort == SORTFROM || sort == SORTSUBJECT || sort == SORTTO || sort == SORTCC || sort == SORTSIZE) ) { @@ -2726,7 +2695,7 @@ PHP_FUNCTION(imap_sort) mypgm->function = (short) sort; mypgm->next = NIL; - slst = mail_sort(imap_le_struct->imap_stream, (charset ? ZSTR_VAL(charset) : NIL), spg, mypgm, flags); + slst = mail_sort(imap_conn_struct->imap_stream, (charset ? ZSTR_VAL(charset) : NIL), spg, mypgm, flags); mail_free_sortpgm(&mypgm); if (spg && !(flags & SE_FREE)) { @@ -2746,17 +2715,15 @@ PHP_FUNCTION(imap_sort) /* {{{ Get the full unfiltered header for a message */ PHP_FUNCTION(imap_fetchheader) { - zval *streamind; + zval *imap_conn_obj; zend_long msgno, flags = 0; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl|l", &streamind, &msgno, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol|l", &imap_conn_obj, php_imap_ce, &msgno, &flags) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); PHP_IMAP_CHECK_MSGNO_MAYBE_UID_PRE_FLAG_CHECKS(msgno, 2); @@ -2767,45 +2734,41 @@ PHP_FUNCTION(imap_fetchheader) PHP_IMAP_CHECK_MSGNO_MAYBE_UID_POST_FLAG_CHECKS(msgno, 2, flags, FT_UID); - RETVAL_STRING(mail_fetchheader_full(imap_le_struct->imap_stream, msgno, NIL, NIL, flags)); + RETVAL_STRING(mail_fetchheader_full(imap_conn_struct->imap_stream, msgno, NIL, NIL, flags)); } /* }}} */ /* {{{ Get the unique message id associated with a standard sequential message number */ PHP_FUNCTION(imap_uid) { - zval *streamind; + zval *imap_conn_obj; zend_long msgno; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &streamind, &msgno) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &imap_conn_obj, php_imap_ce, &msgno) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); PHP_IMAP_CHECK_MSGNO(msgno, 2); - RETURN_LONG(mail_uid(imap_le_struct->imap_stream, msgno)); + RETURN_LONG(mail_uid(imap_conn_struct->imap_stream, msgno)); } /* }}} */ /* {{{ Get the sequence number associated with a UID */ PHP_FUNCTION(imap_msgno) { - zval *streamind; + zval *imap_conn_obj; zend_long msg_uid; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rl", &streamind, &msg_uid) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "Ol", &imap_conn_obj, php_imap_ce, &msg_uid) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* Do NOT use the PHP_IMAP_CHECK_MSGNO() macro as UID cannot be checked for their upper bound. */ if (msg_uid < 1) { @@ -2813,25 +2776,23 @@ PHP_FUNCTION(imap_msgno) RETURN_THROWS(); } - RETURN_LONG(mail_msgno(imap_le_struct->imap_stream, msg_uid)); + RETURN_LONG(mail_msgno(imap_conn_struct->imap_stream, msg_uid)); } /* }}} */ /* {{{ Get status info from a mailbox */ PHP_FUNCTION(imap_status) { - zval *streamind; + zval *imap_conn_obj; zend_string *mbx; zend_long flags; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rSl", &streamind, &mbx, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OSl", &imap_conn_obj, php_imap_ce, &mbx, &flags) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); if (flags && ((flags & ~(SA_MESSAGES | SA_RECENT | SA_UNSEEN | SA_UIDNEXT | SA_UIDVALIDITY /*| SA_ALL*/)) != 0)) { zend_argument_value_error(3, "must be a bitmask of SA_* constants"); @@ -2840,7 +2801,7 @@ PHP_FUNCTION(imap_status) object_init(return_value); - if (mail_status(imap_le_struct->imap_stream, ZSTR_VAL(mbx), flags)) { + if (mail_status(imap_conn_struct->imap_stream, ZSTR_VAL(mbx), flags)) { add_property_long(return_value, "flags", IMAPG(status_flags)); if (IMAPG(status_flags) & SA_MESSAGES) { add_property_long(return_value, "messages", IMAPG(status_messages)); @@ -2866,25 +2827,23 @@ PHP_FUNCTION(imap_status) /* {{{ Read the structure of a specified body section of a specific message */ PHP_FUNCTION(imap_bodystruct) { - zval *streamind; + zval *imap_conn_obj; zend_long msgno; zend_string *section; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; zval parametres, param, dparametres, dparam; PARAMETER *par, *dpar; BODY *body; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rlS", &streamind, &msgno, §ion) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OlS", &imap_conn_obj, php_imap_ce, &msgno, §ion) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); PHP_IMAP_CHECK_MSGNO(msgno, 2); - body=mail_body(imap_le_struct->imap_stream, msgno, (unsigned char*)ZSTR_VAL(section)); + body=mail_body(imap_conn_struct->imap_stream, msgno, (unsigned char*)ZSTR_VAL(section)); if (body == NULL) { RETURN_FALSE; } @@ -2974,40 +2933,38 @@ PHP_FUNCTION(imap_bodystruct) /* {{{ Read an overview of the information in the headers of the given message sequence */ PHP_FUNCTION(imap_fetch_overview) { - zval *streamind; + zval *imap_conn_obj; zend_string *sequence; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; zval myoverview; zend_string *address; zend_long status, flags = 0L; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "rS|l", &streamind, &sequence, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "OS|l", &imap_conn_obj, php_imap_ce, &sequence, &flags) == FAILURE) { RETURN_THROWS(); } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); + if (flags && ((flags & ~FT_UID) != 0)) { zend_argument_value_error(3, "must be FT_UID or 0"); RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } - array_init(return_value); status = (flags & FT_UID) - ? mail_uid_sequence(imap_le_struct->imap_stream, (unsigned char*)ZSTR_VAL(sequence)) - : mail_sequence(imap_le_struct->imap_stream, (unsigned char*)ZSTR_VAL(sequence)); + ? mail_uid_sequence(imap_conn_struct->imap_stream, (unsigned char*)ZSTR_VAL(sequence)) + : mail_sequence(imap_conn_struct->imap_stream, (unsigned char*)ZSTR_VAL(sequence)); if (status) { MESSAGECACHE *elt; ENVELOPE *env; unsigned long i; - for (i = 1; i <= imap_le_struct->imap_stream->nmsgs; i++) { - if (((elt = mail_elt (imap_le_struct->imap_stream, i))->sequence) && - (env = mail_fetch_structure (imap_le_struct->imap_stream, i, NIL, NIL))) { + for (i = 1; i <= imap_conn_struct->imap_stream->nmsgs; i++) { + if (((elt = mail_elt (imap_conn_struct->imap_stream, i))->sequence) && + (env = mail_fetch_structure (imap_conn_struct->imap_stream, i, NIL, NIL))) { object_init(&myoverview); if (env->subject) { add_property_string(&myoverview, "subject", env->subject); @@ -3039,7 +2996,7 @@ PHP_FUNCTION(imap_fetch_overview) add_property_string(&myoverview, "in_reply_to", env->in_reply_to); } add_property_long(&myoverview, "size", elt->rfc822_size); - add_property_long(&myoverview, "uid", mail_uid(imap_le_struct->imap_stream, i)); + add_property_long(&myoverview, "uid", mail_uid(imap_conn_struct->imap_stream, i)); add_property_long(&myoverview, "msgno", i); add_property_long(&myoverview, "recent", elt->recent); add_property_long(&myoverview, "flagged", elt->flagged); @@ -3697,22 +3654,20 @@ PHP_FUNCTION(imap_mail) /* {{{ Return a list of messages matching the given criteria */ PHP_FUNCTION(imap_search) { - zval *streamind; + zval *imap_conn_obj; zend_string *criteria, *charset = NULL; zend_long flags = SE_FREE; - pils *imap_le_struct; + php_imap_object *imap_conn_struct; char *search_criteria; MESSAGELIST *cur; int argc = ZEND_NUM_ARGS(); SEARCHPGM *pgm = NIL; - if (zend_parse_parameters(argc, "rS|lS", &streamind, &criteria, &flags, &charset) == FAILURE) { + if (zend_parse_parameters(argc, "OS|lS", &imap_conn_obj, php_imap_ce, &criteria, &flags, &charset) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* TODO Update docs to allow SE_FREE as an option */ if (flags && ((flags & ~(SE_FREE | SE_UID)) != 0)) { @@ -3725,7 +3680,7 @@ PHP_FUNCTION(imap_search) IMAPG(imap_messages) = IMAPG(imap_messages_tail) = NIL; pgm = mail_criteria(search_criteria); - mail_search_full(imap_le_struct->imap_stream, (argc == 4 ? ZSTR_VAL(charset) : NIL), pgm, flags); + mail_search_full(imap_conn_struct->imap_stream, (argc == 4 ? ZSTR_VAL(charset) : NIL), pgm, flags); if (pgm && !(flags & SE_FREE)) { mail_free_searchpgm(&pgm); @@ -4129,6 +4084,8 @@ static void _php_make_header_object(zval *myzvalue, ENVELOPE *en) add_property_str(myzvalue, "return_pathaddress", fulladdress); } php_imap_hash_add_object(myzvalue, "return_path", &paddress); + // From rebase might need? + //add_assoc_object(myzvalue, "return_path", &paddress); } } /* }}} */ @@ -4293,25 +4250,23 @@ static int build_thread_tree(THREADNODE *top, zval **tree) /* {{{ Return threaded by REFERENCES tree */ PHP_FUNCTION(imap_thread) { - zval *streamind; - pils *imap_le_struct; + zval *imap_conn_obj; + php_imap_object *imap_conn_struct; zend_long flags = SE_FREE; char criteria[] = "ALL"; THREADNODE *top; SEARCHPGM *pgm = NIL; - if (zend_parse_parameters(ZEND_NUM_ARGS(), "r|l", &streamind, &flags) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS(), "O|l", &imap_conn_obj, php_imap_ce, &flags) == FAILURE) { RETURN_THROWS(); } - if ((imap_le_struct = (pils *)zend_fetch_resource(Z_RES_P(streamind), "imap", le_imap)) == NULL) { - RETURN_THROWS(); - } + GET_IMAP_STREAM(imap_conn_struct, imap_conn_obj); /* TODO Check if flags are valid (documentation is not present on php.net so need to check this first) */ pgm = mail_criteria(criteria); - top = mail_thread(imap_le_struct->imap_stream, "REFERENCES", NIL, pgm, flags); + top = mail_thread(imap_conn_struct->imap_stream, "REFERENCES", NIL, pgm, flags); if (pgm && !(flags & SE_FREE)) { mail_free_searchpgm(&pgm); } diff --git a/ext/imap/php_imap.h b/ext/imap/php_imap.h index 0ba2306ede..9ff0cf9c73 100644 --- a/ext/imap/php_imap.h +++ b/ext/imap/php_imap.h @@ -85,11 +85,6 @@ typedef enum { FLIST_OBJECT } folderlist_style_t; -typedef struct php_imap_le_struct { - MAILSTREAM *imap_stream; - long flags; -} pils; - typedef struct php_imap_mailbox_struct { SIZEDTEXT text; DTYPE delimiter; diff --git a/ext/imap/php_imap.stub.php b/ext/imap/php_imap.stub.php index 7b3d01afa0..0c597badec 100644 --- a/ext/imap/php_imap.stub.php +++ b/ext/imap/php_imap.stub.php @@ -1,33 +1,23 @@ <?php /** @generate-function-entries */ +class IMAPConnection { -/** - * @return resource|false - */ -function imap_open(string $mailbox, string $user, string $password, int $flags = 0, int $retries = 0, array $options = []) {} +} -/** - * @param resource $imap - */ -function imap_reopen($imap, string $mailbox, int $flags = 0, int $retries = 0): bool {} +function imap_open(string $mailbox, string $user, string $password, int $flags = 0, int $retries = 0, array $options = []): IMAPConnection|false {} -/** - * @param resource $imap - */ -function imap_close($imap, int $flags = 0): bool {} +function imap_reopen(IMAPConnection $imap, string $mailbox, int $flags = 0, int $retries = 0): bool {} -/** @param resource $imap */ -function imap_num_msg($imap): int|false {} +function imap_close(IMAPConnection $imap, int $flags = 0): bool {} -/** @param resource $imap */ -function imap_num_recent($imap): int|false {} +function imap_num_msg(IMAPConnection $imap): int|false {} -/** @param resource $imap */ -function imap_headers($imap): array|false {} +function imap_num_recent(IMAPConnection $imap): int|false {} -/** @param resource $imap */ -function imap_headerinfo($imap, int $message_num, int $from_length = 0, int $subject_length = 0): stdClass|false {} +function imap_headers(IMAPConnection $imap): array|false {} + +function imap_headerinfo(IMAPConnection $imap, int $message_num, int $from_length = 0, int $subject_length = 0): stdClass|false {} function imap_rfc822_parse_headers(string $headers, string $default_hostname = "UNKNOWN"): stdClass {} @@ -35,117 +25,87 @@ function imap_rfc822_write_address(string $mailbox, string $hostname, string $pe function imap_rfc822_parse_adrlist(string $string, string $default_hostname): array {} -/** @param resource $imap */ -function imap_body($imap, int $message_num, int $flags = 0): string|false {} +function imap_body(IMAPConnection $imap, int $message_num, int $flags = 0): string|false {} /** - * @param resource $imap * @alias imap_body */ -function imap_fetchtext($imap, int $message_num, int $flags = 0): string|false {} +function imap_fetchtext(IMAPConnection $imap, int $message_num, int $flags = 0): string|false {} -/** - * @param resource $imap - * @return stdClass|false - */ -function imap_bodystruct($imap, int $message_num, string $section) {} +function imap_bodystruct(IMAPConnection $imap, int $message_num, string $section): stdClass|false {} -/** @param resource $imap */ -function imap_fetchbody($imap, int $message_num, string $section, int $flags = 0): string|false {} +function imap_fetchbody(IMAPConnection $imap, int $message_num, string $section, int $flags = 0): string|false {} -/** @param resource $imap */ -function imap_fetchmime($imap, int $message_num, string $section, int $flags = 0): string|false {} +function imap_fetchmime(IMAPConnection $imap, int $message_num, string $section, int $flags = 0): string|false {} /** - * @param resource $imap * @param resource|string|int $file */ -function imap_savebody($imap, $file, int $message_num, string $section = "", int $flags = 0): bool {} +function imap_savebody(IMAPConnection $imap, $file, int $message_num, string $section = "", int $flags = 0): bool {} -/** @param resource $imap */ -function imap_fetchheader($imap, int $message_num, int $flags = 0): string|false {} +function imap_fetchheader(IMAPConnection $imap, int $message_num, int $flags = 0): string|false {} -/** @param resource $imap */ -function imap_fetchstructure($imap, int $message_num, int $flags = 0): stdClass|false {} +function imap_fetchstructure(IMAPConnection $imap, int $message_num, int $flags = 0): stdClass|false {} /** - * @param resource $imap */ -function imap_gc($imap, int $flags): bool {} +function imap_gc(IMAPConnection $imap, int $flags): bool {} /** - * @param resource $imap */ -function imap_expunge($imap): bool {} +function imap_expunge(IMAPConnection $imap): bool {} /** - * @param resource $imap */ -function imap_delete($imap, string $message_num, int $flags = 0): bool {} +function imap_delete(IMAPConnection $imap, string $message_num, int $flags = 0): bool {} /** - * @param resource $imap */ -function imap_undelete($imap, string $message_num, int $flags = 0): bool {} +function imap_undelete(IMAPConnection $imap, string $message_num, int $flags = 0): bool {} -/** @param resource $imap */ -function imap_check($imap): stdClass|false {} +function imap_check(IMAPConnection $imap): stdClass|false {} -/** @param resource $imap */ -function imap_listscan($imap, string $reference, string $pattern, string $content): array|false {} +function imap_listscan(IMAPConnection $imap, string $reference, string $pattern, string $content): array|false {} /** - * @param resource $imap * @alias imap_listscan */ -function imap_scan($imap, string $reference, string $pattern, string $content): array|false {} +function imap_scan(IMAPConnection $imap, string $reference, string $pattern, string $content): array|false {} /** - * @param resource $imap * @alias imap_listscan */ -function imap_scanmailbox($imap, string $reference, string $pattern, string $content): array|false {} +function imap_scanmailbox(IMAPConnection $imap, string $reference, string $pattern, string $content): array|false {} -/** @param resource $imap */ -function imap_mail_copy($imap, string $message_nums, string $mailbox, int $flags = 0): bool {} +function imap_mail_copy(IMAPConnection $imap, string $message_nums, string $mailbox, int $flags = 0): bool {} -/** @param resource $imap */ -function imap_mail_move($imap, string $message_nums, string $mailbox, int $flags = 0): bool {} +function imap_mail_move(IMAPConnection $imap, string $message_nums, string $mailbox, int $flags = 0): bool {} function imap_mail_compose(array $envelope, array $bodies): string|false {} -/** @param resource $imap */ -function imap_createmailbox($imap, string $mailbox): bool {} +function imap_createmailbox(IMAPConnection $imap, string $mailbox): bool {} /** - * @param resource $imap * @alias imap_createmailbox */ -function imap_create($imap, string $mailbox): bool {} +function imap_create(IMAPConnection $imap, string $mailbox): bool {} -/** @param resource $imap */ -function imap_renamemailbox($imap, string $from, string $to): bool {} +function imap_renamemailbox(IMAPConnection $imap, string $from, string $to): bool {} /** - * @param resource $imap * @alias imap_renamemailbox */ -function imap_rename($imap, string $from, string $to): bool {} +function imap_rename(IMAPConnection $imap, string $from, string $to): bool {} -/** @param resource $imap */ -function imap_deletemailbox($imap, string $mailbox): bool {} +function imap_deletemailbox(IMAPConnection $imap, string $mailbox): bool {} -/** @param resource $imap */ -function imap_subscribe($imap, string $mailbox): bool {} +function imap_subscribe(IMAPConnection $imap, string $mailbox): bool {} -/** @param resource $imap */ -function imap_unsubscribe($imap, string $mailbox): bool {} +function imap_unsubscribe(IMAPConnection $imap, string $mailbox): bool {} -/** @param resource $imap */ -function imap_append($imap, string $folder, string $message, ?string $options = null, ?string $internal_date = null): bool {} +function imap_append(IMAPConnection $imap, string $folder, string $message, ?string $options = null, ?string $internal_date = null): bool {} -/** @param resource $imap */ -function imap_ping($imap): bool {} +function imap_ping(IMAPConnection $imap): bool {} function imap_base64(string $string): string|false {} @@ -157,56 +117,39 @@ function imap_binary(string $string): string|false {} function imap_utf8(string $mime_encoded_text): string {} -/** - * @param resource $imap - * @return stdClass|false - */ -function imap_status($imap, string $mailbox, int $flags) {} +function imap_status(IMAPConnection $imap, string $mailbox, int $flags): stdClass|false {} -/** @param resource $imap */ -function imap_mailboxmsginfo($imap): stdClass {} +function imap_mailboxmsginfo(IMAPConnection $imap): stdClass {} -/** @param resource $imap */ -function imap_setflag_full($imap, string $sequence, string $flag, int $options = 0): bool {} +function imap_setflag_full(IMAPConnection $imap, string $sequence, string $flag, int $options = 0): bool {} -/** @param resource $imap */ -function imap_clearflag_full($imap, string $sequence, string $flag, int $options = 0): bool {} +function imap_clearflag_full(IMAPConnection $imap, string $sequence, string $flag, int $options = 0): bool {} -/** @param resource $imap */ -function imap_sort($imap, int $criteria, bool $reverse, int $flags = 0, ?string $search_criteria = null, ?string $charset = null): array|false {} +function imap_sort(IMAPConnection $imap, int $criteria, bool $reverse, int $flags = 0, ?string $search_criteria = null, ?string $charset = null): array|false {} -/** @param resource $imap */ -function imap_uid($imap, int $message_num): int|false {} +function imap_uid(IMAPConnection $imap, int $message_num): int|false {} -/** @param resource $imap */ -function imap_msgno($imap, int $message_uid): int|false {} +function imap_msgno(IMAPConnection $imap, int $message_uid): int|false {} -/** @param resource $imap */ -function imap_list($imap, string $reference, string $pattern): array|false {} +function imap_list(IMAPConnection $imap, string $reference, string $pattern): array|false {} /** - * @param resource $imap * @alias imap_list */ -function imap_listmailbox($imap, string $reference, string $pattern): array|false {} +function imap_listmailbox(IMAPConnection $imap, string $reference, string $pattern): array|false {} -/** @param resource $imap */ -function imap_lsub($imap, string $reference, string $pattern): array|false {} +function imap_lsub(IMAPConnection $imap, string $reference, string $pattern): array|false {} /** - * @param resource $imap * @alias imap_lsub */ -function imap_listsubscribed($imap, string $reference, string $pattern): array|false {} +function imap_listsubscribed(IMAPConnection $imap, string $reference, string $pattern): array|false {} -/** @param resource $imap */ -function imap_getsubscribed($imap, string $reference, string $pattern): array|false {} +function imap_getsubscribed(IMAPConnection $imap, string $reference, string $pattern): array|false {} -/** @param resource $imap */ -function imap_getmailboxes($imap, string $reference, string $pattern): array|false {} +function imap_getmailboxes(IMAPConnection $imap, string $reference, string $pattern): array|false {} -/** @param resource $imap */ -function imap_fetch_overview($imap, string $sequence, int $flags = 0): array|false {} +function imap_fetch_overview(IMAPConnection $imap, string $sequence, int $flags = 0): array|false {} function imap_alerts(): array|false {} @@ -214,8 +157,7 @@ function imap_errors(): array|false {} function imap_last_error(): string|false {} -/** @param resource $imap */ -function imap_search($imap, string $criteria, int $flags = SE_FREE, string $charset = ""): array|false {} +function imap_search(IMAPConnection $imap, string $criteria, int $flags = SE_FREE, string $charset = ""): array|false {} function imap_utf7_decode(string $string): string|false {} @@ -229,26 +171,20 @@ function imap_mutf7_to_utf8(string $string): string|false {} function imap_mime_header_decode(string $string): array|false {} -/** @param resource $imap */ -function imap_thread($imap, int $flags = SE_FREE): array|false {} +function imap_thread(IMAPConnection $imap, int $flags = SE_FREE): array|false {} function imap_timeout(int $timeout_type, int $timeout = -1): int|bool {} #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001) -/** @param resource $imap */ -function imap_get_quota($imap, string $quota_root): array|false {} +function imap_get_quota(IMAPConnection $imap, string $quota_root): array|false {} -/** @param resource $imap */ -function imap_get_quotaroot($imap, string $mailbox): array|false {} +function imap_get_quotaroot(IMAPConnection $imap, string $mailbox): array|false {} -/** @param resource $imap */ -function imap_set_quota($imap, string $quota_root, int $mailbox_size): bool {} +function imap_set_quota(IMAPConnection $imap, string $quota_root, int $mailbox_size): bool {} -/** @param resource $imap */ -function imap_setacl($imap, string $mailbox, string $user_id, string $rights): bool {} +function imap_setacl(IMAPConnection $imap, string $mailbox, string $user_id, string $rights): bool {} -/** @param resource $imap */ -function imap_getacl($imap, string $mailbox): array|false {} +function imap_getacl(IMAPConnection $imap, string $mailbox): array|false {} #endif function imap_mail(string $to, string $subject, string $message, ?string $additional_headers = null, ?string $cc = null, ?string $bcc = null, ?string $return_path = null): bool {} diff --git a/ext/imap/php_imap_arginfo.h b/ext/imap/php_imap_arginfo.h index b1ff14da91..ec292138df 100644 --- a/ext/imap/php_imap_arginfo.h +++ b/ext/imap/php_imap_arginfo.h @@ -1,7 +1,7 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 326cb0410034aecc702e9397cd88ef91adaa254c */ + * Stub hash: 1dbf85a4f8740bf02df35a4e184a67af6cf93e91 */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_open, 0, 0, 3) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imap_open, 0, 3, IMAPConnection, MAY_BE_FALSE) ZEND_ARG_TYPE_INFO(0, mailbox, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, user, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0) @@ -11,29 +11,29 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_open, 0, 0, 3) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_reopen, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, mailbox, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, retries, IS_LONG, 0, "0") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_close, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_num_msg, 0, 1, MAY_BE_LONG|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_END_ARG_INFO() #define arginfo_imap_num_recent arginfo_imap_num_msg ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_headers, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imap_headerinfo, 0, 2, stdClass, MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, message_num, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, from_length, IS_LONG, 0, "0") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, subject_length, IS_LONG, 0, "0") @@ -56,21 +56,21 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_rfc822_parse_adrlist, 0, 2, ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_body, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, message_num, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") ZEND_END_ARG_INFO() #define arginfo_imap_fetchtext arginfo_imap_body -ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_bodystruct, 0, 0, 3) - ZEND_ARG_INFO(0, imap) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imap_bodystruct, 0, 3, stdClass, MAY_BE_FALSE) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, message_num, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, section, IS_STRING, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_fetchbody, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, message_num, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, section, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") @@ -79,7 +79,7 @@ ZEND_END_ARG_INFO() #define arginfo_imap_fetchmime arginfo_imap_fetchbody ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_savebody, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_INFO(0, file) ZEND_ARG_TYPE_INFO(0, message_num, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, section, IS_STRING, 0, "\"\"") @@ -89,22 +89,22 @@ ZEND_END_ARG_INFO() #define arginfo_imap_fetchheader arginfo_imap_body ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imap_fetchstructure, 0, 2, stdClass, MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, message_num, IS_LONG, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_gc, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_expunge, 0, 1, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_delete, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, message_num, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") ZEND_END_ARG_INFO() @@ -112,11 +112,11 @@ ZEND_END_ARG_INFO() #define arginfo_imap_undelete arginfo_imap_delete ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imap_check, 0, 1, stdClass, MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_listscan, 0, 4, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, reference, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, content, IS_STRING, 0) @@ -127,7 +127,7 @@ ZEND_END_ARG_INFO() #define arginfo_imap_scanmailbox arginfo_imap_listscan ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_mail_copy, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, message_nums, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, mailbox, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") @@ -141,14 +141,14 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_mail_compose, 0, 2, MAY_BE_ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_createmailbox, 0, 2, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, mailbox, IS_STRING, 0) ZEND_END_ARG_INFO() #define arginfo_imap_create arginfo_imap_createmailbox ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_renamemailbox, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, from, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, to, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -162,7 +162,7 @@ ZEND_END_ARG_INFO() #define arginfo_imap_unsubscribe arginfo_imap_createmailbox ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_append, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, folder, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_STRING, 1, "null") @@ -185,18 +185,18 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_utf8, 0, 1, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, mime_encoded_text, IS_STRING, 0) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_status, 0, 0, 3) - ZEND_ARG_INFO(0, imap) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_imap_status, 0, 3, stdClass, MAY_BE_FALSE) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, mailbox, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, flags, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_imap_mailboxmsginfo, 0, 1, stdClass, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_setflag_full, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, sequence, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, flag, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_LONG, 0, "0") @@ -205,7 +205,7 @@ ZEND_END_ARG_INFO() #define arginfo_imap_clearflag_full arginfo_imap_setflag_full ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_sort, 0, 3, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, criteria, IS_LONG, 0) ZEND_ARG_TYPE_INFO(0, reverse, _IS_BOOL, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") @@ -214,17 +214,17 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_sort, 0, 3, MAY_BE_ARRAY|MA ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_uid, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, message_num, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_msgno, 0, 2, MAY_BE_LONG|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, message_uid, IS_LONG, 0) ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_list, 0, 3, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, reference, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -240,7 +240,7 @@ ZEND_END_ARG_INFO() #define arginfo_imap_getmailboxes arginfo_imap_list ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_fetch_overview, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, sequence, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0") ZEND_END_ARG_INFO() @@ -254,7 +254,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_last_error, 0, 0, MAY_BE_ST ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_search, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, criteria, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "SE_FREE") ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, charset, IS_STRING, 0, "\"\"") @@ -281,7 +281,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_mime_header_decode, 0, 1, M ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_thread, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "SE_FREE") ZEND_END_ARG_INFO() @@ -292,21 +292,21 @@ ZEND_END_ARG_INFO() #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_get_quota, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, quota_root, IS_STRING, 0) ZEND_END_ARG_INFO() #endif #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_imap_get_quotaroot, 0, 2, MAY_BE_ARRAY|MAY_BE_FALSE) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, mailbox, IS_STRING, 0) ZEND_END_ARG_INFO() #endif #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_set_quota, 0, 3, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, quota_root, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, mailbox_size, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -314,7 +314,7 @@ ZEND_END_ARG_INFO() #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_imap_setacl, 0, 4, _IS_BOOL, 0) - ZEND_ARG_INFO(0, imap) + ZEND_ARG_OBJ_INFO(0, imap, IMAPConnection, 0) ZEND_ARG_TYPE_INFO(0, mailbox, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, user_id, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, rights, IS_STRING, 0) @@ -510,3 +510,8 @@ static const zend_function_entry ext_functions[] = { ZEND_FE(imap_mail, arginfo_imap_mail) ZEND_FE_END }; + + +static const zend_function_entry class_IMAPConnection_methods[] = { + ZEND_FE_END +}; diff --git a/ext/imap/tests/bug75774.phpt b/ext/imap/tests/bug75774.phpt index 08883ad8f0..dc6b2910b6 100644 --- a/ext/imap/tests/bug75774.phpt +++ b/ext/imap/tests/bug75774.phpt @@ -20,6 +20,5 @@ fclose($var1); unlink($fn); ?> ---EXPECTF-- -Warning: imap_append(): Internal date not correctly formatted in %s on line %d -imap_append(): supplied resource is not a valid imap resource +--EXPECT-- +imap_append(): Argument #1 ($imap) must be of type IMAPConnection, resource given |