mail 2.6.6 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +5 -5
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +134 -119
  4. data/lib/mail/attachments_list.rb +10 -9
  5. data/lib/mail/body.rb +73 -84
  6. data/lib/mail/check_delivery_params.rb +28 -21
  7. data/lib/mail/configuration.rb +2 -0
  8. data/lib/mail/constants.rb +27 -5
  9. data/lib/mail/elements/address.rb +53 -47
  10. data/lib/mail/elements/address_list.rb +11 -19
  11. data/lib/mail/elements/content_disposition_element.rb +9 -16
  12. data/lib/mail/elements/content_location_element.rb +6 -11
  13. data/lib/mail/elements/content_transfer_encoding_element.rb +6 -11
  14. data/lib/mail/elements/content_type_element.rb +16 -23
  15. data/lib/mail/elements/date_time_element.rb +7 -15
  16. data/lib/mail/elements/envelope_from_element.rb +22 -23
  17. data/lib/mail/elements/message_ids_element.rb +18 -13
  18. data/lib/mail/elements/mime_version_element.rb +7 -15
  19. data/lib/mail/elements/phrase_list.rb +12 -10
  20. data/lib/mail/elements/received_element.rb +27 -19
  21. data/lib/mail/encodings/7bit.rb +9 -14
  22. data/lib/mail/encodings/8bit.rb +2 -21
  23. data/lib/mail/encodings/base64.rb +11 -12
  24. data/lib/mail/encodings/binary.rb +3 -22
  25. data/lib/mail/encodings/identity.rb +24 -0
  26. data/lib/mail/encodings/quoted_printable.rb +6 -6
  27. data/lib/mail/encodings/transfer_encoding.rb +38 -29
  28. data/lib/mail/encodings/unix_to_unix.rb +3 -1
  29. data/lib/mail/encodings.rb +81 -54
  30. data/lib/mail/envelope.rb +11 -14
  31. data/lib/mail/field.rb +119 -98
  32. data/lib/mail/field_list.rb +60 -7
  33. data/lib/mail/fields/bcc_field.rb +34 -52
  34. data/lib/mail/fields/cc_field.rb +28 -49
  35. data/lib/mail/fields/comments_field.rb +27 -37
  36. data/lib/mail/fields/common_address_field.rb +170 -0
  37. data/lib/mail/fields/common_date_field.rb +58 -0
  38. data/lib/mail/fields/common_field.rb +77 -0
  39. data/lib/mail/fields/common_message_id_field.rb +42 -0
  40. data/lib/mail/fields/content_description_field.rb +7 -14
  41. data/lib/mail/fields/content_disposition_field.rb +13 -38
  42. data/lib/mail/fields/content_id_field.rb +24 -51
  43. data/lib/mail/fields/content_location_field.rb +11 -25
  44. data/lib/mail/fields/content_transfer_encoding_field.rb +31 -31
  45. data/lib/mail/fields/content_type_field.rb +50 -80
  46. data/lib/mail/fields/date_field.rb +23 -52
  47. data/lib/mail/fields/from_field.rb +28 -49
  48. data/lib/mail/fields/in_reply_to_field.rb +38 -49
  49. data/lib/mail/fields/keywords_field.rb +18 -31
  50. data/lib/mail/fields/message_id_field.rb +25 -71
  51. data/lib/mail/fields/mime_version_field.rb +19 -30
  52. data/lib/mail/fields/named_structured_field.rb +11 -0
  53. data/lib/mail/fields/named_unstructured_field.rb +11 -0
  54. data/lib/mail/fields/optional_field.rb +9 -7
  55. data/lib/mail/fields/{common/parameter_hash.rb → parameter_hash.rb} +13 -11
  56. data/lib/mail/fields/received_field.rb +43 -57
  57. data/lib/mail/fields/references_field.rb +35 -49
  58. data/lib/mail/fields/reply_to_field.rb +28 -49
  59. data/lib/mail/fields/resent_bcc_field.rb +28 -49
  60. data/lib/mail/fields/resent_cc_field.rb +28 -49
  61. data/lib/mail/fields/resent_date_field.rb +5 -30
  62. data/lib/mail/fields/resent_from_field.rb +28 -49
  63. data/lib/mail/fields/resent_message_id_field.rb +5 -29
  64. data/lib/mail/fields/resent_sender_field.rb +27 -56
  65. data/lib/mail/fields/resent_to_field.rb +28 -49
  66. data/lib/mail/fields/return_path_field.rb +50 -54
  67. data/lib/mail/fields/sender_field.rb +34 -55
  68. data/lib/mail/fields/structured_field.rb +3 -30
  69. data/lib/mail/fields/subject_field.rb +9 -11
  70. data/lib/mail/fields/to_field.rb +28 -49
  71. data/lib/mail/fields/unstructured_field.rb +32 -47
  72. data/lib/mail/header.rb +71 -110
  73. data/lib/mail/mail.rb +2 -10
  74. data/lib/mail/matchers/attachment_matchers.rb +15 -0
  75. data/lib/mail/matchers/has_sent_mail.rb +21 -1
  76. data/lib/mail/message.rb +113 -117
  77. data/lib/mail/multibyte/chars.rb +21 -178
  78. data/lib/mail/multibyte/unicode.rb +10 -10
  79. data/lib/mail/multibyte/utils.rb +26 -43
  80. data/lib/mail/multibyte.rb +55 -16
  81. data/lib/mail/network/delivery_methods/exim.rb +5 -4
  82. data/lib/mail/network/delivery_methods/file_delivery.rb +11 -10
  83. data/lib/mail/network/delivery_methods/logger_delivery.rb +34 -0
  84. data/lib/mail/network/delivery_methods/sendmail.rb +62 -21
  85. data/lib/mail/network/delivery_methods/smtp.rb +75 -50
  86. data/lib/mail/network/delivery_methods/smtp_connection.rb +3 -4
  87. data/lib/mail/network/delivery_methods/test_mailer.rb +4 -2
  88. data/lib/mail/network/retriever_methods/base.rb +8 -8
  89. data/lib/mail/network/retriever_methods/imap.rb +20 -7
  90. data/lib/mail/network/retriever_methods/pop3.rb +5 -3
  91. data/lib/mail/network/retriever_methods/test_retriever.rb +2 -1
  92. data/lib/mail/network.rb +1 -0
  93. data/lib/mail/parser_tools.rb +15 -0
  94. data/lib/mail/parsers/address_lists_parser.rb +33225 -116
  95. data/lib/mail/parsers/address_lists_parser.rl +179 -0
  96. data/lib/mail/parsers/content_disposition_parser.rb +882 -49
  97. data/lib/mail/parsers/content_disposition_parser.rl +89 -0
  98. data/lib/mail/parsers/content_location_parser.rb +809 -23
  99. data/lib/mail/parsers/content_location_parser.rl +78 -0
  100. data/lib/mail/parsers/content_transfer_encoding_parser.rb +509 -21
  101. data/lib/mail/parsers/content_transfer_encoding_parser.rl +71 -0
  102. data/lib/mail/parsers/content_type_parser.rb +1037 -56
  103. data/lib/mail/parsers/content_type_parser.rl +90 -0
  104. data/lib/mail/parsers/date_time_parser.rb +877 -25
  105. data/lib/mail/parsers/date_time_parser.rl +69 -0
  106. data/lib/mail/parsers/envelope_from_parser.rb +3669 -40
  107. data/lib/mail/parsers/envelope_from_parser.rl +89 -0
  108. data/lib/mail/parsers/message_ids_parser.rb +5146 -25
  109. data/lib/mail/parsers/message_ids_parser.rl +93 -0
  110. data/lib/mail/parsers/mime_version_parser.rb +497 -26
  111. data/lib/mail/parsers/mime_version_parser.rl +68 -0
  112. data/lib/mail/parsers/phrase_lists_parser.rb +870 -22
  113. data/lib/mail/parsers/phrase_lists_parser.rl +90 -0
  114. data/lib/mail/parsers/received_parser.rb +8776 -43
  115. data/lib/mail/parsers/received_parser.rl +91 -0
  116. data/lib/mail/parsers/rfc2045_content_transfer_encoding.rl +13 -0
  117. data/lib/mail/parsers/rfc2045_content_type.rl +25 -0
  118. data/lib/mail/parsers/rfc2045_mime.rl +16 -0
  119. data/lib/mail/parsers/rfc2183_content_disposition.rl +15 -0
  120. data/lib/mail/parsers/rfc3629_utf8.rl +19 -0
  121. data/lib/mail/parsers/rfc5234_abnf_core_rules.rl +22 -0
  122. data/lib/mail/parsers/rfc5322.rl +74 -0
  123. data/lib/mail/parsers/rfc5322_address.rl +72 -0
  124. data/lib/mail/parsers/{ragel/date_time.rl → rfc5322_date_time.rl} +8 -1
  125. data/lib/mail/parsers/rfc5322_lexical_tokens.rl +60 -0
  126. data/lib/mail/parsers.rb +11 -25
  127. data/lib/mail/part.rb +6 -10
  128. data/lib/mail/parts_list.rb +62 -6
  129. data/lib/mail/smtp_envelope.rb +57 -0
  130. data/lib/mail/utilities.rb +343 -74
  131. data/lib/mail/version.rb +2 -2
  132. data/lib/mail/yaml.rb +30 -0
  133. data/lib/mail.rb +5 -35
  134. metadata +111 -66
  135. data/CHANGELOG.rdoc +0 -803
  136. data/CONTRIBUTING.md +0 -60
  137. data/Dependencies.txt +0 -2
  138. data/Gemfile +0 -14
  139. data/Rakefile +0 -29
  140. data/TODO.rdoc +0 -9
  141. data/lib/mail/core_extensions/smtp.rb +0 -25
  142. data/lib/mail/core_extensions/string/access.rb +0 -146
  143. data/lib/mail/core_extensions/string/multibyte.rb +0 -79
  144. data/lib/mail/core_extensions/string.rb +0 -21
  145. data/lib/mail/fields/common/address_container.rb +0 -17
  146. data/lib/mail/fields/common/common_address.rb +0 -136
  147. data/lib/mail/fields/common/common_date.rb +0 -36
  148. data/lib/mail/fields/common/common_field.rb +0 -61
  149. data/lib/mail/fields/common/common_message_id.rb +0 -49
  150. data/lib/mail/multibyte/exceptions.rb +0 -9
  151. data/lib/mail/parsers/ragel/common.rl +0 -185
  152. data/lib/mail/parsers/ragel/parser_info.rb +0 -61
  153. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb +0 -14864
  154. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl +0 -37
  155. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb +0 -751
  156. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl +0 -37
  157. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb +0 -614
  158. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl +0 -37
  159. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb +0 -447
  160. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl +0 -37
  161. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb +0 -825
  162. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl +0 -37
  163. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb +0 -817
  164. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl +0 -37
  165. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb +0 -2149
  166. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl +0 -37
  167. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb +0 -1570
  168. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl +0 -37
  169. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb +0 -440
  170. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl +0 -37
  171. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb +0 -564
  172. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl +0 -37
  173. data/lib/mail/parsers/ragel/ruby/machines/rb_actions.rl +0 -51
  174. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb +0 -5144
  175. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl +0 -37
  176. data/lib/mail/parsers/ragel/ruby/parser.rb.rl.erb +0 -37
  177. data/lib/mail/parsers/ragel/ruby.rb +0 -40
  178. data/lib/mail/parsers/ragel.rb +0 -18
  179. data/lib/mail/version_specific/ruby_1_8.rb +0 -126
  180. data/lib/mail/version_specific/ruby_1_9.rb +0 -226
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fffa789ce57e01eb58d470854eef55242eae6f9c
4
- data.tar.gz: fa95a3e43e7c7b80972dd81989688ed00ef5e22c
2
+ SHA256:
3
+ metadata.gz: ea4015fe2858f6c1b123e04d4d407169567b1aeea1155b7b145fe75d9d3781b5
4
+ data.tar.gz: 20cdb386c2f878560b9f61ab63b4f0c264c9f9115af5c835b8c66f49486cb274
5
5
  SHA512:
6
- metadata.gz: '06621968e5681c087041b046f1f52cb7316116bedf04e38ab4255118249142488f768fba638c6fc2b99eb69d15a6d84823383f073f33bc8b05a6b3be635417d7'
7
- data.tar.gz: f890a870876c79ca6014c8cccc84af35834cfc79576a2032aeef5a6f34ff183661e5fd73796b4693de53c1a288059e7733e359e7f0252548fe8c49e657f5bc7f
6
+ metadata.gz: b2eb55bc6f51b2d93e6d6abed5bb74876b3f96fd1eea00105047b3a211007b2b906ac89bcd1bed52603c211c595d439b6642bd897943decbcc9ac541f88e2049
7
+ data.tar.gz: 063dd68ef655b93d96412bdcf66ab6f191eaf0bfbafa10730ecfa99a447eb3d2a4469d6d1de67ae144bbaada65eaec4c7d8dbb5fe04509146dc1434a5c557fff
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2017 Mikel Lindsaar
1
+ Copyright (c) 2009-2016 Mikel Lindsaar
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,81 +1,93 @@
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
- -------------
30
-
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.
33
-
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
-
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>
40
-
41
-
42
- Compatibility
43
- -------------
44
-
45
- Mail supports Ruby 1.8.7+, including JRuby and Rubinius.
46
-
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
- ```
54
-
55
- Discussion
56
- ----------
25
+ ## You can contribute to this library
26
+
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.
32
+
33
+
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)
47
+
48
+ ## Compatibility
49
+
50
+ Mail is tested against:
51
+
52
+ * Ruby: 2.5
53
+ * Ruby: 2.6
54
+ * Ruby: 2.7
55
+ * Ruby: 3.0
56
+ * Ruby: 3.1
57
+ * Ruby: 3.2
58
+ * JRuby: 9.2
59
+ * JRuby: 9.3
60
+ * JRuby: 9.4
61
+ * JRuby: stable
62
+ * JRuby: head
63
+ * Truffleruby: stable
64
+ * Truffleruby: head
65
+
66
+ 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.
67
+
68
+ Every Mail commit is tested by GitHub Actions on [all supported Ruby versions](https://github.com/mikel/mail/blob/master/.github/workflows/test.yml).
69
+
70
+ ## Discussion
57
71
 
58
72
  If you want to discuss mail with like minded individuals, please subscribe to
59
73
  the [Google Group](http://groups.google.com/group/mail-ruby).
60
74
 
61
- Current Capabilities of Mail
62
- ----------------------------
75
+ ## Current Capabilities of Mail
63
76
 
64
- * RFC2822 Support, Reading and Writing
65
- * RFC2045-2049 Support for multipart emails
66
- * Support for creating multipart alternate emails
67
- * Support for reading multipart/report emails &amp; getting details from such
68
- * Support for multibyte emails - needs quite a lot of work and testing
77
+ * RFC5322 Support, Reading and Writing
78
+ * RFC6532 Support, reading UTF-8 headers
79
+ * RFC2045-2049 Support for multipart email
80
+ * Support for creating multipart alternate email
81
+ * Support for reading multipart/report email &amp; getting details from such
69
82
  * Wrappers for File, Net/POP3, Net/SMTP
70
- * Auto encoding of non US-ASCII header fields
71
- * Auto encoding of non US-ASCII bodies
83
+ * Auto-encoding of non-US-ASCII bodies and header fields
72
84
 
73
- Mail is RFC2822 compliant now, that is, it can parse and generate valid US-ASCII
74
- emails. There are a few obsoleted syntax emails that it will have problems with, but
75
- it also is quite robust, meaning, if it finds something it doesn't understand it will
76
- not crash, instead, it will skip the problem and keep parsing. In the case of a header
77
- it doesn't understand, it will initialise the header as an optional unstructured
78
- field and continue parsing.
85
+ Mail is RFC5322 and RFC6532 compliant now, that is, it can parse US-ASCII and UTF-8
86
+ email and generate US-ASCII email. There are a few obsoleted email syntax that
87
+ it will have problems with, but it also is quite robust, meaning, if it finds something
88
+ it doesn't understand it will not crash, instead, it will skip the problem and keep
89
+ parsing. In the case of a header it doesn't understand, it will initialise the header
90
+ as an optional unstructured field and continue parsing.
79
91
 
80
92
  This means Mail won't (ever) crunch your data (I think).
81
93
 
@@ -83,16 +95,14 @@ You can also create MIME emails. There are helper methods for making a
83
95
  multipart/alternate email for text/plain and text/html (the most common pair)
84
96
  and you can manually create any other type of MIME email.
85
97
 
86
- Roadmap
87
- -------
98
+ ## Roadmap
88
99
 
89
100
  Next TODO:
90
101
 
91
102
  * Improve MIME support for character sets in headers, currently works, mostly, needs
92
103
  refinement.
93
104
 
94
- Testing Policy
95
- --------------
105
+ ## Testing Policy
96
106
 
97
107
  Basically... we do BDD on Mail. No method gets written in Mail without a
98
108
  corresponding or covering spec. We expect as a minimum 100% coverage
@@ -102,25 +112,24 @@ the gem gets released.
102
112
 
103
113
  It also means you can be sure Mail will behave correctly.
104
114
 
105
- Note: If you care about core extensions (aka "monkey-patching"), please read the Core Extensions section near the end of this README.
115
+ You can run tests locally by running `bundle exec rspec`.
116
+
117
+ You can run tests on all supported Ruby versions by using [act](https://github.com/nektos/act).
106
118
 
107
- API Policy
108
- ----------
119
+ ## API Policy
109
120
 
110
121
  No API removals within a single point release. All removals to be deprecated with
111
122
  warnings for at least one MINOR point release before removal.
112
123
 
113
124
  Also, all private or protected methods to be declared as such - though this is still I/P.
114
125
 
115
- Installation
116
- ------------
126
+ ## Installation
117
127
 
118
128
  Installation is fairly simple, I host mail on rubygems, so you can just do:
119
129
 
120
130
  # gem install mail
121
131
 
122
- Encodings
123
- ---------
132
+ ## Encodings
124
133
 
125
134
  If you didn't know, handling encodings in Emails is not as straight forward as you
126
135
  would hope.
@@ -152,17 +161,17 @@ I have tried to simplify it some:
152
161
  provide encoded parameter values when you call the parameter names through the
153
162
  <code>object.parameters['<parameter_name>']</code> method call.
154
163
 
155
- Contributing
156
- ------------
164
+ ## Contributing
157
165
 
158
- Please do! Contributing is easy in Mail. Please read the CONTRIBUTING.md document for more info
166
+ Please do! Contributing is easy in Mail. Please read the [CONTRIBUTING.md](CONTRIBUTING.md) document for more info.
159
167
 
160
- Usage
161
- -----
168
+ ## Usage
162
169
 
163
170
  All major mail functions should be able to happen from the Mail module.
164
171
  So, you should be able to just <code>require 'mail'</code> to get started.
165
172
 
173
+ `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).
174
+
166
175
  ### Making an email
167
176
 
168
177
  ```ruby
@@ -226,7 +235,7 @@ what you are doing.
226
235
  ### Sending an email:
227
236
 
228
237
  Mail defaults to sending via SMTP to local host port 25. If you have a
229
- sendmail or postfix daemon running on on this port, sending email is as
238
+ sendmail or postfix daemon running on this port, sending email is as
230
239
  easy as:
231
240
 
232
241
  ```ruby
@@ -286,12 +295,23 @@ mail.delivery_method :exim, :location => "/usr/bin/exim"
286
295
  mail.deliver
287
296
  ```
288
297
 
289
- ### Getting emails from a pop server:
298
+ Mail may be "delivered" to a logfile, too, for development and testing:
299
+
300
+ ```ruby
301
+ # Delivers by logging the encoded message to $stdout
302
+ mail.delivery_method :logger
303
+
304
+ # Delivers to an existing logger at :debug severity
305
+ mail.delivery_method :logger, logger: other_logger, severity: :debug
306
+ ```
307
+
308
+ ### Getting Emails from a POP or IMAP Server:
290
309
 
291
310
  You can configure Mail to receive email using <code>retriever_method</code>
292
311
  within <code>Mail.defaults</code>:
293
312
 
294
313
  ```ruby
314
+ # e.g. POP3
295
315
  Mail.defaults do
296
316
  retriever_method :pop3, :address => "pop.gmail.com",
297
317
  :port => 995,
@@ -299,6 +319,15 @@ Mail.defaults do
299
319
  :password => '<password>',
300
320
  :enable_ssl => true
301
321
  end
322
+
323
+ # IMAP
324
+ Mail.defaults do
325
+ retriever_method :imap, :address => "imap.mailbox.org",
326
+ :port => 993,
327
+ :user_name => '<username>',
328
+ :password => '<password>',
329
+ :enable_ssl => true
330
+ end
302
331
  ```
303
332
 
304
333
  You can access incoming email in a number of ways.
@@ -339,7 +368,7 @@ mail.cc #=> 'sam@test.lindsaar.net'
339
368
  mail.subject #=> "This is the subject"
340
369
  mail.date.to_s #=> '21 Nov 1997 09:55:06 -0600'
341
370
  mail.message_id #=> '<4D6AA7EB.6490534@xxx.xxx>'
342
- mail.body.decoded #=> 'This is the body of the email...
371
+ mail.decoded #=> 'This is the body of the email...
343
372
  ```
344
373
 
345
374
  Many more methods available.
@@ -365,7 +394,7 @@ is another message which can have many or no parts.
365
394
  A message will only have parts if it is a multipart/mixed or multipart/related
366
395
  content type and has a boundary defined.
367
396
 
368
- ### Testing and extracting attachments
397
+ ### Testing and Extracting Attachments
369
398
  ```ruby
370
399
  mail.attachments.each do | attachment |
371
400
  # Attachments is an AttachmentsList object containing a
@@ -374,14 +403,14 @@ mail.attachments.each do | attachment |
374
403
  # extracting images for example...
375
404
  filename = attachment.filename
376
405
  begin
377
- File.open(images_dir + filename, "w+b", 0644) {|f| f.write attachment.body.decoded}
406
+ File.open(images_dir + filename, "w+b", 0644) {|f| f.write attachment.decoded}
378
407
  rescue => e
379
408
  puts "Unable to save data for #{filename} because #{e.message}"
380
409
  end
381
410
  end
382
411
  end
383
412
  ```
384
- ### Writing and sending a multipart/alternative (html and text) email
413
+ ### Writing and Sending a Multipart/Alternative (HTML and Text) Email
385
414
 
386
415
  Mail makes some basic assumptions and makes doing the common thing as
387
416
  simple as possible.... (asking a lot from a mail library)
@@ -441,13 +470,13 @@ Content-Transfer-Encoding: 7bit
441
470
  ```
442
471
 
443
472
  Mail inserts the content transfer encoding, the mime version,
444
- the content-id's and handles the content-type and boundary.
473
+ the content-IDs and handles the content-type and boundary.
445
474
 
446
475
  Mail assumes that if your text in the body is only us-ascii, that your
447
476
  transfer encoding is 7bit and it is text/plain. You can override this
448
477
  by explicitly declaring it.
449
478
 
450
- ### Making Multipart/Alternate, without a block
479
+ ### Making Multipart/Alternate, Without a Block
451
480
 
452
481
  You don't have to use a block with the text and html part included, you
453
482
  can just do it declaratively. However, you need to add Mail::Parts to
@@ -475,7 +504,7 @@ mail.html_part = html_part
475
504
 
476
505
  Results in the same email as done using the block form
477
506
 
478
- ### Getting error reports from an email:
507
+ ### Getting Error Reports from an Email:
479
508
 
480
509
  ```ruby
481
510
  @mail = Mail.read('/path/to/bounce_message.eml')
@@ -519,7 +548,6 @@ than mail (this should be rarely needed)
519
548
 
520
549
  ```ruby
521
550
  @mail = Mail.new
522
- file_data = File.read('path/to/myfile.pdf')
523
551
  @mail.attachments['myfile.pdf'] = { :mime_type => 'application/x-pdf',
524
552
  :content => File.read('path/to/myfile.pdf') }
525
553
  @mail.parts.first.mime_type #=> 'application/x-pdf'
@@ -552,8 +580,7 @@ end
552
580
  ```
553
581
  See "Testing and extracting attachments" above for more details.
554
582
 
555
- Using Mail with Testing or Spec'ing Libraries
556
- ---------------------------------------------
583
+ ## Using Mail with Testing or Spec'ing Libraries
557
584
 
558
585
  If mail is part of your system, you'll need a way to test it without actually
559
586
  sending emails, the TestMailer can do this for you.
@@ -603,70 +630,59 @@ describe "sending an email" do
603
630
  end
604
631
  end
605
632
 
606
- it { should have_sent_email } # passes if any email at all was sent
633
+ it { is_expected.to have_sent_email } # passes if any email at all was sent
607
634
 
608
- it { should have_sent_email.from('you@you.com') }
609
- it { should have_sent_email.to('mike1@me.com') }
635
+ it { is_expected.to have_sent_email.from('you@you.com') }
636
+ it { is_expected.to have_sent_email.to('mike1@me.com') }
610
637
 
611
638
  # can specify a list of recipients...
612
- it { should have_sent_email.to(['mike1@me.com', 'mike2@me.com']) }
639
+ it { is_expected.to have_sent_email.to(['mike1@me.com', 'mike2@me.com']) }
613
640
 
614
641
  # ...or chain recipients together
615
- it { should have_sent_email.to('mike1@me.com').to('mike2@me.com') }
642
+ it { is_expected.to have_sent_email.to('mike1@me.com').to('mike2@me.com') }
616
643
 
617
- it { should have_sent_email.with_subject('testing') }
644
+ it { is_expected.to have_sent_email.with_subject('testing') }
618
645
 
619
- it { should have_sent_email.with_body('hello') }
646
+ it { is_expected.to have_sent_email.with_body('hello') }
620
647
 
621
648
  # Can match subject or body with a regex
622
649
  # (or anything that responds_to? :match)
623
650
 
624
- it { should have_sent_email.matching_subject(/test(ing)?/) }
625
- it { should have_sent_email.matching_body(/h(a|e)llo/) }
651
+ it { is_expected.to have_sent_email.matching_subject(/test(ing)?/) }
652
+ it { is_expected.to have_sent_email.matching_body(/h(a|e)llo/) }
626
653
 
627
654
  # Can chain together modifiers
628
655
  # Note that apart from recipients, repeating a modifier overwrites old value.
629
656
 
630
- it { should have_sent_email.from('you@you.com').to('mike1@me.com').matching_body(/hell/)
657
+ it { is_expected.to have_sent_email.from('you@you.com').to('mike1@me.com').matching_body(/hell/)
631
658
 
632
659
  # test for attachments
633
660
 
634
661
  # ... by specific attachment
635
- it { should_have_sent_email.with_attachments(my_attachment) }
662
+ it { is_expected.to have_sent_email.with_attachments(my_attachment) }
636
663
 
637
664
  # ... or any attachment
638
- it { should_have_sent_email.with_attachments(any_attachment) }
665
+ it { is_expected.to have_sent_email.with_attachments(any_attachment) }
666
+
667
+ # ... or attachment with filename
668
+ it { is_expected.to have_sent_email.with_attachments(an_attachment_with_filename('file.txt')) }
669
+
670
+ # ... or attachment with mime_type
671
+ it { is_expected.to have_sent_email.with_attachments(an_attachment_with_mime_type('application/pdf')) }
639
672
 
640
673
  # ... by array of attachments
641
- it { should_have_sent_email.with_attachments([my_attachment1, my_attachment2]) } #note that order is important
674
+ it { is_expected.to have_sent_email.with_attachments([my_attachment1, my_attachment2]) } #note that order is important
642
675
 
643
676
  #... by presence
644
- it { should_have_sent_email.with_any_attachments }
677
+ it { is_expected.to have_sent_email.with_any_attachments }
645
678
 
646
679
  #... or by absence
647
- it { should_have_sent_email.with_no_attachments }
680
+ it { is_expected.to have_sent_email.with_no_attachments }
648
681
 
649
682
  end
650
683
  ```
651
684
 
652
- Core Extensions
653
- ---------------
654
-
655
- The mail gem adds several constants and methods to Ruby's core objects (similar to the activesupport gem from the Rails project). For example:
656
-
657
- NilClass::blank?
658
- NilClass::to_crlf
659
- NilClass::to_lf
660
- Object::blank?
661
- String::to_crlf
662
- String::to_lf
663
- String::blank?
664
- ...etc...
665
-
666
- For all the details, check out lib/mail/core_extensions/.
667
-
668
- Excerpts from TREC Spam Corpus 2005
669
- -----------------------------------
685
+ ## Excerpts from TREC Spam Corpus 2005
670
686
 
671
687
  The spec fixture files in spec/fixtures/emails/from_trec_2005 are from the
672
688
  2005 TREC Public Spam Corpus. They remain copyrighted under the terms of
@@ -684,12 +700,11 @@ They are used as allowed by 'Permitted Uses, Clause 3':
684
700
 
685
701
  -- http://plg.uwaterloo.ca/~gvcormac/treccorpus/
686
702
 
687
- License
688
- -------
703
+ ## License
689
704
 
690
705
  (The MIT License)
691
706
 
692
- Copyright (c) 2009-2017 Mikel Lindsaar
707
+ Copyright (c) 2009-2016 Mikel Lindsaar
693
708
 
694
709
  Permission is hereby granted, free of charge, to any person obtaining
695
710
  a copy of this software and associated documentation files (the
@@ -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
@@ -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