diff options
Diffstat (limited to 'ext/imap/php_imap.c')
-rw-r--r-- | ext/imap/php_imap.c | 901 |
1 files changed, 429 insertions, 472 deletions
diff --git a/ext/imap/php_imap.c b/ext/imap/php_imap.c index 9ff1ae0618..9a1ded643b 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,67 @@ 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 zend_function *imap_object_get_constructor(zend_object *zobj) { + zend_throw_error(NULL, "Cannot directly construct IMAPConnection, use imap_open() instead"); + return NULL; +} + +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,43 +212,31 @@ 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; \ + } \ -/* {{{ add_assoc_object */ -static zval *add_assoc_object(zval *arg, char *key, zval *tmp) +/* {{{ php_imap_hash_add_object */ +static zval *php_imap_hash_add_object(zval *arg, char *key, zval *tmp) { HashTable *symtable; @@ -211,8 +249,8 @@ static zval *add_assoc_object(zval *arg, char *key, zval *tmp) } /* }}} */ -/* {{{ add_next_index_object */ -static inline zval *add_next_index_object(zval *arg, zval *tmp) +/* {{{ php_imap_list_add_object */ +static inline zval *php_imap_list_add_object(zval *arg, zval *tmp) { HashTable *symtable; @@ -439,6 +477,17 @@ PHP_MINIT_FUNCTION(imap) ssl_onceonlyinit (); #endif + php_imap_ce = register_class_IMAPConnection(); + 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.get_constructor = imap_object_get_constructor; + 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 +682,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 +776,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) { @@ -835,31 +882,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 */ /* Check for PHP_EXPUNGE and not CL_EXPUNGE as the user land facing CL_EXPUNGE constant is defined @@ -883,7 +926,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) { @@ -895,9 +938,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; } @@ -908,16 +951,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 */ @@ -943,13 +985,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; @@ -960,54 +1000,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); } /* }}} */ @@ -1015,24 +1049,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; @@ -1043,24 +1075,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; @@ -1071,61 +1101,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); @@ -1134,7 +1158,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; @@ -1148,18 +1172,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; } @@ -1168,24 +1190,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; @@ -1195,36 +1215,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; @@ -1234,27 +1254,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' : ' '; @@ -1265,17 +1283,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); } @@ -1285,19 +1303,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); @@ -1308,7 +1324,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 { @@ -1321,25 +1337,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; @@ -1351,18 +1365,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"); @@ -1372,7 +1384,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; @@ -1383,19 +1395,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; @@ -1406,19 +1416,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; @@ -1429,19 +1437,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; @@ -1452,24 +1458,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; } @@ -1490,25 +1494,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; } @@ -1527,7 +1529,7 @@ PHP_FUNCTION(imap_getmailboxes) #else add_property_string(&mboxob, "delimiter", cur->delimiter); #endif - add_next_index_object(return_value, &mboxob); + php_imap_list_add_object(return_value, &mboxob); cur=cur->next; } mail_free_foblist(&IMAPG(imap_folder_objects), &IMAPG(imap_folder_objects_tail)); @@ -1539,21 +1541,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; } @@ -1573,30 +1573,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; } @@ -1606,18 +1604,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? @@ -1626,7 +1622,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; } /* }}} */ @@ -1634,45 +1632,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); @@ -1686,13 +1680,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 */ @@ -1720,12 +1714,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); } } @@ -1758,25 +1752,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; @@ -1797,26 +1789,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; @@ -1836,7 +1826,7 @@ PHP_FUNCTION(imap_getsubscribed) #else add_property_string(&mboxob, "delimiter", cur->delimiter); #endif - add_next_index_object(return_value, &mboxob); + php_imap_list_add_object(return_value, &mboxob); cur=cur->next; } mail_free_foblist (&IMAPG(imap_sfolder_objects), &IMAPG(imap_sfolder_objects_tail)); @@ -1848,19 +1838,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; @@ -1871,19 +1859,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; @@ -1894,18 +1880,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); @@ -1918,7 +1902,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"); @@ -1932,20 +1916,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); @@ -1956,7 +1938,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"); @@ -1971,20 +1953,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); @@ -1995,7 +1975,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"); @@ -2009,20 +1989,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) @@ -2056,7 +2035,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; @@ -2159,26 +2138,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++; @@ -2191,13 +2168,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); } /* }}} */ @@ -2278,7 +2255,7 @@ PHP_FUNCTION(imap_rfc822_parse_adrlist) if (addresstmp->adl) { add_property_string(&tovals, "adl", addresstmp->adl); } - add_next_index_object(return_value, &tovals); + php_imap_list_add_object(return_value, &tovals); } while ((addresstmp = addresstmp->next)); mail_free_envelope(&env); @@ -2637,25 +2614,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; } /* }}} */ @@ -2663,25 +2638,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; } /* }}} */ @@ -2689,23 +2662,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; + bool rev; + 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) ) { @@ -2734,7 +2705,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)) { @@ -2742,7 +2713,7 @@ PHP_FUNCTION(imap_sort) } array_init(return_value); - if (slst != NIL && slst != 0) { + if (slst != NULL) { for (sl = slst; *sl; sl++) { add_next_index_long(return_value, *sl); } @@ -2754,17 +2725,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); @@ -2775,45 +2744,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) { @@ -2821,25 +2786,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"); @@ -2848,7 +2811,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)); @@ -2874,25 +2837,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; } @@ -2947,9 +2908,9 @@ PHP_FUNCTION(imap_bodystruct) object_init(&dparam); add_property_string(&dparam, "attribute", dpar->attribute); add_property_string(&dparam, "value", dpar->value); - add_next_index_object(&dparametres, &dparam); + php_imap_list_add_object(&dparametres, &dparam); } while ((dpar = dpar->next)); - add_assoc_object(return_value, "dparameters", &dparametres); + php_imap_hash_add_object(return_value, "dparameters", &dparametres); } else { add_property_long(return_value, "ifdparameters", 0); } @@ -2968,13 +2929,13 @@ PHP_FUNCTION(imap_bodystruct) add_property_string(¶m, "value", par->value); } - add_next_index_object(¶metres, ¶m); + php_imap_list_add_object(¶metres, ¶m); } while ((par = par->next)); } else { object_init(¶metres); add_property_long(return_value, "ifparameters", 0); } - add_assoc_object(return_value, "parameters", ¶metres); + php_imap_hash_add_object(return_value, "parameters", ¶metres); } /* }}} */ @@ -2982,40 +2943,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); @@ -3047,7 +3006,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); @@ -3056,7 +3015,7 @@ PHP_FUNCTION(imap_fetch_overview) add_property_long(&myoverview, "seen", elt->seen); add_property_long(&myoverview, "draft", elt->draft); add_property_long(&myoverview, "udate", mail_longdate(elt)); - add_next_index_object(return_value, &myoverview); + php_imap_list_add_object(return_value, &myoverview); } } } @@ -3093,47 +3052,47 @@ PHP_FUNCTION(imap_mail_compose) env = mail_newenvelope(); if ((pvalue = zend_hash_str_find(envelope, "remail", sizeof("remail") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); env->remail = cpystr(Z_STRVAL_P(pvalue)); } if ((pvalue = zend_hash_str_find(envelope, "return_path", sizeof("return_path") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); PHP_RFC822_PARSE_ADRLIST(&env->return_path, pvalue); } if ((pvalue = zend_hash_str_find(envelope, "date", sizeof("date") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); env->date = (unsigned char*)cpystr(Z_STRVAL_P(pvalue)); } if ((pvalue = zend_hash_str_find(envelope, "from", sizeof("from") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); PHP_RFC822_PARSE_ADRLIST(&env->from, pvalue); } if ((pvalue = zend_hash_str_find(envelope, "reply_to", sizeof("reply_to") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); PHP_RFC822_PARSE_ADRLIST(&env->reply_to, pvalue); } if ((pvalue = zend_hash_str_find(envelope, "in_reply_to", sizeof("in_reply_to") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); env->in_reply_to = cpystr(Z_STRVAL_P(pvalue)); } if ((pvalue = zend_hash_str_find(envelope, "subject", sizeof("subject") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); env->subject = cpystr(Z_STRVAL_P(pvalue)); } if ((pvalue = zend_hash_str_find(envelope, "to", sizeof("to") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); PHP_RFC822_PARSE_ADRLIST(&env->to, pvalue); } if ((pvalue = zend_hash_str_find(envelope, "cc", sizeof("cc") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); PHP_RFC822_PARSE_ADRLIST(&env->cc, pvalue); } if ((pvalue = zend_hash_str_find(envelope, "bcc", sizeof("bcc") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); PHP_RFC822_PARSE_ADRLIST(&env->bcc, pvalue); } if ((pvalue = zend_hash_str_find(envelope, "message_id", sizeof("message_id") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); env->message_id=cpystr(Z_STRVAL_P(pvalue)); } @@ -3143,7 +3102,7 @@ PHP_FUNCTION(imap_mail_compose) SEPARATE_ARRAY(pvalue); ZEND_HASH_FOREACH_VAL(Z_ARRVAL_P(pvalue), env_data) { custom_headers_param = mail_newbody_parameter(); - convert_to_string_ex(env_data); + convert_to_string(env_data); custom_headers_param->value = (char *) fs_get(Z_STRLEN_P(env_data) + 1); custom_headers_param->attribute = NULL; memcpy(custom_headers_param->value, Z_STRVAL_P(env_data), Z_STRLEN_P(env_data) + 1); @@ -3185,7 +3144,7 @@ PHP_FUNCTION(imap_mail_compose) } } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "charset", sizeof("charset") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); tmp_param = mail_newbody_parameter(); tmp_param->value = cpystr(Z_STRVAL_P(pvalue)); tmp_param->attribute = cpystr("CHARSET"); @@ -3200,7 +3159,7 @@ PHP_FUNCTION(imap_mail_compose) if (key == NULL) continue; disp_param = mail_newbody_parameter(); disp_param->attribute = cpystr(ZSTR_VAL(key)); - convert_to_string_ex(disp_data); + convert_to_string(disp_data); disp_param->value = (char *) fs_get(Z_STRLEN_P(disp_data) + 1); memcpy(disp_param->value, Z_STRVAL_P(disp_data), Z_STRLEN_P(disp_data) + 1); disp_param->next = tmp_param; @@ -3210,19 +3169,19 @@ PHP_FUNCTION(imap_mail_compose) } } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "subtype", sizeof("subtype") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->subtype = cpystr(Z_STRVAL_P(pvalue)); } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "id", sizeof("id") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->id = cpystr(Z_STRVAL_P(pvalue)); } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "description", sizeof("description") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->description = cpystr(Z_STRVAL_P(pvalue)); } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "disposition.type", sizeof("disposition.type") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->disposition.type = (char *) fs_get(Z_STRLEN_P(pvalue) + 1); memcpy(bod->disposition.type, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1); } @@ -3234,7 +3193,7 @@ PHP_FUNCTION(imap_mail_compose) if (key == NULL) continue; disp_param = mail_newbody_parameter(); disp_param->attribute = cpystr(ZSTR_VAL(key)); - convert_to_string_ex(disp_data); + convert_to_string(disp_data); disp_param->value = (char *) fs_get(Z_STRLEN_P(disp_data) + 1); memcpy(disp_param->value, Z_STRVAL_P(disp_data), Z_STRLEN_P(disp_data) + 1); disp_param->next = tmp_param; @@ -3247,7 +3206,7 @@ PHP_FUNCTION(imap_mail_compose) bod->nested.msg = mail_newmsg(); } else { if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1); memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1); bod->contents.text.size = Z_STRLEN_P(pvalue); @@ -3264,7 +3223,7 @@ PHP_FUNCTION(imap_mail_compose) bod->size.bytes = zval_get_long(pvalue); } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "md5", sizeof("md5") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->md5 = cpystr(Z_STRVAL_P(pvalue)); } } else if (Z_TYPE_P(data) == IS_ARRAY && topbod->type == TYPEMULTIPART) { @@ -3296,7 +3255,7 @@ PHP_FUNCTION(imap_mail_compose) } } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "charset", sizeof("charset") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); tmp_param = mail_newbody_parameter(); tmp_param->value = (char *) fs_get(Z_STRLEN_P(pvalue) + 1); memcpy(tmp_param->value, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue) + 1); @@ -3312,7 +3271,7 @@ PHP_FUNCTION(imap_mail_compose) if (key == NULL) continue; disp_param = mail_newbody_parameter(); disp_param->attribute = cpystr(ZSTR_VAL(key)); - convert_to_string_ex(disp_data); + convert_to_string(disp_data); disp_param->value = (char *)fs_get(Z_STRLEN_P(disp_data) + 1); memcpy(disp_param->value, Z_STRVAL_P(disp_data), Z_STRLEN_P(disp_data) + 1); disp_param->next = tmp_param; @@ -3322,19 +3281,19 @@ PHP_FUNCTION(imap_mail_compose) } } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "subtype", sizeof("subtype") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->subtype = cpystr(Z_STRVAL_P(pvalue)); } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "id", sizeof("id") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->id = cpystr(Z_STRVAL_P(pvalue)); } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "description", sizeof("description") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->description = cpystr(Z_STRVAL_P(pvalue)); } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "disposition.type", sizeof("disposition.type") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->disposition.type = (char *) fs_get(Z_STRLEN_P(pvalue) + 1); memcpy(bod->disposition.type, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue)+1); } @@ -3346,7 +3305,7 @@ PHP_FUNCTION(imap_mail_compose) if (key == NULL) continue; disp_param = mail_newbody_parameter(); disp_param->attribute = cpystr(ZSTR_VAL(key)); - convert_to_string_ex(disp_data); + convert_to_string(disp_data); disp_param->value = (char *) fs_get(Z_STRLEN_P(disp_data) + 1); memcpy(disp_param->value, Z_STRVAL_P(disp_data), Z_STRLEN_P(disp_data) + 1); disp_param->next = tmp_param; @@ -3359,7 +3318,7 @@ PHP_FUNCTION(imap_mail_compose) bod->nested.msg = mail_newmsg(); } else { if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "contents.data", sizeof("contents.data") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->contents.text.data = fs_get(Z_STRLEN_P(pvalue) + 1); memcpy(bod->contents.text.data, Z_STRVAL_P(pvalue), Z_STRLEN_P(pvalue) + 1); bod->contents.text.size = Z_STRLEN_P(pvalue); @@ -3376,7 +3335,7 @@ PHP_FUNCTION(imap_mail_compose) bod->size.bytes = zval_get_long(pvalue); } if ((pvalue = zend_hash_str_find(Z_ARRVAL_P(data), "md5", sizeof("md5") - 1)) != NULL) { - convert_to_string_ex(pvalue); + convert_to_string(pvalue); bod->md5 = cpystr(Z_STRVAL_P(pvalue)); } } @@ -3705,22 +3664,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)) { @@ -3733,7 +3690,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); @@ -4051,7 +4008,7 @@ static zend_string* _php_imap_parse_address (ADDRESS *addresslist, zval *paddres if (addresstmp->adl) add_property_string(&tmpvals, "adl", addresstmp->adl); if (addresstmp->mailbox) add_property_string(&tmpvals, "mailbox", addresstmp->mailbox); if (addresstmp->host) add_property_string(&tmpvals, "host", addresstmp->host); - add_next_index_object(paddress, &tmpvals); + php_imap_list_add_object(paddress, &tmpvals); } while ((addresstmp = addresstmp->next)); return fulladdress; } @@ -4082,7 +4039,7 @@ static void _php_make_header_object(zval *myzvalue, ENVELOPE *en) if (fulladdress) { add_property_str(myzvalue, "toaddress", fulladdress); } - add_assoc_object(myzvalue, "to", &paddress); + php_imap_hash_add_object(myzvalue, "to", &paddress); } if (en->from) { @@ -4091,7 +4048,7 @@ static void _php_make_header_object(zval *myzvalue, ENVELOPE *en) if (fulladdress) { add_property_str(myzvalue, "fromaddress", fulladdress); } - add_assoc_object(myzvalue, "from", &paddress); + php_imap_hash_add_object(myzvalue, "from", &paddress); } if (en->cc) { @@ -4100,7 +4057,7 @@ static void _php_make_header_object(zval *myzvalue, ENVELOPE *en) if (fulladdress) { add_property_str(myzvalue, "ccaddress", fulladdress); } - add_assoc_object(myzvalue, "cc", &paddress); + php_imap_hash_add_object(myzvalue, "cc", &paddress); } if (en->bcc) { @@ -4109,7 +4066,7 @@ static void _php_make_header_object(zval *myzvalue, ENVELOPE *en) if (fulladdress) { add_property_str(myzvalue, "bccaddress", fulladdress); } - add_assoc_object(myzvalue, "bcc", &paddress); + php_imap_hash_add_object(myzvalue, "bcc", &paddress); } if (en->reply_to) { @@ -4118,7 +4075,7 @@ static void _php_make_header_object(zval *myzvalue, ENVELOPE *en) if (fulladdress) { add_property_str(myzvalue, "reply_toaddress", fulladdress); } - add_assoc_object(myzvalue, "reply_to", &paddress); + php_imap_hash_add_object(myzvalue, "reply_to", &paddress); } if (en->sender) { @@ -4127,7 +4084,7 @@ static void _php_make_header_object(zval *myzvalue, ENVELOPE *en) if (fulladdress) { add_property_str(myzvalue, "senderaddress", fulladdress); } - add_assoc_object(myzvalue, "sender", &paddress); + php_imap_hash_add_object(myzvalue, "sender", &paddress); } if (en->return_path) { @@ -4136,7 +4093,9 @@ static void _php_make_header_object(zval *myzvalue, ENVELOPE *en) if (fulladdress) { add_property_str(myzvalue, "return_pathaddress", fulladdress); } - add_assoc_object(myzvalue, "return_path", &paddress); + php_imap_hash_add_object(myzvalue, "return_path", &paddress); + // From rebase might need? + //add_assoc_object(myzvalue, "return_path", &paddress); } } /* }}} */ @@ -4201,9 +4160,9 @@ void _php_imap_add_body(zval *arg, BODY *body) object_init(&dparam); add_property_string(&dparam, "attribute", dpar->attribute); add_property_string(&dparam, "value", dpar->value); - add_next_index_object(&dparametres, &dparam); + php_imap_list_add_object(&dparametres, &dparam); } while ((dpar = dpar->next)); - add_assoc_object(arg, "dparameters", &dparametres); + php_imap_hash_add_object(arg, "dparameters", &dparametres); } else { add_property_long(arg, "ifdparameters", 0); } @@ -4222,13 +4181,13 @@ void _php_imap_add_body(zval *arg, BODY *body) add_property_string(¶m, "value", par->value); } - add_next_index_object(¶metres, ¶m); + php_imap_list_add_object(¶metres, ¶m); } while ((par = par->next)); } else { object_init(¶metres); add_property_long(arg, "ifparameters", 0); } - add_assoc_object(arg, "parameters", ¶metres); + php_imap_hash_add_object(arg, "parameters", ¶metres); /* multipart message ? */ if (body->type == TYPEMULTIPART) { @@ -4236,9 +4195,9 @@ void _php_imap_add_body(zval *arg, BODY *body) for (part = body->CONTENT_PART; part; part = part->next) { object_init(¶m); _php_imap_add_body(¶m, &part->body); - add_next_index_object(¶metres, ¶m); + php_imap_list_add_object(¶metres, ¶m); } - add_assoc_object(arg, "parts", ¶metres); + php_imap_hash_add_object(arg, "parts", ¶metres); } /* encapsulated message ? */ @@ -4247,8 +4206,8 @@ void _php_imap_add_body(zval *arg, BODY *body) array_init(¶metres); object_init(¶m); _php_imap_add_body(¶m, body); - add_next_index_object(¶metres, ¶m); - add_assoc_object(arg, "parts", ¶metres); + php_imap_list_add_object(¶metres, ¶m); + php_imap_hash_add_object(arg, "parts", ¶metres); } } /* }}} */ @@ -4301,25 +4260,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); } |