Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem parsing mail #29

Closed
lls opened this issue Feb 1, 2010 · 3 comments
Closed

Problem parsing mail #29

lls opened this issue Feb 1, 2010 · 3 comments

Comments

@lls
Copy link

lls commented Feb 1, 2010

Using Email gem mail 2.1.2, I have problems parsing a mail with "From" in the body and some dots in a concrete order. If I change the "From" for a "from" it works. Here an example (first one fails, second one works):

require 'rubygems'
require 'mail'
mail = Mail.new("Subject: Welcome\nFrom: Test <test@test.com>\nTo: test@test.com\nContent-Type: text/plain\nMime-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\nFrom .\n.\n\n")
puts mail.subject
mail2 = Mail.new("Subject: Welcome\nFrom: Test <test@test.com>\nTo: test@test.com\nContent-Type: text/plain\nMime-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\nfrom .\n.\n\n")
puts mail2.subject

the output is:

$ irb
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'mail'
=> true
irb(main):003:0> mail = Mail.new("Subject: Welcome\nFrom: Test <test@test.com>\nTo: test@test.com\nContent-Type: text/plain\nMime-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\nFrom .\n.\n\n")
=> #<Mail::Message:0x7f14ab81fd00 @raw_envelope=".", @perform_deliveries=true, @delivery_notification_observers=[], @html_part=nil, @delivery_handler=nil, @raw_source=".", @text_part=nil, @header=#<Mail::Header:0x7f14ab81f120 @fields=[#<Mail::Field:0x7f14ab81edb0 @field=#<Mail::OptionalField:0x7f14ab81ed10 @value=nil, @length=nil, @element=nil, @name=".", @tree=nil>>], @raw_source=".", @unfolded_header=".">, @envelope=#<Mail::Envelope:0x7f14ab81f3f0 @value=".", @length=nil, @element=nil, @name=/[!-9;-~]+/, @tree=nil>, @delivery_method=#<Mail::SMTP:0x7f14ab81fc38 @settings={:user_name=>nil, :enable_starttls_auto=>true, :authentication=>nil, :address=>"localhost", :password=>nil, :port=>25, :domain=>"localhost.localdomain"}>, @raise_delivery_errors=true, @body=#<Mail::Body:0x7f14ab81ee50 @charset="US-ASCII", @preamble=nil, @boundary=nil, @encoding=nil, @parts=[], @part_sort_order=["text/plain", "text/enriched", "text/html"], @raw_source="", @epilogue=nil>>
irb(main):004:0> puts mail.subject
nil
=> nil
irb(main):005:0> mail2 = Mail.new("Subject: Welcome\nFrom: Test <test@test.com>\nTo: test@test.com\nContent-Type: text/plain\nMime-Version: 1.0\nContent-Transfer-Encoding: 7bit\n\nfrom .\n.\n\n")
=> #<Mail::Message:0x7f14ab809230 @perform_deliveries=true, @delivery_notification_observers=[], @html_part=nil, @delivery_handler=nil, @raw_source="Subject: Welcome\r\nFrom: Test <test@test.com>\r\nTo: test@test.com\r\nContent-Type: text/plain\r\nMime-Version: 1.0\r\nContent-Transfer-Encoding: 7bit\r\n\r\nfrom .\r\n.", @text_part=nil, @header=#<Mail::Header:0x7f14ab808998 @fields=[#<Mail::Field:0x7f14ab808178 @field=#<Mail::FromField:0x7f14ab807a48 @value="Test <test@test.com>", @length=nil, @element=nil, @name="From", @tree=#<Mail::AddressList:0x7f14ab8078e0 @address_nodes=[SyntaxNode+Address1+NameAddr0 offset=0, "Test <test@test.com>" (angle_addr,comments,display_name,dig_comments):
  SyntaxNode offset=0, "Test ":
    SyntaxNode+Atom0 offset=0, "Test ":
      SyntaxNode+CFWS1 offset=0, "":
    SyntaxNode offset=0, ""
    SyntaxNode offset=0, ""
      SyntaxNode offset=0, "Test":
    SyntaxNode offset=0, "T"
    SyntaxNode offset=1, "e"
    SyntaxNode offset=2, "s"
    SyntaxNode offset=3, "t"
      SyntaxNode+CFWS1 offset=4, " ":
    SyntaxNode offset=4, ""
    SyntaxNode+ObsFWS1 offset=4, " ":
      SyntaxNode offset=4, " ":
        SyntaxNode offset=4, " "
      SyntaxNode offset=5, ""
  SyntaxNode+AngleAddr0 offset=5, "<test@test.com>" (addr_spec):
    SyntaxNode+CFWS1 offset=5, "":
      SyntaxNode offset=5, ""
      SyntaxNode offset=5, ""
    SyntaxNode offset=5, "<"
    SyntaxNode+AddrSpec0 offset=6, "test@test.com" (domain,local_part):
      SyntaxNode+LocalDotAtom0 offset=6, "test" (local_dot_atom_text):
    SyntaxNode+CFWS1 offset=6, "":
      SyntaxNode offset=6, ""
      SyntaxNode offset=6, ""
    SyntaxNode offset=6, "test":
      SyntaxNode+LocalDotAtomText0 offset=6, "test" (domain_text):
        SyntaxNode offset=6, ""
        SyntaxNode offset=6, "test":
          SyntaxNode offset=6, "t"
          SyntaxNode offset=7, "e"
          SyntaxNode offset=8, "s"
          SyntaxNode offset=9, "t"
    SyntaxNode+CFWS1 offset=10, "":
      SyntaxNode offset=10, ""
      SyntaxNode offset=10, ""
      SyntaxNode offset=10, "@"
      SyntaxNode+DotAtom0 offset=11, "test.com" (dot_atom_text):
    SyntaxNode+CFWS1 offset=11, "":
      SyntaxNode offset=11, ""
      SyntaxNode offset=11, ""
    SyntaxNode offset=11, "test.com":
      SyntaxNode+DotAtomText0 offset=11, "test." (domain_text):
        SyntaxNode offset=11, "test":
          SyntaxNode offset=11, "t"
          SyntaxNode offset=12, "e"
          SyntaxNode offset=13, "s"
          SyntaxNode offset=14, "t"
        SyntaxNode offset=15, "."
      SyntaxNode+DotAtomText0 offset=16, "com" (domain_text):
        SyntaxNode offset=16, "com":
          SyntaxNode offset=16, "c"
          SyntaxNode offset=17, "o"
          SyntaxNode offset=18, "m"
        SyntaxNode offset=19, ""
    SyntaxNode+CFWS1 offset=19, "":
      SyntaxNode offset=19, ""
      SyntaxNode offset=19, ""
    SyntaxNode offset=19, ">"
    SyntaxNode+CFWS1 offset=20, "":
      SyntaxNode offset=20, ""
      SyntaxNode offset=20, ""]>>>, #<Mail::Field:0x7f14ab7fb270 @field=#<Mail::ToField:0x7f14ab7faf78 @value="test@test.com", @length=nil, @element=nil, @name="To", @tree=#<Mail::AddressList:0x7f14ab7fae10 @address_nodes=[SyntaxNode+Address1+AddrSpec0 offset=0, "test@test.com" (comments,domain,local_part,dig_comments):
  SyntaxNode+LocalDotAtom0 offset=0, "test" (local_dot_atom_text):
    SyntaxNode+CFWS1 offset=0, "":
      SyntaxNode offset=0, ""
      SyntaxNode offset=0, ""
    SyntaxNode offset=0, "test":
      SyntaxNode+LocalDotAtomText0 offset=0, "test" (domain_text):
    SyntaxNode offset=0, ""
    SyntaxNode offset=0, "test":
      SyntaxNode offset=0, "t"
      SyntaxNode offset=1, "e"
      SyntaxNode offset=2, "s"
      SyntaxNode offset=3, "t"
    SyntaxNode+CFWS1 offset=4, "":
      SyntaxNode offset=4, ""
      SyntaxNode offset=4, ""
  SyntaxNode offset=4, "@"
  SyntaxNode+DotAtom0 offset=5, "test.com" (dot_atom_text):
    SyntaxNode+CFWS1 offset=5, "":
      SyntaxNode offset=5, ""
      SyntaxNode offset=5, ""
    SyntaxNode offset=5, "test.com":
      SyntaxNode+DotAtomText0 offset=5, "test." (domain_text):
    SyntaxNode offset=5, "test":
      SyntaxNode offset=5, "t"
      SyntaxNode offset=6, "e"
      SyntaxNode offset=7, "s"
      SyntaxNode offset=8, "t"
    SyntaxNode offset=9, "."
      SyntaxNode+DotAtomText0 offset=10, "com" (domain_text):
    SyntaxNode offset=10, "com":
      SyntaxNode offset=10, "c"
      SyntaxNode offset=11, "o"
      SyntaxNode offset=12, "m"
    SyntaxNode offset=13, ""
    SyntaxNode+CFWS1 offset=13, "":
      SyntaxNode offset=13, ""
      SyntaxNode offset=13, ""]>>>, #<Mail::Field:0x7f14ab808128 @field=#<Mail::SubjectField:0x7f14ab807e58 @value="Welcome", @length=nil, @element=nil, @name="Subject", @tree=nil>>, #<Mail::Field:0x7f14ab7ee6b0 @field=#<Mail::MimeVersionField:0x7f14ab7ee368 @value="1.0", @length=nil, @element=#<Mail::MimeVersionElement:0x7f14ab7ee1b0 @minor="0", @major="1">, @name="Mime-Version", @tree=nil>>, #<Mail::Field:0x7f14ab7f1dd8 @field=#<Mail::ContentTypeField:0x7f14ab7f1a90 @parameters=nil, @value="text/plain", @length=nil, @element=#<Mail::ContentTypeElement:0x7f14ab7f18b0 @parameters=[], @main_type="text", @sub_type="plain">, @main_type="text", @name="Content-Type", @tree=nil, @sub_type=nil>>, #<Mail::Field:0x7f14ab7ead30 @field=#<Mail::ContentTransferEncodingField:0x7f14ab7ea9c0 @value="7bit", @length=nil, @element=nil, @name="Content-Transfer-Encoding", @tree=nil>>], @raw_source="Subject: Welcome\r\nFrom: Test <test@test.com>\r\nTo: test@test.com\r\nContent-Type: text/plain\r\nMime-Version: 1.0\r\nContent-Transfer-Encoding: 7bit", @unfolded_header="Subject: Welcome\r\nFrom: Test <test@test.com>\r\nTo: test@test.com\r\nContent-Type: text/plain\r\nMime-Version: 1.0\r\nContent-Transfer-Encoding: 7bit">, @delivery_method=#<Mail::SMTP:0x7f14ab8091b8 @settings={:user_name=>nil, :enable_starttls_auto=>true, :authentication=>nil, :address=>"localhost", :password=>nil, :port=>25, :domain=>"localhost.localdomain"}>, @raise_delivery_errors=true, @body=#<Mail::Body:0x7f14ab7eada8 @charset="US-ASCII", @preamble=nil, @boundary=nil, @encoding="7bit", @parts=[], @part_sort_order=["text/plain", "text/enriched", "text/html"], @raw_source="from .\r\n.", @epilogue=nil>>
irb(main):006:0> puts mail2.subject
Welcome
=> nil
irb(main):007:0>
@mikel
Copy link
Owner

mikel commented Feb 5, 2010

I believe this just got fixed with my most recent commit, please check :)

@lls
Copy link
Author

lls commented Feb 8, 2010

I have dowloaded from git and tested. It seems to work fine.

Thanks :)

@mikel
Copy link
Owner

mikel commented Feb 16, 2010

cool

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants