Skip to content
This repository has been archived by the owner on Jan 29, 2021. It is now read-only.

Commit

Permalink
Parse the invalid foo@bar <baz@yow> as if it were "foo@bar" <baz@yow>.
Browse files Browse the repository at this point in the history
  • Loading branch information
matta committed Dec 1, 2008
1 parent 51b8d23 commit b3a4296
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
18 changes: 15 additions & 3 deletions lib/rmail/address.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#--
# Copyright (C) 2001, 2002, 2003 Matt Armstrong. All rights
# Copyright (C) 2001, 2002, 2003, 2008 Matt Armstrong. All rights
# reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -50,7 +50,6 @@ class Address
# is parsed for mail addresses and if one is found, it is used to
# initialize this object.
def initialize(string = nil)

@local = @domain = @comments = @display_name = nil

if string.kind_of?(String)
Expand Down Expand Up @@ -421,7 +420,6 @@ def address
# local-part ':' -> it is a display-name of a group
# display-name '<' -> it is a mailbox display name
# display-name ':' -> it is a group display name
#

# set lookahead to '@' '<' or ':' (or another value for
# invalid input)
Expand Down Expand Up @@ -472,6 +470,20 @@ def mailbox(lookahead)
@addresses.last.local = get_text
expect(SYM_AT_SIGN)
domain

if @sym == SYM_LESS_THAN
# Workaround for invalid input. Treat 'foo@bar <foo@bar>' as if it
# were '"foo@bar" <foo@bar>'. The domain parser will eat
# 'bar' but stop at '<'. At this point, we've been
# parsing the display name as if it were an address, so we
# throw the address into display_name and parse an
# angle_addr.
@addresses.last.display_name =
format("%s@%s", @addresses.last.local, @addresses.last.domain)
@addresses.last.local = nil
@addresses.last.domain = nil
angle_addr
end
end
end

Expand Down
20 changes: 16 additions & 4 deletions test/testaddress.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby
#--
# Copyright (C) 2001, 2002, 2003, 2007 Matt Armstrong. All rights reserved.
# Copyright (C) 2001, 2002, 2003, 2007, 2008 Matt Armstrong. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
Expand Down Expand Up @@ -419,7 +419,7 @@ def test_majordomoII
:format => '"Jason @ Tibbitts" <[email protected]>' } ] ]

# Majordomo II parses all of these with an error. We have deleted
# some of the tests since when they are actually legal.
# some of the tests when they are actually legal.
validate_case ['[email protected] Jason Tibbitts', [] ]
validate_case ['@uh.edu', [] ] # Can't start with @
validate_case ['J <tibbs>', [] ] # Not FQDN
Expand Down Expand Up @@ -644,7 +644,6 @@ def test_mailtools_suite()
end

def test_rfc_822

validate_case\
['":sysmail"@ Some-Group. Some-Org, Muhammed.(I am the greatest) Ali @(the)Vegas.WBA',
[ { :name => nil,
Expand All @@ -664,7 +663,6 @@ def test_rfc_822
end

def test_misc_addresses()

# Make sure that parsing empty stuff works
assert_equal([], RMail::Address.parse(nil))
assert_equal([], RMail::Address.parse(""))
Expand Down Expand Up @@ -794,6 +792,20 @@ def test_misc_addresses()
} ] ]
end

def test_bug_1754
# http://rubyforge.org/tracker/?func=detail&atid=1754&aid=23043&group_id=446
validate_case\
['[email protected]?= <[email protected]>',
[ { :name => '[email protected]?=',
:display_name => '[email protected]?=',
:address => '[email protected]',
:comments => nil,
:domain => 'example.com',
:local => 'acme',
:format => '"[email protected]?=" <[email protected]>',
} ] ]
end

def test_invalid_addresses()
# The display name isn't encoded -- bad, but we parse it.
validate_case\
Expand Down

0 comments on commit b3a4296

Please sign in to comment.