mail 2.6.1 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. checksums.yaml +5 -5
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +150 -107
  4. data/lib/mail/attachments_list.rb +13 -10
  5. data/lib/mail/body.rb +104 -90
  6. data/lib/mail/check_delivery_params.rb +55 -10
  7. data/lib/mail/configuration.rb +3 -0
  8. data/lib/mail/constants.rb +79 -0
  9. data/lib/mail/elements/address.rb +96 -108
  10. data/lib/mail/elements/address_list.rb +13 -30
  11. data/lib/mail/elements/content_disposition_element.rb +10 -16
  12. data/lib/mail/elements/content_location_element.rb +9 -13
  13. data/lib/mail/elements/content_transfer_encoding_element.rb +7 -11
  14. data/lib/mail/elements/content_type_element.rb +17 -23
  15. data/lib/mail/elements/date_time_element.rb +8 -15
  16. data/lib/mail/elements/envelope_from_element.rb +23 -23
  17. data/lib/mail/elements/message_ids_element.rb +22 -15
  18. data/lib/mail/elements/mime_version_element.rb +8 -15
  19. data/lib/mail/elements/phrase_list.rb +13 -10
  20. data/lib/mail/elements/received_element.rb +28 -19
  21. data/lib/mail/elements.rb +1 -0
  22. data/lib/mail/encodings/7bit.rb +10 -14
  23. data/lib/mail/encodings/8bit.rb +5 -18
  24. data/lib/mail/encodings/base64.rb +15 -10
  25. data/lib/mail/encodings/binary.rb +4 -22
  26. data/lib/mail/encodings/identity.rb +24 -0
  27. data/lib/mail/encodings/quoted_printable.rb +13 -7
  28. data/lib/mail/encodings/transfer_encoding.rb +47 -28
  29. data/lib/mail/encodings/unix_to_unix.rb +20 -0
  30. data/lib/mail/encodings.rb +102 -92
  31. data/lib/mail/envelope.rb +12 -14
  32. data/lib/mail/field.rb +121 -85
  33. data/lib/mail/field_list.rb +62 -8
  34. data/lib/mail/fields/bcc_field.rb +42 -48
  35. data/lib/mail/fields/cc_field.rb +29 -50
  36. data/lib/mail/fields/comments_field.rb +28 -37
  37. data/lib/mail/fields/common_address_field.rb +170 -0
  38. data/lib/mail/fields/common_date_field.rb +58 -0
  39. data/lib/mail/fields/common_field.rb +77 -0
  40. data/lib/mail/fields/common_message_id_field.rb +42 -0
  41. data/lib/mail/fields/content_description_field.rb +8 -14
  42. data/lib/mail/fields/content_disposition_field.rb +20 -44
  43. data/lib/mail/fields/content_id_field.rb +25 -51
  44. data/lib/mail/fields/content_location_field.rb +12 -25
  45. data/lib/mail/fields/content_transfer_encoding_field.rb +32 -31
  46. data/lib/mail/fields/content_type_field.rb +51 -80
  47. data/lib/mail/fields/date_field.rb +24 -52
  48. data/lib/mail/fields/from_field.rb +29 -50
  49. data/lib/mail/fields/in_reply_to_field.rb +39 -49
  50. data/lib/mail/fields/keywords_field.rb +19 -32
  51. data/lib/mail/fields/message_id_field.rb +26 -71
  52. data/lib/mail/fields/mime_version_field.rb +20 -30
  53. data/lib/mail/fields/named_structured_field.rb +11 -0
  54. data/lib/mail/fields/named_unstructured_field.rb +11 -0
  55. data/lib/mail/fields/optional_field.rb +10 -7
  56. data/lib/mail/fields/{common/parameter_hash.rb → parameter_hash.rb} +16 -13
  57. data/lib/mail/fields/received_field.rb +44 -57
  58. data/lib/mail/fields/references_field.rb +36 -49
  59. data/lib/mail/fields/reply_to_field.rb +29 -50
  60. data/lib/mail/fields/resent_bcc_field.rb +29 -50
  61. data/lib/mail/fields/resent_cc_field.rb +29 -50
  62. data/lib/mail/fields/resent_date_field.rb +6 -30
  63. data/lib/mail/fields/resent_from_field.rb +29 -50
  64. data/lib/mail/fields/resent_message_id_field.rb +6 -29
  65. data/lib/mail/fields/resent_sender_field.rb +28 -57
  66. data/lib/mail/fields/resent_to_field.rb +29 -50
  67. data/lib/mail/fields/return_path_field.rb +51 -55
  68. data/lib/mail/fields/sender_field.rb +35 -56
  69. data/lib/mail/fields/structured_field.rb +4 -30
  70. data/lib/mail/fields/subject_field.rb +10 -11
  71. data/lib/mail/fields/to_field.rb +29 -50
  72. data/lib/mail/fields/unstructured_field.rb +36 -50
  73. data/lib/mail/fields.rb +1 -0
  74. data/lib/mail/header.rb +73 -110
  75. data/lib/mail/indifferent_hash.rb +1 -0
  76. data/lib/mail/mail.rb +6 -11
  77. data/lib/mail/matchers/attachment_matchers.rb +44 -0
  78. data/lib/mail/matchers/has_sent_mail.rb +53 -9
  79. data/lib/mail/message.rb +132 -136
  80. data/lib/mail/multibyte/chars.rb +24 -180
  81. data/lib/mail/multibyte/unicode.rb +31 -26
  82. data/lib/mail/multibyte/utils.rb +27 -43
  83. data/lib/mail/multibyte.rb +56 -16
  84. data/lib/mail/network/delivery_methods/exim.rb +9 -11
  85. data/lib/mail/network/delivery_methods/file_delivery.rb +14 -16
  86. data/lib/mail/network/delivery_methods/logger_delivery.rb +34 -0
  87. data/lib/mail/network/delivery_methods/sendmail.rb +68 -24
  88. data/lib/mail/network/delivery_methods/smtp.rb +77 -54
  89. data/lib/mail/network/delivery_methods/smtp_connection.rb +5 -9
  90. data/lib/mail/network/delivery_methods/test_mailer.rb +9 -9
  91. data/lib/mail/network/retriever_methods/base.rb +9 -8
  92. data/lib/mail/network/retriever_methods/imap.rb +21 -7
  93. data/lib/mail/network/retriever_methods/pop3.rb +6 -3
  94. data/lib/mail/network/retriever_methods/test_retriever.rb +4 -2
  95. data/lib/mail/network.rb +2 -0
  96. data/lib/mail/parser_tools.rb +15 -0
  97. data/lib/mail/parsers/address_lists_parser.rb +33226 -116
  98. data/lib/mail/parsers/address_lists_parser.rl +179 -0
  99. data/lib/mail/parsers/content_disposition_parser.rb +883 -49
  100. data/lib/mail/parsers/content_disposition_parser.rl +89 -0
  101. data/lib/mail/parsers/content_location_parser.rb +810 -23
  102. data/lib/mail/parsers/content_location_parser.rl +78 -0
  103. data/lib/mail/parsers/content_transfer_encoding_parser.rb +510 -21
  104. data/lib/mail/parsers/content_transfer_encoding_parser.rl +71 -0
  105. data/lib/mail/parsers/content_type_parser.rb +1031 -47
  106. data/lib/mail/parsers/content_type_parser.rl +90 -0
  107. data/lib/mail/parsers/date_time_parser.rb +879 -24
  108. data/lib/mail/parsers/date_time_parser.rl +69 -0
  109. data/lib/mail/parsers/envelope_from_parser.rb +3670 -40
  110. data/lib/mail/parsers/envelope_from_parser.rl +89 -0
  111. data/lib/mail/parsers/message_ids_parser.rb +5147 -25
  112. data/lib/mail/parsers/message_ids_parser.rl +93 -0
  113. data/lib/mail/parsers/mime_version_parser.rb +498 -26
  114. data/lib/mail/parsers/mime_version_parser.rl +68 -0
  115. data/lib/mail/parsers/phrase_lists_parser.rb +872 -21
  116. data/lib/mail/parsers/phrase_lists_parser.rl +90 -0
  117. data/lib/mail/parsers/received_parser.rb +8777 -42
  118. data/lib/mail/parsers/received_parser.rl +91 -0
  119. data/lib/mail/parsers/rfc2045_content_transfer_encoding.rl +13 -0
  120. data/lib/mail/parsers/rfc2045_content_type.rl +25 -0
  121. data/lib/mail/parsers/rfc2045_mime.rl +16 -0
  122. data/lib/mail/parsers/rfc2183_content_disposition.rl +15 -0
  123. data/lib/mail/parsers/rfc3629_utf8.rl +19 -0
  124. data/lib/mail/parsers/rfc5234_abnf_core_rules.rl +22 -0
  125. data/lib/mail/parsers/rfc5322.rl +74 -0
  126. data/lib/mail/parsers/rfc5322_address.rl +72 -0
  127. data/lib/mail/parsers/{ragel/date_time.rl → rfc5322_date_time.rl} +8 -1
  128. data/lib/mail/parsers/rfc5322_lexical_tokens.rl +60 -0
  129. data/lib/mail/parsers.rb +12 -25
  130. data/lib/mail/part.rb +11 -12
  131. data/lib/mail/parts_list.rb +88 -14
  132. data/lib/mail/smtp_envelope.rb +57 -0
  133. data/lib/mail/utilities.rb +377 -40
  134. data/lib/mail/values/unicode_tables.dat +0 -0
  135. data/lib/mail/version.rb +8 -15
  136. data/lib/mail/yaml.rb +30 -0
  137. data/lib/mail.rb +9 -32
  138. metadata +138 -94
  139. data/CHANGELOG.rdoc +0 -752
  140. data/CONTRIBUTING.md +0 -60
  141. data/Dependencies.txt +0 -2
  142. data/Gemfile +0 -15
  143. data/Rakefile +0 -29
  144. data/TODO.rdoc +0 -9
  145. data/VERSION +0 -4
  146. data/lib/mail/core_extensions/nil.rb +0 -19
  147. data/lib/mail/core_extensions/object.rb +0 -13
  148. data/lib/mail/core_extensions/smtp.rb +0 -24
  149. data/lib/mail/core_extensions/string/access.rb +0 -145
  150. data/lib/mail/core_extensions/string/multibyte.rb +0 -78
  151. data/lib/mail/core_extensions/string.rb +0 -43
  152. data/lib/mail/fields/common/address_container.rb +0 -16
  153. data/lib/mail/fields/common/common_address.rb +0 -135
  154. data/lib/mail/fields/common/common_date.rb +0 -35
  155. data/lib/mail/fields/common/common_field.rb +0 -57
  156. data/lib/mail/fields/common/common_message_id.rb +0 -48
  157. data/lib/mail/multibyte/exceptions.rb +0 -8
  158. data/lib/mail/parsers/ragel/common.rl +0 -184
  159. data/lib/mail/parsers/ragel/parser_info.rb +0 -61
  160. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb +0 -14864
  161. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl +0 -37
  162. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb +0 -751
  163. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl +0 -37
  164. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb +0 -614
  165. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl +0 -37
  166. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb +0 -447
  167. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl +0 -37
  168. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb +0 -825
  169. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl +0 -37
  170. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb +0 -817
  171. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl +0 -37
  172. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb +0 -2129
  173. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl +0 -37
  174. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb +0 -1570
  175. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl +0 -37
  176. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb +0 -440
  177. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl +0 -37
  178. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb +0 -564
  179. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl +0 -37
  180. data/lib/mail/parsers/ragel/ruby/machines/rb_actions.rl +0 -51
  181. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb +0 -5144
  182. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl +0 -37
  183. data/lib/mail/parsers/ragel/ruby/parser.rb.rl.erb +0 -37
  184. data/lib/mail/parsers/ragel/ruby.rb +0 -39
  185. data/lib/mail/parsers/ragel.rb +0 -17
  186. data/lib/mail/patterns.rb +0 -37
  187. data/lib/mail/version_specific/ruby_1_8.rb +0 -119
  188. data/lib/mail/version_specific/ruby_1_9.rb +0 -159
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: b36c7dad6398232438e90270f9814eb04aeda138
4
- data.tar.gz: 7dbe4c27bd7cab8569892fc5d6a676718aaf755b
2
+ SHA256:
3
+ metadata.gz: ea4015fe2858f6c1b123e04d4d407169567b1aeea1155b7b145fe75d9d3781b5
4
+ data.tar.gz: 20cdb386c2f878560b9f61ab63b4f0c264c9f9115af5c835b8c66f49486cb274
5
5
  SHA512:
6
- metadata.gz: 0628c04e7acf3cf0c3a801aff33a6008fe338ebd9a96a1d2b290ffbd98af1c287c0bdd958eda0ec77f495f498880dd69aaf8325da77e2f7d6ddb9f50396b1635
7
- data.tar.gz: 1d813d0f8b64feb0a5a0561e7d031d795b54bf3d0160c02fcd35a9f11e04875dd6ea05a67b5a565b3d67486ce8941a14ac2d1362a288032eb3863641c533fece
6
+ metadata.gz: b2eb55bc6f51b2d93e6d6abed5bb74876b3f96fd1eea00105047b3a211007b2b906ac89bcd1bed52603c211c595d439b6642bd897943decbcc9ac541f88e2049
7
+ data.tar.gz: 063dd68ef655b93d96412bdcf66ab6f191eaf0bfbafa10730ecfa99a447eb3d2a4469d6d1de67ae144bbaada65eaec4c7d8dbb5fe04509146dc1434a5c557fff
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2013 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,89 +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
- 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.
16
+ It is also designed from the ground up to work with the more modern versions
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
- Every Mail commit is tested by Travis on the [following platforms](https://github.com/mikel/mail/blob/master/.travis.yml)
46
-
47
- * ruby-1.8.7-p374 [ i686 ]
48
- * ruby-1.9.2-p320 [ x86_64 ]
49
- * ruby-1.9.3-p327 [ 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
- ```sh
60
- BUNDLE_GEMFILE=gemfiles/mime_types_1.16.gemfile (bundle check || bundle) && rake
61
- ```
62
-
63
- Discussion
64
- ----------
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
65
71
 
66
72
  If you want to discuss mail with like minded individuals, please subscribe to
67
73
  the [Google Group](http://groups.google.com/group/mail-ruby).
68
74
 
69
- Current Capabilities of Mail
70
- ----------------------------
75
+ ## Current Capabilities of Mail
71
76
 
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
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
77
82
  * Wrappers for File, Net/POP3, Net/SMTP
78
- * Auto encoding of non US-ASCII header fields
79
- * Auto encoding of non US-ASCII bodies
83
+ * Auto-encoding of non-US-ASCII bodies and header fields
80
84
 
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.
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.
87
91
 
88
92
  This means Mail won't (ever) crunch your data (I think).
89
93
 
@@ -91,16 +95,14 @@ You can also create MIME emails. There are helper methods for making a
91
95
  multipart/alternate email for text/plain and text/html (the most common pair)
92
96
  and you can manually create any other type of MIME email.
93
97
 
94
- Roadmap
95
- -------
98
+ ## Roadmap
96
99
 
97
100
  Next TODO:
98
101
 
99
102
  * Improve MIME support for character sets in headers, currently works, mostly, needs
100
103
  refinement.
101
104
 
102
- Testing Policy
103
- --------------
105
+ ## Testing Policy
104
106
 
105
107
  Basically... we do BDD on Mail. No method gets written in Mail without a
106
108
  corresponding or covering spec. We expect as a minimum 100% coverage
@@ -110,23 +112,24 @@ the gem gets released.
110
112
 
111
113
  It also means you can be sure Mail will behave correctly.
112
114
 
113
- API Policy
114
- ----------
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).
118
+
119
+ ## API Policy
115
120
 
116
121
  No API removals within a single point release. All removals to be deprecated with
117
122
  warnings for at least one MINOR point release before removal.
118
123
 
119
124
  Also, all private or protected methods to be declared as such - though this is still I/P.
120
125
 
121
- Installation
122
- ------------
126
+ ## Installation
123
127
 
124
128
  Installation is fairly simple, I host mail on rubygems, so you can just do:
125
129
 
126
130
  # gem install mail
127
131
 
128
- Encodings
129
- ---------
132
+ ## Encodings
130
133
 
131
134
  If you didn't know, handling encodings in Emails is not as straight forward as you
132
135
  would hope.
@@ -158,17 +161,17 @@ I have tried to simplify it some:
158
161
  provide encoded parameter values when you call the parameter names through the
159
162
  <code>object.parameters['<parameter_name>']</code> method call.
160
163
 
161
- Contributing
162
- ------------
164
+ ## Contributing
163
165
 
164
- 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.
165
167
 
166
- Usage
167
- -----
168
+ ## Usage
168
169
 
169
170
  All major mail functions should be able to happen from the Mail module.
170
171
  So, you should be able to just <code>require 'mail'</code> to get started.
171
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
+
172
175
  ### Making an email
173
176
 
174
177
  ```ruby
@@ -232,7 +235,7 @@ what you are doing.
232
235
  ### Sending an email:
233
236
 
234
237
  Mail defaults to sending via SMTP to local host port 25. If you have a
235
- 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
236
239
  easy as:
237
240
 
238
241
  ```ruby
@@ -292,12 +295,23 @@ mail.delivery_method :exim, :location => "/usr/bin/exim"
292
295
  mail.deliver
293
296
  ```
294
297
 
295
- ### 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:
296
309
 
297
310
  You can configure Mail to receive email using <code>retriever_method</code>
298
311
  within <code>Mail.defaults</code>:
299
312
 
300
313
  ```ruby
314
+ # e.g. POP3
301
315
  Mail.defaults do
302
316
  retriever_method :pop3, :address => "pop.gmail.com",
303
317
  :port => 995,
@@ -305,6 +319,15 @@ Mail.defaults do
305
319
  :password => '<password>',
306
320
  :enable_ssl => true
307
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
308
331
  ```
309
332
 
310
333
  You can access incoming email in a number of ways.
@@ -345,7 +368,7 @@ mail.cc #=> 'sam@test.lindsaar.net'
345
368
  mail.subject #=> "This is the subject"
346
369
  mail.date.to_s #=> '21 Nov 1997 09:55:06 -0600'
347
370
  mail.message_id #=> '<4D6AA7EB.6490534@xxx.xxx>'
348
- mail.body.decoded #=> 'This is the body of the email...
371
+ mail.decoded #=> 'This is the body of the email...
349
372
  ```
350
373
 
351
374
  Many more methods available.
@@ -371,7 +394,7 @@ is another message which can have many or no parts.
371
394
  A message will only have parts if it is a multipart/mixed or multipart/related
372
395
  content type and has a boundary defined.
373
396
 
374
- ### Testing and extracting attachments
397
+ ### Testing and Extracting Attachments
375
398
  ```ruby
376
399
  mail.attachments.each do | attachment |
377
400
  # Attachments is an AttachmentsList object containing a
@@ -380,14 +403,14 @@ mail.attachments.each do | attachment |
380
403
  # extracting images for example...
381
404
  filename = attachment.filename
382
405
  begin
383
- 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}
384
407
  rescue => e
385
408
  puts "Unable to save data for #{filename} because #{e.message}"
386
409
  end
387
410
  end
388
411
  end
389
412
  ```
390
- ### Writing and sending a multipart/alternative (html and text) email
413
+ ### Writing and Sending a Multipart/Alternative (HTML and Text) Email
391
414
 
392
415
  Mail makes some basic assumptions and makes doing the common thing as
393
416
  simple as possible.... (asking a lot from a mail library)
@@ -447,13 +470,13 @@ Content-Transfer-Encoding: 7bit
447
470
  ```
448
471
 
449
472
  Mail inserts the content transfer encoding, the mime version,
450
- the content-id's and handles the content-type and boundary.
473
+ the content-IDs and handles the content-type and boundary.
451
474
 
452
475
  Mail assumes that if your text in the body is only us-ascii, that your
453
476
  transfer encoding is 7bit and it is text/plain. You can override this
454
477
  by explicitly declaring it.
455
478
 
456
- ### Making Multipart/Alternate, without a block
479
+ ### Making Multipart/Alternate, Without a Block
457
480
 
458
481
  You don't have to use a block with the text and html part included, you
459
482
  can just do it declaratively. However, you need to add Mail::Parts to
@@ -481,7 +504,7 @@ mail.html_part = html_part
481
504
 
482
505
  Results in the same email as done using the block form
483
506
 
484
- ### Getting error reports from an email:
507
+ ### Getting Error Reports from an Email:
485
508
 
486
509
  ```ruby
487
510
  @mail = Mail.read('/path/to/bounce_message.eml')
@@ -525,7 +548,6 @@ than mail (this should be rarely needed)
525
548
 
526
549
  ```ruby
527
550
  @mail = Mail.new
528
- file_data = File.read('path/to/myfile.pdf')
529
551
  @mail.attachments['myfile.pdf'] = { :mime_type => 'application/x-pdf',
530
552
  :content => File.read('path/to/myfile.pdf') }
531
553
  @mail.parts.first.mime_type #=> 'application/x-pdf'
@@ -558,8 +580,7 @@ end
558
580
  ```
559
581
  See "Testing and extracting attachments" above for more details.
560
582
 
561
- Using Mail with Testing or Spec'ing Libraries
562
- ---------------------------------------------
583
+ ## Using Mail with Testing or Spec'ing Libraries
563
584
 
564
585
  If mail is part of your system, you'll need a way to test it without actually
565
586
  sending emails, the TestMailer can do this for you.
@@ -588,7 +609,7 @@ Mail::TestMailer.deliveries.clear
588
609
  => []
589
610
  ```
590
611
 
591
- 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):
612
+ There is also a set of RSpec matchers stolen/inspired by Shoulda's ActionMailer matchers (you'll want to set <code>delivery_method</code> as above too):
592
613
 
593
614
  ```ruby
594
615
  Mail.defaults do
@@ -609,36 +630,59 @@ describe "sending an email" do
609
630
  end
610
631
  end
611
632
 
612
- 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
613
634
 
614
- it { should have_sent_email.from('you@you.com') }
615
- 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') }
616
637
 
617
638
  # can specify a list of recipients...
618
- 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']) }
619
640
 
620
641
  # ...or chain recipients together
621
- 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') }
622
643
 
623
- it { should have_sent_email.with_subject('testing') }
644
+ it { is_expected.to have_sent_email.with_subject('testing') }
624
645
 
625
- it { should have_sent_email.with_body('hello') }
646
+ it { is_expected.to have_sent_email.with_body('hello') }
626
647
 
627
648
  # Can match subject or body with a regex
628
649
  # (or anything that responds_to? :match)
629
650
 
630
- it { should have_sent_email.matching_subject(/test(ing)?/) }
631
- 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/) }
632
653
 
633
654
  # Can chain together modifiers
634
655
  # Note that apart from recipients, repeating a modifier overwrites old value.
635
656
 
636
- 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/)
658
+
659
+ # test for attachments
660
+
661
+ # ... by specific attachment
662
+ it { is_expected.to have_sent_email.with_attachments(my_attachment) }
663
+
664
+ # ... or 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')) }
672
+
673
+ # ... by array of attachments
674
+ it { is_expected.to have_sent_email.with_attachments([my_attachment1, my_attachment2]) } #note that order is important
675
+
676
+ #... by presence
677
+ it { is_expected.to have_sent_email.with_any_attachments }
678
+
679
+ #... or by absence
680
+ it { is_expected.to have_sent_email.with_no_attachments }
681
+
637
682
  end
638
683
  ```
639
684
 
640
- Excerpts from TREC Spam Corpus 2005
641
- -----------------------------------
685
+ ## Excerpts from TREC Spam Corpus 2005
642
686
 
643
687
  The spec fixture files in spec/fixtures/emails/from_trec_2005 are from the
644
688
  2005 TREC Public Spam Corpus. They remain copyrighted under the terms of
@@ -656,12 +700,11 @@ They are used as allowed by 'Permitted Uses, Clause 3':
656
700
 
657
701
  -- http://plg.uwaterloo.ca/~gvcormac/treccorpus/
658
702
 
659
- License
660
- -------
703
+ ## License
661
704
 
662
705
  (The MIT License)
663
706
 
664
- Copyright (c) 2009-2013 Mikel Lindsaar
707
+ Copyright (c) 2009-2016 Mikel Lindsaar
665
708
 
666
709
  Permission is hereby granted, free of charge, to any person obtaining
667
710
  a copy of this software and associated documentation files (the
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Mail
2
3
  class AttachmentsList < Array
3
4
 
@@ -5,8 +6,8 @@ module Mail
5
6
  @parts_list = parts_list
6
7
  @content_disposition_type = 'attachment'
7
8
  parts_list.map { |p|
8
- if p.content_type == "message/rfc822"
9
- Mail.new(p.body).attachments
9
+ if p.mime_type == 'message/rfc822'
10
+ Mail.new(p.body.encoded).attachments
10
11
  elsif p.parts.empty?
11
12
  p if p.attachment?
12
13
  else
@@ -29,7 +30,7 @@ module Mail
29
30
  # mail.attachments['test.png'].filename #=> 'test.png'
30
31
  # mail.attachments[1].filename #=> 'test.jpg'
31
32
  def [](index_value)
32
- if index_value.is_a?(Fixnum)
33
+ if index_value.is_a?(Integer)
33
34
  self.fetch(index_value)
34
35
  else
35
36
  self.select { |a| a.filename == index_value }.first
@@ -43,6 +44,9 @@ module Mail
43
44
  :content_disposition => "#{@content_disposition_type}; filename=\"#{encoded_name}\"" }
44
45
 
45
46
  if value.is_a?(Hash)
47
+ if path = value.delete(:filename)
48
+ value[:content] ||= File.open(path, 'rb') { |f| f.read }
49
+ end
46
50
 
47
51
  default_values[:body] = value.delete(:content) if value[:content]
48
52
 
@@ -59,7 +63,7 @@ module Mail
59
63
 
60
64
  if value[:mime_type]
61
65
  default_values[:content_type] = value.delete(:mime_type)
62
- @mime_type = MIME::Types[default_values[:content_type]].first
66
+ @mime_type = MiniMime.lookup_by_content_type(default_values[:content_type])
63
67
  default_values[:content_transfer_encoding] ||= guess_encoding
64
68
  end
65
69
 
@@ -70,7 +74,8 @@ module Mail
70
74
  end
71
75
 
72
76
  if hash[:body].respond_to? :force_encoding and hash[:body].respond_to? :valid_encoding?
73
- 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?
78
+ hash[:body] = hash[:body].dup if hash[:body].frozen?
74
79
  hash[:body].force_encoding("BINARY")
75
80
  end
76
81
  end
@@ -92,12 +97,10 @@ module Mail
92
97
  end
93
98
 
94
99
  def set_mime_type(filename)
95
- # Have to do this because MIME::Types is not Ruby 1.9 safe yet
96
- if RUBY_VERSION >= '1.9'
97
- filename = filename.encode(Encoding::UTF_8) if filename.respond_to?(:encode)
98
- end
100
+ filename = filename.encode(Encoding::UTF_8) if filename.respond_to?(:encode)
99
101
 
100
- @mime_type = MIME::Types.type_for(filename).first
102
+ @mime_type = MiniMime.lookup_by_filename(filename)
103
+ @mime_type && @mime_type.content_type
101
104
  end
102
105
 
103
106
  end