Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:45856 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 71296 invoked from network); 21 Oct 2009 15:37:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Oct 2009 15:37:26 -0000 Authentication-Results: pb1.pair.com header.from=nick@mailtrust.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=nick@mailtrust.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain mailtrust.com designates 207.97.245.203 as permitted sender) X-PHP-List-Original-Sender: nick@mailtrust.com X-Host-Fingerprint: 207.97.245.203 smtp203.iad.emailsrvr.com Linux 2.4/2.6 Received: from [207.97.245.203] ([207.97.245.203:33832] helo=smtp203.iad.emailsrvr.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B6/9A-15002-5BA2FDA4 for ; Wed, 21 Oct 2009 11:37:26 -0400 Received: from relay10.relay.iad.mlsrvr.com (localhost [127.0.0.1]) by relay10.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id 3298B1EBC2C; Wed, 21 Oct 2009 11:37:23 -0400 (EDT) Received: from dynamic7.wm-web.iad.mlsrvr.com (dynamic7.wm-web.iad.mlsrvr.com [192.168.2.148]) by relay10.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id 27E201E9997; Wed, 21 Oct 2009 11:37:23 -0400 (EDT) Received: from mailtrust.com (localhost [127.0.0.1]) by dynamic7.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 19FEF1538050; Wed, 21 Oct 2009 11:37:23 -0400 (EDT) Received: by apps.rackspace.com (Authenticated sender: nick@mailtrust.com, from: nick@mailtrust.com) with HTTP; Wed, 21 Oct 2009 11:37:23 -0400 (EDT) Date: Wed, 21 Oct 2009 11:37:23 -0400 (EDT) To: jani.taskinen@iki.fi Cc: internals@lists.php.net, "Jake Levitt" MIME-Version: 1.0 Content-Type: text/plain;charset=UTF-8 Content-Transfer-Encoding: quoted-printable Importance: Normal X-Priority: 3 (Normal) X-Type: plain In-Reply-To: <4ADEB05D.6090403@iki.fi> References: <1256076610.69357406@192.168.1.71> <4ADEB05D.6090403@iki.fi> Message-ID: <1256139443.104920304@192.168.1.202> X-Mailer: webmail7.0b Subject: =?UTF-8?Q?Re:=20[PHP-DEV]=20Patch:=20Add=20INTERNALDATE=20to=20imap=5Fap?= =?UTF-8?Q?pend()?= From: nick@mailtrust.com ("Nick Fortenberry") Hey Jani,=0A=0AWe looked through the date library but it doesn't look like = there are any functions to verify that a date is in a certain format. Unle= ss we are mistaken, it looks like the only way to verify this would be to u= se a regex.=0A=0AAlso, we read through CODING_STANDARDS and it said to be g= enerous with whitespace and brackets. Were you referring to something in p= articular with regards to whitespace?=0A=0AThanks,=0ANick=0A=0A=0A-----Orig= inal Message-----=0AFrom: "Jani Taskinen" =0ASent: We= dnesday, October 21, 2009 2:55am=0ATo: "Nick Fortenberry" =0ACc: internals@lists.php.net=0ASubject: Re: [PHP-DEV] Patch: Add INTER= NALDATE to imap_append()=0A=0AOn 10/21/2009 01:10 AM, Nick Fortenberry wrot= e:=0A> Hey everyone,=0A>=0A> Jake Levitt and I created this patch which add= s the option to set a message's INTERNALDATE when appending it to a mail se= rver 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/branch= es/PHP_5_3 branch. If you guys need me to apply the changes to a different= branch or snapshot, please let me know.=0A>=0A> Here's the svn diff (done = in my repo).. if you need something else please let me know:=0A>=0A=0AThere= are several problems with it. Whitespace and C++ comments being =0Athe lea= st. :) We have ext/date which is always there, I suggest you use =0Athose f= unctions to handle dates instead of flaky regexps.=0A=0A--Jani=0A=0A>=0A> I= ndex: ext/imap/php_imap.c=0A> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=0A> --- ext/imap/php_imap.c (revision 3405)=0A> +++ ext/imap/= php_imap.c (revision 3406)=0A> @@ -41,6 +41,7 @@=0A> #include "ext/s= tandard/info.h"=0A> #include "ext/standard/file.h"=0A> #include "ext/standa= rd/php_smart_str.h"=0A> +#include "ext/pcre/php_pcre.h"=0A>=0A> #ifdef ERRO= R=0A> #undef ERROR=0A> @@ -118,6 +119,7 @@=0A> ZEND_ARG_INFO(0, fol= der)=0A> ZEND_ARG_INFO(0, message)=0A> ZEND_ARG_INFO(0, opt= ions)=0A> + ZEND_ARG_INFO(0, date)=0A> ZEND_END_ARG_INFO()=0A>=0A> Z= END_BEGIN_ARG_INFO_EX(arginfo_imap_num_msg, 0, 0, 1)=0A> @@ -1270,20 +1272,= 43 @@=0A> PHP_FUNCTION(imap_append)=0A> {=0A> zval *streamind;=0A> = - char *folder, *message, *flags =3D NULL;=0A> - int folder_l= en, message_len, flags_len =3D 0;=0A> + char *folder, *message, *dat= e =3D NULL, *flags =3D NULL;=0A> + int folder_len, message_len, date= _len =3D 0, flags_len =3D 0;=0A> pils *imap_le_struct;=0A> = STRING st;=0A>=0A> - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRML= S_CC, "rss|s",&streamind,&folder,&folder_len,&message,&message_len,&flags,&= flags_len) =3D=3D FAILURE) {=0A> + if (zend_parse_parameters(ZEND_NU= M_ARGS() TSRMLS_CC, "rss|ss",&streamind,&folder,&folder_len,&message,&messa= ge_len,&flags,&flags_len,&date,&date_len) =3D=3D FAILURE) {=0A> = return;=0A> }=0A>=0A> + char* regex =3D "/[ 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}/";=0A> + int re= gex_len =3D strlen(regex);=0A> + pcre_cache_entry *pce; = //Compiled regex=0A> + zval *subpats =3D NULL; = //Parts (not used)=0A> + long regex_fla= gs =3D 0; //Flags (not used)=0A> + lo= ng start_offset =3D 0; //Start offset (not u= sed)=0A> + int global =3D 0;=0A> +=0A> + if (date) {=0A> + = //Make sure the given date string matches the RFC specified fo= rmat=0A> + if ((pce =3D pcre_get_compiled_regex_cache(regex,= regex_len TSRMLS_CC)) =3D=3D NULL) {=0A> + RETURN_F= ALSE;=0A> + }=0A> +=0A> + php_pcre_match_impl= (pce, date, date_len, return_value, subpats, global,=0A> + = 0, regex_flags, start_offset TSRMLS_CC);=0A> +=0A> + = if (!Z_LVAL_P(return_value)) {=0A> + php_error_docre= f(NULL TSRMLS_CC, E_WARNING, "internal date not correctly formatted");=0A> = + date =3D NULL;=0A> + }=0A> + = }=0A> +=0A> ZEND_FETCH_RESOURCE(imap_le_struct, pils *,&streamind,= -1, "imap", le_imap);=0A>=0A> INIT (&st, mail_string, (void *) mes= sage, message_len);=0A>=0A> - if (mail_append_full(imap_le_struct->i= map_stream, folder, (flags ? flags : NIL), NIL,&st)) {=0A> + if (mai= l_append_full(imap_le_struct->imap_stream, folder, (flags ? flags : NIL), (= date ? date : NIL),&st)) {=0A> RETURN_TRUE;=0A> } e= lse {=0A> RETURN_FALSE;=0A>=0A>=0A>=0A> Thanks,=0A>=0A> - N= ick Fortenberry=0A>=0A>=0A>=0A=0A