summaryrefslogtreecommitdiff
path: root/ext/imap/php_imap.c
diff options
context:
space:
mode:
authorGeorge Peter Banyard <girgias@php.net>2020-11-10 11:03:53 +0000
committerGeorge Peter Banyard <girgias@php.net>2020-12-22 03:06:35 +0100
commit383779e5025acf763c87e5562902f40cc6360b97 (patch)
tree03dbc401fe9a4c75b4d2337b03edb099d9971196 /ext/imap/php_imap.c
parent694400616ec364bf19390226254aed486ae000b5 (diff)
downloadphp-git-383779e5025acf763c87e5562902f40cc6360b97.tar.gz
Convert IMAP resource to object
Closes GH-6418
Diffstat (limited to 'ext/imap/php_imap.c')
-rw-r--r--ext/imap/php_imap.c779
1 files changed, 367 insertions, 412 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, &params) == 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, &section, &flags)) {
+ if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "Ozl|Sl", &imap_conn_obj, php_imap_ce, &out, &msgno, &section, &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, &section) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "OlS", &imap_conn_obj, php_imap_ce, &msgno, &section) == 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);
}