Hi,

attached patch adds a new imap_status_current() function.
This function exposes several status variables
about the current selected folder.

The patch was developed for PHP 4.3.11, but also applies
to PHP 5.0.4 with fuzz.

A little sidenote on the normal imap_status() function:
It's undefined to call it for the current folder.

Quoting RFC 3501, section 6.3.10:
The STATUS command is intended to access the
status of mailboxes other than the currently selected
mailbox.  Because the STATUS command can cause the
mailbox to be opened internally, and because this
information is available by other means on the selected
mailbox, the STATUS command SHOULD NOT be used on the
currently selected mailbox.

Maybe it should be added to the documentation to use only
the new imap_status_current() function for the current folder.

Please CC: comments, I'm not on the list.

Best regards,
Thomas Jarosch
diff -u -r -p ext/imap/php_imap.c ext.imap/imap/php_imap.c
--- ext/imap/php_imap.c	Tue Jan 25 15:23:37 2005
+++ ext.imap/imap/php_imap.c	Wed Jun  1 17:35:41 2005
@@ -115,6 +115,7 @@ function_entry imap_functions[] = {
 	PHP_FE(imap_binary,								NULL)
 	PHP_FE(imap_utf8,								NULL)
 	PHP_FE(imap_status,								NULL)
+	PHP_FE(imap_status_current,							NULL)
 	PHP_FE(imap_mailboxmsginfo,						NULL)
 	PHP_FE(imap_setflag_full,						NULL)
 	PHP_FE(imap_clearflag_full,						NULL)
@@ -2548,6 +2549,42 @@ PHP_FUNCTION(imap_msgno)
  	convert_to_long_ex(msgno);
  
  	RETURN_LONG(mail_msgno(imap_le_struct->imap_stream, Z_LVAL_PP(msgno)));
+}
+/* }}} */
+
+/* {{{ proto object imap_status_current(resource stream_id, int options)
+   Get (cached) status info from current mailbox */
+PHP_FUNCTION(imap_status_current)
+{
+ 	zval **streamind, **pflags;
+	pils *imap_le_struct;
+	long flags = 0L;
+
+ 	if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &streamind, &pflags) == FAILURE) {
+ 		ZEND_WRONG_PARAM_COUNT();
+ 	}
+
+	ZEND_FETCH_RESOURCE(imap_le_struct, pils *, streamind, -1, "imap", le_imap);
+
+	convert_to_long_ex(pflags);
+	flags = Z_LVAL_PP(pflags);
+
+	if (object_init(return_value) == FAILURE) {
+		RETURN_FALSE;
+	}
+
+	if (flags & SA_MESSAGES) {
+		add_property_long(return_value, "messages", imap_le_struct->imap_stream->nmsgs);
+	}
+	if (flags & SA_RECENT) {
+		add_property_long(return_value, "recent", imap_le_struct->imap_stream->recent);
+	}
+	if (flags & SA_UIDNEXT) {
+		add_property_long(return_value, "uidnext", imap_le_struct->imap_stream->uid_last+1);
+	}
+	if (flags & SA_UIDVALIDITY) {
+		add_property_long(return_value, "uidvalidity", imap_le_struct->imap_stream->uid_validity);
+	}
 }
 /* }}} */
 
diff -u -r -p ext/imap/php_imap.h ext.imap/imap/php_imap.h
--- ext/imap/php_imap.h	Fri Jun 13 16:45:36 2003
+++ ext.imap/imap/php_imap.h	Wed Jun  1 17:35:49 2005
@@ -151,6 +151,7 @@ PHP_FUNCTION(imap_lsub);
 PHP_FUNCTION(imap_lsub_full);
 PHP_FUNCTION(imap_create);
 PHP_FUNCTION(imap_rename);
+PHP_FUNCTION(imap_status_current);
 PHP_FUNCTION(imap_status);
 PHP_FUNCTION(imap_bodystruct);
 PHP_FUNCTION(imap_fetch_overview);

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to