lib/rmail/address.rb in rmail-1.0.0 vs lib/rmail/address.rb in rmail-1.1.0
- old
+ new
@@ -1,7 +1,7 @@
#--
-# 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
# modification, are permitted provided that the following conditions are met:
#
@@ -48,11 +48,10 @@
# Create a new address. If the +string+ argument is not nil, it
# 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)
addrs = Address.parse(string)
if addrs.length > 0
@@ -419,11 +418,10 @@
# local-part '@' -> it is a local part of a local-part @ domain
# local-part '<' -> it is a display-name of a mailbox
# 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)
lookahead = address_lookahead
@@ -470,10 +468,24 @@
word
end
@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
# Parse this:
# group = word {word | "."} SYNC ":" [mailbox_list] SYNC ";"
@@ -689,10 +701,10 @@
when /\A(\[.*?([^\\]|\\\\)\])/m
@string = $'
@sym = SYM_DOMAIN_LITERAL
@lexeme = $1.gsub(/(^|[^\\])[\r\n\t ]+/, '\1').gsub(/\\(.)/, '\1')
break
- when /\A[\200-\377\w!$%&\'*+\/=?^_\`{\}|~#-]+/m
+ when /\A[\200-\377\w!$%&\'*+\/=?^_\`{\}|~#-]+/nm
# This is just like SYM_ATOM, but includes all characters
# with high bits. This is so we can allow such tokens in
# the display name portion of an address even though it
# violates the RFCs.
@string = $'