php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #43948
Patch imap_annotation.patch revision 2010-07-30 11:51 UTC by mkoppanen@php.net
revision 2010-07-29 08:48 UTC by mkoppanen@php.net
Patch imap_myrights.patch revision 2010-07-29 08:48 UTC by mkoppanen@php.net

Patch imap_annotation.patch for IMAP related Bug #43948

Patch version 2010-07-29 08:48 UTC

Return to Bug #43948 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions:

Developer: mkoppanen@php.net

Index: ext/imap/php_imap.h
===================================================================
--- ext/imap/php_imap.h	(revision 301655)
+++ ext/imap/php_imap.h	(working copy)
@@ -153,6 +153,7 @@
 PHP_FUNCTION(imap_lsub_full);
 PHP_FUNCTION(imap_create);
 PHP_FUNCTION(imap_rename);
+PHP_FUNCTION(imap_status_current);
 PHP_FUNCTION(imap_status);
 PHP_FUNCTION(imap_bodystruct);
 PHP_FUNCTION(imap_fetch_overview);
@@ -179,9 +180,13 @@
 PHP_FUNCTION(imap_set_quota);
 PHP_FUNCTION(imap_setacl);
 PHP_FUNCTION(imap_getacl);
+PHP_FUNCTION(imap_myrights);
 #endif
+#if defined(HAVE_IMAP2005)
+PHP_FUNCTION(imap_setannotation);
+PHP_FUNCTION(imap_getannotation);
+#endif
 
-
 ZEND_BEGIN_MODULE_GLOBALS(imap)
 	char *imap_user;
 	char *imap_password;
@@ -211,6 +216,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)
Index: ext/imap/config.m4
===================================================================
--- ext/imap/config.m4	(revision 301655)
+++ ext/imap/config.m4	(working copy)
@@ -124,6 +124,11 @@
       AC_DEFINE(HAVE_IMAP2004,1,[ ])
     ])
 
+    dnl Check for c-client version 2005
+    AC_EGREP_HEADER(imap_getannotation, $IMAP_INC_DIR/mail.h, [
+      AC_DEFINE(HAVE_IMAP2005,1,[ ])
+    ])
+
     dnl Check for new version of the utf8_mime2text() function
     old_CFLAGS=$CFLAGS
     CFLAGS="-I$IMAP_INC_DIR"
Index: ext/imap/php_imap.c
===================================================================
--- ext/imap/php_imap.c	(revision 301655)
+++ ext/imap/php_imap.c	(working copy)
@@ -164,7 +164,23 @@
 	ZEND_ARG_INFO(0, mailbox)
 ZEND_END_ARG_INFO()
 #endif
+#if defined(HAVE_IMAP2005)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_setannotation, 0, 0, 5)
+	ZEND_ARG_INFO(0, stream_id)
+	ZEND_ARG_INFO(0, mailbox)
+	ZEND_ARG_INFO(0, entry)
+	ZEND_ARG_INFO(0, attr)
+	ZEND_ARG_INFO(0, value)
+ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_getannotation, 0, 0, 4)
+	ZEND_ARG_INFO(0, stream_id)
+	ZEND_ARG_INFO(0, mailbox)
+	ZEND_ARG_INFO(0, entry)
+	ZEND_ARG_INFO(0, attr)
+ZEND_END_ARG_INFO()
+#endif
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_expunge, 0, 0, 1)
 	ZEND_ARG_INFO(0, stream_id)
 ZEND_END_ARG_INFO()
@@ -408,6 +424,11 @@
 	ZEND_ARG_INFO(0, options)
 ZEND_END_ARG_INFO()
 
+ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_status_current, 0, 0, 2)
+	ZEND_ARG_INFO(0, stream_id)
+	ZEND_ARG_INFO(0, options)
+ZEND_END_ARG_INFO()
+
 ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_bodystruct, 0, 0, 3)
 	ZEND_ARG_INFO(0, stream_id)
 	ZEND_ARG_INFO(0, msg_no)
@@ -507,6 +528,7 @@
 	PHP_FE(imap_binary,								arginfo_imap_binary)
 	PHP_FE(imap_utf8,								arginfo_imap_utf8)
 	PHP_FE(imap_status,								arginfo_imap_status)
+	PHP_FE(imap_status_current,						arginfo_imap_status_current)
 	PHP_FE(imap_mailboxmsginfo,						arginfo_imap_mailboxmsginfo)
 	PHP_FE(imap_setflag_full,						arginfo_imap_setflag_full)
 	PHP_FE(imap_clearflag_full,						arginfo_imap_clearflag_full)
@@ -537,6 +559,10 @@
 	PHP_FE(imap_setacl,								arginfo_imap_setacl)
 	PHP_FE(imap_getacl,								arginfo_imap_getacl)
 #endif
+#if defined(HAVE_IMAP2005)
+ 	PHP_FE(imap_setannotation,						arginfo_imap_setannotation)
+ 	PHP_FE(imap_getannotation,						arginfo_imap_getannotation)
+#endif
 
 	PHP_FE(imap_mail,								arginfo_imap_mail)
 
@@ -798,6 +824,28 @@
 /* }}} */
 #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)
+{
+	TSRMLS_FETCH();
+	ANNOTATION_VALUES *cur;
+
+	/* 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)
@@ -824,6 +872,9 @@
 	imap_globals->quota_return = NIL;
 	imap_globals->imap_acl_list = NIL;
 #endif
+#if defined(HAVE_IMAP2005)
+	imap_globals->imap_annotation_list = NIL;
+#endif
 	imap_globals->gets_stream = NIL;
 }
 /* }}} */
@@ -1537,7 +1588,117 @@
 }
 /* }}} */
 #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;
+	char *mailbox, *entry, *attr, *value;
+	int mailbox_len, entry_len, attr_len, value_len;
+	pils *imap_le_struct;
+	long ret;
+	ANNOTATION *annotation;
+	
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rssss", &streamind, &mailbox, &mailbox_len, 
+		&entry, &entry_len, &attr, &attr_len, &value, &value_len) == FAILURE) {
+		return;
+	}
+
+	ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
+
+	/* create annotation object */
+	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 = mailbox;
+	annotation->entry = entry;
+	annotation->values->attr = attr;
+	annotation->values->value = 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;
+	char *mailbox, *entry, *attr;
+	int mailbox_len, entry_len, attr_len;
+	pils *imap_le_struct;
+	long ret;
+	STRINGLIST *cur, *entries, *attributes;
+
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsss", &streamind, &mailbox, &mailbox_len, 
+		&entry, &entry_len, &attr, &attr_len) == FAILURE) {
+		return;
+	}
+
+	ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
+
+	/* fillup calling parameters */
+	entries = mail_newstringlist();
+	if (!entries) {
+		RETURN_FALSE;
+	}
+
+	cur = entries;
+	cur->text.data = (unsigned char *)cpystr(entry);
+	cur->text.size = entry_len;
+	cur->next = NIL;
+
+	attributes = mail_newstringlist();
+	if (!attributes) {
+		mail_free_stringlist(&entries);
+		RETURN_FALSE;
+	}
+
+	cur = attributes;
+	cur->text.data = (unsigned char *)cpystr(attr);
+	cur->text.size = attr_len;
+	cur->next = NIL;
+	
+	array_init(return_value);
+	IMAPG(imap_annotation_list) = return_value;
+
+	/* set the callback for the GET_ANNOTATION function */
+	mail_parameters(NIL, GET_ANNOTATION, (void *) mail_getannotation);
+	ret = imap_getannotation(imap_le_struct->imap_stream, 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 */
 PHP_FUNCTION(imap_expunge)
@@ -3180,6 +3341,39 @@
 }
 /* }}} */
 
+/* {{{ proto object imap_status_current(resource stream_id, int options)
+   Get (cached) status info from current mailbox */
+PHP_FUNCTION(imap_status_current)
+{
+ 	zval *streamind;
+	pils *imap_le_struct;
+	long flags;
+	
+	if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &streamind, &flags) == FAILURE) {
+		return;
+	}
+
+	ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
+
+	if (object_init(return_value) == FAILURE) {
+		RETURN_FALSE;
+	}
+
+	if (flags & SA_MESSAGES) {
+		add_property_long(return_value, "messages", imap_le_struct->imap_stream->nmsgs);
+	}
+	if (flags & SA_RECENT) {
+		add_property_long(return_value, "recent", imap_le_struct->imap_stream->recent);
+	}
+	if (flags & SA_UIDNEXT) {
+		add_property_long(return_value, "uidnext", imap_le_struct->imap_stream->uid_last+1);
+	}
+	if (flags & SA_UIDVALIDITY) {
+		add_property_long(return_value, "uidvalidity", imap_le_struct->imap_stream->uid_validity);
+	}
+}
+/* }}} */
+
 /* {{{ proto object imap_status(resource stream_id, string mailbox, int options)
    Get status info from a mailbox */
 PHP_FUNCTION(imap_status)
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Dec 02 23:01:23 2020 UTC