NetBSD Problem Report #47453

From www@NetBSD.org  Tue Jan 15 17:11:36 2013
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [149.20.53.66])
	by www.NetBSD.org (Postfix) with ESMTP id 2154C63D7B3
	for <gnats-bugs@gnats.NetBSD.org>; Tue, 15 Jan 2013 17:11:36 +0000 (UTC)
Message-Id: <20130115171135.28CF363D7B3@www.NetBSD.org>
Date: Tue, 15 Jan 2013 17:11:35 +0000 (UTC)
From: martin@martinbrandenburg.com
Reply-To: martin@martinbrandenburg.com
To: gnats-bugs@NetBSD.org
Subject: Mail (mail, mailx) does not recognize messages which have RFC 822 format dates.
X-Send-Pr-Version: www-1.0

>Number:         47453
>Category:       bin
>Synopsis:       Mail (mail, mailx) does not recognize messages which have RFC 822 format dates.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 15 17:15:00 +0000 2013
>Last-Modified:  Wed Jan 16 15:25:02 +0000 2013
>Originator:     Martin Brandenburg
>Release:        6.0.1
>Organization:
>Environment:
NetBSD [hostname] 6.0.1 NetBSD 6.0.1 (XEN3_DOMU) amd64
>Description:
The BSD mail program (mail, mailx, Mail) does not recognize mailboxes with From headers containing RFC 822 format dates. Such files are generated by uw-imap, popular Python mail scripts, and probably by many others.

Examples of corrent and offending headers follow:
From address Tue Jan 15 16:49:46 2013
From address Tue Jan 15 10:06:37 2013 +0000

Mail silently drops any messages with headers in the latter format.

As no standard for the format of mailbox files exists and in the interests of interoperability, mail should accept such formats.
>How-To-Repeat:
Generate such a mailbox, either by hand or with uw-imap's mailutil. Run mail -f mbox on it and observe the dropped messages.
>Fix:
Index: usr.bin/mail/head.c
===================================================================
RCS file: /cvsroot/src/usr.bin/mail/head.c,v
retrieving revision 1.22
diff -r1.22 head.c
88a89,92
> 		case '+':
> 			if (*cp++ != '+' && *cp != '-')
> 				return 0;
> 			break;
110a115
>  * '+'	A plus or minus sign
115a121,122
> static char rfc822type[] = "Aaa Aaa O0 00:00:00 0000 +0000";
> static char rfc822alttype[] = "Aaa Aaa O0 00:00:00 0000 AAA";
123c130,131
< 	       cmatch(date, SysV_tmztype) || cmatch(date, SysV_ctype);
---
> 	       cmatch(date, SysV_tmztype) || cmatch(date, SysV_ctype) ||
> 	       cmatch(date, rfc822type) || cmatch(date, rfc822alttype);

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/47453 CVS commit: src/usr.bin/mail
Date: Tue, 15 Jan 2013 12:25:42 -0500

 Module Name:	src
 Committed By:	christos
 Date:		Tue Jan 15 17:25:42 UTC 2013

 Modified Files:
 	src/usr.bin/mail: head.c

 Log Message:
 PR/47453: Martin Branderburg: Mail (mail, mailx) does not recognize messages
 which have RFC 822 format dates.
 XXX: Pullup 6


 To generate a diff of this commit:
 cvs rdiff -u -r1.22 -r1.23 src/usr.bin/mail/head.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: christos@zoulas.com (Christos Zoulas)
To: gnats-bugs@NetBSD.org, gnats-admin@netbsd.org, netbsd-bugs@netbsd.org
Cc: 
Subject: Re: bin/47453: Mail (mail, mailx) does not recognize messages which have RFC 822 format dates.
Date: Tue, 15 Jan 2013 12:27:14 -0500

 On Jan 15,  5:15pm, martin@martinbrandenburg.com (martin@martinbrandenburg.com) wrote:
 -- Subject: bin/47453: Mail (mail, mailx) does not recognize messages which h

 | diff -r1.22 head.c
 | 88a89,92
 | > 		case '+':
 | > 			if (*cp++ != '+' && *cp != '-')
 | > 				return 0;

 Thanks a lot, applied.  This is wrong, because ++ will increment
 before the match for '-'. Also in the future please send diff -u
 output, because the standard diff is not too reliable if the file
 changes.

 Best,

 christos

From: Steffen "Daode" Nurpmeso <sdaoden@gmail.com>
To: gnats-bugs@NetBSD.org
Cc: gnats-admin@netbsd.org, martin@martinbrandenburg.com,
 netbsd-bugs@netbsd.org
Subject: Re: PR/47453 CVS commit: src/usr.bin/mail
Date: Wed, 16 Jan 2013 15:43:39 +0100

 "Christos Zoulas" <christos@netbsd.org> wrote:
  |The following reply was made to PR bin/47453; it has been noted by GN=
 ATS.
  |
  |From: "Christos Zoulas" <christos@netbsd.org>
  |To: gnats-bugs@gnats.NetBSD.org
  |Cc:=20
  |Subject: PR/47453 CVS commit: src/usr.bin/mail
  |Date: Tue, 15 Jan 2013 12:25:42 -0500
  |
  | Module Name:=09src
  | Committed By:=09christos
  | Date:=09=09Tue Jan 15 17:25:42 UTC 2013
  |=20
  | Modified Files:
  | =09src/usr.bin/mail: head.c
  |=20
  | Log Message:
  | PR/47453: Martin Branderburg: Mail (mail, mailx) does not recognize =
 \
  |messages
  | which have RFC 822 format dates.

 Your commit supports zone-style RFC 822 dates.  RFC 5322 marks
 this zone-style as obsolete (obs-zone), but still supports it.
 But then, even if you don't wanna support military style
 single-letter zones, the UT zone exists and will not be supported
 by this commit.

 I'll append a diff that is not correct (since not all possible
 single-letter zones are assigned, and only *UT* has two letters),
 but which will match all thre possible *obs-zone* forms.
 Compiled and tested on a single MBOX.

 Thanks all beside that, my one goofed too.

 --steffen

 --- head.c.orig=092013-01-16 15:25:41.000000000 +0100
 +++ head.c=092013-01-16 15:30:51.000000000 +0100
 @@ -115,23 +115,42 @@ cmatch(const char *cp, const char *tp)
   * 'N'=09A new line
   * '+'=09A plus or minus sign
   */
 -static const char *datetypes[] =3D {
 - =09"Aaa Aaa O0 00:00:00 0000",=09=09/* BSD ctype */
 -=09"Aaa Aaa O0 00:00 0000",=09=09/* SysV ctype */
 -=09"Aaa Aaa O0 00:00:00 AAA 0000",=09=09/* BSD tmztype */
 -=09"Aaa Aaa O0 00:00 AAA 0000",=09=09/* SysV tmztype */
 -=09"Aaa Aaa O0 00:00:00 0000 +0000",=09/* RFC822 type */
 -=09"Aaa Aaa O0 00:00:00 0000 AAA",=09=09/* RFC822 alttype */
 +static struct cmatch_data {
 +=09size_t=09=09tlen;
 +=09char const=09*tdata;
 +} const=09_cmatch_data[] =3D {
 +=09{ 24, "Aaa Aaa O0 00:00:00 0000" },=09=09/* BSD ctype */
 +=09{ 21, "Aaa Aaa O0 00:00 0000" },=09=09/* SysV ctype */
 +=09{ 28, "Aaa Aaa O0 00:00:00 AAA 0000" },=09=09/* BSD tmztype */
 +=09{ 25, "Aaa Aaa O0 00:00 AAA 0000" },=09=09/* SysV tmztype */
 +=09/*
 +=09 * RFC 822-alike From_ lines do not conform to RFC 4155, but seem t=
 o
 +=09 * be used in the wild by UW-imap (MBX format plus)
 +=09 */
 +=09{ 30, "Aaa Aaa O0 00:00:00 0000 +0000" },=09/* RFC822, UT offset */
 +=09/* RFC 822 with zone spec; 1. military, 2. UT, 3. north america tim=
 e
 +=09 * zone strings; note that 1. is strictly speaking not correct as s=
 ome
 +=09 * letters are not used */
 +=09{ 28 - 2, "Aaa Aaa O0 00:00:00 0000 A" },
 +=09{ 28 - 1, "Aaa Aaa O0 00:00:00 0000 AA" },
 +        { 28 - 0, "Aaa Aaa O0 00:00:00 0000 AAA" },
 +=09{ 0, NULL }
  };
 +#define _CMATCH_MINLEN=0921
 =20
  static int
  isdate(const char date[])
  {
 -
 -=09for (size_t i =3D 0; i < __arraycount(datetypes); i++)
 -=09=09if (cmatch(date, datetypes[i]))
 -=09=09=09return 1;
 -=09return 0;
 +=09struct cmatch_data const *cmdp;
 +=09size_t dl =3D strlen(date);
 +=09int ret =3D 0;
 +
 +=09if (dl >=3D _CMATCH_MINLEN)
 +=09=09for (cmdp =3D _cmatch_data; cmdp->tdata !=3D NULL; ++cmdp)
 +=09=09=09if (dl =3D=3D cmdp->tlen &&
 +=09=09=09=09=09(ret =3D cmatch(date, cmdp->tdata)))
 +=09=09=09=09break;
 +=09return ret;
  }
 =20
  static void

From: christos@zoulas.com (Christos Zoulas)
To: Steffen "Daode" Nurpmeso <sdaoden@gmail.com>, gnats-bugs@NetBSD.org
Cc: gnats-admin@netbsd.org, martin@martinbrandenburg.com, 
	netbsd-bugs@netbsd.org
Subject: Re: PR/47453 CVS commit: src/usr.bin/mail
Date: Wed, 16 Jan 2013 10:22:54 -0500

 On Jan 16,  3:43pm, sdaoden@gmail.com (Steffen "Daode" Nurpmeso) wrote:
 -- Subject: Re: PR/47453 CVS commit: src/usr.bin/mail

 | Your commit supports zone-style RFC 822 dates.  RFC 5322 marks
 | this zone-style as obsolete (obs-zone), but still supports it.
 | But then, even if you don't wanna support military style
 | single-letter zones, the UT zone exists and will not be supported
 | by this commit.
 | 
 | I'll append a diff that is not correct (since not all possible
 | single-letter zones are assigned, and only *UT* has two letters),
 | but which will match all thre possible *obs-zone* forms.
 | Compiled and tested on a single MBOX.
 | 
 | Thanks all beside that, my one goofed too.

 Thanks a lot, added.

 christos

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.