mail 2.5.3 → 2.5.4

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of mail might be problematic. Click here for more details.

Files changed (66) hide show
  1. data/CHANGELOG.rdoc +65 -0
  2. data/CONTRIBUTING.md +4 -4
  3. data/Gemfile +7 -20
  4. data/MIT-LICENSE +20 -0
  5. data/README.md +10 -9
  6. data/Rakefile +3 -20
  7. data/lib/VERSION +1 -1
  8. data/lib/mail.rb +0 -1
  9. data/lib/mail/attachments_list.rb +2 -2
  10. data/lib/mail/body.rb +4 -4
  11. data/lib/mail/check_delivery_params.rb +12 -22
  12. data/lib/mail/core_extensions/object.rb +8 -8
  13. data/lib/mail/core_extensions/smtp.rb +12 -13
  14. data/lib/mail/core_extensions/string.rb +4 -4
  15. data/lib/mail/elements/address.rb +13 -5
  16. data/lib/mail/elements/envelope_from_element.rb +15 -2
  17. data/lib/mail/encodings.rb +61 -28
  18. data/lib/mail/encodings/quoted_printable.rb +4 -3
  19. data/lib/mail/field.rb +10 -11
  20. data/lib/mail/fields/bcc_field.rb +2 -2
  21. data/lib/mail/fields/cc_field.rb +2 -2
  22. data/lib/mail/fields/comments_field.rb +1 -1
  23. data/lib/mail/fields/common/common_address.rb +13 -3
  24. data/lib/mail/fields/common/common_field.rb +4 -4
  25. data/lib/mail/fields/content_id_field.rb +1 -2
  26. data/lib/mail/fields/content_transfer_encoding_field.rb +2 -2
  27. data/lib/mail/fields/content_type_field.rb +1 -1
  28. data/lib/mail/fields/date_field.rb +1 -1
  29. data/lib/mail/fields/from_field.rb +2 -2
  30. data/lib/mail/fields/in_reply_to_field.rb +2 -1
  31. data/lib/mail/fields/message_id_field.rb +2 -3
  32. data/lib/mail/fields/references_field.rb +2 -1
  33. data/lib/mail/fields/reply_to_field.rb +2 -2
  34. data/lib/mail/fields/resent_bcc_field.rb +2 -2
  35. data/lib/mail/fields/resent_cc_field.rb +2 -2
  36. data/lib/mail/fields/resent_from_field.rb +2 -2
  37. data/lib/mail/fields/resent_sender_field.rb +2 -2
  38. data/lib/mail/fields/resent_to_field.rb +2 -2
  39. data/lib/mail/fields/sender_field.rb +7 -7
  40. data/lib/mail/fields/to_field.rb +2 -2
  41. data/lib/mail/fields/unstructured_field.rb +1 -1
  42. data/lib/mail/header.rb +5 -1
  43. data/lib/mail/message.rb +133 -37
  44. data/lib/mail/multibyte/chars.rb +2 -2
  45. data/lib/mail/multibyte/unicode.rb +5 -3
  46. data/lib/mail/network/delivery_methods/exim.rb +1 -6
  47. data/lib/mail/network/delivery_methods/file_delivery.rb +1 -1
  48. data/lib/mail/network/delivery_methods/sendmail.rb +32 -10
  49. data/lib/mail/network/delivery_methods/smtp.rb +35 -34
  50. data/lib/mail/network/delivery_methods/smtp_connection.rb +6 -6
  51. data/lib/mail/network/delivery_methods/test_mailer.rb +2 -2
  52. data/lib/mail/parsers/content_transfer_encoding.rb +81 -42
  53. data/lib/mail/parsers/content_transfer_encoding.treetop +4 -6
  54. data/lib/mail/parsers/content_type.rb +16 -12
  55. data/lib/mail/parsers/content_type.treetop +2 -2
  56. data/lib/mail/parsers/rfc2045.rb +12 -55
  57. data/lib/mail/parsers/rfc2045.treetop +1 -2
  58. data/lib/mail/parsers/rfc2822.rb +50 -50
  59. data/lib/mail/parsers/rfc2822.treetop +19 -21
  60. data/lib/mail/part.rb +6 -2
  61. data/lib/mail/patterns.rb +1 -0
  62. data/lib/mail/utilities.rb +25 -17
  63. data/lib/mail/version_specific/ruby_1_8.rb +5 -1
  64. data/lib/mail/version_specific/ruby_1_9.rb +46 -21
  65. metadata +57 -8
  66. data/lib/mail/core_extensions/shell_escape.rb +0 -56
@@ -1,5 +1,70 @@
1
1
  == HEAD
2
2
 
3
+
4
+ == Version 2.5.4 - Tue May 14 14:45:00 +1100 2013 Mikel Lindsaar <mikel@lindsaar.net>
5
+
6
+ Features:
7
+ * Save settings passed to TestMailer#new (svanderbleek)
8
+ * Allow the setting of envelope from directly (jeremy)
9
+ * Accept other IETF/IANA-registered Content-Types and Content-Transfer-Encodings (jeremy)
10
+ * Alias shift-jis charset to Shift_JIS Ruby encoding (jeremy)
11
+ * Add support for ks_c_5601-1987 charset, aliased to CP949 Ruby encoding (jeremy)
12
+ * Don't allow colons in header names (jeremy)
13
+ * Can assign arrays of Message-IDs to References and In-Reply-To (jeremy)
14
+ * Setting the html_ or text_part sets a default text/html or text/plain content type (jeremy)
15
+ * Setting the html_ or text_part to nil removes it (jeremy)
16
+ * Addresses without a parsable email or display name still format as their raw text (jeremy)
17
+ * Close pull request 504 - Alias GB2312 charset to GB18030 Ruby encoding (bpot)
18
+ * Close pull request 399 - Accept :ca_path and :ca_file options for SMTP delivery (ndbroadbent)
19
+ * Close pull request 389 - Don't add superfluous message headers to MIME parts (djmaze, jeremy)
20
+
21
+ Performance:
22
+ * Close pull request 488 - Speed up field construction & comparison (bpot)
23
+
24
+ Bugs:
25
+ * Don't include separating semicolon in paramter value when sanitizing (bpot)
26
+ * Fix fencepost encoding problem with binhex strings and only one token (drasch)
27
+ * Fix sendmail delivery to addresses with a leading hyphen (lifo, jeremy)
28
+ * Correctly format mbox From headers per RFC4155 (bpot, jeremy)
29
+ * Fix bogus '=' at the end of some quoted-printable messages (jeremy)
30
+ * Shouldn't be fooled into encoding strings on 1.8 by unrelated Encoding constant (emiellohr, jeremy)
31
+ * Header encoding should be US-ASCII, not the default external encoding (jeremy)
32
+ * Address elements should return decoded display names by default (jeremy)
33
+ * Fix up tests that depend on utf-8 external encoding; read fixtures as binary (jeremy)
34
+ * Capture stderr from Sendmail and Exim deliveries (jeremy)
35
+ * RFC2822 quoted_string content may be empty (jeremy)
36
+ * Calling #to_s on a field with a nil value returns an empty string instead of nil (jeremy)
37
+ * The Received header may contain zero name/value pairs, qmail-style (jeremy)
38
+ * Fix that setting an attachment with a :mime_type and :encoding would override the :encoding (jeremy)
39
+ * Fix that declaring an html_part but no text_part would use multipart/alternative anyway (jeremy)
40
+ * Close pull request 508 - Don't add an extra CRLF to MIME parts; split MIME parts on correct CRLF boundaries (Aalanar)
41
+ * Close pull request 506 - Escape backslashes in quoted strings (ConradIrwin)
42
+ * Close pull request 496 - Correctly handle quoted-printable line breaks (jeremy)
43
+ * Close pull request 493 - Repair misencoded quoted-printable line breaks (jeremy)
44
+ * Close pull request 487 - Extract comments from group email addresses (bpot)
45
+ * Close pull request 481 - Correctly quote filename attributes (bpot)
46
+ * Close pull request 480 - Support mixed encodings in a single header body (adamvaughan)
47
+ * Close pull request 471 - Fix Ruby 1.8 build when UTF16/32 default to little-endian (kennyj)
48
+
49
+ Coping with third-party bugs:
50
+ * Parse multipart boundary from Content-Type headers containing extra semicolons (jeremy)
51
+ * Close pull request 389 - Only add Content-ID to inline attachments to appease Outlook (djmaze, jeremy)
52
+
53
+ Housekeeping:
54
+ * Add development gem dependency on rdoc (jeremy)
55
+ * Refresh Bundler dependencies & setup (jeremy)
56
+ * Remove i18n dependency and last vestiges of activesupport dependency in specs (jeremy)
57
+ * Clarify that Sender is a single address, not an address list (jeremy)
58
+ * Add an MIT-LICENSE file to make licensing clear & obvious; update to 2013 (jeremy)
59
+ * Close pull request 501 - Tighten up header/body whitespace splitting (ConradIrwin)
60
+ * Close pull request 499 - Clean up some dead code (ConradIrwin)
61
+ * Close pull request 489, 495 - Docs typos (JackDanger, francois)
62
+ * Close pull request 485 - Be explicit about unsupported address parsing (bpot)
63
+ * Close pull request 484 - Remove #tree specs in preparation for deprecation removal (bpot)
64
+ * Close pull request 482 - Update address field specs to reflect to #initialize API (bpot)
65
+ * Close pull request 475 - Shush warning on Object#blank? redefinition (amatsuda)
66
+ * Close pull request 472 - Clean up UTF8/UTF-8 internals (kennyj)
67
+
3
68
  == Version 2.5.3 - Sun Dec 4 15:52:00 +1100 2012 Mikel Lindsaar <mikel@reinteractive.net>
4
69
 
5
70
  * Close pull request 468 - Remove debug output to STDOUT (tadman)
@@ -12,12 +12,12 @@ pull request merged quickly:
12
12
  5. Add a spec for your change. Only refactoring and documentation changes
13
13
  require no new specs. If you are adding functionality or fixing a bug, we need
14
14
  a spec!
15
- 6. Test the spec _at_ _least_ against MRI-1.9.2 and MRI-1.8.7
15
+ 6. Test the spec _at_ _least_ against MRI-1.9.3 and MRI-1.8.7
16
16
  7. Update the README if needed to reflect your change / addition
17
17
  8. With all specs passing push your changes back to your fork
18
18
  9. Send me a pull request
19
19
 
20
- Note, specs that break MRI 1.8.7 will not be accepted.
20
+ Note, specs that break MRI 1.8.7 or 1.9.3 will not be accepted.
21
21
 
22
22
  At this point you're waiting on us. We like to at least comment on, if not
23
23
  accept, pull requests within three business days (and, typically, one business
@@ -28,7 +28,7 @@ taken straight from the Ruby on Rails guide:
28
28
 
29
29
  * Tell me you have tested it against more than one version of Ruby, RVM is great for
30
30
  this. I test against 7 rubies before I push into master.
31
- * Use good, idiomatic, strcutred and modular code
31
+ * Use good, idiomatic, structured and modular code
32
32
  * Include tests that fail without your code, and pass with it
33
33
  * Update the documentation, the surrounding one, examples elsewhere, guides,
34
34
  whatever is affected by your contribution
@@ -42,4 +42,4 @@ Syntax:
42
42
  * a = b and not a=b.
43
43
  * Follow the conventions you see used in the source already.
44
44
 
45
- And in case we didn't emphasize it enough: we love specs!
45
+ And in case we didn't emphasize it enough: we love specs!
data/Gemfile CHANGED
@@ -1,26 +1,13 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
2
4
 
3
- gem "activesupport", ">= 2.3.6"
4
- gem "tlsmail" if RUBY_VERSION <= '1.8.6'
5
- gem "mime-types", "~> 1.16"
6
5
  gem "treetop", "~> 1.4.10"
7
- gem "i18n", ">= 0.4.0"
6
+ gem "mime-types", "~> 1.16"
7
+ gem "tlsmail" if RUBY_VERSION <= '1.8.6'
8
8
 
9
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
10
- gem 'jruby-openssl'
11
- end
9
+ gem 'jruby-openssl', :platform => :jruby
12
10
 
13
11
  group :test do
14
- gem "rake", "> 0.8.7"
15
- gem "rspec", "~> 2.12.0"
16
- case
17
- when defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
18
- # Skip it
19
- when RUBY_PLATFORM == 'java'
20
- # Skip it
21
- when RUBY_VERSION < '1.9'
22
- gem "ruby-debug"
23
- else
24
- # Skip it
25
- end
12
+ gem "ruby-debug", :platform => :mri_18
26
13
  end
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2013 Mikel Lindsaar
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- Mail
1
+ Mail [![Build Status](https://travis-ci.org/mikel/mail.png?branch=master)](https://travis-ci.org/mikel/mail)
2
2
  ====
3
3
 
4
4
  Introduction
@@ -42,11 +42,12 @@ me a nice email :)
42
42
  Compatibility
43
43
  -------------
44
44
 
45
- Mail is tested by Travis ([![Travis Build Status](https://travis-ci.org/mikel/mail.png "Build Status")](https://travis-ci.org/mikel/mail)) and works on the [following platforms](https://github.com/mikel/mail/blob/master/.travis.yml)
45
+ Every Mail commit is tested by Travis on the [following platforms](https://github.com/mikel/mail/blob/master/.travis.yml)
46
46
 
47
47
  * ruby-1.8.7-p370 [ i686 ]
48
48
  * ruby-1.9.2-p290 [ x86_64 ]
49
49
  * ruby-1.9.3-p327 [ x86_64 ]
50
+ * ruby-2.0.0-rc1 [ x86_64 ]
50
51
  * jruby-1.6.8 [ x86_64 ]
51
52
  * jruby-1.7.0 [ x86_64 ]
52
53
  * rbx-d18 [ x86_64 ]
@@ -130,12 +131,12 @@ I have tried to simplify it some:
130
131
  it will include the header field and value and CRLF at the end and wrapped as
131
132
  needed.
132
133
 
133
- 2. All objects that can render into an email, have a :decoded method. Decoded will
134
+ 2. All objects that can render into an email, have a `#decoded` method. Decoded will
134
135
  return the object's "value" only as a string. This means it will not include
135
136
  the header fields (like 'To:' or 'Subject:').
136
137
 
137
138
  3. By default, calling <code>#to_s</code> on a container object will call its encoded
138
- method, while <code>#to_s</code> on a field object will call it's decoded method.
139
+ method, while <code>#to_s</code> on a field object will call its decoded method.
139
140
  So calling <code>#to_s</code> on a Mail object will return the mail, all encoded
140
141
  ready to send, while calling <code>#to_s</code> on the From field or the body will
141
142
  return the decoded value of the object. The header object of Mail is considered a
@@ -202,7 +203,7 @@ mail.to_s =~ /Message\-ID: <[\d\w_]+@.+.mail/ #=> 27
202
203
  Mail will automatically add a Message-ID field if it is missing and
203
204
  give it a unique, random Message-ID along the lines of:
204
205
 
205
- <4a7ff76d7016_13a81ab802e1@local.fqdn.mail>
206
+ <4a7ff76d7016_13a81ab802e1@local.host.mail>
206
207
 
207
208
  ### Or do worry about Message-IDs:
208
209
 
@@ -265,7 +266,7 @@ mail.delivery_method :sendmail
265
266
  mail.deliver
266
267
  ```
267
268
 
268
- Exim requires it's own delivery manager, and can be used like so:
269
+ Exim requires its own delivery manager, and can be used like so:
269
270
 
270
271
  ```ruby
271
272
  mail.delivery_method :exim, :location => "/usr/bin/exim"
@@ -338,8 +339,8 @@ mail = Mail.read('multipart_email')
338
339
 
339
340
  mail.multipart? #=> true
340
341
  mail.parts.length #=> 2
341
- mail.preamble #=> "Text before the first part"
342
- mail.epilogue #=> "Text after the last part"
342
+ mail.body.preamble #=> "Text before the first part"
343
+ mail.body.epilogue #=> "Text after the last part"
343
344
  mail.parts.map { |p| p.content_type } #=> ['text/plain', 'application/pdf']
344
345
  mail.parts.map { |p| p.class } #=> [Mail::Message, Mail::Message]
345
346
  mail.parts[0].content_type_parameters #=> {'charset' => 'ISO-8859-1'}
@@ -642,7 +643,7 @@ License
642
643
 
643
644
  (The MIT License)
644
645
 
645
- Copyright (c) 2009, 2010, 2011, 2012 Mikel Lindsaar
646
+ Copyright (c) 2009-2013 Mikel Lindsaar
646
647
 
647
648
  Permission is hereby granted, free of charge, to any person obtaining
648
649
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,23 +1,6 @@
1
- begin
2
- require "rubygems"
3
- require "bundler"
4
- rescue LoadError
5
- raise "Could not load the bundler gem. Install it with `gem install bundler`."
6
- end
7
-
8
- if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("1.0.0")
9
- raise RuntimeError, "Your bundler version is too old for Mail" +
10
- "Run `gem install bundler` to upgrade."
11
- end
12
-
13
- begin
14
- # Set up load paths for all bundled gems
15
- ENV["BUNDLE_GEMFILE"] = File.expand_path("../Gemfile", __FILE__)
16
- Bundler.setup
17
- rescue Bundler::GemNotFound
18
- raise RuntimeError, "Bundler couldn't find some gems." +
19
- "Did you run `bundle install`?"
20
- end
1
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', __FILE__)
2
+ require 'rubygems'
3
+ require 'bundler/setup'
21
4
 
22
5
  require 'rake/testtask'
23
6
  require 'rspec/core/rake_task'
@@ -1,4 +1,4 @@
1
1
  major:2
2
2
  minor:5
3
- patch:3
3
+ patch:4
4
4
  build:
@@ -29,7 +29,6 @@ module Mail # :doc:
29
29
  require 'mail/core_extensions/nil'
30
30
  require 'mail/core_extensions/object'
31
31
  require 'mail/core_extensions/string'
32
- require 'mail/core_extensions/shell_escape'
33
32
  require 'mail/core_extensions/smtp' if RUBY_VERSION < '1.9.3'
34
33
  require 'mail/indifferent_hash'
35
34
 
@@ -60,7 +60,7 @@ module Mail
60
60
  if value[:mime_type]
61
61
  default_values[:content_type] = value.delete(:mime_type)
62
62
  @mime_type = MIME::Types[default_values[:content_type]].first
63
- default_values[:content_transfer_encoding] = guess_encoding
63
+ default_values[:content_transfer_encoding] ||= guess_encoding
64
64
  end
65
65
 
66
66
  hash = default_values.merge(value)
@@ -94,7 +94,7 @@ module Mail
94
94
  def set_mime_type(filename)
95
95
  # Have to do this because MIME::Types is not Ruby 1.9 safe yet
96
96
  if RUBY_VERSION >= '1.9'
97
- filename = filename.encode(Encoding::UTF_8) if filename.respond_to?(:encode)
97
+ filename = filename.encode(Encoding::UTF_8) if filename.respond_to?(:encode)
98
98
  end
99
99
 
100
100
  @mime_type = MIME::Types.type_for(filename).first
@@ -5,7 +5,7 @@ module Mail
5
5
  #
6
6
  # The body is where the text of the email is stored. Mail treats the body
7
7
  # as a single object. The body itself has no information about boundaries
8
- # used in the MIME standard, it just looks at it's content as either a single
8
+ # used in the MIME standard, it just looks at its content as either a single
9
9
  # block of text, or (if it is a multipart message) as an array of blocks of text.
10
10
  #
11
11
  # A body has to be told to split itself up into a multipart message by calling
@@ -257,7 +257,7 @@ module Mail
257
257
 
258
258
  def split!(boundary)
259
259
  self.boundary = boundary
260
- parts = raw_source.split(/--#{Regexp.escape(boundary)}(?=(?:--)?\s*$)/)
260
+ parts = raw_source.split(/(?:\A|\r\n)--#{Regexp.escape(boundary)}(?=(?:--)?\s*$)/)
261
261
  # Make the preamble equal to the preamble (if any)
262
262
  self.preamble = parts[0].to_s.strip
263
263
  # Make the epilogue equal to the epilogue (if any)
@@ -277,11 +277,11 @@ module Mail
277
277
  private
278
278
 
279
279
  def crlf_boundary
280
- "\r\n\r\n--#{boundary}\r\n"
280
+ "\r\n--#{boundary}\r\n"
281
281
  end
282
282
 
283
283
  def end_boundary
284
- "\r\n\r\n--#{boundary}--\r\n"
284
+ "\r\n--#{boundary}--\r\n"
285
285
  end
286
286
 
287
287
  def set_charset
@@ -1,30 +1,20 @@
1
1
  module Mail
2
-
3
2
  module CheckDeliveryParams
3
+ def check_delivery_params(mail)
4
+ if mail.smtp_envelope_from.blank?
5
+ raise ArgumentError.new('An SMTP From address is required to send a message. Set the message smtp_envelope_from, return_path, sender, or from address.')
6
+ end
4
7
 
5
- def self.included(klass)
6
- klass.class_eval do
7
-
8
- def check_params(mail)
9
- envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
10
- if envelope_from.blank?
11
- raise ArgumentError.new('A sender (Return-Path, Sender or From) required to send a message')
12
- end
13
-
14
- destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations
15
- if destinations.blank?
16
- raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message')
17
- end
18
-
19
- message ||= mail.encoded if mail.respond_to?(:encoded)
20
- if message.blank?
21
- raise ArgumentError.new('A encoded content is required to send a message')
22
- end
23
-
24
- [envelope_from, destinations, message]
25
- end
8
+ if mail.smtp_envelope_to.blank?
9
+ raise ArgumentError.new('An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.')
10
+ end
26
11
 
12
+ message = mail.encoded if mail.respond_to?(:encoded)
13
+ if message.blank?
14
+ raise ArgumentError.new('An encoded message is required to send an email')
27
15
  end
16
+
17
+ [mail.smtp_envelope_from, mail.smtp_envelope_to, message]
28
18
  end
29
19
  end
30
20
  end
@@ -1,13 +1,13 @@
1
1
  # encoding: utf-8
2
2
 
3
- # This is not loaded if ActiveSupport is already loaded
4
-
5
- class Object
6
- def blank?
7
- if respond_to?(:empty?)
8
- empty?
9
- else
10
- !self
3
+ unless Object.method_defined? :blank?
4
+ class Object
5
+ def blank?
6
+ if respond_to?(:empty?)
7
+ empty?
8
+ else
9
+ !self
10
+ end
11
11
  end
12
12
  end
13
13
  end
@@ -5,21 +5,20 @@ module Net
5
5
  # http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&amp;revision=30294
6
6
  #
7
7
  # Fixed in what will be Ruby 1.9.3 - tlsconnect also does not exist in some early versions of ruby
8
- remove_method :tlsconnect if defined?(Net::SMTP.new.tlsconnect)
8
+ begin
9
+ alias_method :original_tlsconnect, :tlsconnect
9
10
 
10
- def tlsconnect(s)
11
- verified = false
12
- s = OpenSSL::SSL::SSLSocket.new s, @ssl_context
13
- logging "TLS connection started"
14
- s.sync_close = true
15
- s.connect
16
- if @ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE
17
- s.post_connection_check(@address)
11
+ def tlsconnect(s)
12
+ verified = false
13
+ begin
14
+ original_tlsconnect(s).tap { verified = true }
15
+ ensure
16
+ unless verified
17
+ s.close rescue nil
18
+ end
19
+ end
18
20
  end
19
- verified = true
20
- s
21
- ensure
22
- s.close unless verified
21
+ rescue NameError
23
22
  end
24
23
  end
25
24
  end
@@ -15,12 +15,12 @@ class String #:nodoc:
15
15
  end
16
16
 
17
17
  unless method_defined?(:ascii_only?)
18
- # Provides all strings with the Ruby 1.9 method of .ascii_only? and
19
- # returns true or false
20
- US_ASCII_REGEXP = %Q{\x00-\x7f}
18
+ # Backport from Ruby 1.9 checks for non-us-ascii characters.
21
19
  def ascii_only?
22
- !(self =~ /[^#{US_ASCII_REGEXP}]/)
20
+ self !~ MATCH_NON_US_ASCII
23
21
  end
22
+
23
+ MATCH_NON_US_ASCII = /[^\x00-\x7f]/
24
24
  end
25
25
 
26
26
  def not_ascii_only?
@@ -5,7 +5,7 @@ module Mail
5
5
  include Mail::Utilities
6
6
 
7
7
  # Mail::Address handles all email addresses in Mail. It takes an email address string
8
- # and parses it, breaking it down into it's component parts and allowing you to get the
8
+ # and parses it, breaking it down into its component parts and allowing you to get the
9
9
  # address, comments, display name, name, local part, domain part and fully formatted
10
10
  # address.
11
11
  #
@@ -21,7 +21,7 @@ module Mail
21
21
  # a.comments #=> ['My email address']
22
22
  # a.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net> (My email address)'
23
23
  def initialize(value = nil)
24
- @output_type = nil
24
+ @output_type = :decode
25
25
  @tree = nil
26
26
  @raw_text = value
27
27
  case
@@ -40,7 +40,7 @@ module Mail
40
40
  end
41
41
 
42
42
  # Returns a correctly formatted address for the email going out. If given
43
- # an incorrectly formatted address as input, Mail::Address will do it's best
43
+ # an incorrectly formatted address as input, Mail::Address will do its best
44
44
  # to format it correctly. This includes quoting display names as needed and
45
45
  # putting the address in angle brackets etc.
46
46
  #
@@ -53,8 +53,10 @@ module Mail
53
53
  ''
54
54
  when display_name
55
55
  [quote_phrase(display_name), "<#{address}>", format_comments].compact.join(" ")
56
- else
56
+ when address
57
57
  [address, format_comments].compact.join(" ")
58
+ else
59
+ tree.text_value
58
60
  end
59
61
  end
60
62
 
@@ -296,6 +298,12 @@ module Mail
296
298
  tree.angle_addr.addr_spec.local_part.text_value
297
299
  when tree.respond_to?(:addr_spec) && tree.addr_spec.respond_to?(:local_part)
298
300
  tree.addr_spec.local_part.text_value
301
+ when tree.respond_to?(:angle_addr) && tree.angle_addr.respond_to?(:addr_spec) && tree.angle_addr.addr_spec.respond_to?(:local_dot_atom_text)
302
+ # Ignore local dot atom text when in angle brackets
303
+ nil
304
+ when tree.respond_to?(:addr_spec) && tree.addr_spec.respond_to?(:local_dot_atom_text)
305
+ # Ignore local dot atom text when in angle brackets
306
+ nil
299
307
  else
300
308
  tree && tree.respond_to?(:local_part) ? tree.local_part.text_value : nil
301
309
  end
@@ -303,4 +311,4 @@ module Mail
303
311
 
304
312
 
305
313
  end
306
- end
314
+ end