ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> ruby-talk
ruby-talk
RACC and YACC problem in TMail
by Mikel Lindsaar other posts by this author
Oct 21 2007 6:42AM messages near this date
Re: "with" statement | How to obtain the default encoding of system?
Hello all,

I am trying to get outlook email through a small set of programs I
wrote to download/modify/and upload emails.

Problem is, TMail seems to not be handling the Microsoft outlook
Content-Type header declaration, specifically:

> Content-Type: multipart/alternative;
boundary=----=_NextPart_000_0093_01C81419.EB75E850

Where as it can handle the Apple mail (and others) for example:

> Content-Type: multipart/alternative; boundary=Apple-Mail-27--96051287

Works fine.

What TMail does to the outlook ones is simply delete them.  This
produces broken email streams, sometimes running two emails into each
other.

Below is the test case and an ugly hack fix, but the summary is that
TMail is parsing the boundary=(.*)$ and is choking on the second '='.

So I wrote some tests to show this failing with 2 to 4 = signs in the
text to the right of boundary=

diff -r tmail-0.10.8/test/testheader.rb tmail-0.10.9/test/testheader.rb
574a575,593
> 
>      h = TMail::HeaderField.new('Content-Type', 'multipart/alternative; boundary=----=_Next
Part_000_0093_01C81419.EB75E850')
>      assert_equal 'multipart', h.main_type
>      assert_equal 'alternative', h.sub_type
>      assert_equal 1, h.params.size
>      assert_equal '----=_NextPart_000_0093_01C81419.EB75E850', h.params['boundary']
> 
>      h = TMail::HeaderField.new('Content-Type', 'multipart/alternative; boundary=----=_=Nex
tPart_000_0093_01C81419.EB75E850')
>      assert_equal 'multipart', h.main_type
>      assert_equal 'alternative', h.sub_type
>      assert_equal 1, h.params.size
>      assert_equal '----=_=NextPart_000_0093_01C81419.EB75E850', h.params['boundary']
> 
>      h = TMail::HeaderField.new('Content-Type', 'multipart/alternative; boundary=----=_=Nex
tPart_000_0093_01C81419=EB75E850')
>      assert_equal 'multipart', h.main_type
>      assert_equal 'alternative', h.sub_type
>      assert_equal 1, h.params.size
>      assert_equal '----=_=NextPart_000_0093_01C81419=EB75E850', h.params['boundary']
> 


Then I dug through the source code and found the following in a RACC file:

            | params ';' TOKEN '=' value
                {
                  val[0][ val[2].downcase ] = val[4]
                  val[0]
                }

Now... I knew NOTHING of YACC or RACC before tonight... so I started
googling etc.

But the only solution I came up with is this:

diff -r tmail-0.10.8/lib/tmail/parser.y tmail-0.10.9/lib/tmail/parser.y
286a287,304
>              | params ';' TOKEN '=' value '=' value
>                  {
>                    l = val.length
>                    val[0][ val[2].downcase ] = val[4..l].join
>                    val[0]
>                  }
>              | params ';' TOKEN '=' value '=' value '=' value
>                  {
>                    l = val.length
>                    val[0][ val[2].downcase ] = val[4..l].join
>                    val[0]
>                  }
>              | params ';' TOKEN '=' value '=' value '=' value '=' value
>                {
>                  l = val.length
>                  val[0][ val[2].downcase ] = val[4..l].join
>                  val[0]
>                }

The above code makes all the test cases pass but is totally ugly, and a hack.

What I WANT to be able to say is:

params ';' TOKEN '=' and_anything_to_end_of_line
{
  val[0][ val[2].downcase ] = val[4]
  val[0]
}

Are there any YACC / RACC people out there that can provide a cleaner
solution so I can send a real fix to the maintainer of TMail?

Thanks,

Mikel

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved