Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Resolved Issue #10 - empty/nil cc/bcc field causes exception (Mail::F…

…ield::ParseError)
  • Loading branch information...
commit d596fa65ccc404114193a5fa10c8d2fbd4602bdc 1 parent 651713a
Mikel Lindsaar authored
4 CHANGELOG.rdoc
View
@@ -1,3 +1,7 @@
+== Sat Nov 14 08:20:21 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
+
+* Resolved Issue #10 - empty/nil cc/bcc field causes exception (Mail::Field::ParseError)
+
== Fri Nov 13 00:31:04 UTC 2009 Mikel Lindsaar <raasdnil@gmail.com>
* Hacked and mutilated the network section, made it easier to extend out with other
4 lib/mail/elements/address_list.rb
View
@@ -18,6 +18,10 @@ class AddressList # :nodoc:
# a.addresses #=> [#<Mail::Address:14943130 Address: |ada@test.lindsaar.net...
# a.group_names #=> ["My Group"]
def initialize(string)
+ if string.blank?
+ @address_nodes = []
+ return self
+ end
parser = Mail::AddressListsParser.new
if tree = parser.parse(string)
@address_nodes = tree.addresses
3  lib/mail/fields/common/common_address.rb
View
@@ -47,7 +47,7 @@ def group_names # :nodoc:
private
def do_encode(field_name)
- return '' unless value
+ return '' if value.blank?
address_array = tree.addresses.reject { |a| group_addresses.include?(a.encoded) }.compact.map { |a| a.encoded }
address_text = address_array.join(", \r\n\t")
group_array = groups.map { |k,v| "#{k}: #{v.map { |a| a.encoded }.join(", \r\n\t")};" }
@@ -57,6 +57,7 @@ def do_encode(field_name)
end
def do_decode
+ return nil if value.blank?
address_array = tree.addresses.reject { |a| group_addresses.include?(a.decoded) }.map { |a| a.decoded }
address_text = address_array.join(", ")
group_array = groups.map { |k,v| "#{k}: #{v.map { |a| a.decoded }.join(", ")};" }
7 spec/mail/elements/address_list_spec.rb
View
@@ -10,9 +10,14 @@
end
it "should raise an error if the input is useless" do
- parse_text = nil
+ parse_text = '@@@@@@'
doing { Mail::AddressList.new(parse_text) }.should raise_error
end
+
+ it "should not raise an error if the input is just blank" do
+ parse_text = nil
+ doing { Mail::AddressList.new(parse_text) }.should_not raise_error
+ end
it "should raise an error if the input is useless" do
parse_text = "This ( is an invalid address!"
14 spec/mail/fields/common/common_address_spec.rb
View
@@ -42,6 +42,20 @@
field.group_addresses.should == ['test2@lindsaar.net', 'me@lindsaar.net']
end
+ it "should handle initializing as an empty string" do
+ field = Mail::ToField.new("To", "")
+ field.addresses.should == []
+ field.value = 'mikel@test.lindsaar.net'
+ field.addresses.should == ['mikel@test.lindsaar.net']
+ end
+
+ it "should encode to an empty string if it has no addresses or groups" do
+ field = Mail::ToField.new("To", "")
+ field.encoded.should == ''
+ field.value = 'mikel@test.lindsaar.net'
+ field.encoded.should == "To: mikel@test.lindsaar.net\r\n"
+ end
+
end
describe "encoding and decoding fields" do
7 spec/mail/message_spec.rb
View
@@ -1432,6 +1432,13 @@ def basic_email
end
mail.destinations.length.should == 1
end
+
+ it "should be able to encode with only one destination" do
+ mail = Mail.new do
+ to 'mikel@test.lindsaar.net'
+ end
+ mail.encoded
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.