diff -Naur php-5.2.2/ext/imap/php_imap.c php-5.2.2.oden/ext/imap/php_imap.c --- php-5.2.2/ext/imap/php_imap.c 2007-03-19 23:56:57.000000000 +0100 +++ php-5.2.2.oden/ext/imap/php_imap.c 2007-05-26 16:44:19.000000000 +0200 @@ -155,6 +155,10 @@ PHP_FE(imap_setacl, NULL) PHP_FE(imap_getacl, NULL) #endif +#if defined(HAVE_IMAP2005) + PHP_FE(imap_setannotation, NULL) + PHP_FE(imap_getannotation, NULL) +#endif PHP_FE(imap_mail, NULL) @@ -416,6 +420,30 @@ #endif +#if defined(HAVE_IMAP2005) +/* {{{ mail_getannotation + * + * Mail GET_ANNOTATION callback + * Called via the mail_parameter function in c-client:src/c-client/mail.c + */ +void mail_getannotation(MAILSTREAM *stream, ANNOTATION *alist) +{ + ANNOTATION_VALUES *cur; + + TSRMLS_FETCH(); + + /* walk through the ANNOTATION_VALUES */ + + for(cur = alist->values; cur; cur = cur->next) { + if (cur->value) + add_assoc_stringl(IMAPG(imap_annotation_list), cur->attr, cur->value, strlen(cur->value), 1); + else + add_assoc_stringl(IMAPG(imap_annotation_list), cur->attr, "", 0, 1); + } +} +/* }}} */ +#endif + /* {{{ PHP_GINIT_FUNCTION */ static PHP_GINIT_FUNCTION(imap) @@ -1092,6 +1120,122 @@ #endif /* HAVE_IMAP2000 || HAVE_IMAP2001 */ +#if defined(HAVE_IMAP2005) + +/* {{{ proto bool imap_setannotation(resource stream_id, string mailbox, string entry, string attr, string value) + Sets an annotation for a given mailbox */ +PHP_FUNCTION(imap_setannotation) +{ + zval **streamind, **mailbox, **entry, **attr, **value; + pils *imap_le_struct; + long ret; + + // TODO: Use zend_parse_parameters here + if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &streamind, &mailbox, &entry, &attr, &value) == FAILURE) { + ZEND_WRONG_PARAM_COUNT(); + } + + ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap); + + convert_to_string_ex(mailbox); + convert_to_string_ex(entry); + convert_to_string_ex(attr); + convert_to_string_ex(value); + + // create annotation object + ANNOTATION *annotation = mail_newannotation(); + if (!annotation) + RETURN_FALSE; + annotation->values = mail_newannotationvalue(); + if (!annotation->values) { + mail_free_annotation(&annotation); + RETURN_FALSE; + } + + // fill in annotation values + annotation->mbox = Z_STRVAL_PP(mailbox); + annotation->entry = Z_STRVAL_PP(entry); + annotation->values->attr = Z_STRVAL_PP(attr); + annotation->values->value = Z_STRVAL_PP(value); + + ret = imap_setannotation(imap_le_struct->imap_stream, annotation); + + // make sure mail_free_annotation doesn't free our variables + annotation->mbox = NULL; + annotation->entry = NULL; + annotation->values->attr = NULL; + annotation->values->value = NULL; + mail_free_annotation(&annotation); + + RETURN_BOOL(ret); +} +/* }}} */ + +/* {{{ proto array imap_getannotation(resource stream_id, string mailbox, string entry, string attr) + Gets the ACL for a given mailbox */ +PHP_FUNCTION(imap_getannotation) +{ + zval **streamind, **mailbox, **entry, **attr; + pils *imap_le_struct; + long ret; + + if(ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &streamind, &mailbox, &entry, &attr) == FAILURE) { + ZEND_WRONG_PARAM_COUNT(); + } + + ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap); + + convert_to_string_ex(mailbox); + convert_to_string_ex(entry); + convert_to_string_ex(attr); + + /* initializing the special array for the return values */ + if (array_init(return_value) == FAILURE) { + RETURN_FALSE; + } + + // fillup calling parameters + STRINGLIST *entries = mail_newstringlist(); + if (!entries) + RETURN_FALSE; + + STRINGLIST *cur = entries; + cur->text.data = (unsigned char *)cpystr(Z_STRVAL_PP(entry)); + cur->text.size = Z_STRLEN_PP(entry); + cur->next = NIL; + + STRINGLIST *attributes = mail_newstringlist(); + cur = attributes; + cur->text.data = (unsigned char *)cpystr (Z_STRVAL_PP(attr)); + cur->text.size = Z_STRLEN_PP(attr); + cur->next = NIL; + + /* initializing the special array for the return values */ + if (array_init(return_value) == FAILURE) { + mail_free_stringlist(&entries); + mail_free_stringlist(&attributes); + RETURN_FALSE; + } + + IMAPG(imap_annotation_list) = return_value; + + /* set the callback for the GET_ANNOTATION function */ + mail_parameters(NIL, SET_ANNOTATION, (void *) mail_getannotation); + ret = imap_getannotation(imap_le_struct->imap_stream, Z_STRVAL_PP(mailbox), entries, attributes); + + mail_free_stringlist(&entries); + mail_free_stringlist(&attributes); + + if (!ret) { + zval_dtor(return_value); + RETURN_FALSE; + } + + IMAPG(imap_annotation_list) = NIL; +} +/* }}} */ + +#endif /* HAVE_IMAP2005 */ /* {{{ proto bool imap_expunge(resource stream_id) Permanently delete all messages marked for deletion */ diff -Naur php-5.2.2/ext/imap/php_imap.h php-5.2.2.oden/ext/imap/php_imap.h --- php-5.2.2/ext/imap/php_imap.h 2007-01-01 10:36:02.000000000 +0100 +++ php-5.2.2.oden/ext/imap/php_imap.h 2007-05-26 16:44:19.000000000 +0200 @@ -168,6 +168,9 @@ PHP_FUNCTION(imap_thread); PHP_FUNCTION(imap_timeout); +// TODO: Needs fixing in configure in +#define HAVE_IMAP2005 1 + #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001) PHP_FUNCTION(imap_get_quota); PHP_FUNCTION(imap_get_quotaroot); @@ -175,7 +178,10 @@ PHP_FUNCTION(imap_setacl); PHP_FUNCTION(imap_getacl); #endif - +#if defined(HAVE_IMAP2005) +PHP_FUNCTION(imap_setannotation); +PHP_FUNCTION(imap_getannotation); +#endif ZEND_BEGIN_MODULE_GLOBALS(imap) char *imap_user; @@ -206,6 +212,9 @@ zval **quota_return; zval *imap_acl_list; #endif +#if defined(HAVE_IMAP2005) + zval *imap_annotation_list; +#endif /* php_stream for php_mail_gets() */ php_stream *gets_stream; ZEND_END_MODULE_GLOBALS(imap)