Skip to content

Commit dea1d41

Browse files
committed
- [DOC] add INTERNALDATE to imap_append (will merge to trunk later)
1 parent 215dd9d commit dea1d41

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ PHP NEWS
99
- Changed "post_max_size" php.ini directive to allow unlimited post size by
1010
setting it to 0. (Rasmus)
1111

12+
- Added INTERNALDATE support to imap_append. (nick at mailtrust dot com)
1213
- Added support for SHA-256 and SHA-512 to php's crypt. (Pierre)
1314
- Added realpath_cache_size() and realpath_cache_get() functions. (Stas)
1415
- Added FILTER_FLAG_STRIP_BACKTICK option to the filter extension. (Ilia)

ext/imap/php_imap.c

+30-5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "ext/standard/info.h"
4242
#include "ext/standard/file.h"
4343
#include "ext/standard/php_smart_str.h"
44+
#include "ext/pcre/php_pcre.h"
4445

4546
#ifdef ERROR
4647
#undef ERROR
@@ -118,6 +119,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_append, 0, 0, 3)
118119
ZEND_ARG_INFO(0, folder)
119120
ZEND_ARG_INFO(0, message)
120121
ZEND_ARG_INFO(0, options)
122+
ZEND_ARG_INFO(0, date)
121123
ZEND_END_ARG_INFO()
122124

123125
ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_num_msg, 0, 0, 1)
@@ -1265,25 +1267,48 @@ PHP_FUNCTION(imap_reopen)
12651267
}
12661268
/* }}} */
12671269

1268-
/* {{{ proto bool imap_append(resource stream_id, string folder, string message [, string options])
1270+
/* {{{ proto bool imap_append(resource stream_id, string folder, string message [, string options [, string internal_date]])
12691271
Append a new message to a specified mailbox */
12701272
PHP_FUNCTION(imap_append)
12711273
{
12721274
zval *streamind;
1273-
char *folder, *message, *flags = NULL;
1274-
int folder_len, message_len, flags_len = 0;
1275+
char *folder, *message, *internal_date = NULL, *flags = NULL;
1276+
int folder_len, message_len, internal_date_len = 0, flags_len = 0;
12751277
pils *imap_le_struct;
12761278
STRING st;
12771279

1278-
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss|s", &streamind, &folder, &folder_len, &message, &message_len, &flags, &flags_len) == FAILURE) {
1280+
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss|ss", &streamind, &folder, &folder_len, &message, &message_len, &flags, &flags_len, &internal_date, &internal_date_len) == FAILURE) {
12791281
return;
12801282
}
12811283

1284+
char* regex = "/[0-3][0-9]-((Jan)|(Feb)|(Mar)|(Apr)|(May)|(Jun)|(Jul)|(Aug)|(Sep)|(Oct)|(Nov)|(Dec))-[0-9]{4} [0-2][0-9]:[0-5][0-9]:[0-5][0-9] [+-][0-9]{4}/";
1285+
int regex_len = strlen(regex);
1286+
pcre_cache_entry *pce; /* Compiled regex */
1287+
zval *subpats = NULL; /* Parts (not used) */
1288+
long regex_flags = 0; /* Flags (not used) */
1289+
long start_offset = 0; /* Start offset (not used) */
1290+
int global = 0;
1291+
1292+
if (internal_date) {
1293+
/* Make sure the given internal_date string matches the RFC specifiedformat */
1294+
if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC))== NULL) {
1295+
RETURN_FALSE;
1296+
}
1297+
1298+
php_pcre_match_impl(pce, internal_date, internal_date_len, return_value, subpats, global,
1299+
0, regex_flags, start_offset TSRMLS_CC);
1300+
1301+
if (!Z_LVAL_P(return_value)) {
1302+
php_error_docref(NULL TSRMLS_CC, E_WARNING, "internal date not correctly formatted");
1303+
internal_date = NULL;
1304+
}
1305+
}
1306+
12821307
ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
12831308

12841309
INIT (&st, mail_string, (void *) message, message_len);
12851310

1286-
if (mail_append_full(imap_le_struct->imap_stream, folder, (flags ? flags : NIL), NIL, &st)) {
1311+
if (mail_append_full(imap_le_struct->imap_stream, folder, (flags ? flags : NIL), (internal_date ? internal_date : NIL), &st)) {
12871312
RETURN_TRUE;
12881313
} else {
12891314
RETURN_FALSE;

0 commit comments

Comments
 (0)