|
41 | 41 | #include "ext/standard/info.h"
|
42 | 42 | #include "ext/standard/file.h"
|
43 | 43 | #include "ext/standard/php_smart_str.h"
|
| 44 | +#include "ext/pcre/php_pcre.h" |
44 | 45 |
|
45 | 46 | #ifdef ERROR
|
46 | 47 | #undef ERROR
|
@@ -118,6 +119,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_append, 0, 0, 3)
|
118 | 119 | ZEND_ARG_INFO(0, folder)
|
119 | 120 | ZEND_ARG_INFO(0, message)
|
120 | 121 | ZEND_ARG_INFO(0, options)
|
| 122 | + ZEND_ARG_INFO(0, date) |
121 | 123 | ZEND_END_ARG_INFO()
|
122 | 124 |
|
123 | 125 | ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_num_msg, 0, 0, 1)
|
@@ -1265,25 +1267,48 @@ PHP_FUNCTION(imap_reopen)
|
1265 | 1267 | }
|
1266 | 1268 | /* }}} */
|
1267 | 1269 |
|
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]]) |
1269 | 1271 | Append a new message to a specified mailbox */
|
1270 | 1272 | PHP_FUNCTION(imap_append)
|
1271 | 1273 | {
|
1272 | 1274 | 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; |
1275 | 1277 | pils *imap_le_struct;
|
1276 | 1278 | STRING st;
|
1277 | 1279 |
|
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) { |
1279 | 1281 | return;
|
1280 | 1282 | }
|
1281 | 1283 |
|
| 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 | + |
1282 | 1307 | ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
|
1283 | 1308 |
|
1284 | 1309 | INIT (&st, mail_string, (void *) message, message_len);
|
1285 | 1310 |
|
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)) { |
1287 | 1312 | RETURN_TRUE;
|
1288 | 1313 | } else {
|
1289 | 1314 | RETURN_FALSE;
|
|
0 commit comments