mikel/mail — pull request #575 by srawlins (2013-07-02 00:00:04+00:00)
Title: Fixing #557 by duping a String before storing it as @display_name

This fixes #557 by duping a String before storing it as @display_name

`Mail::Address#format` alters a String that has been passed into `#display_name=`. Specifically, the encoding is being changed. This is actually happening down in `Mail::Utilities`, in `#quote_phrase`, with:

str.force_encoding('ASCII-8BIT')

This PR just dups the string before assigning to `@display_name`, with tests. Tests pass in 1.8.7 and 1.9.3 (also just got the notice from Travis that everything is green). The new spec just asserts that the original String hasn't changed. Here's the failure before this PR:

```
Failures:

1) Mail::Address assigning values directly should not modify the display name source during format
Failure/Error: name.should eq name_copy

expected: "Zoé"
got: "Zo\xC3\xA9"

(compared using ==)
# ./spec/mail/elements/address_spec.rb:182:in `block (3 levels) in '
```

I had tried adding a spec to ensure the `#encoding` on the original String hadn't changed, but that of course didn't work in 1.8. In any case, here's the result of that assertion, which was not committed:

```
Failures:

1) Mail::Address assigning values directly should not modify the display name source during format
Failure/Error: name.encoding.should eq original_encoding

expected: #
got: #

(compared using ==)

Diff:
@@ -1,2 +1,2 @@
-#
+#
# ./spec/mail/elements/address_spec.rb:183:in `block (3 levels) in '
```