Skip to content

Commit d4e6d96

Browse files
committed
- [DOC] add imap_gc (purge cache(s) and constants IMAP_GC_ELT, IMAP_GC_ENV and IMAP_GC_TEXTS to control imap_gc behavior
1 parent 9e36fae commit d4e6d96

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

ext/imap/php_imap.c

+40
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,11 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_expunge, 0, 0, 1)
167167
ZEND_ARG_INFO(0, stream_id)
168168
ZEND_END_ARG_INFO()
169169

170+
ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_gc, 0, 0, 1)
171+
ZEND_ARG_INFO(0, stream_id)
172+
ZEND_ARG_INFO(0, flags)
173+
ZEND_END_ARG_INFO()
174+
170175
ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_close, 0, 0, 1)
171176
ZEND_ARG_INFO(0, stream_id)
172177
ZEND_ARG_INFO(0, options)
@@ -468,6 +473,7 @@ const zend_function_entry imap_functions[] = {
468473
PHP_FE(imap_savebody, arginfo_imap_savebody)
469474
PHP_FE(imap_fetchheader, arginfo_imap_fetchheader)
470475
PHP_FE(imap_fetchstructure, arginfo_imap_fetchstructure)
476+
PHP_FE(imap_gc, arginfo_imap_gc)
471477
PHP_FE(imap_expunge, arginfo_imap_expunge)
472478
PHP_FE(imap_delete, arginfo_imap_delete)
473479
PHP_FE(imap_undelete, arginfo_imap_undelete)
@@ -1025,6 +1031,15 @@ PHP_MINIT_FUNCTION(imap)
10251031
ENCOTHER unknown
10261032
*/
10271033

1034+
REGISTER_LONG_CONSTANT("IMAP_GC_ELT", GC_ELT , CONST_PERSISTENT | CONST_CS);
1035+
REGISTER_LONG_CONSTANT("IMAP_GC_ENV", GC_ENV , CONST_PERSISTENT | CONST_CS);
1036+
REGISTER_LONG_CONSTANT("IMAP_GC_TEXTS", GC_TEXTS , CONST_PERSISTENT | CONST_CS);
1037+
/*
1038+
GC_ELT message cache elements
1039+
GC_ENV ENVELOPEs and BODYs
1040+
GC_TEXTS texts
1041+
*/
1042+
10281043
le_imap = zend_register_list_destructors_ex(mail_close_it, NULL, "imap", module_number);
10291044
return SUCCESS;
10301045
}
@@ -1472,6 +1487,31 @@ PHP_FUNCTION(imap_expunge)
14721487
}
14731488
/* }}} */
14741489

1490+
/* {{{ proto bool imap_gc(resource stream_id, int flags)
1491+
This function garbage collects (purges) the cache of entries of a specific type. */
1492+
PHP_FUNCTION(imap_gc)
1493+
{
1494+
zval *streamind;
1495+
pils *imap_le_struct;
1496+
long flags;
1497+
1498+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &streamind, &flags) == FAILURE) {
1499+
return;
1500+
}
1501+
1502+
if (flags && ((flags & ~(GC_TEXTS | GC_ELT | GC_ENV)) != 0)) {
1503+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "invalid value for the flags parameter");
1504+
RETURN_FALSE;
1505+
}
1506+
1507+
ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
1508+
1509+
mail_gc(imap_le_struct->imap_stream, flags);
1510+
1511+
RETURN_TRUE;
1512+
}
1513+
/* }}} */
1514+
14751515
/* {{{ proto bool imap_close(resource stream_id [, int options])
14761516
Close an IMAP stream */
14771517
PHP_FUNCTION(imap_close)

ext/imap/php_imap.h

+1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ PHP_FUNCTION(imap_body);
115115
PHP_FUNCTION(imap_fetchstructure);
116116
PHP_FUNCTION(imap_fetchbody);
117117
PHP_FUNCTION(imap_savebody);
118+
PHP_FUNCTION(imap_gc);
118119
PHP_FUNCTION(imap_expunge);
119120
PHP_FUNCTION(imap_delete);
120121
PHP_FUNCTION(imap_undelete);

0 commit comments

Comments
 (0)