mail 2.6.6 → 2.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/MIT-LICENSE +1 -1
- data/README.md +134 -119
- data/lib/mail/attachments_list.rb +10 -9
- data/lib/mail/body.rb +73 -84
- data/lib/mail/check_delivery_params.rb +28 -21
- data/lib/mail/configuration.rb +2 -0
- data/lib/mail/constants.rb +27 -5
- data/lib/mail/elements/address.rb +53 -47
- data/lib/mail/elements/address_list.rb +11 -19
- data/lib/mail/elements/content_disposition_element.rb +9 -16
- data/lib/mail/elements/content_location_element.rb +6 -11
- data/lib/mail/elements/content_transfer_encoding_element.rb +6 -11
- data/lib/mail/elements/content_type_element.rb +16 -23
- data/lib/mail/elements/date_time_element.rb +7 -15
- data/lib/mail/elements/envelope_from_element.rb +22 -23
- data/lib/mail/elements/message_ids_element.rb +18 -13
- data/lib/mail/elements/mime_version_element.rb +7 -15
- data/lib/mail/elements/phrase_list.rb +12 -10
- data/lib/mail/elements/received_element.rb +27 -19
- data/lib/mail/encodings/7bit.rb +9 -14
- data/lib/mail/encodings/8bit.rb +2 -21
- data/lib/mail/encodings/base64.rb +11 -12
- data/lib/mail/encodings/binary.rb +3 -22
- data/lib/mail/encodings/identity.rb +24 -0
- data/lib/mail/encodings/quoted_printable.rb +6 -6
- data/lib/mail/encodings/transfer_encoding.rb +38 -29
- data/lib/mail/encodings/unix_to_unix.rb +3 -1
- data/lib/mail/encodings.rb +81 -54
- data/lib/mail/envelope.rb +11 -14
- data/lib/mail/field.rb +119 -98
- data/lib/mail/field_list.rb +60 -7
- data/lib/mail/fields/bcc_field.rb +34 -52
- data/lib/mail/fields/cc_field.rb +28 -49
- data/lib/mail/fields/comments_field.rb +27 -37
- data/lib/mail/fields/common_address_field.rb +170 -0
- data/lib/mail/fields/common_date_field.rb +58 -0
- data/lib/mail/fields/common_field.rb +77 -0
- data/lib/mail/fields/common_message_id_field.rb +42 -0
- data/lib/mail/fields/content_description_field.rb +7 -14
- data/lib/mail/fields/content_disposition_field.rb +13 -38
- data/lib/mail/fields/content_id_field.rb +24 -51
- data/lib/mail/fields/content_location_field.rb +11 -25
- data/lib/mail/fields/content_transfer_encoding_field.rb +31 -31
- data/lib/mail/fields/content_type_field.rb +50 -80
- data/lib/mail/fields/date_field.rb +23 -52
- data/lib/mail/fields/from_field.rb +28 -49
- data/lib/mail/fields/in_reply_to_field.rb +38 -49
- data/lib/mail/fields/keywords_field.rb +18 -31
- data/lib/mail/fields/message_id_field.rb +25 -71
- data/lib/mail/fields/mime_version_field.rb +19 -30
- data/lib/mail/fields/named_structured_field.rb +11 -0
- data/lib/mail/fields/named_unstructured_field.rb +11 -0
- data/lib/mail/fields/optional_field.rb +9 -7
- data/lib/mail/fields/{common/parameter_hash.rb → parameter_hash.rb} +13 -11
- data/lib/mail/fields/received_field.rb +43 -57
- data/lib/mail/fields/references_field.rb +35 -49
- data/lib/mail/fields/reply_to_field.rb +28 -49
- data/lib/mail/fields/resent_bcc_field.rb +28 -49
- data/lib/mail/fields/resent_cc_field.rb +28 -49
- data/lib/mail/fields/resent_date_field.rb +5 -30
- data/lib/mail/fields/resent_from_field.rb +28 -49
- data/lib/mail/fields/resent_message_id_field.rb +5 -29
- data/lib/mail/fields/resent_sender_field.rb +27 -56
- data/lib/mail/fields/resent_to_field.rb +28 -49
- data/lib/mail/fields/return_path_field.rb +50 -54
- data/lib/mail/fields/sender_field.rb +34 -55
- data/lib/mail/fields/structured_field.rb +3 -30
- data/lib/mail/fields/subject_field.rb +9 -11
- data/lib/mail/fields/to_field.rb +28 -49
- data/lib/mail/fields/unstructured_field.rb +32 -47
- data/lib/mail/header.rb +71 -110
- data/lib/mail/mail.rb +2 -10
- data/lib/mail/matchers/attachment_matchers.rb +15 -0
- data/lib/mail/matchers/has_sent_mail.rb +21 -1
- data/lib/mail/message.rb +113 -117
- data/lib/mail/multibyte/chars.rb +21 -178
- data/lib/mail/multibyte/unicode.rb +10 -10
- data/lib/mail/multibyte/utils.rb +26 -43
- data/lib/mail/multibyte.rb +55 -16
- data/lib/mail/network/delivery_methods/exim.rb +5 -4
- data/lib/mail/network/delivery_methods/file_delivery.rb +11 -10
- data/lib/mail/network/delivery_methods/logger_delivery.rb +34 -0
- data/lib/mail/network/delivery_methods/sendmail.rb +62 -21
- data/lib/mail/network/delivery_methods/smtp.rb +75 -50
- data/lib/mail/network/delivery_methods/smtp_connection.rb +3 -4
- data/lib/mail/network/delivery_methods/test_mailer.rb +4 -2
- data/lib/mail/network/retriever_methods/base.rb +8 -8
- data/lib/mail/network/retriever_methods/imap.rb +20 -7
- data/lib/mail/network/retriever_methods/pop3.rb +5 -3
- data/lib/mail/network/retriever_methods/test_retriever.rb +2 -1
- data/lib/mail/network.rb +1 -0
- data/lib/mail/parser_tools.rb +15 -0
- data/lib/mail/parsers/address_lists_parser.rb +33225 -116
- data/lib/mail/parsers/address_lists_parser.rl +179 -0
- data/lib/mail/parsers/content_disposition_parser.rb +882 -49
- data/lib/mail/parsers/content_disposition_parser.rl +89 -0
- data/lib/mail/parsers/content_location_parser.rb +809 -23
- data/lib/mail/parsers/content_location_parser.rl +78 -0
- data/lib/mail/parsers/content_transfer_encoding_parser.rb +509 -21
- data/lib/mail/parsers/content_transfer_encoding_parser.rl +71 -0
- data/lib/mail/parsers/content_type_parser.rb +1037 -56
- data/lib/mail/parsers/content_type_parser.rl +90 -0
- data/lib/mail/parsers/date_time_parser.rb +877 -25
- data/lib/mail/parsers/date_time_parser.rl +69 -0
- data/lib/mail/parsers/envelope_from_parser.rb +3669 -40
- data/lib/mail/parsers/envelope_from_parser.rl +89 -0
- data/lib/mail/parsers/message_ids_parser.rb +5146 -25
- data/lib/mail/parsers/message_ids_parser.rl +93 -0
- data/lib/mail/parsers/mime_version_parser.rb +497 -26
- data/lib/mail/parsers/mime_version_parser.rl +68 -0
- data/lib/mail/parsers/phrase_lists_parser.rb +870 -22
- data/lib/mail/parsers/phrase_lists_parser.rl +90 -0
- data/lib/mail/parsers/received_parser.rb +8776 -43
- data/lib/mail/parsers/received_parser.rl +91 -0
- data/lib/mail/parsers/rfc2045_content_transfer_encoding.rl +13 -0
- data/lib/mail/parsers/rfc2045_content_type.rl +25 -0
- data/lib/mail/parsers/rfc2045_mime.rl +16 -0
- data/lib/mail/parsers/rfc2183_content_disposition.rl +15 -0
- data/lib/mail/parsers/rfc3629_utf8.rl +19 -0
- data/lib/mail/parsers/rfc5234_abnf_core_rules.rl +22 -0
- data/lib/mail/parsers/rfc5322.rl +74 -0
- data/lib/mail/parsers/rfc5322_address.rl +72 -0
- data/lib/mail/parsers/{ragel/date_time.rl → rfc5322_date_time.rl} +8 -1
- data/lib/mail/parsers/rfc5322_lexical_tokens.rl +60 -0
- data/lib/mail/parsers.rb +11 -25
- data/lib/mail/part.rb +6 -10
- data/lib/mail/parts_list.rb +62 -6
- data/lib/mail/smtp_envelope.rb +57 -0
- data/lib/mail/utilities.rb +343 -74
- data/lib/mail/version.rb +2 -2
- data/lib/mail/yaml.rb +30 -0
- data/lib/mail.rb +5 -35
- metadata +111 -66
- data/CHANGELOG.rdoc +0 -803
- data/CONTRIBUTING.md +0 -60
- data/Dependencies.txt +0 -2
- data/Gemfile +0 -14
- data/Rakefile +0 -29
- data/TODO.rdoc +0 -9
- data/lib/mail/core_extensions/smtp.rb +0 -25
- data/lib/mail/core_extensions/string/access.rb +0 -146
- data/lib/mail/core_extensions/string/multibyte.rb +0 -79
- data/lib/mail/core_extensions/string.rb +0 -21
- data/lib/mail/fields/common/address_container.rb +0 -17
- data/lib/mail/fields/common/common_address.rb +0 -136
- data/lib/mail/fields/common/common_date.rb +0 -36
- data/lib/mail/fields/common/common_field.rb +0 -61
- data/lib/mail/fields/common/common_message_id.rb +0 -49
- data/lib/mail/multibyte/exceptions.rb +0 -9
- data/lib/mail/parsers/ragel/common.rl +0 -185
- data/lib/mail/parsers/ragel/parser_info.rb +0 -61
- data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb +0 -14864
- data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl +0 -37
- data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb +0 -751
- data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl +0 -37
- data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb +0 -614
- data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl +0 -37
- data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb +0 -447
- data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl +0 -37
- data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb +0 -825
- data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl +0 -37
- data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb +0 -817
- data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl +0 -37
- data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb +0 -2149
- data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl +0 -37
- data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb +0 -1570
- data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl +0 -37
- data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb +0 -440
- data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl +0 -37
- data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb +0 -564
- data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl +0 -37
- data/lib/mail/parsers/ragel/ruby/machines/rb_actions.rl +0 -51
- data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb +0 -5144
- data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl +0 -37
- data/lib/mail/parsers/ragel/ruby/parser.rb.rl.erb +0 -37
- data/lib/mail/parsers/ragel/ruby.rb +0 -40
- data/lib/mail/parsers/ragel.rb +0 -18
- data/lib/mail/version_specific/ruby_1_8.rb +0 -126
- data/lib/mail/version_specific/ruby_1_9.rb +0 -226
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: ea4015fe2858f6c1b123e04d4d407169567b1aeea1155b7b145fe75d9d3781b5
|
4
|
+
data.tar.gz: 20cdb386c2f878560b9f61ab63b4f0c264c9f9115af5c835b8c66f49486cb274
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2eb55bc6f51b2d93e6d6abed5bb74876b3f96fd1eea00105047b3a211007b2b906ac89bcd1bed52603c211c595d439b6642bd897943decbcc9ac541f88e2049
|
7
|
+
data.tar.gz: 063dd68ef655b93d96412bdcf66ab6f191eaf0bfbafa10730ecfa99a447eb3d2a4469d6d1de67ae144bbaada65eaec4c7d8dbb5fe04509146dc1434a5c557fff
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,81 +1,93 @@
|
|
1
|
-
Mail [![Build Status](https://
|
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
|
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
|
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
|
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.
|
20
|
-
|
21
|
-
|
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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
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
|
-
*
|
65
|
-
*
|
66
|
-
* Support for
|
67
|
-
* Support for
|
68
|
-
* Support for
|
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 & getting details from such
|
69
82
|
* Wrappers for File, Net/POP3, Net/SMTP
|
70
|
-
* Auto
|
71
|
-
* Auto encoding of non US-ASCII bodies
|
83
|
+
* Auto-encoding of non-US-ASCII bodies and header fields
|
72
84
|
|
73
|
-
Mail is
|
74
|
-
|
75
|
-
it also is quite robust, meaning, if it finds something
|
76
|
-
not crash, instead, it will skip the problem and keep
|
77
|
-
it doesn't understand, it will initialise the header
|
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
|
-
|
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
|
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
|
-
|
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.
|
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
|
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.
|
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
|
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-
|
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,
|
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
|
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 {
|
633
|
+
it { is_expected.to have_sent_email } # passes if any email at all was sent
|
607
634
|
|
608
|
-
it {
|
609
|
-
it {
|
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 {
|
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 {
|
642
|
+
it { is_expected.to have_sent_email.to('mike1@me.com').to('mike2@me.com') }
|
616
643
|
|
617
|
-
it {
|
644
|
+
it { is_expected.to have_sent_email.with_subject('testing') }
|
618
645
|
|
619
|
-
it {
|
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 {
|
625
|
-
it {
|
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 {
|
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 {
|
662
|
+
it { is_expected.to have_sent_email.with_attachments(my_attachment) }
|
636
663
|
|
637
664
|
# ... or any attachment
|
638
|
-
it {
|
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 {
|
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 {
|
677
|
+
it { is_expected.to have_sent_email.with_any_attachments }
|
645
678
|
|
646
679
|
#... or by absence
|
647
|
-
it {
|
680
|
+
it { is_expected.to have_sent_email.with_no_attachments }
|
648
681
|
|
649
682
|
end
|
650
683
|
```
|
651
684
|
|
652
|
-
|
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-
|
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.
|
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 =
|
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].
|
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
|
-
|
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 =
|
102
|
+
@mime_type = MiniMime.lookup_by_filename(filename)
|
103
|
+
@mime_type && @mime_type.content_type
|
103
104
|
end
|
104
105
|
|
105
106
|
end
|