mail 2.6.4 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +111 -118
  3. data/lib/mail/attachments_list.rb +11 -10
  4. data/lib/mail/body.rb +73 -84
  5. data/lib/mail/check_delivery_params.rb +54 -10
  6. data/lib/mail/configuration.rb +2 -0
  7. data/lib/mail/constants.rb +27 -5
  8. data/lib/mail/elements/address.rb +61 -50
  9. data/lib/mail/elements/address_list.rb +11 -19
  10. data/lib/mail/elements/content_disposition_element.rb +9 -16
  11. data/lib/mail/elements/content_location_element.rb +6 -11
  12. data/lib/mail/elements/content_transfer_encoding_element.rb +6 -11
  13. data/lib/mail/elements/content_type_element.rb +16 -23
  14. data/lib/mail/elements/date_time_element.rb +7 -15
  15. data/lib/mail/elements/envelope_from_element.rb +22 -23
  16. data/lib/mail/elements/message_ids_element.rb +18 -13
  17. data/lib/mail/elements/mime_version_element.rb +7 -15
  18. data/lib/mail/elements/phrase_list.rb +12 -10
  19. data/lib/mail/elements/received_element.rb +27 -19
  20. data/lib/mail/encodings/7bit.rb +9 -14
  21. data/lib/mail/encodings/8bit.rb +2 -21
  22. data/lib/mail/encodings/base64.rb +11 -12
  23. data/lib/mail/encodings/binary.rb +3 -22
  24. data/lib/mail/encodings/identity.rb +24 -0
  25. data/lib/mail/encodings/quoted_printable.rb +6 -6
  26. data/lib/mail/encodings/transfer_encoding.rb +38 -29
  27. data/lib/mail/encodings/unix_to_unix.rb +3 -1
  28. data/lib/mail/encodings.rb +81 -54
  29. data/lib/mail/envelope.rb +11 -14
  30. data/lib/mail/field.rb +119 -98
  31. data/lib/mail/field_list.rb +60 -7
  32. data/lib/mail/fields/bcc_field.rb +34 -52
  33. data/lib/mail/fields/cc_field.rb +28 -49
  34. data/lib/mail/fields/comments_field.rb +27 -37
  35. data/lib/mail/fields/common_address_field.rb +170 -0
  36. data/lib/mail/fields/common_date_field.rb +58 -0
  37. data/lib/mail/fields/common_field.rb +77 -0
  38. data/lib/mail/fields/common_message_id_field.rb +42 -0
  39. data/lib/mail/fields/content_description_field.rb +7 -14
  40. data/lib/mail/fields/content_disposition_field.rb +13 -38
  41. data/lib/mail/fields/content_id_field.rb +24 -51
  42. data/lib/mail/fields/content_location_field.rb +11 -25
  43. data/lib/mail/fields/content_transfer_encoding_field.rb +31 -31
  44. data/lib/mail/fields/content_type_field.rb +50 -80
  45. data/lib/mail/fields/date_field.rb +23 -52
  46. data/lib/mail/fields/from_field.rb +28 -49
  47. data/lib/mail/fields/in_reply_to_field.rb +38 -49
  48. data/lib/mail/fields/keywords_field.rb +18 -31
  49. data/lib/mail/fields/message_id_field.rb +25 -71
  50. data/lib/mail/fields/mime_version_field.rb +19 -30
  51. data/lib/mail/fields/named_structured_field.rb +11 -0
  52. data/lib/mail/fields/named_unstructured_field.rb +11 -0
  53. data/lib/mail/fields/optional_field.rb +9 -7
  54. data/lib/mail/fields/{common/parameter_hash.rb → parameter_hash.rb} +13 -11
  55. data/lib/mail/fields/received_field.rb +43 -57
  56. data/lib/mail/fields/references_field.rb +35 -49
  57. data/lib/mail/fields/reply_to_field.rb +28 -49
  58. data/lib/mail/fields/resent_bcc_field.rb +28 -49
  59. data/lib/mail/fields/resent_cc_field.rb +28 -49
  60. data/lib/mail/fields/resent_date_field.rb +5 -30
  61. data/lib/mail/fields/resent_from_field.rb +28 -49
  62. data/lib/mail/fields/resent_message_id_field.rb +5 -29
  63. data/lib/mail/fields/resent_sender_field.rb +27 -56
  64. data/lib/mail/fields/resent_to_field.rb +28 -49
  65. data/lib/mail/fields/return_path_field.rb +50 -54
  66. data/lib/mail/fields/sender_field.rb +34 -55
  67. data/lib/mail/fields/structured_field.rb +3 -30
  68. data/lib/mail/fields/subject_field.rb +9 -11
  69. data/lib/mail/fields/to_field.rb +28 -49
  70. data/lib/mail/fields/unstructured_field.rb +32 -47
  71. data/lib/mail/header.rb +71 -110
  72. data/lib/mail/mail.rb +2 -10
  73. data/lib/mail/matchers/attachment_matchers.rb +15 -0
  74. data/lib/mail/matchers/has_sent_mail.rb +21 -1
  75. data/lib/mail/message.rb +113 -117
  76. data/lib/mail/multibyte/chars.rb +23 -180
  77. data/lib/mail/multibyte/unicode.rb +10 -10
  78. data/lib/mail/multibyte/utils.rb +26 -43
  79. data/lib/mail/multibyte.rb +55 -16
  80. data/lib/mail/network/delivery_methods/exim.rb +8 -11
  81. data/lib/mail/network/delivery_methods/file_delivery.rb +13 -16
  82. data/lib/mail/network/delivery_methods/logger_delivery.rb +34 -0
  83. data/lib/mail/network/delivery_methods/sendmail.rb +32 -35
  84. data/lib/mail/network/delivery_methods/smtp.rb +76 -54
  85. data/lib/mail/network/delivery_methods/smtp_connection.rb +4 -9
  86. data/lib/mail/network/delivery_methods/test_mailer.rb +8 -9
  87. data/lib/mail/network/retriever_methods/base.rb +8 -8
  88. data/lib/mail/network/retriever_methods/imap.rb +20 -7
  89. data/lib/mail/network/retriever_methods/pop3.rb +5 -3
  90. data/lib/mail/network/retriever_methods/test_retriever.rb +3 -2
  91. data/lib/mail/network.rb +1 -0
  92. data/lib/mail/parser_tools.rb +15 -0
  93. data/lib/mail/parsers/address_lists_parser.rb +33225 -116
  94. data/lib/mail/parsers/address_lists_parser.rl +179 -0
  95. data/lib/mail/parsers/content_disposition_parser.rb +882 -49
  96. data/lib/mail/parsers/content_disposition_parser.rl +89 -0
  97. data/lib/mail/parsers/content_location_parser.rb +809 -23
  98. data/lib/mail/parsers/content_location_parser.rl +78 -0
  99. data/lib/mail/parsers/content_transfer_encoding_parser.rb +509 -21
  100. data/lib/mail/parsers/content_transfer_encoding_parser.rl +71 -0
  101. data/lib/mail/parsers/content_type_parser.rb +1037 -56
  102. data/lib/mail/parsers/content_type_parser.rl +90 -0
  103. data/lib/mail/parsers/date_time_parser.rb +877 -25
  104. data/lib/mail/parsers/date_time_parser.rl +69 -0
  105. data/lib/mail/parsers/envelope_from_parser.rb +3669 -40
  106. data/lib/mail/parsers/envelope_from_parser.rl +89 -0
  107. data/lib/mail/parsers/message_ids_parser.rb +5146 -25
  108. data/lib/mail/parsers/message_ids_parser.rl +93 -0
  109. data/lib/mail/parsers/mime_version_parser.rb +497 -26
  110. data/lib/mail/parsers/mime_version_parser.rl +68 -0
  111. data/lib/mail/parsers/phrase_lists_parser.rb +870 -22
  112. data/lib/mail/parsers/phrase_lists_parser.rl +90 -0
  113. data/lib/mail/parsers/received_parser.rb +8776 -43
  114. data/lib/mail/parsers/received_parser.rl +91 -0
  115. data/lib/mail/parsers/rfc2045_content_transfer_encoding.rl +13 -0
  116. data/lib/mail/parsers/rfc2045_content_type.rl +25 -0
  117. data/lib/mail/parsers/rfc2045_mime.rl +16 -0
  118. data/lib/mail/parsers/rfc2183_content_disposition.rl +15 -0
  119. data/lib/mail/parsers/rfc3629_utf8.rl +19 -0
  120. data/lib/mail/parsers/rfc5234_abnf_core_rules.rl +22 -0
  121. data/lib/mail/parsers/rfc5322.rl +74 -0
  122. data/lib/mail/parsers/rfc5322_address.rl +72 -0
  123. data/lib/mail/parsers/{ragel/date_time.rl → rfc5322_date_time.rl} +8 -1
  124. data/lib/mail/parsers/rfc5322_lexical_tokens.rl +60 -0
  125. data/lib/mail/parsers.rb +11 -25
  126. data/lib/mail/part.rb +6 -10
  127. data/lib/mail/parts_list.rb +62 -6
  128. data/lib/mail/smtp_envelope.rb +57 -0
  129. data/lib/mail/utilities.rb +357 -74
  130. data/lib/mail/version.rb +2 -2
  131. data/lib/mail/yaml.rb +30 -0
  132. data/lib/mail.rb +5 -35
  133. metadata +111 -66
  134. data/CHANGELOG.rdoc +0 -787
  135. data/CONTRIBUTING.md +0 -60
  136. data/Dependencies.txt +0 -2
  137. data/Gemfile +0 -11
  138. data/Rakefile +0 -29
  139. data/TODO.rdoc +0 -9
  140. data/lib/mail/core_extensions/smtp.rb +0 -25
  141. data/lib/mail/core_extensions/string/access.rb +0 -146
  142. data/lib/mail/core_extensions/string/multibyte.rb +0 -79
  143. data/lib/mail/core_extensions/string.rb +0 -21
  144. data/lib/mail/fields/common/address_container.rb +0 -17
  145. data/lib/mail/fields/common/common_address.rb +0 -136
  146. data/lib/mail/fields/common/common_date.rb +0 -36
  147. data/lib/mail/fields/common/common_field.rb +0 -61
  148. data/lib/mail/fields/common/common_message_id.rb +0 -49
  149. data/lib/mail/multibyte/exceptions.rb +0 -9
  150. data/lib/mail/parsers/ragel/common.rl +0 -185
  151. data/lib/mail/parsers/ragel/parser_info.rb +0 -61
  152. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb +0 -14864
  153. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl +0 -37
  154. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb +0 -751
  155. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl +0 -37
  156. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb +0 -614
  157. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl +0 -37
  158. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb +0 -447
  159. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl +0 -37
  160. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb +0 -825
  161. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl +0 -37
  162. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb +0 -817
  163. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl +0 -37
  164. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb +0 -2149
  165. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl +0 -37
  166. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb +0 -1570
  167. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl +0 -37
  168. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb +0 -440
  169. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl +0 -37
  170. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb +0 -564
  171. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl +0 -37
  172. data/lib/mail/parsers/ragel/ruby/machines/rb_actions.rl +0 -51
  173. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb +0 -5144
  174. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl +0 -37
  175. data/lib/mail/parsers/ragel/ruby/parser.rb.rl.erb +0 -37
  176. data/lib/mail/parsers/ragel/ruby.rb +0 -40
  177. data/lib/mail/parsers/ragel.rb +0 -18
  178. data/lib/mail/version_specific/ruby_1_8.rb +0 -126
  179. data/lib/mail/version_specific/ruby_1_9.rb +0 -223
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: f91f133d2e44832ecef1cb4bfe9cc57391aedf84
4
- data.tar.gz: 23d0cdbc09cdbaafee76b01d7c3820a6c0dfb6d1
2
+ SHA256:
3
+ metadata.gz: fa5b2d445e65e58dc7c1716cd6f2eebd4f2397548eb1aa1d9230222df09f6aa3
4
+ data.tar.gz: cae304c28819a9903baf718616f8bb94e2ea860b0b2db43bfb3a3e0f9f12eaac
5
5
  SHA512:
6
- metadata.gz: c788407da309561bee6a59ec746efeea7c0cc8633206eb2085f08ad6b161df92475109a988de748e554248d2ca47e6cd31c3fd0394d0eddac5950e7bb28783a8
7
- data.tar.gz: 55b70f9d539420d254373c7abfccf6bc85228f34c38696086be363a36fb4f966415238aaa8e9ec9e6eed02207af2a3940b9f85c5f3076e735cd19e095764abc2
6
+ metadata.gz: b72cc59bc03570e9f5347d796e38b6d4365143a7122e7353559314e82b2523479fb5adf90fce65d1d8a5c7e95a97964b2118c082de5b6bb535f663bf4056fa8f
7
+ data.tar.gz: 64157d336e45117c5e32db4a599ccf97e3b8b6aa2c761b4d5923f18b6b506ee8a20795ce5e9e8494c4d39c7c4784e2317da7674d89ffc75cb5fd6d19f5473073
data/README.md CHANGED
@@ -1,89 +1,79 @@
1
- Mail [![Build Status](https://travis-ci.org/mikel/mail.png?branch=master)](https://travis-ci.org/mikel/mail)
2
- ====
1
+ # Mail [![Build Status](https://github.com/mikel/mail/actions/workflows/test.yml/badge.svg)](https://github.com/mikel/mail/actions/workflows/test.yml)
3
2
 
4
- Introduction
5
- ------------
3
+ ## Introduction
6
4
 
7
- Mail is an internet library for Ruby that is designed to handle emails
5
+ Mail is an internet library for Ruby that is designed to handle email
8
6
  generation, parsing and sending in a simple, rubyesque manner.
9
7
 
10
8
  The purpose of this library is to provide a single point of access to handle
11
- all email functions, including sending and receiving emails. All network
9
+ all email functions, including sending and receiving email. All network
12
10
  type actions are done through proxy methods to Net::SMTP, Net::POP3 etc.
13
11
 
14
12
  Built from my experience with TMail, it is designed to be a pure ruby
15
- implementation that makes generating, sending and parsing emails a no
13
+ implementation that makes generating, sending and parsing email a no
16
14
  brainer.
17
15
 
18
16
  It is also designed from 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.
17
+ of Ruby. Modern Rubies handle text encodings much more wonderfully than before
18
+ so these features have been taken full advantage of in this library allowing
19
+ Mail to handle a lot more messages more cleanly than TMail.
23
20
 
24
21
  Finally, Mail has been designed with a very simple object oriented system
25
22
  that really opens up the email messages you are parsing, if you know what
26
23
  you are doing, you can fiddle with every last bit of your email directly.
27
24
 
28
- Donations
29
- -------------
25
+ ## You can contribute to this library
30
26
 
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.
27
+ Yes, you! Mail is used in countless apps by people around the world. It is,
28
+ like all open source software, a labour of love borne from our free time.
29
+ If you would like to say thanks, please dig in and contribute alongside us!
30
+ Triage and fix [GitHub issues](https://github.com/mikel/mail/issues), improve
31
+ our documentation, add new features—up to you! Thank you for pitching in.
33
32
 
34
- It is (like all open source software) a labour of love and something I am doing
35
- with my own free time. If you would like to say thanks, please feel free to
36
- [make a donation](http://www.pledgie.com/campaigns/8790) and feel free to send
37
- me a nice email :)
38
33
 
39
- <a href='http://www.pledgie.com/campaigns/8790'><img alt='Click here to lend your support to: mail and make a donation at www.pledgie.com !' src='http://www.pledgie.com/campaigns/8790.png?skin_name=chrome' border='0' /></a>
34
+ # Contents
35
+ * [Compatibility](#compatibility)
36
+ * [Discussion](#discussion)
37
+ * [Current Capabilities of Mail](#current-capabilities-of-mail)
38
+ * [Roadmap](#roadmap)
39
+ * [Testing Policy](#testing-policy)
40
+ * [API Policy](#api-policy)
41
+ * [Installation](#installation)
42
+ * [Encodings](#encodings)
43
+ * [Contributing](#contributing)
44
+ * [Usage](#usage)
45
+ * [Excerpts from TREC Span Corpus 2005](#excerpts-from-trec-span-corpus-2005)
46
+ * [License](#license)
40
47
 
48
+ ## Compatibility
41
49
 
42
- Compatibility
43
- -------------
50
+ Mail supports Ruby 2.5+, including JRuby and TruffleRuby.
44
51
 
45
- Every Mail commit is tested by Travis on the [following platforms](https://github.com/mikel/mail/blob/master/.travis.yml)
52
+ As new versions of Ruby are released, Mail will be compatible with support for the "preview" and all "normal maintenance", "security maintenance" and the two most recent "end of life" versions listed at the [Ruby Maintenance Branches](https://www.ruby-lang.org/en/downloads/branches/) page. Pull requests to assist in adding support for new preview releases are more than welcome.
46
53
 
47
- * ruby-1.8.7 [ i686 ]
48
- * ruby-1.9.2 [ x86_64 ]
49
- * ruby-1.9.3 [ x86_64 ]
50
- * ruby-2.0.0 [ 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 ]
54
+ Every Mail commit is tested by GitHub Actions on [all supported Ruby versions](https://github.com/mikel/mail/blob/master/.github/workflows/test.yml).
56
55
 
57
- Testing a specific mime type (needed for 1.8.7 for example) can be done manually with:
58
-
59
- ```sh
60
- BUNDLE_GEMFILE=gemfiles/mime_types_1.16.gemfile (bundle check || bundle) && rake
61
- ```
62
-
63
- Discussion
64
- ----------
56
+ ## Discussion
65
57
 
66
58
  If you want to discuss mail with like minded individuals, please subscribe to
67
59
  the [Google Group](http://groups.google.com/group/mail-ruby).
68
60
 
69
- Current Capabilities of Mail
70
- ----------------------------
61
+ ## Current Capabilities of Mail
71
62
 
72
- * RFC2822 Support, Reading and Writing
73
- * RFC2045-2049 Support for multipart emails
74
- * Support for creating multipart alternate emails
75
- * Support for reading multipart/report emails &amp; getting details from such
76
- * Support for multibyte emails - needs quite a lot of work and testing
63
+ * RFC5322 Support, Reading and Writing
64
+ * RFC6532 Support, reading UTF-8 headers
65
+ * RFC2045-2049 Support for multipart email
66
+ * Support for creating multipart alternate email
67
+ * Support for reading multipart/report email &amp; getting details from such
77
68
  * Wrappers for File, Net/POP3, Net/SMTP
78
- * Auto encoding of non US-ASCII header fields
79
- * Auto encoding of non US-ASCII bodies
69
+ * Auto-encoding of non-US-ASCII bodies and header fields
80
70
 
81
- Mail is RFC2822 compliant now, that is, it can parse and generate valid US-ASCII
82
- emails. There are a few obsoleted syntax emails that it will have problems with, but
83
- it also is quite robust, meaning, if it finds something it doesn't understand it will
84
- not crash, instead, it will skip the problem and keep parsing. In the case of a header
85
- it doesn't understand, it will initialise the header as an optional unstructured
86
- field and continue parsing.
71
+ Mail is RFC5322 and RFC6532 compliant now, that is, it can parse US-ASCII and UTF-8
72
+ email and generate US-ASCII email. There are a few obsoleted email syntax that
73
+ it will have problems with, but it also is quite robust, meaning, if it finds something
74
+ it doesn't understand it will not crash, instead, it will skip the problem and keep
75
+ parsing. In the case of a header it doesn't understand, it will initialise the header
76
+ as an optional unstructured field and continue parsing.
87
77
 
88
78
  This means Mail won't (ever) crunch your data (I think).
89
79
 
@@ -91,16 +81,14 @@ You can also create MIME emails. There are helper methods for making a
91
81
  multipart/alternate email for text/plain and text/html (the most common pair)
92
82
  and you can manually create any other type of MIME email.
93
83
 
94
- Roadmap
95
- -------
84
+ ## Roadmap
96
85
 
97
86
  Next TODO:
98
87
 
99
88
  * Improve MIME support for character sets in headers, currently works, mostly, needs
100
89
  refinement.
101
90
 
102
- Testing Policy
103
- --------------
91
+ ## Testing Policy
104
92
 
105
93
  Basically... we do BDD on Mail. No method gets written in Mail without a
106
94
  corresponding or covering spec. We expect as a minimum 100% coverage
@@ -110,25 +98,24 @@ the gem gets released.
110
98
 
111
99
  It also means you can be sure Mail will behave correctly.
112
100
 
113
- Note: If you care about core extensions (aka "monkey-patching"), please read the Core Extensions section near the end of this README.
101
+ You can run tests locally by running `bundle exec rspec`.
114
102
 
115
- API Policy
116
- ----------
103
+ You can run tests on all supported Ruby versions by using [act](https://github.com/nektos/act).
104
+
105
+ ## API Policy
117
106
 
118
107
  No API removals within a single point release. All removals to be deprecated with
119
108
  warnings for at least one MINOR point release before removal.
120
109
 
121
110
  Also, all private or protected methods to be declared as such - though this is still I/P.
122
111
 
123
- Installation
124
- ------------
112
+ ## Installation
125
113
 
126
114
  Installation is fairly simple, I host mail on rubygems, so you can just do:
127
115
 
128
116
  # gem install mail
129
117
 
130
- Encodings
131
- ---------
118
+ ## Encodings
132
119
 
133
120
  If you didn't know, handling encodings in Emails is not as straight forward as you
134
121
  would hope.
@@ -160,17 +147,17 @@ I have tried to simplify it some:
160
147
  provide encoded parameter values when you call the parameter names through the
161
148
  <code>object.parameters['<parameter_name>']</code> method call.
162
149
 
163
- Contributing
164
- ------------
150
+ ## Contributing
165
151
 
166
- Please do! Contributing is easy in Mail. Please read the CONTRIBUTING.md document for more info
152
+ Please do! Contributing is easy in Mail. Please read the [CONTRIBUTING.md](CONTRIBUTING.md) document for more info.
167
153
 
168
- Usage
169
- -----
154
+ ## Usage
170
155
 
171
156
  All major mail functions should be able to happen from the Mail module.
172
157
  So, you should be able to just <code>require 'mail'</code> to get started.
173
158
 
159
+ `mail` is pretty well documented in its Ruby code. You can look it up e.g. at [rubydoc.info](https://www.rubydoc.info/gems/mail).
160
+
174
161
  ### Making an email
175
162
 
176
163
  ```ruby
@@ -234,7 +221,7 @@ what you are doing.
234
221
  ### Sending an email:
235
222
 
236
223
  Mail defaults to sending via SMTP to local host port 25. If you have a
237
- sendmail or postfix daemon running on on this port, sending email is as
224
+ sendmail or postfix daemon running on this port, sending email is as
238
225
  easy as:
239
226
 
240
227
  ```ruby
@@ -294,12 +281,23 @@ mail.delivery_method :exim, :location => "/usr/bin/exim"
294
281
  mail.deliver
295
282
  ```
296
283
 
297
- ### Getting emails from a pop server:
284
+ Mail may be "delivered" to a logfile, too, for development and testing:
285
+
286
+ ```ruby
287
+ # Delivers by logging the encoded message to $stdout
288
+ mail.delivery_method :logger
289
+
290
+ # Delivers to an existing logger at :debug severity
291
+ mail.delivery_method :logger, logger: other_logger, severity: :debug
292
+ ```
293
+
294
+ ### Getting Emails from a POP or IMAP Server:
298
295
 
299
296
  You can configure Mail to receive email using <code>retriever_method</code>
300
297
  within <code>Mail.defaults</code>:
301
298
 
302
299
  ```ruby
300
+ # e.g. POP3
303
301
  Mail.defaults do
304
302
  retriever_method :pop3, :address => "pop.gmail.com",
305
303
  :port => 995,
@@ -307,6 +305,15 @@ Mail.defaults do
307
305
  :password => '<password>',
308
306
  :enable_ssl => true
309
307
  end
308
+
309
+ # IMAP
310
+ Mail.defaults do
311
+ retriever_method :imap, :address => "imap.mailbox.org",
312
+ :port => 993,
313
+ :user_name => '<username>',
314
+ :password => '<password>',
315
+ :enable_ssl => true
316
+ end
310
317
  ```
311
318
 
312
319
  You can access incoming email in a number of ways.
@@ -347,7 +354,7 @@ mail.cc #=> 'sam@test.lindsaar.net'
347
354
  mail.subject #=> "This is the subject"
348
355
  mail.date.to_s #=> '21 Nov 1997 09:55:06 -0600'
349
356
  mail.message_id #=> '<4D6AA7EB.6490534@xxx.xxx>'
350
- mail.body.decoded #=> 'This is the body of the email...
357
+ mail.decoded #=> 'This is the body of the email...
351
358
  ```
352
359
 
353
360
  Many more methods available.
@@ -373,7 +380,7 @@ is another message which can have many or no parts.
373
380
  A message will only have parts if it is a multipart/mixed or multipart/related
374
381
  content type and has a boundary defined.
375
382
 
376
- ### Testing and extracting attachments
383
+ ### Testing and Extracting Attachments
377
384
  ```ruby
378
385
  mail.attachments.each do | attachment |
379
386
  # Attachments is an AttachmentsList object containing a
@@ -382,14 +389,14 @@ mail.attachments.each do | attachment |
382
389
  # extracting images for example...
383
390
  filename = attachment.filename
384
391
  begin
385
- File.open(images_dir + filename, "w+b", 0644) {|f| f.write attachment.body.decoded}
392
+ File.open(images_dir + filename, "w+b", 0644) {|f| f.write attachment.decoded}
386
393
  rescue => e
387
394
  puts "Unable to save data for #{filename} because #{e.message}"
388
395
  end
389
396
  end
390
397
  end
391
398
  ```
392
- ### Writing and sending a multipart/alternative (html and text) email
399
+ ### Writing and Sending a Multipart/Alternative (HTML and Text) Email
393
400
 
394
401
  Mail makes some basic assumptions and makes doing the common thing as
395
402
  simple as possible.... (asking a lot from a mail library)
@@ -449,13 +456,13 @@ Content-Transfer-Encoding: 7bit
449
456
  ```
450
457
 
451
458
  Mail inserts the content transfer encoding, the mime version,
452
- the content-id's and handles the content-type and boundary.
459
+ the content-IDs and handles the content-type and boundary.
453
460
 
454
461
  Mail assumes that if your text in the body is only us-ascii, that your
455
462
  transfer encoding is 7bit and it is text/plain. You can override this
456
463
  by explicitly declaring it.
457
464
 
458
- ### Making Multipart/Alternate, without a block
465
+ ### Making Multipart/Alternate, Without a Block
459
466
 
460
467
  You don't have to use a block with the text and html part included, you
461
468
  can just do it declaratively. However, you need to add Mail::Parts to
@@ -483,7 +490,7 @@ mail.html_part = html_part
483
490
 
484
491
  Results in the same email as done using the block form
485
492
 
486
- ### Getting error reports from an email:
493
+ ### Getting Error Reports from an Email:
487
494
 
488
495
  ```ruby
489
496
  @mail = Mail.read('/path/to/bounce_message.eml')
@@ -527,7 +534,6 @@ than mail (this should be rarely needed)
527
534
 
528
535
  ```ruby
529
536
  @mail = Mail.new
530
- file_data = File.read('path/to/myfile.pdf')
531
537
  @mail.attachments['myfile.pdf'] = { :mime_type => 'application/x-pdf',
532
538
  :content => File.read('path/to/myfile.pdf') }
533
539
  @mail.parts.first.mime_type #=> 'application/x-pdf'
@@ -560,8 +566,7 @@ end
560
566
  ```
561
567
  See "Testing and extracting attachments" above for more details.
562
568
 
563
- Using Mail with Testing or Spec'ing Libraries
564
- ---------------------------------------------
569
+ ## Using Mail with Testing or Spec'ing Libraries
565
570
 
566
571
  If mail is part of your system, you'll need a way to test it without actually
567
572
  sending emails, the TestMailer can do this for you.
@@ -611,70 +616,59 @@ describe "sending an email" do
611
616
  end
612
617
  end
613
618
 
614
- it { should have_sent_email } # passes if any email at all was sent
619
+ it { is_expected.to have_sent_email } # passes if any email at all was sent
615
620
 
616
- it { should have_sent_email.from('you@you.com') }
617
- it { should have_sent_email.to('mike1@me.com') }
621
+ it { is_expected.to have_sent_email.from('you@you.com') }
622
+ it { is_expected.to have_sent_email.to('mike1@me.com') }
618
623
 
619
624
  # can specify a list of recipients...
620
- it { should have_sent_email.to(['mike1@me.com', 'mike2@me.com']) }
625
+ it { is_expected.to have_sent_email.to(['mike1@me.com', 'mike2@me.com']) }
621
626
 
622
627
  # ...or chain recipients together
623
- it { should have_sent_email.to('mike1@me.com').to('mike2@me.com') }
628
+ it { is_expected.to have_sent_email.to('mike1@me.com').to('mike2@me.com') }
624
629
 
625
- it { should have_sent_email.with_subject('testing') }
630
+ it { is_expected.to have_sent_email.with_subject('testing') }
626
631
 
627
- it { should have_sent_email.with_body('hello') }
632
+ it { is_expected.to have_sent_email.with_body('hello') }
628
633
 
629
634
  # Can match subject or body with a regex
630
635
  # (or anything that responds_to? :match)
631
636
 
632
- it { should have_sent_email.matching_subject(/test(ing)?/) }
633
- it { should have_sent_email.matching_body(/h(a|e)llo/) }
637
+ it { is_expected.to have_sent_email.matching_subject(/test(ing)?/) }
638
+ it { is_expected.to have_sent_email.matching_body(/h(a|e)llo/) }
634
639
 
635
640
  # Can chain together modifiers
636
641
  # Note that apart from recipients, repeating a modifier overwrites old value.
637
642
 
638
- it { should have_sent_email.from('you@you.com').to('mike1@me.com').matching_body(/hell/)
643
+ it { is_expected.to have_sent_email.from('you@you.com').to('mike1@me.com').matching_body(/hell/)
639
644
 
640
645
  # test for attachments
641
646
 
642
647
  # ... by specific attachment
643
- it { should_have_sent_email.with_attachments(my_attachment) }
648
+ it { is_expected.to have_sent_email.with_attachments(my_attachment) }
644
649
 
645
650
  # ... or any attachment
646
- it { should_have_sent_email.with_attachments(any_attachment) }
651
+ it { is_expected.to have_sent_email.with_attachments(any_attachment) }
652
+
653
+ # ... or attachment with filename
654
+ it { is_expected.to have_sent_email.with_attachments(an_attachment_with_filename('file.txt')) }
655
+
656
+ # ... or attachment with mime_type
657
+ it { is_expected.to have_sent_email.with_attachments(an_attachment_with_mime_type('application/pdf')) }
647
658
 
648
659
  # ... by array of attachments
649
- it { should_have_sent_email.with_attachments([my_attachment1, my_attachment2]) } #note that order is important
660
+ it { is_expected.to have_sent_email.with_attachments([my_attachment1, my_attachment2]) } #note that order is important
650
661
 
651
662
  #... by presence
652
- it { should_have_sent_email.with_any_attachments }
663
+ it { is_expected.to have_sent_email.with_any_attachments }
653
664
 
654
665
  #... or by absence
655
- it { should_have_sent_email.with_no_attachments }
666
+ it { is_expected.to have_sent_email.with_no_attachments }
656
667
 
657
668
  end
658
669
  ```
659
670
 
660
- Core Extensions
661
- ---------------
662
-
663
- The mail gem adds several constants and methods to Ruby's core objects (similar to the activesupport gem from the Rails project). For example:
664
-
665
- NilClass::blank?
666
- NilClass::to_crlf
667
- NilClass::to_lf
668
- Object::blank?
669
- String::to_crlf
670
- String::to_lf
671
- String::blank?
672
- ...etc...
673
-
674
- For all the details, check out lib/mail/core_extensions/.
675
-
676
- Excerpts from TREC Spam Corpus 2005
677
- -----------------------------------
671
+ ## Excerpts from TREC Spam Corpus 2005
678
672
 
679
673
  The spec fixture files in spec/fixtures/emails/from_trec_2005 are from the
680
674
  2005 TREC Public Spam Corpus. They remain copyrighted under the terms of
@@ -692,8 +686,7 @@ They are used as allowed by 'Permitted Uses, Clause 3':
692
686
 
693
687
  -- http://plg.uwaterloo.ca/~gvcormac/treccorpus/
694
688
 
695
- License
696
- -------
689
+ ## License
697
690
 
698
691
  (The MIT License)
699
692
 
@@ -6,8 +6,8 @@ module Mail
6
6
  @parts_list = parts_list
7
7
  @content_disposition_type = 'attachment'
8
8
  parts_list.map { |p|
9
- if p.content_type == "message/rfc822"
10
- Mail.new(p.body).attachments
9
+ if p.mime_type == 'message/rfc822'
10
+ Mail.new(p.body.encoded).attachments
11
11
  elsif p.parts.empty?
12
12
  p if p.attachment?
13
13
  else
@@ -30,7 +30,7 @@ module Mail
30
30
  # mail.attachments['test.png'].filename #=> 'test.png'
31
31
  # mail.attachments[1].filename #=> 'test.jpg'
32
32
  def [](index_value)
33
- if index_value.is_a?(Fixnum)
33
+ if index_value.is_a?(Integer)
34
34
  self.fetch(index_value)
35
35
  else
36
36
  self.select { |a| a.filename == index_value }.first
@@ -44,6 +44,9 @@ module Mail
44
44
  :content_disposition => "#{@content_disposition_type}; filename=\"#{encoded_name}\"" }
45
45
 
46
46
  if value.is_a?(Hash)
47
+ if path = value.delete(:filename)
48
+ value[:content] ||= File.open(path, 'rb') { |f| f.read }
49
+ end
47
50
 
48
51
  default_values[:body] = value.delete(:content) if value[:content]
49
52
 
@@ -60,7 +63,7 @@ module Mail
60
63
 
61
64
  if value[:mime_type]
62
65
  default_values[:content_type] = value.delete(:mime_type)
63
- @mime_type = MIME::Types[default_values[:content_type]].first
66
+ @mime_type = MiniMime.lookup_by_content_type(default_values[:content_type])
64
67
  default_values[:content_transfer_encoding] ||= guess_encoding
65
68
  end
66
69
 
@@ -71,7 +74,7 @@ module Mail
71
74
  end
72
75
 
73
76
  if hash[:body].respond_to? :force_encoding and hash[:body].respond_to? :valid_encoding?
74
- if not hash[:body].valid_encoding? and default_values[:content_transfer_encoding].downcase == "binary"
77
+ if not hash[:body].valid_encoding? and default_values[:content_transfer_encoding].casecmp('binary').zero?
75
78
  hash[:body] = hash[:body].dup if hash[:body].frozen?
76
79
  hash[:body].force_encoding("BINARY")
77
80
  end
@@ -94,12 +97,10 @@ module Mail
94
97
  end
95
98
 
96
99
  def set_mime_type(filename)
97
- # Have to do this because MIME::Types is not Ruby 1.9 safe yet
98
- if RUBY_VERSION >= '1.9'
99
- filename = filename.encode(Encoding::UTF_8) if filename.respond_to?(:encode)
100
- end
100
+ filename = filename.encode(Encoding::UTF_8) if filename.respond_to?(:encode)
101
101
 
102
- @mime_type = MIME::Types.type_for(filename).first
102
+ @mime_type = MiniMime.lookup_by_filename(filename)
103
+ @mime_type && @mime_type.content_type
103
104
  end
104
105
 
105
106
  end