To those of you reading this,

I'd like to submit the following patch for testing by the general public.
It should add a few bug fixes to the IMAP quota system, and some new
features.  Unfortunately I cannot test this out, as my local machine
cannot build cclient (for some unknown reason), and the IMAP server I have
access to does not have quota capabilities turned on.

First off this should fix a bug in the imap_get_quota, where only the last
values are consider for the usage and limit.  It will now return an array
of arrays that looks like so:

[NAME]  => usage
        => limit
[NAME2] => usage
        => limit
... etc ...

The rest of this function works exactly the same as manual page describes.

Secondly this should add the functionality of imap_get_quotaroot to PHP.
As I haven't been able to get a result back, I'm not sure if the return
array looks decent or not.  But this should work fairly similiar to
imap_get_quota, only there is no need to be the mailadmin user to view
quota settings.

If those of you using IMAP can test these functions out and tell me how
they work, I would appriciate it.  Or if you can give me access to an IMAP
server with quota services, that would be just as good.

This patch was made against 4.2.1, but there is no reason it shouldn't
work against 4.2.2.  Thanks for your time, and please cc me in any
comments, I'm not subsribed to the list.

>---------------------------------------------------------------<
Dan Kalowsky                    "A little less conversation,
http://www.deadmime.org/~dank    a little more action."
[EMAIL PROTECTED]         - "A Little Less Conversation",
[EMAIL PROTECTED]                 Elvis Presley
Only in imap: .deps
Only in imap: .libs
Only in imap: Makefile
Only in imap: libimap.la
Only in imap: libs.mk
diff -u imap-orig/php_imap.c imap/php_imap.c
--- imap-orig/php_imap.c        Wed Apr 24 11:30:16 2002
+++ imap/php_imap.c     Mon Jul 22 16:19:10 2002
@@ -22,6 +22,7 @@
    |          Andrew Skalski      <[EMAIL PROTECTED]>                  |
    |          Hartmut Holzgraefe  <[EMAIL PROTECTED]>                        |
    |          Jani Taskinen       <[EMAIL PROTECTED]>                         |
+   |          Daniel R. Kalowsky  <[EMAIL PROTECTED]>                      |
    | PHP 4.0 updates:  Zeev Suraski <[EMAIL PROTECTED]>                       |
    +----------------------------------------------------------------------+
  */
@@ -132,6 +133,7 @@
 
 #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
        PHP_FE(imap_get_quota,                                                  NULL)
+       PHP_FE(imap_get_quotaroot,                                              NULL)
        PHP_FE(imap_set_quota,                                                  NULL)
        PHP_FE(imap_setacl,                                                            
 NULL)
 #endif
@@ -371,12 +373,22 @@
 {
        TSRMLS_FETCH();
 
-       /* this should only be run through once */
-       for (; qlist; qlist = qlist->next)
-       {
-               IMAPG(quota_usage) = qlist->usage;
-               IMAPG(quota_limit) = qlist->limit;
-       }
+       IMAPG(quota_return) = qlist;
+
+}
+/* }}} */
+
+/* {{{ mail_getquotaroot
+ *
+ * Mail GET_QUOTAROOT callback
+ * Called via the mail_parameter function in c-client:src/c-client/mail.c
+ * Author DRK
+ */
+void mail_getquotaroot(MAILSTREAM *stream, char *mbx, STRINGLIST *qroot)
+{
+       TSRMLS_FETCH();
+
+       IMAPG(quotaroot_return) = qroot;
 }
 /* }}} */
 #endif
@@ -396,6 +408,10 @@
        imap_globals->imap_folder_objects = NIL;
        imap_globals->imap_sfolder_objects = NIL;
        imap_globals->folderlist_style = FLIST_ARRAY;
+#if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
+       imap_globals->quota_return = NIL;
+       imap_globals->quotaroot_return = NIL;
+#endif
 }
 /* }}} */
 
@@ -1016,7 +1032,10 @@
 PHP_FUNCTION(imap_get_quota)
 {
        zval **streamind, **qroot;
+       zval *quota_map;
+       char *quota_name;
        pils *imap_le_struct;
+       QUOTALIST *qlist;
 
        if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &streamind, &qroot) == 
FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
@@ -1037,9 +1056,63 @@
                php_error(E_WARNING, "Unable to allocate array memory");
                RETURN_FALSE;
        }
-               
-       add_assoc_long(return_value, "usage", IMAPG(quota_usage));
-       add_assoc_long(return_value, "limit", IMAPG(quota_limit));
+
+       qlist = IMAPG(quota_return);
+
+       for (; qlist; qlist = qlist->next) {
+               if (array_init(quota_map) == FAILURE) {
+                       php_error(E_WARNING, "Unable to allocate array memory for 
+quota_map");
+                       FREE_ZVAL(quota_map);
+                       IMAPG(quota_return) = NIL;
+                       RETURN_FALSE;
+               }
+       
+               quota_name = qlist->name;
+
+               add_assoc_long(quota_map, "usage", qlist->usage);
+               add_assoc_long(quota_map, "limit", qlist->limit);
+               add_assoc_zval_ex(return_value, quota_name, strlen(quota_name), 
+quota_map);
+       }
+
+       IMAPG(quota_return) = NIL;
+}
+/* }}} */
+
+/* {{{ proto array imap_get_quotaroot(int stream_id, string mbox)
+    Returns the quota set to the mailbox account mbox */
+PHP_FUNCTION(imap_get_quotaroot)
+{
+    zval **streamind, **mbox;
+    pils *imap_le_struct;
+    STRINGLIST *qlist;
+
+    if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &streamind, &mbox) == 
+FAILURE) {
+        ZEND_WRONG_PARAM_COUNT();
+    }
+
+    ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
+
+    convert_to_string_ex(mbox);
+
+    /* set the callback for the GET_QUOTAROOT function */
+    mail_parameters(NIL, SET_QUOTAROOT, (void *) mail_getquotaroot);
+    if(!imap_getquotaroot(imap_le_struct->imap_stream, Z_STRVAL_PP(mbox))) {
+        php_error(E_WARNING, "c-client imap_getquotaroot failed");
+        RETURN_FALSE;
+    }
+
+    if (array_init(return_value) == FAILURE) {
+        php_error(E_WARNING, "Unable to allocate array memory");
+        RETURN_FALSE;
+    }
+
+       qlist = IMAPG(quotaroot_return);
+
+       for (; qlist; qlist = qlist->next) {
+               add_assoc_long(return_value, qlist->text.data, qlist->text.size);
+       }
+       
+       IMAPG(quotaroot_return) = NIL;
 }
 /* }}} */
 
diff -u imap-orig/php_imap.h imap/php_imap.h
--- imap-orig/php_imap.h        Mon Mar 11 18:11:37 2002
+++ imap/php_imap.h     Mon Jul 15 23:07:35 2002
@@ -177,6 +177,7 @@
 
 #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
 PHP_FUNCTION(imap_get_quota);
+PHP_FUNCTION(imap_get_quotaroot);
 PHP_FUNCTION(imap_set_quota);
 PHP_FUNCTION(imap_setacl);
 #endif
@@ -201,8 +202,8 @@
        unsigned long status_uidnext;
        unsigned long status_uidvalidity;
 #if defined(HAVE_IMAP2000) || defined(HAVE_IMAP2001)
-       unsigned long quota_usage;
-       unsigned long quota_limit;
+       QUOTALIST *quota_return;
+       STRINGLIST *quotaroot_return;
 #endif
 ZEND_END_MODULE_GLOBALS(imap)
 
Only in imap: php_imap.lo
Only in imap: php_imap.o
-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to