mail 2.4.4 → 2.5.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.rdoc +140 -1
  3. data/CONTRIBUTING.md +4 -4
  4. data/Gemfile +14 -8
  5. data/MIT-LICENSE +20 -0
  6. data/README.md +24 -23
  7. data/Rakefile +3 -22
  8. data/lib/VERSION +2 -2
  9. data/lib/load_parsers.rb +35 -0
  10. data/lib/mail/attachments_list.rb +2 -2
  11. data/lib/mail/body.rb +5 -5
  12. data/lib/mail/check_delivery_params.rb +57 -0
  13. data/lib/mail/configuration.rb +1 -1
  14. data/lib/mail/core_extensions/nil.rb +4 -2
  15. data/lib/mail/core_extensions/object.rb +8 -8
  16. data/lib/mail/core_extensions/smtp.rb +12 -13
  17. data/lib/mail/core_extensions/string.rb +4 -4
  18. data/lib/mail/elements/address.rb +13 -5
  19. data/lib/mail/elements/envelope_from_element.rb +15 -2
  20. data/lib/mail/elements.rb +12 -12
  21. data/lib/mail/encodings/quoted_printable.rb +4 -3
  22. data/lib/mail/encodings.rb +66 -35
  23. data/lib/mail/field.rb +76 -99
  24. data/lib/mail/fields/bcc_field.rb +2 -2
  25. data/lib/mail/fields/cc_field.rb +2 -2
  26. data/lib/mail/fields/comments_field.rb +1 -1
  27. data/lib/mail/fields/common/common_address.rb +19 -4
  28. data/lib/mail/fields/common/common_field.rb +8 -2
  29. data/lib/mail/fields/common/common_message_id.rb +9 -5
  30. data/lib/mail/fields/content_disposition_field.rb +1 -0
  31. data/lib/mail/fields/content_id_field.rb +1 -2
  32. data/lib/mail/fields/content_transfer_encoding_field.rb +2 -2
  33. data/lib/mail/fields/content_type_field.rb +5 -2
  34. data/lib/mail/fields/date_field.rb +14 -14
  35. data/lib/mail/fields/from_field.rb +2 -2
  36. data/lib/mail/fields/in_reply_to_field.rb +2 -1
  37. data/lib/mail/fields/keywords_field.rb +1 -1
  38. data/lib/mail/fields/message_id_field.rb +2 -3
  39. data/lib/mail/fields/references_field.rb +2 -1
  40. data/lib/mail/fields/reply_to_field.rb +2 -2
  41. data/lib/mail/fields/resent_bcc_field.rb +2 -2
  42. data/lib/mail/fields/resent_cc_field.rb +2 -2
  43. data/lib/mail/fields/resent_from_field.rb +2 -2
  44. data/lib/mail/fields/resent_sender_field.rb +2 -2
  45. data/lib/mail/fields/resent_to_field.rb +2 -2
  46. data/lib/mail/fields/sender_field.rb +7 -7
  47. data/lib/mail/fields/to_field.rb +2 -2
  48. data/lib/mail/fields/unstructured_field.rb +34 -27
  49. data/lib/mail/fields.rb +32 -32
  50. data/lib/mail/header.rb +37 -14
  51. data/lib/mail/message.rb +140 -45
  52. data/lib/mail/multibyte/chars.rb +4 -4
  53. data/lib/mail/multibyte/unicode.rb +8 -0
  54. data/lib/mail/network/delivery_methods/exim.rb +6 -11
  55. data/lib/mail/network/delivery_methods/file_delivery.rb +7 -6
  56. data/lib/mail/network/delivery_methods/sendmail.rb +40 -11
  57. data/lib/mail/network/delivery_methods/smtp.rb +33 -47
  58. data/lib/mail/network/delivery_methods/smtp_connection.rb +7 -24
  59. data/lib/mail/network/delivery_methods/test_mailer.rb +9 -8
  60. data/lib/mail/network/retriever_methods/imap.rb +14 -6
  61. data/lib/mail/network/retriever_methods/pop3.rb +2 -2
  62. data/lib/mail/network/retriever_methods/test_retriever.rb +11 -15
  63. data/lib/mail/network.rb +9 -9
  64. data/lib/mail/parsers/content_transfer_encoding.rb +81 -42
  65. data/lib/mail/parsers/content_transfer_encoding.treetop +4 -6
  66. data/lib/mail/parsers/content_type.rb +16 -12
  67. data/lib/mail/parsers/content_type.treetop +2 -2
  68. data/lib/mail/parsers/rfc2045.rb +12 -55
  69. data/lib/mail/parsers/rfc2045.treetop +1 -2
  70. data/lib/mail/parsers/rfc2822.rb +127 -71
  71. data/lib/mail/parsers/rfc2822.treetop +22 -24
  72. data/lib/mail/part.rb +6 -2
  73. data/lib/mail/parts_list.rb +1 -1
  74. data/lib/mail/patterns.rb +1 -1
  75. data/lib/mail/utilities.rb +25 -17
  76. data/lib/mail/values/unicode_tables.dat +0 -0
  77. data/lib/mail/version_specific/ruby_1_8.rb +23 -2
  78. data/lib/mail/version_specific/ruby_1_9.rb +55 -21
  79. data/lib/mail.rb +18 -18
  80. metadata +89 -37
  81. data/Gemfile.lock +0 -36
  82. data/lib/mail/core_extensions/shell_escape.rb +0 -56
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 483ee321c6ec26a7fb20deb57c50254f916c5055
4
+ data.tar.gz: 49bbe456db7b901b8f9a17cc404ed6cdd4ac84f2
5
+ SHA512:
6
+ metadata.gz: bc79fcc391b2358f8aecd403453c934399a561bd2cf0c3cb32bf850815a6c99086c47104e0680a7d77a62585453bef8ca27d885f0345d102e0191a1f5354973d
7
+ data.tar.gz: cd1ea707e1b61aa29bb452d3b2eaa7a245721b28d17448061cef63beff93c794f3a05d0c104afa79a9cb7026f0b20376f422b76747170d35fe72a59ed64e40e6
data/CHANGELOG.rdoc CHANGED
@@ -1,4 +1,143 @@
1
- == HEAD
1
+ == Version 2.5.5 - 2017-06-09 Jeremy Daer <jeremydaer@gmail.com>
2
+
3
+ Security:
4
+ * #1097 – SMTP security: prevent command injection via To/From addresses. (jeremy)
5
+
6
+ Bugs:
7
+ * #633 – Cope with message parts that have an empty Content-Type (ThomasKoppensteiner, zeepeeare)
8
+ * #689 - Fix Exim delivery method broken by #477 in 2.5.4. (jethrogb)
9
+
10
+ == Version 2.5.4 - Tue May 14 14:45:00 +1100 2013 Mikel Lindsaar <mikel@lindsaar.net>
11
+
12
+ Features:
13
+ * Save settings passed to TestMailer#new (svanderbleek)
14
+ * Allow the setting of envelope from directly (jeremy)
15
+ * Accept other IETF/IANA-registered Content-Types and Content-Transfer-Encodings (jeremy)
16
+ * Alias shift-jis charset to Shift_JIS Ruby encoding (jeremy)
17
+ * Add support for ks_c_5601-1987 charset, aliased to CP949 Ruby encoding (jeremy)
18
+ * Don't allow colons in header names (jeremy)
19
+ * Can assign arrays of Message-IDs to References and In-Reply-To (jeremy)
20
+ * Setting the html_ or text_part sets a default text/html or text/plain content type (jeremy)
21
+ * Setting the html_ or text_part to nil removes it (jeremy)
22
+ * Addresses without a parsable email or display name still format as their raw text (jeremy)
23
+ * Close pull request 504 - Alias GB2312 charset to GB18030 Ruby encoding (bpot)
24
+ * Close pull request 399 - Accept :ca_path and :ca_file options for SMTP delivery (ndbroadbent)
25
+ * Close pull request 389 - Don't add superfluous message headers to MIME parts (djmaze, jeremy)
26
+
27
+ Performance:
28
+ * Close pull request 488 - Speed up field construction & comparison (bpot)
29
+
30
+ Bugs:
31
+ * Don't include separating semicolon in paramter value when sanitizing (bpot)
32
+ * Fix fencepost encoding problem with binhex strings and only one token (drasch)
33
+ * Fix sendmail delivery to addresses with a leading hyphen (lifo, jeremy)
34
+ * Correctly format mbox From headers per RFC4155 (bpot, jeremy)
35
+ * Fix bogus '=' at the end of some quoted-printable messages (jeremy)
36
+ * Shouldn't be fooled into encoding strings on 1.8 by unrelated Encoding constant (emiellohr, jeremy)
37
+ * Header encoding should be US-ASCII, not the default external encoding (jeremy)
38
+ * Address elements should return decoded display names by default (jeremy)
39
+ * Fix up tests that depend on utf-8 external encoding; read fixtures as binary (jeremy)
40
+ * Capture stderr from Sendmail and Exim deliveries (jeremy)
41
+ * RFC2822 quoted_string content may be empty (jeremy)
42
+ * Calling #to_s on a field with a nil value returns an empty string instead of nil (jeremy)
43
+ * The Received header may contain zero name/value pairs, qmail-style (jeremy)
44
+ * Fix that setting an attachment with a :mime_type and :encoding would override the :encoding (jeremy)
45
+ * Fix that declaring an html_part but no text_part would use multipart/alternative anyway (jeremy)
46
+ * Close pull request 508 - Don't add an extra CRLF to MIME parts; split MIME parts on correct CRLF boundaries (Aalanar)
47
+ * Close pull request 506 - Escape backslashes in quoted strings (ConradIrwin)
48
+ * Close pull request 496 - Correctly handle quoted-printable line breaks (jeremy)
49
+ * Close pull request 493 - Repair misencoded quoted-printable line breaks (jeremy)
50
+ * Close pull request 487 - Extract comments from group email addresses (bpot)
51
+ * Close pull request 481 - Correctly quote filename attributes (bpot)
52
+ * Close pull request 480 - Support mixed encodings in a single header body (adamvaughan)
53
+ * Close pull request 471 - Fix Ruby 1.8 build when UTF16/32 default to little-endian (kennyj)
54
+
55
+ Coping with third-party bugs:
56
+ * Parse multipart boundary from Content-Type headers containing extra semicolons (jeremy)
57
+ * Close pull request 389 - Only add Content-ID to inline attachments to appease Outlook (djmaze, jeremy)
58
+
59
+ Housekeeping:
60
+ * Add development gem dependency on rdoc (jeremy)
61
+ * Refresh Bundler dependencies & setup (jeremy)
62
+ * Remove i18n dependency and last vestiges of activesupport dependency in specs (jeremy)
63
+ * Clarify that Sender is a single address, not an address list (jeremy)
64
+ * Add an MIT-LICENSE file to make licensing clear & obvious; update to 2013 (jeremy)
65
+ * Close pull request 501 - Tighten up header/body whitespace splitting (ConradIrwin)
66
+ * Close pull request 499 - Clean up some dead code (ConradIrwin)
67
+ * Close pull request 489, 495 - Docs typos (JackDanger, francois)
68
+ * Close pull request 485 - Be explicit about unsupported address parsing (bpot)
69
+ * Close pull request 484 - Remove #tree specs in preparation for deprecation removal (bpot)
70
+ * Close pull request 482 - Update address field specs to reflect to #initialize API (bpot)
71
+ * Close pull request 475 - Shush warning on Object#blank? redefinition (amatsuda)
72
+ * Close pull request 472 - Clean up UTF8/UTF-8 internals (kennyj)
73
+
74
+ == Version 2.5.3 - Sun Dec 4 15:52:00 +1100 2012 Mikel Lindsaar <mikel@reinteractive.net>
75
+
76
+ * Close pull request 468 - Remove debug output to STDOUT (tadman)
77
+ * Fix up spec warnings
78
+ * Remove un needed require
79
+ * Ensure spec_helper constants only defined once
80
+ * Use stub against time instead of DateTime to avoid double redefinition error
81
+
82
+ == Version 2.5.2 - Sun Nov 18 15:01:00 +1100 2012 Mikel Lindsaar <mikel@reinteractive.net>
83
+
84
+ * Removing double loading of treetop parsers to remove warnings
85
+ * Making parsers auto compile on spec suite and load in production code to avoid error that caused yank of 2.5.0
86
+ * Reapply pull request 443 - CC fields with semicolon are now parsed right (paulwittmann)
87
+
88
+ == Version 2.5.1 - Sun Nov 18 14:01:00 +1100 2012 Mikel Lindsaar <mikel@reinteractive.net>
89
+
90
+ * Yanked 2.5.0
91
+ * Reverted pull request 443 - CC fields with semicolon are now parsed right (paulwittmann)
92
+
93
+ == Version 2.5.0 - Sun Nov 18 12:20:00 +1100 2012 Mikel Lindsaar <mikel@reinteractive.net>
94
+
95
+ Features:
96
+ * Close pull request 406 - Add Mail#eager_autoload! to load all autoloaded files on demand (bpot)
97
+ * Close pull request 461 - Allow string as delivery_method (skyeagle, radar)
98
+ * Close pull request 407 - Do not require Net::IMAP or Net::POP if they're already loaded (bpot)
99
+ * Close pull request 400 - Raise exception if delivery values or from values are missing completely from an email that is getting delivered (dmathieu)
100
+ * Close pull request 397 - Support dots in local part of the addresses (eac)
101
+ * Close pull request 477 - Fixed handling content_type with superfluous spaces (ledermann)
102
+ * Close pull request 451 - Ignore nil in addresses so things do not blow up when e.g. a user had no email (grosser)
103
+ * Close pull request 362 - Enable TLS in Ruby 1.8 (kingargyle)
104
+ * Close pull request 358 - Fix Mail::CommonAddress#value=, Mail::CommonAddress#<< and Mail::Encodings.encode_non_usascii (mrkn)
105
+ * Close pull request 350 - Makes mail Header object ennumerable (ged)
106
+
107
+ Performance:
108
+ * Close pull request 369 - Mail::Header#charset is called pretty often during header parser work (bogdan)
109
+ * Close pull request 368 - Improve existing code by moving some objects to contstant instead of constructing them over and over again. (bogdan)
110
+ * Close pull request 366 - Headers parsing performance optimization (bogdan)
111
+ * Close pull request 365 - Add maximum_amount of parsed headers configuration parameter (bogdan)
112
+
113
+ Bugs:
114
+ * Close pull request 444 - Fix typo in spec (cczona)
115
+ * Close pull request 439 - Fix Ruby 1.9 behaviour to match 1.8.7 behaviour on ignoring invalid or undefined characters (ochko)
116
+ * Close pull request 430 - Unstructured field converts to string before calling encoding on it (brupm mikel)
117
+ * Close pull request 424 - Use String#to_crlf instead of String#gsub (okkez)
118
+ * Close pull request 429 - Fix an obvious bug in exim delivery_method (dskim)
119
+ * Close pull request 425 - Remove Gemfile.lock from generated gem (kbackowski)
120
+ * Close pull request 414 - Fix typo on "ignoring" (derwiki)
121
+ * Close pull request 405 - Fix stack overflow (RegexpError) triggered by large emails with an envelope (bpot)
122
+ * Close pull request 402 - Prevent InReplyTo, Keyword, References or ResentMessageId fields from generating lines longer than 998 chars (pplr)
123
+ * Close pull request 391 - Fixed failed attachment parsing when file name in headers contains spaces and is not wrapped in quotes (danieltreacy)
124
+ * Close pull request 385 - Fix Multibyte::Chars#upcase/downcase (technoweenie)
125
+ * Close pull request 384 - copy dat unicode over from active support (technoweenie)
126
+ * Close pull request 380 - Split strictly on MIME boundary lines (ConradIrwin)
127
+ * Close pull request 277 - Fix specific email decoding failure example (yalab)
128
+ * Close pull request 361 - Support 8bit encoding for ruby 1.9 (bogdan)
129
+ * Close pull request 346 - Fix two bugs of TestRetriever (ermaker)
130
+ * Close pull request 337 - Make the behavior of value_decode the same between Ruby 1.8 and Ruby 1.9. (kennyj)
131
+ * Close pull request 336 - Fix more warning: possibly useless use of == in void context (kennyj)
132
+ * Close pull request 293 - make charset and mime type more resliant to bad header values (kmeehl)
133
+ * Fix failing spec Issue 453 on Ruby 1.9.3
134
+ * Fix mail reading: don't raise invalid byte sequence in UTF-8 when reading non-UTF-8 emails (mreinsch)
135
+ * Close pull request 353 - define NilClass#blank? only if not defined yet (amatsuda)
136
+ * Close pull request 357 - Fixes #349 an inverted condition on imap open read_only (felixroeser)
137
+ * Remove duplicated line feed from regexp
138
+ * Remove unused variable
139
+ * Updated IMAP documentation
140
+ * Tweak publisher
2
141
 
3
142
  == Version 2.4.4 - Wed Mar 14 22:44:00 +1100 2012 Mikel Lindsaar <mikel@reinteractive.net>
4
143
 
data/CONTRIBUTING.md CHANGED
@@ -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,17 +1,23 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
2
 
3
- gem "activesupport", ">= 2.3.6"
3
+ gemspec
4
+
5
+ if RUBY_VERSION < '1.9.3'
6
+ gem 'activesupport', '< 4'
7
+ elsif RUBY_VERSION < '2.2.2'
8
+ gem 'activesupport', '< 5'
9
+ end
10
+ gem 'i18n', '< 0.7.0' if RUBY_VERSION < '1.9.3'
4
11
  gem "tlsmail" if RUBY_VERSION <= '1.8.6'
5
12
  gem "mime-types", "~> 1.16"
6
13
  gem "treetop", "~> 1.4.10"
7
- gem "i18n", ">= 0.4.0"
8
14
 
9
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
10
- gem 'jruby-openssl'
11
- end
15
+ gem 'jruby-openssl', :platform => :jruby
12
16
 
13
- group :test do
14
- gem "rake", "> 0.8.7"
17
+ # For gems not required to run tests
18
+ group :local_development, :test do
19
+ gem 'rake', '> 0.8.7', '< 11.0.1'
20
+ gem 'rdoc', '< 4.3' if RUBY_VERSION < '1.9.3'
15
21
  gem "rspec", "~> 2.8.0"
16
22
  case
17
23
  when defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
data/MIT-LICENSE ADDED
@@ -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
@@ -15,11 +15,11 @@ Built from my experience with TMail, it is designed to be a pure ruby
15
15
  implementation that makes generating, sending and parsing emails a no
16
16
  brainer.
17
17
 
18
- It is also designed form the ground up to work with Ruby 1.9. This is because
19
- Ruby 1.9 handles text encodings much more magically than Ruby 1.8.x and so
20
- these features have been taken full advantage of in this library allowing
21
- Mail to handle a lot more messages more cleanly than TMail. Mail does run on
22
- Ruby 1.8.x... it's just not as fun to code.
18
+ It is also designed form the ground up to work with the more modern versions
19
+ of Ruby. This is because Ruby > 1.9 handles text encodings much more wonderfully
20
+ than Ruby 1.8.x and so these features have been taken full advantage of in this
21
+ library allowing Mail to handle a lot more messages more cleanly than TMail.
22
+ Mail does run on Ruby 1.8.x... it's just not as fun to code.
23
23
 
24
24
  Finally, Mail has been designed with a very simple object oriented system
25
25
  that really opens up the email messages you are parsing, if you know what
@@ -29,7 +29,7 @@ Donations
29
29
  -------------
30
30
 
31
31
  Mail has been downloaded millions of times, by people around the world, in fact,
32
- it represents more than 1% of *all* gems downloaded.
32
+ it represents more than 1% of *all* gems downloaded.
33
33
 
34
34
  It is (like all open source software) a labour of love and something I am doing
35
35
  with my own free time. If you would like to say thanks, please feel free to
@@ -42,14 +42,15 @@ me a nice email :)
42
42
  Compatibility
43
43
  -------------
44
44
 
45
- Mail is tested by Travis (![Travis Build Status](https://secure.travis-ci.org/mikel/mail.png "Build Status")) and works on the following platforms:
45
+ Mail supports Ruby 1.8.7+, including JRuby and Rubinius.
46
46
 
47
- * jruby-1.6.5.1 [ x86_64 ]
48
- * rbx-head-d18 [ x86_64 ]
49
- * ree-1.8.7-2011.03 [ i686 ]
50
- * ruby-1.8.7-p357 [ i686 ]
51
- * ruby-1.9.2-p290 [ x86_64 ]
52
- * ruby-1.9.3-p0 [ x86_64 ]
47
+ Every Mail commit is tested by Travis on [all supported Ruby versions](https://github.com/mikel/mail/blob/master/.travis.yml).
48
+
49
+ Testing a specific version of mime-types (needed for Ruby 1.8.7, for example) can be done manually with:
50
+
51
+ ```sh
52
+ BUNDLE_GEMFILE=gemfiles/mime_types_1.16.gemfile bundle && rake
53
+ ```
53
54
 
54
55
  Discussion
55
56
  ----------
@@ -104,7 +105,7 @@ It also means you can be sure Mail will behave correctly.
104
105
  API Policy
105
106
  ----------
106
107
 
107
- No API removals within a single point release. All removals to be depreciated with
108
+ No API removals within a single point release. All removals to be deprecated with
108
109
  warnings for at least one MINOR point release before removal.
109
110
 
110
111
  Also, all private or protected methods to be declared as such - though this is still I/P.
@@ -129,12 +130,12 @@ I have tried to simplify it some:
129
130
  it will include the header field and value and CRLF at the end and wrapped as
130
131
  needed.
131
132
 
132
- 2. All objects that can render into an email, have a :decoded method. Decoded will
133
+ 2. All objects that can render into an email, have a `#decoded` method. Decoded will
133
134
  return the object's "value" only as a string. This means it will not include
134
135
  the header fields (like 'To:' or 'Subject:').
135
136
 
136
137
  3. By default, calling <code>#to_s</code> on a container object will call its encoded
137
- method, while <code>#to_s</code> on a field object will call it's decoded method.
138
+ method, while <code>#to_s</code> on a field object will call its decoded method.
138
139
  So calling <code>#to_s</code> on a Mail object will return the mail, all encoded
139
140
  ready to send, while calling <code>#to_s</code> on the From field or the body will
140
141
  return the decoded value of the object. The header object of Mail is considered a
@@ -201,7 +202,7 @@ mail.to_s =~ /Message\-ID: <[\d\w_]+@.+.mail/ #=> 27
201
202
  Mail will automatically add a Message-ID field if it is missing and
202
203
  give it a unique, random Message-ID along the lines of:
203
204
 
204
- <4a7ff76d7016_13a81ab802e1@local.fqdn.mail>
205
+ <4a7ff76d7016_13a81ab802e1@local.host.mail>
205
206
 
206
207
  ### Or do worry about Message-IDs:
207
208
 
@@ -264,7 +265,7 @@ mail.delivery_method :sendmail
264
265
  mail.deliver
265
266
  ```
266
267
 
267
- Exim requires it's own delivery manager, and can be used like so:
268
+ Exim requires its own delivery manager, and can be used like so:
268
269
 
269
270
  ```ruby
270
271
  mail.delivery_method :exim, :location => "/usr/bin/exim"
@@ -294,7 +295,7 @@ The most recent email:
294
295
  ```ruby
295
296
  Mail.all #=> Returns an array of all emails
296
297
  Mail.first #=> Returns the first unread email
297
- Mail.last #=> Returns the first unread email
298
+ Mail.last #=> Returns the last unread email
298
299
  ```
299
300
 
300
301
  The first 10 emails sorted by date in ascending order:
@@ -337,8 +338,8 @@ mail = Mail.read('multipart_email')
337
338
 
338
339
  mail.multipart? #=> true
339
340
  mail.parts.length #=> 2
340
- mail.preamble #=> "Text before the first part"
341
- mail.epilogue #=> "Text after the last part"
341
+ mail.body.preamble #=> "Text before the first part"
342
+ mail.body.epilogue #=> "Text after the last part"
342
343
  mail.parts.map { |p| p.content_type } #=> ['text/plain', 'application/pdf']
343
344
  mail.parts.map { |p| p.class } #=> [Mail::Message, Mail::Message]
344
345
  mail.parts[0].content_type_parameters #=> {'charset' => 'ISO-8859-1'}
@@ -641,7 +642,7 @@ License
641
642
 
642
643
  (The MIT License)
643
644
 
644
- Copyright (c) 2009, 2010, 2011, 2012
645
+ Copyright (c) 2009-2013 Mikel Lindsaar
645
646
 
646
647
  Permission is hereby granted, free of charge, to any person obtaining
647
648
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,25 +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
21
-
22
- require File.expand_path('../spec/environment', __FILE__)
1
+ ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', __FILE__)
2
+ require 'rubygems'
3
+ require 'bundler/setup'
23
4
 
24
5
  require 'rake/testtask'
25
6
  require 'rspec/core/rake_task'
data/lib/VERSION CHANGED
@@ -1,4 +1,4 @@
1
1
  major:2
2
- minor:4
3
- patch:4
2
+ minor:5
3
+ patch:5
4
4
  build:
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+ # This file loads up the parsers for mail to use. It also will attempt to compile parsers
3
+ # if they don't exist.
4
+ #
5
+ # It also only uses the compiler if we are running the SPEC suite
6
+ module Mail # :doc:
7
+ require 'treetop/runtime'
8
+
9
+ def self.compile_parser(parser)
10
+ require 'treetop/compiler'
11
+ Treetop.load(File.join(File.dirname(__FILE__)) + "/mail/parsers/#{parser}")
12
+ end
13
+
14
+ parsers = %w[ rfc2822_obsolete rfc2822 address_lists phrase_lists
15
+ date_time received message_ids envelope_from rfc2045
16
+ mime_version content_type content_disposition
17
+ content_transfer_encoding content_location ]
18
+
19
+ if defined?(MAIL_SPEC_SUITE_RUNNING)
20
+ parsers.each do |parser|
21
+ compile_parser(parser)
22
+ end
23
+
24
+ else
25
+ parsers.each do |parser|
26
+ begin
27
+ require "mail/parsers/#{parser}"
28
+ rescue LoadError
29
+ compile_parser(parser)
30
+ end
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -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
data/lib/mail/body.rb CHANGED
@@ -5,8 +5,8 @@ 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
9
- # block of text, or (if it is a multipart message) as an array of blocks o text.
8
+ # used in the MIME standard, it just looks at its content as either a single
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
12
12
  # #split with the correct boundary. This is because the body object has no way
@@ -257,7 +257,7 @@ module Mail
257
257
 
258
258
  def split!(boundary)
259
259
  self.boundary = boundary
260
- parts = raw_source.split("--#{boundary}")
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
@@ -0,0 +1,57 @@
1
+ module Mail
2
+ module CheckDeliveryParams #:nodoc:
3
+ class << self
4
+ def check(mail)
5
+ [ check_from(mail.smtp_envelope_from),
6
+ check_to(mail.smtp_envelope_to),
7
+ check_message(mail) ]
8
+ end
9
+
10
+ def check_from(addr)
11
+ if addr.blank?
12
+ raise ArgumentError, "SMTP From address may not be blank: #{addr.inspect}"
13
+ end
14
+
15
+ check_addr 'From', addr
16
+ end
17
+
18
+ def check_to(addrs)
19
+ if addrs.blank?
20
+ raise ArgumentError, "SMTP To address may not be blank: #{addrs.inspect}"
21
+ end
22
+
23
+ Array(addrs).map do |addr|
24
+ check_addr 'To', addr
25
+ end
26
+ end
27
+
28
+ def check_addr(addr_name, addr)
29
+ validate_smtp_addr addr do |error_message|
30
+ raise ArgumentError, "SMTP #{addr_name} address #{error_message}: #{addr.inspect}"
31
+ end
32
+ end
33
+
34
+ def validate_smtp_addr(addr)
35
+ if addr.bytesize > 2048
36
+ yield 'may not exceed 2kB'
37
+ end
38
+
39
+ if /[\r\n]/ =~ addr
40
+ yield 'may not contain CR or LF line breaks'
41
+ end
42
+
43
+ addr
44
+ end
45
+
46
+ def check_message(message)
47
+ message = message.encoded if message.respond_to?(:encoded)
48
+
49
+ if message.blank?
50
+ raise ArgumentError, 'An encoded message is required to send an email'
51
+ end
52
+
53
+ message
54
+ end
55
+ end
56
+ end
57
+ end
@@ -26,7 +26,7 @@ module Mail
26
26
  end
27
27
 
28
28
  def lookup_delivery_method(method)
29
- case method
29
+ case method.is_a?(String) ? method.to_sym : method
30
30
  when nil
31
31
  Mail::SMTP
32
32
  when :smtp
@@ -3,8 +3,10 @@
3
3
  # This is not loaded if ActiveSupport is already loaded
4
4
 
5
5
  class NilClass #:nodoc:
6
- def blank?
7
- true
6
+ unless nil.respond_to? :blank?
7
+ def blank?
8
+ true
9
+ end
8
10
  end
9
11
 
10
12
  def to_crlf
@@ -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?