]> granicus.if.org Git - php/commitdiff
- [DOC] add INTERNALDATE to imap_append (will merge to trunk later)
authorPierre Joye <pajoye@php.net>
Thu, 17 Dec 2009 17:28:26 +0000 (17:28 +0000)
committerPierre Joye <pajoye@php.net>
Thu, 17 Dec 2009 17:28:26 +0000 (17:28 +0000)
NEWS
ext/imap/php_imap.c

diff --git a/NEWS b/NEWS
index d9e7ddda4f71457d599cc3c2de4849209a853d5d..c51abd9ea761bb547a5778d804c4fd2aa07c832e 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@ PHP                                                                        NEWS
 - Changed "post_max_size" php.ini directive to allow unlimited post size by
   setting it to 0. (Rasmus)
 
+- Added INTERNALDATE support to imap_append. (nick at mailtrust dot com)
 - Added support for SHA-256 and SHA-512 to php's crypt. (Pierre)
 - Added realpath_cache_size() and realpath_cache_get() functions. (Stas)
 - Added FILTER_FLAG_STRIP_BACKTICK option to the filter extension. (Ilia)
index 630a38a84000e9193074d28fd04ab8d937ab4a64..b255999a34258df495489270ed52d5df68733f26 100644 (file)
@@ -41,6 +41,7 @@
 #include "ext/standard/info.h"
 #include "ext/standard/file.h"
 #include "ext/standard/php_smart_str.h"
+#include "ext/pcre/php_pcre.h"
 
 #ifdef ERROR
 #undef ERROR
@@ -118,6 +119,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_append, 0, 0, 3)
        ZEND_ARG_INFO(0, folder)
        ZEND_ARG_INFO(0, message)
        ZEND_ARG_INFO(0, options)
+       ZEND_ARG_INFO(0, date)
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_imap_num_msg, 0, 0, 1)
@@ -1265,25 +1267,48 @@ PHP_FUNCTION(imap_reopen)
 }
 /* }}} */
 
-/* {{{ proto bool imap_append(resource stream_id, string folder, string message [, string options])
+/* {{{ proto bool imap_append(resource stream_id, string folder, string message [, string options [, string internal_date]])
    Append a new message to a specified mailbox */
 PHP_FUNCTION(imap_append)
 {
        zval *streamind;
-       char *folder, *message, *flags = NULL;
-       int folder_len, message_len, flags_len = 0;
+       char *folder, *message, *internal_date = NULL, *flags = NULL;
+       int folder_len, message_len, internal_date_len = 0, flags_len = 0;
        pils *imap_le_struct;
        STRING st;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss|s", &streamind, &folder, &folder_len, &message, &message_len, &flags, &flags_len) == FAILURE) {
+       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) {
                return;
        }
 
+       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}/";
+       int regex_len = strlen(regex);
+       pcre_cache_entry *pce;                          /* Compiled regex */
+       zval *subpats = NULL;                           /* Parts (not used) */
+       long regex_flags = 0;                           /* Flags (not used) */
+       long start_offset = 0;                          /* Start offset (not used) */
+       int global = 0;
+
+       if (internal_date) {
+               /* Make sure the given internal_date string matches the RFC specifiedformat */
+               if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC))== NULL) {
+                       RETURN_FALSE;
+               }
+
+               php_pcre_match_impl(pce, internal_date, internal_date_len, return_value, subpats, global,
+                       0, regex_flags, start_offset TSRMLS_CC);
+
+               if (!Z_LVAL_P(return_value)) {
+                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "internal date not correctly formatted");
+                       internal_date = NULL;
+               }
+       }
+
        ZEND_FETCH_RESOURCE(imap_le_struct, pils *, &streamind, -1, "imap", le_imap);
 
        INIT (&st, mail_string, (void *) message, message_len);
 
-       if (mail_append_full(imap_le_struct->imap_stream, folder, (flags ? flags : NIL), NIL, &st)) {
+       if (mail_append_full(imap_le_struct->imap_stream, folder, (flags ? flags : NIL), (internal_date ? internal_date : NIL), &st)) {
                RETURN_TRUE;
        } else {
                RETURN_FALSE;