1 Provides get/set ANNOTATIONS support to PHP. [Version: 5.2.6]
3 diff -r 4f78d3c907b7 ext/imap/php_imap.c
4 --- a/ext/imap/php_imap.c Fri May 02 11:21:11 2008 +0200
5 +++ b/ext/imap/php_imap.c Mon Jun 09 10:35:56 2008 +0200
7 PHP_FE(imap_binary, NULL)
8 PHP_FE(imap_utf8, NULL)
9 PHP_FE(imap_status, NULL)
10 + PHP_FE(imap_status_current, NULL)
11 PHP_FE(imap_mailboxmsginfo, NULL)
12 PHP_FE(imap_setflag_full, NULL)
13 PHP_FE(imap_clearflag_full, NULL)
15 PHP_FE(imap_setacl, NULL)
16 PHP_FE(imap_getacl, NULL)
18 +#if defined(HAVE_IMAP2005)
19 + PHP_FE(imap_setannotation, NULL)
20 + PHP_FE(imap_getannotation, NULL)
23 PHP_FE(imap_mail, NULL)
29 +#if defined(HAVE_IMAP2005)
30 +/* {{{ mail_getannotation
32 + * Mail GET_ANNOTATION callback
33 + * Called via the mail_parameter function in c-client:src/c-client/mail.c
35 +void mail_getannotation(MAILSTREAM *stream, ANNOTATION *alist)
37 + ANNOTATION_VALUES *cur;
41 + /* walk through the ANNOTATION_VALUES */
43 + for(cur = alist->values; cur; cur = cur->next) {
45 + add_assoc_stringl(IMAPG(imap_annotation_list), cur->attr, cur->value, strlen(cur->value), 1);
47 + add_assoc_stringl(IMAPG(imap_annotation_list), cur->attr, "", 0, 1);
53 /* {{{ PHP_GINIT_FUNCTION
55 static PHP_GINIT_FUNCTION(imap)
57 #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
58 imap_globals->quota_return = NIL;
59 imap_globals->imap_acl_list = NIL;
60 + imap_globals->imap_annotation_list = NIL;
62 imap_globals->gets_stream = NIL;
64 @@ -1097,6 +1127,117 @@
66 #endif /* HAVE_IMAP2000 || HAVE_IMAP2001 */
68 +#if defined(HAVE_IMAP2005)
70 +/* {{{ proto bool imap_setannotation(resource stream_id, string mailbox, string entry, string attr, string value)
71 + Sets an annotation for a given mailbox */
72 +PHP_FUNCTION(imap_setannotation)
74 + zval **streamind, **mailbox, **entry, **attr, **value;
75 + pils *imap_le_struct;
78 + // TODO: Use zend_parse_parameters here
79 + if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &streamind, &mailbox, &entry, &attr, &value) == FAILURE) {
80 + ZEND_WRONG_PARAM_COUNT();
83 + ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
85 + convert_to_string_ex(mailbox);
86 + convert_to_string_ex(entry);
87 + convert_to_string_ex(attr);
88 + convert_to_string_ex(value);
90 + // create annotation object
91 + ANNOTATION *annotation = mail_newannotation();
94 + annotation->values = mail_newannotationvalue();
95 + if (!annotation->values) {
96 + mail_free_annotation(&annotation);
100 + // fill in annotation values
101 + annotation->mbox = Z_STRVAL_PP(mailbox);
102 + annotation->entry = Z_STRVAL_PP(entry);
103 + annotation->values->attr = Z_STRVAL_PP(attr);
104 + annotation->values->value = Z_STRVAL_PP(value);
106 + ret = imap_setannotation(imap_le_struct->imap_stream, annotation);
108 + // make sure mail_free_annotation doesn't free our variables
109 + annotation->mbox = NULL;
110 + annotation->entry = NULL;
111 + annotation->values->attr = NULL;
112 + annotation->values->value = NULL;
113 + mail_free_annotation(&annotation);
119 +/* {{{ proto array imap_getannotation(resource stream_id, string mailbox, string entry, string attr)
120 + Gets the ACL for a given mailbox */
121 +PHP_FUNCTION(imap_getannotation)
123 + zval **streamind, **mailbox, **entry, **attr;
124 + pils *imap_le_struct;
127 + if(ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &streamind, &mailbox, &entry, &attr) == FAILURE) {
128 + ZEND_WRONG_PARAM_COUNT();
131 + ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
133 + convert_to_string_ex(mailbox);
134 + convert_to_string_ex(entry);
135 + convert_to_string_ex(attr);
137 + /* initializing the special array for the return values */
138 + if (array_init(return_value) == FAILURE) {
142 + // fillup calling parameters
143 + STRINGLIST *entries = mail_newstringlist();
147 + STRINGLIST *cur = entries;
148 + cur->text.data = (unsigned char *)cpystr(Z_STRVAL_PP(entry));
149 + cur->text.size = Z_STRLEN_PP(entry);
152 + STRINGLIST *attributes = mail_newstringlist();
156 + cur->text.data = (unsigned char *)cpystr (Z_STRVAL_PP(attr));
157 + cur->text.size = Z_STRLEN_PP(attr);
160 + IMAPG(imap_annotation_list) = return_value;
162 + /* set the callback for the GET_ANNOTATION function */
163 + mail_parameters(NIL, SET_ANNOTATION, (void *) mail_getannotation);
164 + ret = imap_getannotation(imap_le_struct->imap_stream, Z_STRVAL_PP(mailbox), entries, attributes);
166 + mail_free_stringlist(&entries);
167 + mail_free_stringlist(&attributes);
170 + zval_dtor(return_value);
174 + IMAPG(imap_annotation_list) = NIL;
178 +#endif /* HAVE_IMAP2005 */
180 /* {{{ proto bool imap_expunge(resource stream_id)
181 Permanently delete all messages marked for deletion */
182 @@ -2707,6 +2848,42 @@
186 +/* {{{ proto object imap_status_current(resource stream_id, int options)
187 + Get (cached) status info from current mailbox */
188 +PHP_FUNCTION(imap_status_current)
190 + zval **streamind, **pflags;
191 + pils *imap_le_struct;
194 + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &streamind, &pflags) == FAILURE) {
195 + ZEND_WRONG_PARAM_COUNT();
198 + ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
200 + convert_to_long_ex(pflags);
201 + flags = Z_LVAL_PP(pflags);
203 + if (object_init(return_value) == FAILURE) {
207 + if (flags & SA_MESSAGES) {
208 + add_property_long(return_value, "messages", imap_le_struct->imap_stream->nmsgs);
210 + if (flags & SA_RECENT) {
211 + add_property_long(return_value, "recent", imap_le_struct->imap_stream->recent);
213 + if (flags & SA_UIDNEXT) {
214 + add_property_long(return_value, "uidnext", imap_le_struct->imap_stream->uid_last+1);
216 + if (flags & SA_UIDVALIDITY) {
217 + add_property_long(return_value, "uidvalidity", imap_le_struct->imap_stream->uid_validity);
222 /* {{{ proto object imap_status(resource stream_id, string mailbox, int options)
223 Get status info from a mailbox */
224 PHP_FUNCTION(imap_status)
225 diff -r 4f78d3c907b7 ext/imap/php_imap.h
226 --- a/ext/imap/php_imap.h Fri May 02 11:21:11 2008 +0200
227 +++ b/ext/imap/php_imap.h Mon Jun 09 10:35:56 2008 +0200
229 PHP_FUNCTION(imap_lsub_full);
230 PHP_FUNCTION(imap_create);
231 PHP_FUNCTION(imap_rename);
232 +PHP_FUNCTION(imap_status_current);
233 PHP_FUNCTION(imap_status);
234 PHP_FUNCTION(imap_bodystruct);
235 PHP_FUNCTION(imap_fetch_overview);
237 PHP_FUNCTION(imap_thread);
238 PHP_FUNCTION(imap_timeout);
240 +// TODO: Needs fixing in configure in
241 +#define HAVE_IMAP2005 1
243 #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
244 PHP_FUNCTION(imap_get_quota);
245 PHP_FUNCTION(imap_get_quotaroot);
247 PHP_FUNCTION(imap_setacl);
248 PHP_FUNCTION(imap_getacl);
251 +#if defined(HAVE_IMAP2005)
252 +PHP_FUNCTION(imap_setannotation);
253 +PHP_FUNCTION(imap_getannotation);
256 ZEND_BEGIN_MODULE_GLOBALS(imap)
262 +#if defined(HAVE_IMAP2005)
263 + zval *imap_annotation_list;
265 /* php_stream for php_mail_gets() */
266 php_stream *gets_stream;
267 ZEND_END_MODULE_GLOBALS(imap)