1 Provides get/set ANNOTATIONS support to PHP. [Version: 5.2.6]
3 diff -r 76412c484360 ext/imap/php_imap.c
4 --- a/ext/imap/php_imap.c Wed Dec 23 22:18:41 2009 +0100
5 +++ b/ext/imap/php_imap.c Wed Dec 23 22:46:34 2009 +0100
7 ZEND_ARG_INFO(0, mailbox)
10 +#if defined(HAVE_IMAP2005)
11 +ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_setannotation, 0, 0, 5)
12 + ZEND_ARG_INFO(0, stream_id)
13 + ZEND_ARG_INFO(0, mailbox)
14 + ZEND_ARG_INFO(0, entry)
15 + ZEND_ARG_INFO(0, attr)
16 + ZEND_ARG_INFO(0, value)
19 +ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_getannotation, 0, 0, 4)
20 + ZEND_ARG_INFO(0, stream_id)
21 + ZEND_ARG_INFO(0, mailbox)
22 + ZEND_ARG_INFO(0, entry)
23 + ZEND_ARG_INFO(0, attr)
27 ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_expunge, 0, 0, 1)
28 ZEND_ARG_INFO(0, stream_id)
30 ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_status, 0, 0, 3)
31 ZEND_ARG_INFO(0, stream_id)
32 ZEND_ARG_INFO(0, mailbox)
33 + ZEND_ARG_INFO(0, options)
36 +ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_status_current, 0, 0, 2)
37 + ZEND_ARG_INFO(0, stream_id)
38 ZEND_ARG_INFO(0, options)
42 PHP_FE(imap_binary, arginfo_imap_binary)
43 PHP_FE(imap_utf8, arginfo_imap_utf8)
44 PHP_FE(imap_status, arginfo_imap_status)
45 + PHP_FE(imap_status_current, arginfo_imap_status_current)
46 PHP_FE(imap_mailboxmsginfo, arginfo_imap_mailboxmsginfo)
47 PHP_FE(imap_setflag_full, arginfo_imap_setflag_full)
48 PHP_FE(imap_clearflag_full, arginfo_imap_clearflag_full)
50 PHP_FE(imap_setacl, arginfo_imap_setacl)
51 PHP_FE(imap_getacl, arginfo_imap_getacl)
53 +#if defined(HAVE_IMAP2005)
54 + PHP_FE(imap_setannotation, arginfo_imap_setannotation)
55 + PHP_FE(imap_getannotation, arginfo_imap_getannotation)
58 PHP_FE(imap_mail, arginfo_imap_mail)
64 +#if defined(HAVE_IMAP2005)
65 +/* {{{ mail_getannotation
67 + * Mail GET_ANNOTATION callback
68 + * Called via the mail_parameter function in c-client:src/c-client/mail.c
70 +void mail_getannotation(MAILSTREAM *stream, ANNOTATION *alist)
72 + ANNOTATION_VALUES *cur;
76 + /* walk through the ANNOTATION_VALUES */
78 + for(cur = alist->values; cur; cur = cur->next) {
80 + add_assoc_stringl(IMAPG(imap_annotation_list), cur->attr, cur->value, strlen(cur->value), 1);
82 + add_assoc_stringl(IMAPG(imap_annotation_list), cur->attr, "", 0, 1);
88 /* {{{ PHP_GINIT_FUNCTION
90 static PHP_GINIT_FUNCTION(imap)
92 #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
93 imap_globals->quota_return = NIL;
94 imap_globals->imap_acl_list = NIL;
95 + imap_globals->imap_annotation_list = NIL;
97 imap_globals->gets_stream = NIL;
99 @@ -1475,7 +1526,119 @@
102 #endif /* HAVE_IMAP2000 || HAVE_IMAP2001 */
105 +#if defined(HAVE_IMAP2005)
107 +/* {{{ proto bool imap_setannotation(resource stream_id, string mailbox, string entry, string attr, string value)
108 + Sets an annotation for a given mailbox */
109 +PHP_FUNCTION(imap_setannotation)
111 + zval **streamind, **mailbox, **entry, **attr, **value;
112 + pils *imap_le_struct;
115 + // TODO: Use zend_parse_parameters here
116 + if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &streamind, &mailbox, &entry, &attr, &value) == FAILURE) {
117 + ZEND_WRONG_PARAM_COUNT();
120 + ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
122 + convert_to_string_ex(mailbox);
123 + convert_to_string_ex(entry);
124 + convert_to_string_ex(attr);
125 + convert_to_string_ex(value);
127 + // create annotation object
128 + ANNOTATION *annotation = mail_newannotation();
131 + annotation->values = mail_newannotationvalue();
132 + if (!annotation->values) {
133 + mail_free_annotation(&annotation);
137 + // fill in annotation values
138 + annotation->mbox = Z_STRVAL_PP(mailbox);
139 + annotation->entry = Z_STRVAL_PP(entry);
140 + annotation->values->attr = Z_STRVAL_PP(attr);
141 + annotation->values->value = Z_STRVAL_PP(value);
143 + ret = imap_setannotation(imap_le_struct->imap_stream, annotation);
145 + // make sure mail_free_annotation doesn't free our variables
146 + annotation->mbox = NULL;
147 + annotation->entry = NULL;
148 + annotation->values->attr = NULL;
149 + annotation->values->value = NULL;
150 + mail_free_annotation(&annotation);
156 +/* {{{ proto array imap_getannotation(resource stream_id, string mailbox, string entry, string attr)
157 + Gets the ACL for a given mailbox */
158 +PHP_FUNCTION(imap_getannotation)
160 + zval **streamind, **mailbox, **entry, **attr;
161 + pils *imap_le_struct;
164 + if(ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &streamind, &mailbox, &entry, &attr) == FAILURE) {
165 + ZEND_WRONG_PARAM_COUNT();
168 + ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
170 + convert_to_string_ex(mailbox);
171 + convert_to_string_ex(entry);
172 + convert_to_string_ex(attr);
174 + /* initializing the special array for the return values */
175 + if (array_init(return_value) == FAILURE) {
179 + // fillup calling parameters
180 + STRINGLIST *entries = mail_newstringlist();
184 + STRINGLIST *cur = entries;
185 + cur->text.data = (unsigned char *)cpystr(Z_STRVAL_PP(entry));
186 + cur->text.size = Z_STRLEN_PP(entry);
189 + STRINGLIST *attributes = mail_newstringlist();
193 + cur->text.data = (unsigned char *)cpystr (Z_STRVAL_PP(attr));
194 + cur->text.size = Z_STRLEN_PP(attr);
197 + IMAPG(imap_annotation_list) = return_value;
199 + /* set the callback for the GET_ANNOTATION function */
200 + mail_parameters(NIL, SET_ANNOTATION, (void *) mail_getannotation);
201 + ret = imap_getannotation(imap_le_struct->imap_stream, Z_STRVAL_PP(mailbox), entries, attributes);
203 + mail_free_stringlist(&entries);
204 + mail_free_stringlist(&attributes);
207 + zval_dtor(return_value);
211 + IMAPG(imap_annotation_list) = NIL;
215 +#endif /* HAVE_IMAP2005 */
217 /* {{{ proto bool imap_expunge(resource stream_id)
218 Permanently delete all messages marked for deletion */
219 PHP_FUNCTION(imap_expunge)
220 @@ -3118,6 +3281,42 @@
224 +/* {{{ proto object imap_status_current(resource stream_id, int options)
225 + Get (cached) status info from current mailbox */
226 +PHP_FUNCTION(imap_status_current)
228 + zval **streamind, **pflags;
229 + pils *imap_le_struct;
232 + if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &streamind, &pflags) == FAILURE) {
233 + ZEND_WRONG_PARAM_COUNT();
236 + ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
238 + convert_to_long_ex(pflags);
239 + flags = Z_LVAL_PP(pflags);
241 + if (object_init(return_value) == FAILURE) {
245 + if (flags & SA_MESSAGES) {
246 + add_property_long(return_value, "messages", imap_le_struct->imap_stream->nmsgs);
248 + if (flags & SA_RECENT) {
249 + add_property_long(return_value, "recent", imap_le_struct->imap_stream->recent);
251 + if (flags & SA_UIDNEXT) {
252 + add_property_long(return_value, "uidnext", imap_le_struct->imap_stream->uid_last+1);
254 + if (flags & SA_UIDVALIDITY) {
255 + add_property_long(return_value, "uidvalidity", imap_le_struct->imap_stream->uid_validity);
260 /* {{{ proto object imap_status(resource stream_id, string mailbox, int options)
261 Get status info from a mailbox */
262 PHP_FUNCTION(imap_status)
263 diff -r 76412c484360 ext/imap/php_imap.h
264 --- a/ext/imap/php_imap.h Wed Dec 23 22:18:41 2009 +0100
265 +++ b/ext/imap/php_imap.h Wed Dec 23 22:46:34 2009 +0100
267 PHP_FUNCTION(imap_lsub_full);
268 PHP_FUNCTION(imap_create);
269 PHP_FUNCTION(imap_rename);
270 +PHP_FUNCTION(imap_status_current);
271 PHP_FUNCTION(imap_status);
272 PHP_FUNCTION(imap_bodystruct);
273 PHP_FUNCTION(imap_fetch_overview);
275 PHP_FUNCTION(imap_thread);
276 PHP_FUNCTION(imap_timeout);
278 +// TODO: Needs fixing in configure in
279 +#define HAVE_IMAP2005 1
281 #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
282 PHP_FUNCTION(imap_get_quota);
283 PHP_FUNCTION(imap_get_quotaroot);
285 PHP_FUNCTION(imap_setacl);
286 PHP_FUNCTION(imap_getacl);
289 +#if defined(HAVE_IMAP2005)
290 +PHP_FUNCTION(imap_setannotation);
291 +PHP_FUNCTION(imap_getannotation);
294 ZEND_BEGIN_MODULE_GLOBALS(imap)
300 +#if defined(HAVE_IMAP2005)
301 + zval *imap_annotation_list;
303 /* php_stream for php_mail_gets() */
304 php_stream *gets_stream;
305 ZEND_END_MODULE_GLOBALS(imap)