Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45852 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93146 invoked from network); 21 Oct 2009 06:55:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Oct 2009 06:55:31 -0000 Authentication-Results: pb1.pair.com header.from=jani.taskinen@iki.fi; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=jani.taskinen@iki.fi; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain iki.fi from 204.13.248.72 cause and error) X-PHP-List-Original-Sender: jani.taskinen@iki.fi X-Host-Fingerprint: 204.13.248.72 mho-02-ewr.mailhop.org Received: from [204.13.248.72] ([204.13.248.72:59702] helo=mho-02-ewr.mailhop.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CE/E1-17709-260BEDA4 for ; Wed, 21 Oct 2009 02:55:31 -0400 Received: from a88-112-30-186.elisa-laajakaista.fi ([88.112.30.186] helo=localhost.localdomain) by mho-02-ewr.mailhop.org with esmtpsa (TLSv1:CAMELLIA256-SHA:256) (Exim 4.68) (envelope-from ) id 1N0V6V-000Njm-Ma; Wed, 21 Oct 2009 06:55:28 +0000 X-Mail-Handler: MailHop Outbound by DynDNS X-Originating-IP: 88.112.30.186 X-Report-Abuse-To: abuse@dyndns.com (see http://www.dyndns.com/services/mailhop/outbound_abuse.html for abuse reporting information) X-MHO-User: U2FsdGVkX18j5CRnHFEN7w3r89UEy9UdGrjgKvBAH38= Message-ID: <4ADEB05D.6090403@iki.fi> Date: Wed, 21 Oct 2009 09:55:25 +0300 Reply-To: jani.taskinen@iki.fi User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.4pre) Gecko/20091014 Fedora/3.0-2.8.b4.fc11 Thunderbird/3.0b4 MIME-Version: 1.0 To: Nick Fortenberry CC: internals@lists.php.net References: <1256076610.69357406@192.168.1.71> In-Reply-To: <1256076610.69357406@192.168.1.71> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Patch: Add INTERNALDATE to imap_append() From: jani.taskinen@iki.fi (Jani Taskinen) On 10/21/2009 01:10 AM, Nick Fortenberry wrote: > Hey everyone, > > Jake Levitt and I created this patch which adds the option to set a message's INTERNALDATE when appending it to a mail server using imap. Any chance we can get this included into the php 5.3 and 6 development branches? The diff below was done against the php-src/branches/PHP_5_3 branch. If you guys need me to apply the changes to a different branch or snapshot, please let me know. > > Here's the svn diff (done in my repo).. if you need something else please let me know: > There are several problems with it. Whitespace and C++ comments being the least. :) We have ext/date which is always there, I suggest you use those functions to handle dates instead of flaky regexps. --Jani > > Index: ext/imap/php_imap.c > =================================================================== > --- ext/imap/php_imap.c (revision 3405) > +++ ext/imap/php_imap.c (revision 3406) > @@ -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_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) > @@ -1270,20 +1272,43 @@ > PHP_FUNCTION(imap_append) > { > zval *streamind; > - char *folder, *message, *flags = NULL; > - int folder_len, message_len, flags_len = 0; > + char *folder, *message, *date = NULL, *flags = NULL; > + int folder_len, message_len, 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,&date,&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 (date) { > + //Make sure the given date string matches the RFC specified format > + if ((pce = pcre_get_compiled_regex_cache(regex, regex_len TSRMLS_CC)) == NULL) { > + RETURN_FALSE; > + } > + > + php_pcre_match_impl(pce, date, 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"); > + 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), (date ? date : NIL),&st)) { > RETURN_TRUE; > } else { > RETURN_FALSE; > > > > Thanks, > > - Nick Fortenberry > > >