Permalink
Browse files

Now functional at a basic level, start writing tests

  • Loading branch information...
1 parent f3fbb2d commit 5c6ebc3db099a3bc7efab1bf3034b5b2796ca966 @retupmoca retupmoca committed Feb 13, 2012
View
18 README
@@ -1,3 +1,19 @@
This is my attempt at porting Email::Simple from perl 5 to perl 6 (mostly just because I can)
-It is currently in a non-functional state.
+It will currently parse some simple emails, at least, although there are unimplemented functions.
+
+DIFFERENCES FROM PERL 5'S EMAIL::SIMPLE
+---------------------------------------
+I've tried to keep the api the same, with one exception:
+$mail.header-pairs now returns an array of arrays instead of a flat array.
+
+TODO
+----
+* write more tests
+* implement the following functions:
+** Email::Simple
+*** create
+** Email::Simple::Header
+*** header
+*** header-set
+* Allow for user to specify their own header class
View
@@ -7,26 +7,26 @@ has $!header;
has $!crlf;
grammar Message {
- token TOP {
+ regex TOP {
<headers>
<newline>
<body>
}
token newline {
- "\n" | "\r" | "\r\n" | "\n\r"
+ \n | \r | \r\n | \n\r
}
token body {
.*
}
- token headers {
- .* <newline>
+ regex headers {
+ .*? <newline>
}
}
method new (Str $text) {
my $parsed = Message.parse($text);
- my $header-object = Email::Simple::Header.new($parsed<headers>, crlf => $parsed<newline>);
- self.bless(*, body => $parsed<body>, header => $header-object, crlf => $parsed<newline>);
+ my $header-object = Email::Simple::Header.new(~$parsed<headers>, crlf => ~$parsed<newline>);
+ self.bless(*, body => $parsed<body>, header => $header-object, crlf => ~$parsed<newline>);
}
method create (:$header, :$body) {
@@ -4,30 +4,34 @@ has $!crlf;
has @!headers;
grammar Headers {
- token TOP {
- <name>: \s* <value> <newline>
+ regex TOP {
+ <entry>+
+ }
+ regex entry {
+ <name>\: \s* <value> <newline>
}
token name {
- [^: ]*
+ <-[: ]>*
}
- token value {
- [^<newline>]*
- ( <newline> \s+ [^:] [^<newline>]* ) *
+ regex value {
+ \N*
+ (<newline> \s+ \N*)?
}
token newline {
- "\n" | "\r" | "\r\n" | "\n\r"
+ \n | \r | \r\n | \n\r
}
}
method new ($header-text, :$crlf = "\r\n") {
-
my $parsed = Headers.parse($header-text);
+ my @entries = $parsed<entry>;
my @headers;
- for 1..+@parsed<name> {
- my $name = @parsed<name>[$_];
- my $value = @parsed<value>[$_];
- $value ~~ s/\s*$crlf\s*/ /g;
- push(@headers, [$name, $value]);
+ for @entries {
+ my $name = $_<name>;
+ my $value = $_<value>;
+ $value = $value.Str;
+ $value ~~ s:g/\s* $crlf \s*/ /;
+ push(@headers, [~$name, $value]);
}
self.bless(*, crlf => $crlf, headers => @headers);
@@ -48,11 +52,17 @@ method as-string {
method Str { self.as-string }
method header-names {
-
+ my @names = gather {
+ for @!headers {
+ take $_[0];
+ }
+ }
+
+ return @names;
}
method header-pairs {
-
+ return @!headers;
}
method header ($name) {
View
@@ -0,0 +1,15 @@
+use v6;
+use Test;
+
+BEGIN { @*INC.push: './lib'; }
+
+use Email::Simple;
+
+my $mail-text = slurp './t/test-mails/josey-nofold';
+
+my $mail = Email::Simple.new($mail-text);
+
+plan 1;
+
+my $old-from;
+is $old-from = $mail.header('From'), 'Andrew Josey <ajosey@rdg.opengroup.org>', "We can get a header";
View
@@ -0,0 +1,48 @@
+Return-Path: <sundar@foo.com>
+Received: from murder ([unix socket])
+ (authenticated user=adam bits=0)
+ by mail1.foo.com (Cyrus v2.2.12-OS X 10.4.0) with LMTPA;
+ Tue, 25 Oct 2005 07:26:59 -0400
+X-Sieve: CMU Sieve 2.2
+X-Original-To: adam@mail1.internal.foo.com
+Delivered-To: adam@mail1.internal.foo.com
+Received: from localhost (localhost [127.0.0.1])
+ by mail1.foo.com (Postfix) with ESMTP id C24ABADEA15
+ for <adam@mail1.internal.foo.com>; Tue, 25 Oct 2005 07:26:58 -0400 (EDT)
+Received: from mail1.foo.com ([127.0.0.1])
+ by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP
+ id 20330-05 for <adam@mail1.internal.foo.com>;
+ Tue, 25 Oct 2005 07:26:55 -0400 (EDT)
+Received: from mta.internal.foo.com (mta.internal.foo.com [0.0.0.0])
+ by mail1.foo.com (Postfix) with ESMTP id 1D919ADE9FE
+ for <adam@mail1.internal.foo.com>; Tue, 25 Oct 2005 07:26:55 -0400 (EDT)
+Received: from [0.0.0.0] ([0.0.0.0])
+ (authenticated bits=0)
+ by mta.internal.foo.com (8.12.8/8.12.8) with ESMTP id j9PBQoCT026374
+ (version=TLSv1/SSLv3 cipher=RC4-MD5 bits=128 verify=NO)
+ for <adam@foo.com>; Tue, 25 Oct 2005 07:26:53 -0400
+Message-ID: <blah@foo.com>
+Date: Tue, 25 Oct 2005 07:30:17 -0400
+From: x <x@foo.com>
+Reply-To: x@foo.com
+User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)
+X-Accept-Language: en-us, en
+MIME-Version: 1.0
+To: Adam Worrall <adam@foo.com>
+Subject: My subject
+X-Enigmail-Version: 0.91.0.0
+Content-Type: multipart/mixed;
+ boundary="------------040701020305070002070307"
+X-PMX-Version: 4.6.1.107272
+X-Virus-Scanned: by amavisd-new at foo.com
+
+This is a multi-part message in MIME format.
+--------------040701020305070002070307
+Content-Type: text/plain; charset=ISO-8859-1
+Content-Transfer-Encoding: 7bit
+
+Blah blah
+
+--------------040701020305070002070307--
+
+
@@ -0,0 +1,6 @@
+Bar: Bar
+Badly-Folded: This header is badly folded because even though it goes onto the
+second line, it has no indent.
+Foo: Foo
+
+This is the body!
View
@@ -0,0 +1,106 @@
+From mail-miner-10529@localhost Wed Dec 18 12:07:55 2002
+Received: from mailman.opengroup.org ([192.153.166.9])
+ by deep-dark-truthful-mirror.pad with smtp (Exim 3.36 #1 (Debian))
+ id 18Buh5-0006Zr-00
+ for <posix@simon-cozens.org>; Wed, 13 Nov 2002 10:24:23 +0000
+Received: (qmail 1679 invoked by uid 503); 13 Nov 2002 10:10:49 -0000
+Resent-Date: 13 Nov 2002 10:10:49 -0000
+Date: Wed, 13 Nov 2002 10:06:51 GMT
+From: Andrew Josey <ajosey@rdg.opengroup.org>
+Message-Id: <1021113100650.ZM12997@skye.rdg.opengroup.org>
+In-Reply-To: Joanna Farley's message as of Nov 13, 9:56am.
+References:
+ <200211120937.JAA28130@xoneweb.opengroup.org>
+ <1021112125524.ZM7503@skye.rdg.opengroup.org>
+ <3DD221BB.13116D47@sun.com>
+X-Mailer: Z-Mail (5.0.0 30July97)
+To: austin-group-l@opengroup.org
+Subject: Re: Defect in XBD lround
+MIME-Version: 1.0
+Resent-Message-ID: <gZGK1B.A.uY.iUi09@mailman>
+Resent-To: austin-group-l@opengroup.org
+Resent-From: austin-group-l@opengroup.org
+X-Mailing-List: austin-group-l:archive/latest/4823
+X-Loop: austin-group-l@opengroup.org
+Precedence: list
+Resent-Sender: austin-group-l-request@opengroup.org
+Content-Type: text/plain; charset=us-ascii
+
+Joanna, All
+
+Thanks. I got the following response from Fred Tydeman.
+
+C99 Defect Report (DR) 240 covers this. The main body of C99
+(7.12.9.7) says range error, while Annex F (F.9.6.7 and F.9.6.5)
+says "invalid" (domain error). The result was to change 7.12.9.7
+to allow for either range or domain error. The preferred error
+is domain error (so as match Annex F). So, no need to change XBD.
+
+regards
+Andrew
+
+On Nov 13, 9:56am in "Re: Defect in XBD lr", Joanna Farley wrote:
+> Sun's expert in this area after some discussions with a colleague
+> outside of Sun concluded that for lround, to align with both C99 and SUS
+> changes of the following form were necessary:
+>
+> + If x is +/-Inf/NaN, a domain error occurs, and
+> + errno is set to EDOM in MATH_ERRNO mode;
+> + the invalid exception is raised in MATH_ERREXCEPT mode.
+> [to align with C99 Annex F.4]
+>
+> + If x is too large to be represented as a long, a *range* error
+> may occur, and
+> + errno *may be* set to ERANGE in MATH_ERRNO mode;
+> [to align with C99 7.12.9.7]
+> + the invalid exception *is* raised in MATH_ERREXCEPT mode.
+> [to align with C99 Annex F.4]
+>
+> They believe it is a bit awkward to have errno set to ERANGE in
+> MATH_ERRNO mode yet the invalid exception raised in MAH_ERREXCEPT mode,
+> but that just reflects an imperfect mapping of the C notion of errno to
+> the IEEE 754 notion of data conversion.
+>
+> I'll work with our expert to draft text refecting the above to suggest
+> replacement text for lines 23678-23684 on lround page 721 of XSH6.
+>
+> Thanks
+>
+> Joanna
+>
+>
+> Andrew Josey wrote:
+> >
+> > The text referred to is MX shaded and part of the ISO 60559 floating
+> > point option. I do not think changing the Domain Error to a Range Error
+> > is the fix or at least not the fix for the NaN and +-Inf cases. ISO C
+> > 99 describes the range error case if the magnitude of x is too large as a
+> > may fail. I'll ask Fred T for his thoughts on this one...
+> > regards
+> > Andrew
+> >
+> > On Nov 12, 9:37am in "Defect in XBD lround", Erwin.Unruh@fujitsu-siemens.com wrote:
+> > > Defect report from : Erwin Unruh , Fujitsu Siemens Computers
+> > >
+> > > (Please direct followup comments direct to austin-group-l@opengroup.org)
+> > >
+> > > @ page 0 line 0 section lround objection {0}
+> > >
+> > > Problem:
+> > >
+> > > Defect code : 1. Error
+> > >
+> > > The function lround is described in http://www.opengroup.org/onlinepubs/007904975/functions/lround.html
+> > > On Error it is specified that errno has to be set to EDOM. However, the C99 standard ISO/IEC 9899:1999 (E) specifies this as a range error, which would result in a value of ERANGE. So an implementation could not be conformant to both these standards.
+> > >
+> > > Action:
+> > >
+> > > Change the value of errno to ERANGE, if the result is not represantable. More specific: In the description of the function, replace all occurences of "domain error" with "range error" and replace "EDOM" with "ERANGE"
+> > >-- End of excerpt from Erwin.Unruh@fujitsu-siemens.com
+> >
+
+-----
+Andrew Josey The Open Group
+Austin Group Chair Apex Plaza,Forbury Road,
+Email: a.josey@opengroup.org Reading,Berks.RG1 1AX,England
+Tel: +44 118 9508311 ext 2250 Fax: +44 118 9500110
View
@@ -0,0 +1,18 @@
+Received: (qmail 1679 invoked by uid 503); 13 Nov 2002 10:10:49 -0000
+Resent-Date: 13 Nov 2002 10:10:49 -0000
+Date: Wed, 13 Nov 2002 10:06:51 GMT
+From: Andrew Josey <ajosey@rdg.opengroup.org>
+Message-Id: <1021113100650.ZM12997@skye.rdg.opengroup.org>
+In-Reply-To: Joanna Farley's message as of Nov 13, 9:56am.
+X-Mailer: Z-Mail (5.0.0 30July97)
+To: austin-group-l@opengroup.org
+Subject: Re: Defect in XBD lround
+MIME-Version: 1.0
+Resent-Message-ID: <gZGK1B.A.uY.iUi09@mailman>
+Resent-To: austin-group-l@opengroup.org
+Resent-From: austin-group-l@opengroup.org
+X-Mailing-List: austin-group-l:archive/latest/4823
+X-Loop: austin-group-l@opengroup.org
+Precedence: list
+Resent-Sender: austin-group-l-request@opengroup.org
+Content-Type: text/plain; charset=us-ascii
@@ -0,0 +1,19 @@
+Received: (qmail 1679 invoked by uid 503); 13 Nov 2002 10:10:49 -0000
+Resent-Date: 13 Nov 2002 10:10:49 -0000
+Date: Wed, 13 Nov 2002 10:06:51 GMT
+From: Andrew Josey <ajosey@rdg.opengroup.org>
+Message-Id: <1021113100650.ZM12997@skye.rdg.opengroup.org>
+In-Reply-To: Joanna Farley's message as of Nov 13, 9:56am.
+X-Mailer: Z-Mail (5.0.0 30July97)
+To: austin-group-l@opengroup.org
+Subject: Re: Defect in XBD lround
+MIME-Version: 1.0
+Resent-Message-ID: <gZGK1B.A.uY.iUi09@mailman>
+Resent-To: austin-group-l@opengroup.org
+Resent-From: austin-group-l@opengroup.org
+X-Mailing-List: austin-group-l:archive/latest/4823
+X-Loop: austin-group-l@opengroup.org
+Precedence: list
+Resent-Sender: austin-group-l-request@opengroup.org
+Content-Type: text/plain; charset=us-ascii
+
Oops, something went wrong.

0 comments on commit 5c6ebc3

Please sign in to comment.