]> git.pld-linux.org Git - packages/php.git/blame - php-imap-annotations.patch
- make it possible to coinstall phpXY-pdo-pgsql
[packages/php.git] / php-imap-annotations.patch
CommitLineData
3a72593a
ER
1Provides get/set ANNOTATIONS support to PHP. [Version: 5.2.6]
2
3diff -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
6@@ -129,6 +129,7 @@
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)
14@@ -155,6 +156,10 @@
15 PHP_FE(imap_setacl, NULL)
16 PHP_FE(imap_getacl, NULL)
17 #endif
18+#if defined(HAVE_IMAP2005)
19+ PHP_FE(imap_setannotation, NULL)
20+ PHP_FE(imap_getannotation, NULL)
21+#endif
22
23 PHP_FE(imap_mail, NULL)
24
25@@ -416,6 +421,30 @@
26 #endif
27
28
29+#if defined(HAVE_IMAP2005)
30+/* {{{ mail_getannotation
31+ *
32+ * Mail GET_ANNOTATION callback
33+ * Called via the mail_parameter function in c-client:src/c-client/mail.c
34+ */
35+void mail_getannotation(MAILSTREAM *stream, ANNOTATION *alist)
36+{
37+ ANNOTATION_VALUES *cur;
38+
39+ TSRMLS_FETCH();
40+
41+ /* walk through the ANNOTATION_VALUES */
42+
43+ for(cur = alist->values; cur; cur = cur->next) {
44+ if (cur->value)
45+ add_assoc_stringl(IMAPG(imap_annotation_list), cur->attr, cur->value, strlen(cur->value), 1);
46+ else
47+ add_assoc_stringl(IMAPG(imap_annotation_list), cur->attr, "", 0, 1);
48+ }
49+}
50+/* }}} */
51+#endif
52+
53 /* {{{ PHP_GINIT_FUNCTION
54 */
55 static PHP_GINIT_FUNCTION(imap)
56@@ -441,6 +470,7 @@
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;
61 #endif
62 imap_globals->gets_stream = NIL;
63 }
64@@ -1097,6 +1127,117 @@
65
66 #endif /* HAVE_IMAP2000 || HAVE_IMAP2001 */
67
68+#if defined(HAVE_IMAP2005)
69+
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)
73+{
74+ zval **streamind, **mailbox, **entry, **attr, **value;
75+ pils *imap_le_struct;
76+ long ret;
77+
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();
81+ }
82+
83+ ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
84+
85+ convert_to_string_ex(mailbox);
86+ convert_to_string_ex(entry);
87+ convert_to_string_ex(attr);
88+ convert_to_string_ex(value);
89+
90+ // create annotation object
91+ ANNOTATION *annotation = mail_newannotation();
92+ if (!annotation)
93+ RETURN_FALSE;
94+ annotation->values = mail_newannotationvalue();
95+ if (!annotation->values) {
96+ mail_free_annotation(&annotation);
97+ RETURN_FALSE;
98+ }
99+
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);
105+
106+ ret = imap_setannotation(imap_le_struct->imap_stream, annotation);
107+
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);
114+
115+ RETURN_BOOL(ret);
116+}
117+/* }}} */
118+
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)
122+{
123+ zval **streamind, **mailbox, **entry, **attr;
124+ pils *imap_le_struct;
125+ long ret;
126+
127+ if(ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &streamind, &mailbox, &entry, &attr) == FAILURE) {
128+ ZEND_WRONG_PARAM_COUNT();
129+ }
130+
131+ ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
132+
133+ convert_to_string_ex(mailbox);
134+ convert_to_string_ex(entry);
135+ convert_to_string_ex(attr);
136+
137+ /* initializing the special array for the return values */
138+ if (array_init(return_value) == FAILURE) {
139+ RETURN_FALSE;
140+ }
141+
142+ // fillup calling parameters
143+ STRINGLIST *entries = mail_newstringlist();
144+ if (!entries)
145+ RETURN_FALSE;
146+
147+ STRINGLIST *cur = entries;
148+ cur->text.data = (unsigned char *)cpystr(Z_STRVAL_PP(entry));
149+ cur->text.size = Z_STRLEN_PP(entry);
150+ cur->next = NIL;
151+
152+ STRINGLIST *attributes = mail_newstringlist();
153+ if (!attributes)
154+ RETURN_FALSE;
155+ cur = attributes;
156+ cur->text.data = (unsigned char *)cpystr (Z_STRVAL_PP(attr));
157+ cur->text.size = Z_STRLEN_PP(attr);
158+ cur->next = NIL;
159+
160+ IMAPG(imap_annotation_list) = return_value;
161+
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);
165+
166+ mail_free_stringlist(&entries);
167+ mail_free_stringlist(&attributes);
168+
169+ if (!ret) {
170+ zval_dtor(return_value);
171+ RETURN_FALSE;
172+ }
173+
174+ IMAPG(imap_annotation_list) = NIL;
175+}
176+/* }}} */
177+
178+#endif /* HAVE_IMAP2005 */
179
180 /* {{{ proto bool imap_expunge(resource stream_id)
181 Permanently delete all messages marked for deletion */
182@@ -2707,6 +2848,42 @@
183 }
184 /* }}} */
185
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)
189+{
190+ zval **streamind, **pflags;
191+ pils *imap_le_struct;
192+ long flags = 0L;
193+
194+ if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &streamind, &pflags) == FAILURE) {
195+ ZEND_WRONG_PARAM_COUNT();
196+ }
197+
198+ ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
199+
200+ convert_to_long_ex(pflags);
201+ flags = Z_LVAL_PP(pflags);
202+
203+ if (object_init(return_value) == FAILURE) {
204+ RETURN_FALSE;
205+ }
206+
207+ if (flags & SA_MESSAGES) {
208+ add_property_long(return_value, "messages", imap_le_struct->imap_stream->nmsgs);
209+ }
210+ if (flags & SA_RECENT) {
211+ add_property_long(return_value, "recent", imap_le_struct->imap_stream->recent);
212+ }
213+ if (flags & SA_UIDNEXT) {
214+ add_property_long(return_value, "uidnext", imap_le_struct->imap_stream->uid_last+1);
215+ }
216+ if (flags & SA_UIDVALIDITY) {
217+ add_property_long(return_value, "uidvalidity", imap_le_struct->imap_stream->uid_validity);
218+ }
219+}
220+/* }}} */
221+
222 /* {{{ proto object imap_status(resource stream_id, string mailbox, int options)
223 Get status info from a mailbox */
224 PHP_FUNCTION(imap_status)
225diff -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
228@@ -152,6 +152,7 @@
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);
236@@ -168,6 +169,9 @@
237 PHP_FUNCTION(imap_thread);
238 PHP_FUNCTION(imap_timeout);
239
240+// TODO: Needs fixing in configure in
241+#define HAVE_IMAP2005 1
242+
243 #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
244 PHP_FUNCTION(imap_get_quota);
245 PHP_FUNCTION(imap_get_quotaroot);
246@@ -175,7 +179,10 @@
247 PHP_FUNCTION(imap_setacl);
248 PHP_FUNCTION(imap_getacl);
249 #endif
250-
251+#if defined(HAVE_IMAP2005)
252+PHP_FUNCTION(imap_setannotation);
253+PHP_FUNCTION(imap_getannotation);
254+#endif
255
256 ZEND_BEGIN_MODULE_GLOBALS(imap)
257 char *imap_user;
258@@ -206,6 +213,9 @@
259 zval **quota_return;
260 zval *imap_acl_list;
261 #endif
262+#if defined(HAVE_IMAP2005)
263+ zval *imap_annotation_list;
264+#endif
265 /* php_stream for php_mail_gets() */
266 php_stream *gets_stream;
267 ZEND_END_MODULE_GLOBALS(imap)
This page took 0.051771 seconds and 4 git commands to generate.