]> git.pld-linux.org Git - packages/php.git/blob - php-imap-annotations.patch
up to php-7.2.0RC6, likely last RC
[packages/php.git] / php-imap-annotations.patch
1 Provides get/set ANNOTATIONS support to PHP. [Version: 5.2.6]
2
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
6 @@ -161,6 +161,22 @@
7         ZEND_ARG_INFO(0, mailbox)
8  ZEND_END_ARG_INFO()
9  #endif
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)
17 +ZEND_END_ARG_INFO()
18 +
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)
24 +ZEND_END_ARG_INFO()
25 +#endif
26  
27  ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_expunge, 0, 0, 1)
28         ZEND_ARG_INFO(0, stream_id)
29 @@ -402,6 +418,11 @@
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)
34 +ZEND_END_ARG_INFO()
35 +
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)
39  ZEND_END_ARG_INFO()
40  
41 @@ -504,6 +525,7 @@
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)
49 @@ -534,6 +556,10 @@
50         PHP_FE(imap_setacl,                                                             arginfo_imap_setacl)
51         PHP_FE(imap_getacl,                                                             arginfo_imap_getacl)
52  #endif
53 +#if defined(HAVE_IMAP2005)
54 +       PHP_FE(imap_setannotation,                                              arginfo_imap_setannotation)
55 +       PHP_FE(imap_getannotation,                                              arginfo_imap_getannotation)
56 +#endif
57  
58         PHP_FE(imap_mail,                                                               arginfo_imap_mail)
59  
60 @@ -795,6 +821,30 @@
61  /* }}} */
62  #endif
63  
64 +#if defined(HAVE_IMAP2005)
65 +/* {{{ mail_getannotation
66 + *
67 + * Mail GET_ANNOTATION callback
68 + * Called via the mail_parameter function in c-client:src/c-client/mail.c
69 + */
70 +void mail_getannotation(MAILSTREAM *stream, ANNOTATION *alist)
71 +{
72 +        ANNOTATION_VALUES *cur;
73 +        
74 +       TSRMLS_FETCH();
75 +
76 +       /* walk through the ANNOTATION_VALUES */
77 +        
78 +       for(cur = alist->values; cur; cur = cur->next) {
79 +           if (cur->value)
80 +               add_assoc_stringl(IMAPG(imap_annotation_list), cur->attr, cur->value, strlen(cur->value), 1);
81 +           else
82 +               add_assoc_stringl(IMAPG(imap_annotation_list), cur->attr, "", 0, 1);
83 +       }
84 +}
85 +/* }}} */
86 +#endif
87 +
88  /* {{{ PHP_GINIT_FUNCTION
89   */
90  static PHP_GINIT_FUNCTION(imap)
91 @@ -820,6 +870,7 @@
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;
96  #endif
97         imap_globals->gets_stream = NIL;
98  }
99 @@ -1475,7 +1526,119 @@
100  }
101  /* }}} */
102  #endif /* HAVE_IMAP2000 || HAVE_IMAP2001 */
103 -
104
105 +#if defined(HAVE_IMAP2005)
106 +
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)
110 +{
111 +       zval **streamind, **mailbox, **entry, **attr, **value;
112 +       pils *imap_le_struct;
113 +        long ret;
114 +       
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();
118 +       }
119 +
120 +       ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
121 +
122 +       convert_to_string_ex(mailbox);
123 +       convert_to_string_ex(entry);
124 +       convert_to_string_ex(attr);
125 +       convert_to_string_ex(value);
126 +
127 +        // create annotation object
128 +        ANNOTATION *annotation = mail_newannotation();
129 +        if (!annotation)
130 +            RETURN_FALSE;
131 +        annotation->values = mail_newannotationvalue();
132 +        if (!annotation->values) {
133 +            mail_free_annotation(&annotation);
134 +            RETURN_FALSE;
135 +        }
136 +        
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);
142 +        
143 +        ret = imap_setannotation(imap_le_struct->imap_stream, annotation);
144 +                
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);
151 +        
152 +        RETURN_BOOL(ret);
153 +}
154 +/* }}} */
155 +
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)
159 +{
160 +       zval **streamind, **mailbox, **entry, **attr;
161 +       pils *imap_le_struct;
162 +        long ret;
163 +
164 +       if(ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &streamind, &mailbox, &entry, &attr) == FAILURE) {
165 +               ZEND_WRONG_PARAM_COUNT();
166 +       }
167 +
168 +       ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
169 +
170 +       convert_to_string_ex(mailbox);
171 +       convert_to_string_ex(entry);
172 +       convert_to_string_ex(attr);
173 +
174 +       /* initializing the special array for the return values */
175 +       if (array_init(return_value) == FAILURE) {
176 +               RETURN_FALSE;
177 +       }
178 +
179 +        // fillup calling parameters
180 +        STRINGLIST *entries = mail_newstringlist();
181 +        if (!entries)
182 +            RETURN_FALSE;
183 +        
184 +        STRINGLIST *cur = entries;
185 +        cur->text.data = (unsigned char *)cpystr(Z_STRVAL_PP(entry));
186 +        cur->text.size = Z_STRLEN_PP(entry);
187 +        cur->next = NIL;
188 +        
189 +        STRINGLIST *attributes = mail_newstringlist();
190 +        if (!attributes)
191 +            RETURN_FALSE;
192 +        cur = attributes;
193 +        cur->text.data = (unsigned char *)cpystr (Z_STRVAL_PP(attr));
194 +        cur->text.size = Z_STRLEN_PP(attr);
195 +        cur->next = NIL;
196 +        
197 +        IMAPG(imap_annotation_list) = return_value;
198 +        
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);
202 +        
203 +        mail_free_stringlist(&entries);
204 +        mail_free_stringlist(&attributes);
205 +        
206 +        if (!ret) {
207 +            zval_dtor(return_value);
208 +            RETURN_FALSE;
209 +        }
210 +        
211 +       IMAPG(imap_annotation_list) = NIL;
212 +}
213 +/* }}} */
214 +
215 +#endif /* HAVE_IMAP2005 */
216
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 @@
221  }
222  /* }}} */
223  
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)
227 +{
228 +       zval **streamind, **pflags;
229 +       pils *imap_le_struct;
230 +       long flags = 0L;
231 +
232 +       if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &streamind, &pflags) == FAILURE) {
233 +               ZEND_WRONG_PARAM_COUNT();
234 +       }
235 +
236 +       ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
237 +
238 +       convert_to_long_ex(pflags);
239 +       flags = Z_LVAL_PP(pflags);
240 +
241 +       if (object_init(return_value) == FAILURE) {
242 +               RETURN_FALSE;
243 +       }
244 +
245 +       if (flags & SA_MESSAGES) {
246 +               add_property_long(return_value, "messages", imap_le_struct->imap_stream->nmsgs);
247 +       }
248 +       if (flags & SA_RECENT) {
249 +               add_property_long(return_value, "recent", imap_le_struct->imap_stream->recent);
250 +       }
251 +       if (flags & SA_UIDNEXT) {
252 +               add_property_long(return_value, "uidnext", imap_le_struct->imap_stream->uid_last+1);
253 +       }
254 +       if (flags & SA_UIDVALIDITY) {
255 +               add_property_long(return_value, "uidvalidity", imap_le_struct->imap_stream->uid_validity);
256 +       }
257 +}
258 +/* }}} */
259 +
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
266 @@ -153,6 +153,7 @@
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);
274 @@ -173,6 +174,9 @@
275  PHP_FUNCTION(imap_thread);
276  PHP_FUNCTION(imap_timeout);
277  
278 +// TODO: Needs fixing in configure in
279 +#define HAVE_IMAP2005 1
280 +
281  #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
282  PHP_FUNCTION(imap_get_quota);
283  PHP_FUNCTION(imap_get_quotaroot);
284 @@ -180,7 +184,10 @@
285  PHP_FUNCTION(imap_setacl);
286  PHP_FUNCTION(imap_getacl);
287  #endif
288 -
289 +#if defined(HAVE_IMAP2005)
290 +PHP_FUNCTION(imap_setannotation);
291 +PHP_FUNCTION(imap_getannotation);
292 +#endif
293  
294  ZEND_BEGIN_MODULE_GLOBALS(imap)
295         char *imap_user;
296 @@ -211,6 +218,9 @@
297         zval **quota_return;
298         zval *imap_acl_list;
299  #endif
300 +#if defined(HAVE_IMAP2005)
301 +        zval *imap_annotation_list;
302 +#endif
303         /* php_stream for php_mail_gets() */
304         php_stream *gets_stream;
305  ZEND_END_MODULE_GLOBALS(imap)
This page took 0.047449 seconds and 3 git commands to generate.