mail 2.5.3 → 2.6.0

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 (151) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.rdoc +70 -0
  3. data/CONTRIBUTING.md +17 -4
  4. data/Dependencies.txt +0 -1
  5. data/Gemfile +10 -21
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +50 -29
  8. data/Rakefile +11 -20
  9. data/VERSION +4 -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 +12 -22
  13. data/lib/mail/core_extensions/object.rb +8 -8
  14. data/lib/mail/core_extensions/smtp.rb +12 -13
  15. data/lib/mail/core_extensions/string.rb +16 -6
  16. data/lib/mail/elements/address.rb +43 -79
  17. data/lib/mail/elements/address_list.rb +19 -42
  18. data/lib/mail/elements/content_disposition_element.rb +3 -7
  19. data/lib/mail/elements/content_location_element.rb +2 -6
  20. data/lib/mail/elements/content_transfer_encoding_element.rb +3 -10
  21. data/lib/mail/elements/content_type_element.rb +4 -8
  22. data/lib/mail/elements/date_time_element.rb +3 -7
  23. data/lib/mail/elements/envelope_from_element.rb +18 -13
  24. data/lib/mail/elements/message_ids_element.rb +1 -6
  25. data/lib/mail/elements/mime_version_element.rb +3 -7
  26. data/lib/mail/elements/phrase_list.rb +2 -7
  27. data/lib/mail/elements/received_element.rb +3 -7
  28. data/lib/mail/encodings/quoted_printable.rb +4 -3
  29. data/lib/mail/encodings.rb +60 -28
  30. data/lib/mail/envelope.rb +0 -5
  31. data/lib/mail/field.rb +63 -28
  32. data/lib/mail/field_list.rb +18 -18
  33. data/lib/mail/fields/bcc_field.rb +2 -2
  34. data/lib/mail/fields/cc_field.rb +2 -2
  35. data/lib/mail/fields/comments_field.rb +1 -1
  36. data/lib/mail/fields/common/common_address.rb +26 -21
  37. data/lib/mail/fields/common/common_date.rb +0 -7
  38. data/lib/mail/fields/common/common_field.rb +5 -5
  39. data/lib/mail/fields/content_id_field.rb +1 -2
  40. data/lib/mail/fields/content_transfer_encoding_field.rb +2 -8
  41. data/lib/mail/fields/content_type_field.rb +1 -1
  42. data/lib/mail/fields/date_field.rb +1 -1
  43. data/lib/mail/fields/from_field.rb +2 -2
  44. data/lib/mail/fields/in_reply_to_field.rb +2 -1
  45. data/lib/mail/fields/message_id_field.rb +2 -3
  46. data/lib/mail/fields/references_field.rb +2 -1
  47. data/lib/mail/fields/reply_to_field.rb +2 -2
  48. data/lib/mail/fields/resent_bcc_field.rb +2 -2
  49. data/lib/mail/fields/resent_cc_field.rb +2 -2
  50. data/lib/mail/fields/resent_from_field.rb +2 -2
  51. data/lib/mail/fields/resent_sender_field.rb +3 -3
  52. data/lib/mail/fields/resent_to_field.rb +2 -2
  53. data/lib/mail/fields/sender_field.rb +8 -8
  54. data/lib/mail/fields/to_field.rb +2 -2
  55. data/lib/mail/fields/unstructured_field.rb +8 -2
  56. data/lib/mail/header.rb +13 -23
  57. data/lib/mail/mail.rb +12 -0
  58. data/lib/mail/matchers/has_sent_mail.rb +34 -1
  59. data/lib/mail/message.rb +151 -48
  60. data/lib/mail/multibyte/chars.rb +2 -2
  61. data/lib/mail/multibyte/unicode.rb +6 -4
  62. data/lib/mail/network/delivery_methods/exim.rb +1 -6
  63. data/lib/mail/network/delivery_methods/file_delivery.rb +1 -1
  64. data/lib/mail/network/delivery_methods/sendmail.rb +32 -10
  65. data/lib/mail/network/delivery_methods/smtp.rb +31 -34
  66. data/lib/mail/network/delivery_methods/smtp_connection.rb +6 -6
  67. data/lib/mail/network/delivery_methods/test_mailer.rb +2 -2
  68. data/lib/mail/network/retriever_methods/imap.rb +18 -13
  69. data/lib/mail/parsers/address_lists_parser.rb +132 -0
  70. data/lib/mail/parsers/content_disposition_parser.rb +67 -0
  71. data/lib/mail/parsers/content_location_parser.rb +35 -0
  72. data/lib/mail/parsers/content_transfer_encoding_parser.rb +33 -0
  73. data/lib/mail/parsers/content_type_parser.rb +64 -0
  74. data/lib/mail/parsers/date_time_parser.rb +36 -0
  75. data/lib/mail/parsers/envelope_from_parser.rb +45 -0
  76. data/lib/mail/parsers/message_ids_parser.rb +39 -0
  77. data/lib/mail/parsers/mime_version_parser.rb +41 -0
  78. data/lib/mail/parsers/phrase_lists_parser.rb +33 -0
  79. data/lib/mail/parsers/ragel/common.rl +184 -0
  80. data/lib/mail/parsers/ragel/date_time.rl +30 -0
  81. data/lib/mail/parsers/ragel/parser_info.rb +61 -0
  82. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb +14864 -0
  83. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl +37 -0
  84. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb +751 -0
  85. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl +37 -0
  86. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb +614 -0
  87. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl +37 -0
  88. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb +447 -0
  89. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl +37 -0
  90. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb +825 -0
  91. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl +37 -0
  92. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb +817 -0
  93. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl +37 -0
  94. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb +2129 -0
  95. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl +37 -0
  96. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb +1570 -0
  97. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl +37 -0
  98. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb +440 -0
  99. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl +37 -0
  100. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb +564 -0
  101. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl +37 -0
  102. data/lib/mail/parsers/ragel/ruby/machines/rb_actions.rl +51 -0
  103. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb +5144 -0
  104. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl +37 -0
  105. data/lib/mail/parsers/ragel/ruby/parser.rb.rl.erb +37 -0
  106. data/lib/mail/parsers/ragel/ruby.rb +29 -0
  107. data/lib/mail/parsers/ragel.rb +17 -0
  108. data/lib/mail/parsers/received_parser.rb +47 -0
  109. data/lib/mail/parsers.rb +26 -0
  110. data/lib/mail/part.rb +6 -2
  111. data/lib/mail/parts_list.rb +5 -3
  112. data/lib/mail/patterns.rb +4 -1
  113. data/lib/mail/utilities.rb +28 -18
  114. data/lib/mail/version.rb +1 -1
  115. data/lib/mail/version_specific/ruby_1_8.rb +6 -2
  116. data/lib/mail/version_specific/ruby_1_9.rb +61 -21
  117. data/lib/mail.rb +1 -2
  118. metadata +112 -73
  119. data/lib/VERSION +0 -4
  120. data/lib/load_parsers.rb +0 -35
  121. data/lib/mail/core_extensions/shell_escape.rb +0 -56
  122. data/lib/mail/parsers/address_lists.rb +0 -64
  123. data/lib/mail/parsers/address_lists.treetop +0 -19
  124. data/lib/mail/parsers/content_disposition.rb +0 -535
  125. data/lib/mail/parsers/content_disposition.treetop +0 -46
  126. data/lib/mail/parsers/content_location.rb +0 -139
  127. data/lib/mail/parsers/content_location.treetop +0 -20
  128. data/lib/mail/parsers/content_transfer_encoding.rb +0 -162
  129. data/lib/mail/parsers/content_transfer_encoding.treetop +0 -20
  130. data/lib/mail/parsers/content_type.rb +0 -967
  131. data/lib/mail/parsers/content_type.treetop +0 -68
  132. data/lib/mail/parsers/date_time.rb +0 -114
  133. data/lib/mail/parsers/date_time.treetop +0 -11
  134. data/lib/mail/parsers/envelope_from.rb +0 -194
  135. data/lib/mail/parsers/envelope_from.treetop +0 -32
  136. data/lib/mail/parsers/message_ids.rb +0 -45
  137. data/lib/mail/parsers/message_ids.treetop +0 -15
  138. data/lib/mail/parsers/mime_version.rb +0 -144
  139. data/lib/mail/parsers/mime_version.treetop +0 -19
  140. data/lib/mail/parsers/phrase_lists.rb +0 -45
  141. data/lib/mail/parsers/phrase_lists.treetop +0 -15
  142. data/lib/mail/parsers/received.rb +0 -71
  143. data/lib/mail/parsers/received.treetop +0 -11
  144. data/lib/mail/parsers/rfc2045.rb +0 -464
  145. data/lib/mail/parsers/rfc2045.treetop +0 -36
  146. data/lib/mail/parsers/rfc2822.rb +0 -5397
  147. data/lib/mail/parsers/rfc2822.treetop +0 -410
  148. data/lib/mail/parsers/rfc2822_obsolete.rb +0 -3768
  149. data/lib/mail/parsers/rfc2822_obsolete.treetop +0 -241
  150. data/lib/tasks/corpus.rake +0 -125
  151. data/lib/tasks/treetop.rake +0 -10
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ecb5e9115e61802f251480eef90c6698ac665d0b
4
+ data.tar.gz: a1105d5defc2c7b374598a392e5f5dc4d1452a21
5
+ SHA512:
6
+ metadata.gz: 103d2126c02d1aeb5ffd4982f261407af16652fd181f6e0fc63bf12702e5aa1ea3c7f863a3c39f822ba3b8e8cf704782d1beb7c4e2e28cba5f4fc2931151cf0e
7
+ data.tar.gz: 6f25c0decaf77a0314b42d0fbf6c61edfc7f2fe9b4bbeef004e34a7127882093b660108cd7728a108f26b1b3dcf2664beac4e5e6d0d0d3e68565f78fdd273d4e
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,75 @@
1
1
  == HEAD
2
2
 
3
+ == Version 2.6.0 - Mon Jun 2 22:49 +1100 2014 Mikel Lindsaar <mikel@reinteractive.net>
4
+
5
+ Features:
6
+ * Allow interceptors and observers to be unregistered (zuhao)
7
+ * Added feature to find the mail in uid (taketin)
8
+ * Save settings passed to TestMailer#new (svanderbleek)
9
+ * Allow the setting of envelope from directly (jeremy)
10
+ * Accept other IETF/IANA-registered Content-Types and Content-Transfer-Encodings (jeremy)
11
+ * Alias shift-jis charset to Shift_JIS Ruby encoding (jeremy)
12
+ * Add support for ks_c_5601-1987 charset, aliased to CP949 Ruby encoding (jeremy)
13
+ * Don't allow colons in header names (jeremy)
14
+ * Can assign arrays of Message-IDs to References and In-Reply-To (jeremy)
15
+ * Setting the html_ or text_part sets a default text/html or text/plain content type (jeremy)
16
+ * Setting the html_ or text_part to nil removes it (jeremy)
17
+ * Addresses without a parsable email or display name still format as their raw text (jeremy)
18
+ * Close pull request 504 - Alias GB2312 charset to GB18030 Ruby encoding (bpot)
19
+ * Close pull request 399 - Accept :ca_path and :ca_file options for SMTP delivery (ndbroadbent)
20
+ * Close pull request 389 - Don't add superfluous message headers to MIME parts (djmaze, jeremy)
21
+
22
+ Performance:
23
+ * Migrate to RAGEL based parser, awesome work by (bpot)
24
+ * Performance improvements for people parsing email headers (ConradIrwin)
25
+ * Close pull request 488 - Speed up field construction & comparison (bpot)
26
+
27
+ Bugs:
28
+ * Fix for when content looks like field name (kjg)
29
+ * Don't change original when you change a copy (TylerRick)
30
+ * Don't include separating semicolon in paramter value when sanitizing (bpot)
31
+ * Fix fencepost encoding problem with binhex strings and only one token (drasch)
32
+ * Fix sendmail delivery to addresses with a leading hyphen (lifo, jeremy)
33
+ * Correctly format mbox From headers per RFC4155 (bpot, jeremy)
34
+ * Fix bogus '=' at the end of some quoted-printable messages (jeremy)
35
+ * Shouldn't be fooled into encoding strings on 1.8 by unrelated Encoding constant (emiellohr, jeremy)
36
+ * Header encoding should be US-ASCII, not the default external encoding (jeremy)
37
+ * Address elements should return decoded display names by default (jeremy)
38
+ * Fix up tests that depend on utf-8 external encoding; read fixtures as binary (jeremy)
39
+ * Capture stderr from Sendmail and Exim deliveries (jeremy)
40
+ * RFC2822 quoted_string content may be empty (jeremy)
41
+ * Calling #to_s on a field with a nil value returns an empty string instead of nil (jeremy)
42
+ * The Received header may contain zero name/value pairs, qmail-style (jeremy)
43
+ * Fix that setting an attachment with a :mime_type and :encoding would override the :encoding (jeremy)
44
+ * Fix that declaring an html_part but no text_part would use multipart/alternative anyway (jeremy)
45
+ * Close pull request 508 - Don't add an extra CRLF to MIME parts; split MIME parts on correct CRLF boundaries (Aalanar)
46
+ * Close pull request 506 - Escape backslashes in quoted strings (ConradIrwin)
47
+ * Close pull request 496 - Correctly handle quoted-printable line breaks (jeremy)
48
+ * Close pull request 493 - Repair misencoded quoted-printable line breaks (jeremy)
49
+ * Close pull request 487 - Extract comments from group email addresses (bpot)
50
+ * Close pull request 481 - Correctly quote filename attributes (bpot)
51
+ * Close pull request 480 - Support mixed encodings in a single header body (adamvaughan)
52
+ * Close pull request 471 - Fix Ruby 1.8 build when UTF16/32 default to little-endian (kennyj)
53
+
54
+ Coping with third-party bugs:
55
+ * Parse multipart boundary from Content-Type headers containing extra semicolons (jeremy)
56
+ * Close pull request 389 - Only add Content-ID to inline attachments to appease Outlook (djmaze, jeremy)
57
+
58
+ Housekeeping:
59
+ * Add development gem dependency on rdoc (jeremy)
60
+ * Refresh Bundler dependencies & setup (jeremy)
61
+ * Remove i18n dependency and last vestiges of activesupport dependency in specs (jeremy)
62
+ * Clarify that Sender is a single address, not an address list (jeremy)
63
+ * Add an MIT-LICENSE file to make licensing clear & obvious; update to 2013 (jeremy)
64
+ * Close pull request 501 - Tighten up header/body whitespace splitting (ConradIrwin)
65
+ * Close pull request 499 - Clean up some dead code (ConradIrwin)
66
+ * Close pull request 489, 495 - Docs typos (JackDanger, francois)
67
+ * Close pull request 485 - Be explicit about unsupported address parsing (bpot)
68
+ * Close pull request 484 - Remove #tree specs in preparation for deprecation removal (bpot)
69
+ * Close pull request 482 - Update address field specs to reflect to #initialize API (bpot)
70
+ * Close pull request 475 - Shush warning on Object#blank? redefinition (amatsuda)
71
+ * Close pull request 472 - Clean up UTF8/UTF-8 internals (kennyj)
72
+
3
73
  == Version 2.5.3 - Sun Dec 4 15:52:00 +1100 2012 Mikel Lindsaar <mikel@reinteractive.net>
4
74
 
5
75
  * Close pull request 468 - Remove debug output to STDOUT (tadman)
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,17 @@ 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!
46
+
47
+ ### Testing against mime-types versions:
48
+
49
+ Use [appraisal](https://github.com/thoughtbot/appraisal) to run against all supported versions of mime-types.
50
+
51
+ 1. Run `(bundle check || bundle) && appraisal` so that all the 'appraised' gemfiles are bundled.
52
+ 2. Run either `appraisal rake` or `rake appraisal` to run all the tests.
53
+
54
+ To run only one 'appraised' gemfile, run. e.g. `BUNDLE_GEMFILE=gemfiles/mime_types_edge.gemfile (bundle check || bundle) && rake`
55
+
56
+ To change the appraisals, modify the `Appraisals` file, run `appraisal`, commit the generated gemfiles, and modify the .travis.yml matrix.
57
+
58
+ To run on all rubies / gemfiles, just like TravisCI, see [WWTD](https://github.com/grosser/wwtd).
data/Dependencies.txt CHANGED
@@ -1,3 +1,2 @@
1
- treetop: we need to include this in the gem spec
2
1
  tlsmail: if ruby < 1.8.6... we could make it optional, or embed it in Mail
3
2
  mime/types: I think we embed a simplified version, or help maintain it, it is old (2006)
data/Gemfile CHANGED
@@ -1,26 +1,15 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
- gem "activesupport", ">= 2.3.6"
4
- gem "tlsmail" if RUBY_VERSION <= '1.8.6'
5
- gem "mime-types", "~> 1.16"
6
- gem "treetop", "~> 1.4.10"
7
- gem "i18n", ">= 0.4.0"
3
+ gemspec
8
4
 
9
- if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
10
- gem 'jruby-openssl'
5
+ gem "tlsmail", "~> 0.0.1" if RUBY_VERSION <= "1.8.6"
6
+ gem "jruby-openssl", :platforms => :jruby
7
+
8
+ group :development, :test do
9
+ gem "appraisal", "~> 1.0"
11
10
  end
12
11
 
13
- 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
+ # For gems not required to run tests
13
+ group :local_development, :test do
14
+ gem "ruby-debug", :platforms => :mri_18
26
15
  end
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
@@ -42,15 +42,25 @@ 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
- * ruby-1.8.7-p370 [ i686 ]
48
- * ruby-1.9.2-p290 [ x86_64 ]
47
+ * ruby-1.8.7-p374 [ i686 ]
48
+ * ruby-1.9.2-p320 [ x86_64 ]
49
49
  * ruby-1.9.3-p327 [ x86_64 ]
50
- * jruby-1.6.8 [ x86_64 ]
51
- * jruby-1.7.0 [ x86_64 ]
52
- * rbx-d18 [ x86_64 ]
53
- * rbx-d19 [ x86_64 ]
50
+ * ruby-2.0.0-p451 [ x86_64 ]
51
+ * ruby-2.1.2 [ x86_64 ]
52
+ * ruby-head [ x86_64 ]
53
+ * jruby [ x86_64 ]
54
+ * jruby-head [ x86_64 ]
55
+ * rbx-2 [ x86_64 ]
56
+
57
+ Testing a specific mime type (needed for 1.8.7 for example) can be done manually with:
58
+
59
+ $ BUNDLE_GEMFILE=gemfiles/mime_types_1.16.gemfile bundle check
60
+ $ BUNDLE_GEMFILE=gemfiles/mime_types_1.16.gemfile bundle
61
+ $ BUNDLE_GEMFILE=gemfiles/mime_types_1.16.gemfile rake
62
+
63
+
54
64
 
55
65
  Discussion
56
66
  ----------
@@ -130,12 +140,12 @@ I have tried to simplify it some:
130
140
  it will include the header field and value and CRLF at the end and wrapped as
131
141
  needed.
132
142
 
133
- 2. All objects that can render into an email, have a :decoded method. Decoded will
143
+ 2. All objects that can render into an email, have a `#decoded` method. Decoded will
134
144
  return the object's "value" only as a string. This means it will not include
135
145
  the header fields (like 'To:' or 'Subject:').
136
146
 
137
147
  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.
148
+ method, while <code>#to_s</code> on a field object will call its decoded method.
139
149
  So calling <code>#to_s</code> on a Mail object will return the mail, all encoded
140
150
  ready to send, while calling <code>#to_s</code> on the From field or the body will
141
151
  return the decoded value of the object. The header object of Mail is considered a
@@ -185,6 +195,8 @@ mail['from'] = 'mikel@test.lindsaar.net'
185
195
  mail[:to] = 'you@test.lindsaar.net'
186
196
  mail.subject = 'This is a test email'
187
197
 
198
+ mail.header['X-Custom-Header'] = 'custom value'
199
+
188
200
  mail.to_s #=> "From: mikel@test.lindsaar.net\r\nTo: you@...
189
201
  ```
190
202
 
@@ -202,7 +214,7 @@ mail.to_s =~ /Message\-ID: <[\d\w_]+@.+.mail/ #=> 27
202
214
  Mail will automatically add a Message-ID field if it is missing and
203
215
  give it a unique, random Message-ID along the lines of:
204
216
 
205
- <4a7ff76d7016_13a81ab802e1@local.fqdn.mail>
217
+ <4a7ff76d7016_13a81ab802e1@local.host.mail>
206
218
 
207
219
  ### Or do worry about Message-IDs:
208
220
 
@@ -227,10 +239,10 @@ easy as:
227
239
 
228
240
  ```ruby
229
241
  Mail.deliver do
230
- from 'me@test.lindsaar.net'
231
- to 'you@test.lindsaar.net'
232
- subject 'Here is the image you wanted'
233
- body File.read('body.txt')
242
+ from 'me@test.lindsaar.net'
243
+ to 'you@test.lindsaar.net'
244
+ subject 'Here is the image you wanted'
245
+ body File.read('body.txt')
234
246
  add_file '/full/path/to/somefile.png'
235
247
  end
236
248
  ```
@@ -265,7 +277,16 @@ mail.delivery_method :sendmail
265
277
  mail.deliver
266
278
  ```
267
279
 
268
- Exim requires it's own delivery manager, and can be used like so:
280
+ Sending via smtp (for example to [mailcatcher](https://github.com/sj26/mailcatcher))
281
+ ```ruby
282
+
283
+ Mail.defaults do
284
+ delivery_method :smtp, address: "localhost", port: 1025
285
+ end
286
+ ```
287
+
288
+
289
+ Exim requires its own delivery manager, and can be used like so:
269
290
 
270
291
  ```ruby
271
292
  mail.delivery_method :exim, :location => "/usr/bin/exim"
@@ -318,7 +339,7 @@ emails.length #=> LOTS!
318
339
  ```ruby
319
340
  mail = Mail.read('/path/to/message.eml')
320
341
 
321
- mail.envelope.from #=> 'mikel@test.lindsaar.net'
342
+ mail.envelope_from #=> 'mikel@test.lindsaar.net'
322
343
  mail.from.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
323
344
  mail.sender.address #=> 'mikel@test.lindsaar.net'
324
345
  mail.to #=> 'bob@test.lindsaar.net'
@@ -338,8 +359,8 @@ mail = Mail.read('multipart_email')
338
359
 
339
360
  mail.multipart? #=> true
340
361
  mail.parts.length #=> 2
341
- mail.preamble #=> "Text before the first part"
342
- mail.epilogue #=> "Text after the last part"
362
+ mail.body.preamble #=> "Text before the first part"
363
+ mail.body.epilogue #=> "Text after the last part"
343
364
  mail.parts.map { |p| p.content_type } #=> ['text/plain', 'application/pdf']
344
365
  mail.parts.map { |p| p.class } #=> [Mail::Message, Mail::Message]
345
366
  mail.parts[0].content_type_parameters #=> {'charset' => 'ISO-8859-1'}
@@ -349,7 +370,7 @@ mail.parts[1].content_type_parameters #=> {'name' => 'my.pdf'}
349
370
  Mail generates a tree of parts. Each message has many or no parts. Each part
350
371
  is another message which can have many or no parts.
351
372
 
352
- A message will only have parts if it is a multipart/mixed or related/mixed
373
+ A message will only have parts if it is a multipart/mixed or multipart/related
353
374
  content type and has a boundary defined.
354
375
 
355
376
  ### Testing and extracting attachments
@@ -362,7 +383,7 @@ mail.attachments.each do | attachment |
362
383
  filename = attachment.filename
363
384
  begin
364
385
  File.open(images_dir + filename, "w+b", 0644) {|f| f.write attachment.body.decoded}
365
- rescue Exception => e
386
+ rescue => e
366
387
  puts "Unable to save data for #{filename} because #{e.message}"
367
388
  end
368
389
  end
@@ -545,7 +566,7 @@ Using Mail with Testing or Spec'ing Libraries
545
566
  If mail is part of your system, you'll need a way to test it without actually
546
567
  sending emails, the TestMailer can do this for you.
547
568
 
548
- ```
569
+ ```ruby
549
570
  require 'mail'
550
571
  => true
551
572
  Mail.defaults do
@@ -571,7 +592,7 @@ Mail::TestMailer.deliveries.clear
571
592
 
572
593
  There is also a set of RSpec matchers stolen fr^H^H^H^H^H^H^H^H inspired by Shoulda's ActionMailer matchers (you'll want to set <code>delivery_method</code> as above too):
573
594
 
574
- ```
595
+ ```ruby
575
596
  Mail.defaults do
576
597
  delivery_method :test # in practice you'd do this in spec_helper.rb
577
598
  end
@@ -642,7 +663,7 @@ License
642
663
 
643
664
  (The MIT License)
644
665
 
645
- Copyright (c) 2009, 2010, 2011, 2012 Mikel Lindsaar
666
+ Copyright (c) 2009-2013 Mikel Lindsaar
646
667
 
647
668
  Permission is hereby granted, free of charge, to any person obtaining
648
669
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,23 +1,8 @@
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`?"
1
+ if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __FILE__)
20
3
  end
4
+ require 'rubygems'
5
+ require 'bundler/setup'
21
6
 
22
7
  require 'rake/testtask'
23
8
  require 'rspec/core/rake_task'
@@ -34,5 +19,11 @@ RSpec::Core::RakeTask.new(:spec) do |t|
34
19
  t.rspec_opts = %w(--backtrace --color)
35
20
  end
36
21
 
22
+ begin
23
+ require "appraisal"
24
+ rescue LoadError
25
+ warn "Appraisal is only available in test/development"
26
+ end
27
+
37
28
  # load custom rake tasks
38
- Dir["#{File.dirname(__FILE__)}/lib/tasks/**/*.rake"].sort.each { |ext| load ext }
29
+ Dir["#{File.dirname(__FILE__)}/tasks/**/*.rake"].sort.each { |ext| load ext }
data/VERSION ADDED
@@ -0,0 +1,4 @@
1
+ major:2
2
+ minor:6
3
+ patch:0
4
+ build:
@@ -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,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
@@ -127,9 +127,9 @@ module Mail
127
127
  def sort_parts!
128
128
  @parts.each do |p|
129
129
  p.body.set_sort_order(@part_sort_order)
130
- @parts.sort!(@part_sort_order)
131
130
  p.body.sort_parts!
132
131
  end
132
+ @parts.sort!(@part_sort_order)
133
133
  end
134
134
 
135
135
  # Returns the raw source that the body was initialized with, without
@@ -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
@@ -1,11 +1,21 @@
1
1
  # encoding: utf-8
2
2
  class String #:nodoc:
3
+
4
+ if RUBY_VERSION >= '1.9'
5
+ # This 1.9 only regex can save a reasonable amount of time (~20%)
6
+ # by not matching "\r\n" so the string is returned unchanged in
7
+ # the common case.
8
+ CRLF_REGEX = Regexp.new("(?<!\r)\n|\r(?!\n)")
9
+ else
10
+ CRLF_REGEX = /\n|\r\n|\r/
11
+ end
12
+
3
13
  def to_crlf
4
- to_str.gsub(/\n|\r\n|\r/) { "\r\n" }
14
+ to_str.gsub(CRLF_REGEX, "\r\n")
5
15
  end
6
16
 
7
17
  def to_lf
8
- to_str.gsub(/\n|\r\n|\r/) { "\n" }
18
+ to_str.gsub(/\r\n|\r/, "\n")
9
19
  end
10
20
 
11
21
  unless String.instance_methods(false).map {|m| m.to_sym}.include?(:blank?)
@@ -15,12 +25,12 @@ class String #:nodoc:
15
25
  end
16
26
 
17
27
  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}
28
+ # Backport from Ruby 1.9 checks for non-us-ascii characters.
21
29
  def ascii_only?
22
- !(self =~ /[^#{US_ASCII_REGEXP}]/)
30
+ self !~ MATCH_NON_US_ASCII
23
31
  end
32
+
33
+ MATCH_NON_US_ASCII = /[^\x00-\x7f]/
24
34
  end
25
35
 
26
36
  def not_ascii_only?