Hey there php-dev readers,

Attached is a patch (based off of 4.2.1 release) for the IMAP system that
needs testing.  It's been brought to my attention that the quota support
is sort of... well, not standards compliant.  So I tried to fix that.

In the process I've also hopefully added in imap_get_quotaroot()
capabilities as well.

This patch NEEDS through testing, but would be nice to see in 4.3.
Unfortunately I have no access to an IMAP server with quota capabilities
turned on, so I can't really test.

imap_get_quota() should work the same, only now you will be returned the
name value as well, or whatever that is in quota name field (i.e. a
message).  The qlist array now looks like:

[qlist] => [name]
        => [usage]
        => [limit]

imap_get_quotaroot() should not require the user to be run as a mail-admin
user, making this eventually much more useful.  Here is an example using
it:

<?php

$mbx = imap_open( /* blah blah blah */);
$qroot = imap_get_quotaroot($mbx, "INBOX");
// this should retrieve the quota for the logged in users INBOX
if (!$qroot) {
  print "We have nothing!";
} else {
  foreach ($qroot as $name => $value)
    print "$name and $value\n";
}

?>

As usual please test and send any comments back to me.

>---------------------------------------------------------------<
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.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     Thu Jul 18 18:04:21 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
 }
 /* }}} */
 
@@ -1017,6 +1033,7 @@
 {
        zval **streamind, **qroot;
        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 +1054,54 @@
                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) {
+               add_assoc_long(return_value, "usage", qlist->usage);
+               add_assoc_long(return_value, "limit", qlist->limit);
+               add_assoc_string(return_value, "name", qlist->name, 
+strlen(qlist->name));
+       }
+
+       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)
 
-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to