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

Already on GitHub? Sign in to your account

Exceptions while sending mail. #65

qzz opened this Issue May 23, 2010 · 4 comments


None yet
3 participants

qzz commented May 23, 2010

Exception `NoMethodError' at path-to-gems/mail-2.2.1/lib/mail/field.rb:117 - undefined method `name' for "Content-Transfer-Encoding":String

Multiple such exceptions are displayed when sending mail. This is caused by adding field to FieldList object:
def <<( new_field )
current_entry = self.rindex(new_field.name)

rindex internally calls <=> which compares Field with String

How to fix:
Remove .name, so that it becomes "current_entry = self.rindex(new_field)"


mikel commented Sep 10, 2010

Hi there,

Can you give me an example of how to reproduce with a live email?

I want to fix this, but the data above is not clear. When does field list get given a string instead of a field?

Please let me know


quetz commented Sep 10, 2010

Hello, I just pulled latest sources from repository and did some tests.
First of all I used commit 1215cba as base for testing.
At first it looks fine and no error messages are shown. But it turned out that exception is still generated but is silently caught and discarded.
Following patch proves that:

diff --git a/lib/mail/field.rb b/lib/mail/field.rb
index 29f3c06..f37436b 100644
--- a/lib/mail/field.rb
+++ b/lib/mail/field.rb
@@ -113,9 +113,13 @@ module Mail

def <=>( other )
+         begin
self_order = FIELD_ORDER.rindex(self.name.to_s.downcase) || 100
other_order = FIELD_ORDER.rindex(other.name.to_s.downcase) || 100
self_order <=> other_order
+         rescue Exception => e
+               puts e
+         end

 def method_missing(name, *args, &block)

It happens because 'other' is not a Field, but string (and thus, have no .name method).
<=> method is called from .rindex method in field_list.rb (line 12)

 current_entry = self.rindex(new_field.name)

here we pass String object to rindex instead of Field object, so rindex passes this string to <=> method, which
in turn tries to call .name on that

Sorry for messed up explanation, hope its getting clear what's going on.
Oh, it is reproduced on any email composing attempt.


mikel commented Sep 11, 2010

Awesome. I saw the problem and applied the patch. How the hell did you find that??

Applied in commit #433dd7a

quetz commented Sep 11, 2010

In version 2.2.1 exception was displayed ;)
Thanks for fixing that!

Bira pushed a commit to Bira/mail that referenced this issue Jul 8, 2011

This issue was closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment