mikel/mail — pull request #509 by javan (2013-02-08 22:46:58+00:00)
Title: Fix decoding strings that contain '=?', but are not actually encoded

I ran into an exception today when sending an email that contained "1+1=?" in the subject.

Here's a test (not included in the commit) to simulate that failure:

```ruby
it "should allow setting the value of a field to a string that contains '?='" do
mail = Mail.new
mail.charset = 'utf-8'
mail.subject = "1+1=?"
mail[:subject].encoded.should eq "1+1=?"
end
```

```
Failures:

1) mail encoding using default encoding should allow setting the value of a field to a string that contains '?='
Failure/Error: mail[:subject].encoded.should eq "1+1=?"
NoMethodError:
undefined method `+' for nil:NilClass
# ./lib/mail/encodings.rb:295:in `block in collapse_adjacent_encodings'
# ./lib/mail/encodings.rb:291:in `each'
# ./lib/mail/encodings.rb:291:in `collapse_adjacent_encodings'
# ./lib/mail/encodings.rb:120:in `value_decode'
# ./lib/mail/encodings.rb:101:in `decode_encode'
# ./lib/mail/fields/unstructured_field.rb:73:in `do_decode'
# ./lib/mail/fields/unstructured_field.rb:55:in `decoded'
# ./lib/mail/fields/unstructured_field.rb:122:in `fold'
# ./lib/mail/fields/unstructured_field.rb:103:in `wrapped_value'
# ./lib/mail/fields/unstructured_field.rb:69:in `do_encode'
# ./lib/mail/fields/unstructured_field.rb:51:in `encoded'
# ./lib/mail/field.rb:167:in `method_missing'
# ./spec/mail/encoding_spec.rb:25:in `block (3 levels) in '
```

This fixes the problem by checking more closely (with a regex) to see if the string actually is encoded before proceeding.