mail 2.7.1 → 2.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +135 -59
- data/lib/mail/attachments_list.rb +5 -6
- data/lib/mail/body.rb +51 -74
- data/lib/mail/constants.rb +27 -5
- data/lib/mail/elements/address.rb +27 -27
- data/lib/mail/elements/address_list.rb +1 -1
- data/lib/mail/elements/content_disposition_element.rb +1 -1
- data/lib/mail/elements/content_location_element.rb +1 -1
- data/lib/mail/elements/content_transfer_encoding_element.rb +1 -1
- data/lib/mail/elements/content_type_element.rb +8 -4
- data/lib/mail/elements/date_time_element.rb +1 -1
- data/lib/mail/elements/envelope_from_element.rb +13 -7
- data/lib/mail/elements/message_ids_element.rb +14 -5
- data/lib/mail/elements/mime_version_element.rb +1 -1
- data/lib/mail/elements/phrase_list.rb +7 -2
- data/lib/mail/elements/received_element.rb +20 -6
- data/lib/mail/encodings/7bit.rb +5 -0
- data/lib/mail/encodings/base64.rb +2 -2
- data/lib/mail/encodings/quoted_printable.rb +2 -2
- data/lib/mail/encodings/unix_to_unix.rb +1 -1
- data/lib/mail/encodings.rb +32 -61
- data/lib/mail/envelope.rb +11 -14
- data/lib/mail/field.rb +100 -86
- data/lib/mail/field_list.rb +61 -8
- data/lib/mail/fields/bcc_field.rb +33 -52
- data/lib/mail/fields/cc_field.rb +27 -49
- data/lib/mail/fields/comments_field.rb +26 -37
- data/lib/mail/fields/common_address_field.rb +162 -0
- data/lib/mail/fields/common_date_field.rb +56 -0
- data/lib/mail/fields/common_field.rb +77 -0
- data/lib/mail/fields/common_message_id_field.rb +41 -0
- data/lib/mail/fields/content_description_field.rb +6 -14
- data/lib/mail/fields/content_disposition_field.rb +11 -38
- data/lib/mail/fields/content_id_field.rb +23 -51
- data/lib/mail/fields/content_location_field.rb +10 -25
- data/lib/mail/fields/content_transfer_encoding_field.rb +30 -31
- data/lib/mail/fields/content_type_field.rb +49 -75
- data/lib/mail/fields/date_field.rb +22 -51
- data/lib/mail/fields/from_field.rb +27 -49
- data/lib/mail/fields/in_reply_to_field.rb +37 -49
- data/lib/mail/fields/keywords_field.rb +17 -31
- data/lib/mail/fields/message_id_field.rb +24 -71
- data/lib/mail/fields/mime_version_field.rb +18 -30
- data/lib/mail/fields/named_structured_field.rb +10 -0
- data/lib/mail/fields/named_unstructured_field.rb +10 -0
- data/lib/mail/fields/optional_field.rb +5 -7
- data/lib/mail/fields/{common/parameter_hash.rb → parameter_hash.rb} +12 -10
- data/lib/mail/fields/received_field.rb +42 -57
- data/lib/mail/fields/references_field.rb +34 -49
- data/lib/mail/fields/reply_to_field.rb +27 -49
- data/lib/mail/fields/resent_bcc_field.rb +27 -49
- data/lib/mail/fields/resent_cc_field.rb +27 -49
- data/lib/mail/fields/resent_date_field.rb +4 -29
- data/lib/mail/fields/resent_from_field.rb +27 -49
- data/lib/mail/fields/resent_message_id_field.rb +4 -29
- data/lib/mail/fields/resent_sender_field.rb +26 -56
- data/lib/mail/fields/resent_to_field.rb +27 -49
- data/lib/mail/fields/return_path_field.rb +49 -54
- data/lib/mail/fields/sender_field.rb +33 -55
- data/lib/mail/fields/structured_field.rb +2 -30
- data/lib/mail/fields/subject_field.rb +8 -11
- data/lib/mail/fields/to_field.rb +27 -49
- data/lib/mail/fields/unstructured_field.rb +15 -48
- data/lib/mail/fields.rb +9 -0
- data/lib/mail/header.rb +69 -110
- data/lib/mail/mail.rb +32 -27
- data/lib/mail/matchers/attachment_matchers.rb +15 -0
- data/lib/mail/message.rb +67 -78
- data/lib/mail/multibyte/chars.rb +9 -167
- data/lib/mail/multibyte/unicode.rb +1 -1
- data/lib/mail/multibyte/utils.rb +26 -43
- data/lib/mail/multibyte.rb +1 -11
- data/lib/mail/network/delivery_methods/exim.rb +5 -4
- data/lib/mail/network/delivery_methods/file_delivery.rb +13 -12
- data/lib/mail/network/delivery_methods/logger_delivery.rb +2 -5
- data/lib/mail/network/delivery_methods/sendmail.rb +27 -35
- data/lib/mail/network/delivery_methods/smtp.rb +81 -30
- data/lib/mail/network/delivery_methods/smtp_connection.rb +10 -19
- data/lib/mail/network/delivery_methods/test_mailer.rb +8 -6
- data/lib/mail/network/retriever_methods/base.rb +13 -13
- data/lib/mail/network/retriever_methods/imap.rb +8 -5
- data/lib/mail/network/retriever_methods/pop3.rb +22 -22
- data/lib/mail/network/retriever_methods/test_retriever.rb +2 -1
- data/lib/mail/parsers/address_lists_parser.rb +33073 -33064
- data/lib/mail/parsers/address_lists_parser.rl +11 -0
- data/lib/mail/parsers/content_disposition_parser.rb +837 -828
- data/lib/mail/parsers/content_disposition_parser.rl +11 -0
- data/lib/mail/parsers/content_location_parser.rb +773 -764
- data/lib/mail/parsers/content_location_parser.rl +12 -1
- data/lib/mail/parsers/content_transfer_encoding_parser.rb +477 -468
- data/lib/mail/parsers/content_transfer_encoding_parser.rl +11 -0
- data/lib/mail/parsers/content_type_parser.rb +974 -965
- data/lib/mail/parsers/content_type_parser.rl +11 -0
- data/lib/mail/parsers/date_time_parser.rb +841 -832
- data/lib/mail/parsers/date_time_parser.rl +11 -0
- data/lib/mail/parsers/envelope_from_parser.rb +3627 -3530
- data/lib/mail/parsers/envelope_from_parser.rl +11 -0
- data/lib/mail/parsers/message_ids_parser.rb +5110 -2800
- data/lib/mail/parsers/message_ids_parser.rl +16 -1
- data/lib/mail/parsers/mime_version_parser.rb +466 -457
- data/lib/mail/parsers/mime_version_parser.rl +11 -0
- data/lib/mail/parsers/phrase_lists_parser.rb +839 -830
- data/lib/mail/parsers/phrase_lists_parser.rl +12 -1
- data/lib/mail/parsers/received_parser.rb +8692 -8683
- data/lib/mail/parsers/received_parser.rl +11 -0
- data/lib/mail/parsers/rfc5322.rl +28 -13
- data/lib/mail/parsers.rb +11 -17
- data/lib/mail/part.rb +24 -28
- data/lib/mail/parts_list.rb +57 -0
- data/lib/mail/smtp_envelope.rb +57 -0
- data/lib/mail/utilities.rb +321 -69
- data/lib/mail/version.rb +1 -1
- data/lib/mail/yaml.rb +30 -0
- data/lib/mail.rb +2 -22
- metadata +83 -19
- data/lib/mail/check_delivery_params.rb +0 -60
- data/lib/mail/core_extensions/smtp.rb +0 -28
- data/lib/mail/core_extensions/string.rb +0 -17
- data/lib/mail/fields/common/address_container.rb +0 -17
- data/lib/mail/fields/common/common_address.rb +0 -161
- data/lib/mail/fields/common/common_date.rb +0 -36
- data/lib/mail/fields/common/common_field.rb +0 -52
- data/lib/mail/fields/common/common_message_id.rb +0 -49
- data/lib/mail/version_specific/ruby_1_8.rb +0 -163
- data/lib/mail/version_specific/ruby_1_9.rb +0 -278
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4a67f21ae487544b4e5643f58bbeefc655aeeb71a8a6b1296f70a3772e45e58
|
|
4
|
+
data.tar.gz: 7db8b4d4900cb78bb51a4384f0415deb80253df509b22f55073289dea07021c3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: fe249426a2cb09c463dae570a5a9d13a19e6e9ffcce643f766102da9033ec69bec69642834a29069ade3909e39962abdfb818eba539fe4a1322a2812e9242c93
|
|
7
|
+
data.tar.gz: 146e604d9cfa857f0485485839ab64334656dd287d059d9fa17d5dd5e71d980c5df4b081b148c99c2d3f841eacfa439aaa0c1e0ab9658181ea57357ba17f41cf
|
data/README.md
CHANGED
|
@@ -1,39 +1,35 @@
|
|
|
1
|
-
# Mail [](https://github.com/mikel/mail/actions/workflows/test.yml)
|
|
2
2
|
|
|
3
3
|
## Introduction
|
|
4
4
|
|
|
5
|
-
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
|
|
6
6
|
generation, parsing and sending in a simple, rubyesque manner.
|
|
7
7
|
|
|
8
8
|
The purpose of this library is to provide a single point of access to handle
|
|
9
|
-
all email functions, including sending and receiving
|
|
9
|
+
all email functions, including sending and receiving email. All network
|
|
10
10
|
type actions are done through proxy methods to Net::SMTP, Net::POP3 etc.
|
|
11
11
|
|
|
12
12
|
Built from my experience with TMail, it is designed to be a pure ruby
|
|
13
|
-
implementation that makes generating, sending and parsing
|
|
13
|
+
implementation that makes generating, sending and parsing email a no
|
|
14
14
|
brainer.
|
|
15
15
|
|
|
16
16
|
It is also designed from the ground up to work with the more modern versions
|
|
17
|
-
of Ruby.
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
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.
|
|
21
20
|
|
|
22
21
|
Finally, Mail has been designed with a very simple object oriented system
|
|
23
22
|
that really opens up the email messages you are parsing, if you know what
|
|
24
23
|
you are doing, you can fiddle with every last bit of your email directly.
|
|
25
24
|
|
|
26
|
-
##
|
|
25
|
+
## You can contribute to this library
|
|
27
26
|
|
|
28
|
-
Mail
|
|
29
|
-
|
|
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.
|
|
30
32
|
|
|
31
|
-
It is (like all open source software) a labour of love and something I am doing
|
|
32
|
-
with my own free time. If you would like to say thanks, please feel free to
|
|
33
|
-
[make a donation](http://www.pledgie.com/campaigns/8790) and feel free to send
|
|
34
|
-
me a nice email :)
|
|
35
|
-
|
|
36
|
-
<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>
|
|
37
33
|
|
|
38
34
|
# Contents
|
|
39
35
|
* [Compatibility](#compatibility)
|
|
@@ -46,15 +42,30 @@ me a nice email :)
|
|
|
46
42
|
* [Encodings](#encodings)
|
|
47
43
|
* [Contributing](#contributing)
|
|
48
44
|
* [Usage](#usage)
|
|
49
|
-
* [
|
|
50
|
-
* [Excerpts from TREC Span Corpus 2005](#excerpts-from-trec-span-corpus-2005)
|
|
45
|
+
* [Excerpts from TREC Spam Corpus 2005](#excerpts-from-trec-spam-corpus-2005)
|
|
51
46
|
* [License](#license)
|
|
52
47
|
|
|
53
48
|
## Compatibility
|
|
54
49
|
|
|
55
|
-
Mail
|
|
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.
|
|
56
67
|
|
|
57
|
-
Every Mail commit is tested by
|
|
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).
|
|
58
69
|
|
|
59
70
|
## Discussion
|
|
60
71
|
|
|
@@ -65,14 +76,14 @@ the [Google Group](http://groups.google.com/group/mail-ruby).
|
|
|
65
76
|
|
|
66
77
|
* RFC5322 Support, Reading and Writing
|
|
67
78
|
* RFC6532 Support, reading UTF-8 headers
|
|
68
|
-
* RFC2045-2049 Support for multipart
|
|
69
|
-
* Support for creating multipart alternate
|
|
70
|
-
* Support for reading multipart/report
|
|
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
|
|
71
82
|
* Wrappers for File, Net/POP3, Net/SMTP
|
|
72
83
|
* Auto-encoding of non-US-ASCII bodies and header fields
|
|
73
84
|
|
|
74
85
|
Mail is RFC5322 and RFC6532 compliant now, that is, it can parse US-ASCII and UTF-8
|
|
75
|
-
|
|
86
|
+
email and generate US-ASCII email. There are a few obsoleted email syntax that
|
|
76
87
|
it will have problems with, but it also is quite robust, meaning, if it finds something
|
|
77
88
|
it doesn't understand it will not crash, instead, it will skip the problem and keep
|
|
78
89
|
parsing. In the case of a header it doesn't understand, it will initialise the header
|
|
@@ -101,7 +112,9 @@ the gem gets released.
|
|
|
101
112
|
|
|
102
113
|
It also means you can be sure Mail will behave correctly.
|
|
103
114
|
|
|
104
|
-
|
|
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).
|
|
105
118
|
|
|
106
119
|
## API Policy
|
|
107
120
|
|
|
@@ -150,13 +163,15 @@ I have tried to simplify it some:
|
|
|
150
163
|
|
|
151
164
|
## Contributing
|
|
152
165
|
|
|
153
|
-
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.
|
|
154
167
|
|
|
155
168
|
## Usage
|
|
156
169
|
|
|
157
170
|
All major mail functions should be able to happen from the Mail module.
|
|
158
171
|
So, you should be able to just <code>require 'mail'</code> to get started.
|
|
159
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
|
+
|
|
160
175
|
### Making an email
|
|
161
176
|
|
|
162
177
|
```ruby
|
|
@@ -290,12 +305,13 @@ mail.delivery_method :logger
|
|
|
290
305
|
mail.delivery_method :logger, logger: other_logger, severity: :debug
|
|
291
306
|
```
|
|
292
307
|
|
|
293
|
-
### Getting Emails from a POP Server:
|
|
308
|
+
### Getting Emails from a POP or IMAP Server:
|
|
294
309
|
|
|
295
310
|
You can configure Mail to receive email using <code>retriever_method</code>
|
|
296
311
|
within <code>Mail.defaults</code>:
|
|
297
312
|
|
|
298
313
|
```ruby
|
|
314
|
+
# e.g. POP3
|
|
299
315
|
Mail.defaults do
|
|
300
316
|
retriever_method :pop3, :address => "pop.gmail.com",
|
|
301
317
|
:port => 995,
|
|
@@ -303,6 +319,15 @@ Mail.defaults do
|
|
|
303
319
|
:password => '<password>',
|
|
304
320
|
:enable_ssl => true
|
|
305
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
|
|
306
331
|
```
|
|
307
332
|
|
|
308
333
|
You can access incoming email in a number of ways.
|
|
@@ -392,18 +417,21 @@ simple as possible.... (asking a lot from a mail library)
|
|
|
392
417
|
|
|
393
418
|
```ruby
|
|
394
419
|
mail = Mail.deliver do
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
420
|
+
part :content_type => "multipart/mixed" do |p1|
|
|
421
|
+
p1.part :content_type => "multipart/related" do |p2|
|
|
422
|
+
p2.part :content_type => "multipart/alternative",
|
|
423
|
+
:content_disposition => "inline" do |p3|
|
|
424
|
+
p3.part :content_type => "text/plain; charset=utf-8",
|
|
425
|
+
:body => "Here is the attachment you wanted\n"
|
|
426
|
+
p3.part :content_type => "text/html; charset=utf-8",
|
|
427
|
+
:body => "<h1>Funky Title</h1><p>Here is the attachment you wanted</p>\n"
|
|
428
|
+
end
|
|
429
|
+
end
|
|
430
|
+
add_file '/path/to/myfile.pdf'
|
|
406
431
|
end
|
|
432
|
+
from "Mikel Lindsaar <mikel@test.lindsaar.net.au>"
|
|
433
|
+
to "nicolas@test.lindsaar.net.au"
|
|
434
|
+
subject "First multipart email sent with Mail"
|
|
407
435
|
end
|
|
408
436
|
```
|
|
409
437
|
|
|
@@ -414,38 +442,80 @@ so desire...
|
|
|
414
442
|
```
|
|
415
443
|
puts mail.to_s #=>
|
|
416
444
|
|
|
417
|
-
|
|
445
|
+
Date: Tue, 26 Apr 2022 20:12:07 +0200
|
|
418
446
|
From: Mikel Lindsaar <mikel@test.lindsaar.net.au>
|
|
447
|
+
To: nicolas@test.lindsaar.net.au
|
|
448
|
+
Message-ID: <626835f736e19_10873fdfa3c2ffd4947a3@sender.at.mail>
|
|
419
449
|
Subject: First multipart email sent with Mail
|
|
450
|
+
MIME-Version: 1.0
|
|
451
|
+
Content-Type: multipart/mixed;
|
|
452
|
+
boundary=\"--==_mimepart_626835f733867_10873fdfa3c2ffd494636\";
|
|
453
|
+
charset=UTF-8
|
|
454
|
+
Content-Transfer-Encoding: 7bit
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
----==_mimepart_626835f733867_10873fdfa3c2ffd494636
|
|
458
|
+
Content-Type: multipart/mixed;
|
|
459
|
+
boundary=\"--==_mimepart_626835f73382a_10873fdfa3c2ffd494518\";
|
|
460
|
+
charset=UTF-8
|
|
461
|
+
Content-Transfer-Encoding: 7bit
|
|
462
|
+
|
|
463
|
+
|
|
464
|
+
----==_mimepart_626835f73382a_10873fdfa3c2ffd494518
|
|
465
|
+
Content-Type: multipart/related;
|
|
466
|
+
boundary=\"--==_mimepart_626835f7337f5_10873fdfa3c2ffd494438\";
|
|
467
|
+
charset=UTF-8
|
|
468
|
+
Content-Transfer-Encoding: 7bit
|
|
469
|
+
|
|
470
|
+
|
|
471
|
+
----==_mimepart_626835f7337f5_10873fdfa3c2ffd494438
|
|
420
472
|
Content-Type: multipart/alternative;
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
Date: Mon, 24 Aug 2009 00:15:46 +1000
|
|
424
|
-
Mime-Version: 1.0
|
|
473
|
+
boundary=\"--==_mimepart_626835f733702_10873fdfa3c2ffd494376\";
|
|
474
|
+
charset=UTF-8
|
|
425
475
|
Content-Transfer-Encoding: 7bit
|
|
476
|
+
Content-Disposition: inline
|
|
477
|
+
Content-ID: <626835f738373_10873fdfa3c2ffd49488b@sender.at.mail>
|
|
426
478
|
|
|
427
479
|
|
|
428
|
-
----==
|
|
429
|
-
Content-
|
|
430
|
-
|
|
431
|
-
Mime-Version: 1.0
|
|
432
|
-
Content-Type: text/plain
|
|
480
|
+
----==_mimepart_626835f733702_10873fdfa3c2ffd494376
|
|
481
|
+
Content-Type: text/plain;
|
|
482
|
+
charset=utf-8
|
|
433
483
|
Content-Transfer-Encoding: 7bit
|
|
434
484
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
Content-
|
|
439
|
-
|
|
440
|
-
|
|
485
|
+
Here is the attachment you wanted
|
|
486
|
+
|
|
487
|
+
----==_mimepart_626835f733702_10873fdfa3c2ffd494376
|
|
488
|
+
Content-Type: text/html;
|
|
489
|
+
charset=utf-8
|
|
490
|
+
Content-Transfer-Encoding: 7bit
|
|
491
|
+
|
|
492
|
+
<h1>Funky Title</h1><p>Here is the attachment you wanted</p>
|
|
493
|
+
|
|
494
|
+
----==_mimepart_626835f733702_10873fdfa3c2ffd494376--
|
|
495
|
+
|
|
496
|
+
----==_mimepart_626835f7337f5_10873fdfa3c2ffd494438--
|
|
497
|
+
|
|
498
|
+
----==_mimepart_626835f73382a_10873fdfa3c2ffd494518--
|
|
499
|
+
|
|
500
|
+
----==_mimepart_626835f733867_10873fdfa3c2ffd494636
|
|
501
|
+
Content-Type: text/plain;
|
|
502
|
+
charset=UTF-8;
|
|
503
|
+
filename=myfile.txt
|
|
441
504
|
Content-Transfer-Encoding: 7bit
|
|
505
|
+
Content-Disposition: attachment;
|
|
506
|
+
filename=myfile.txt
|
|
507
|
+
Content-ID: <6
|
|
508
|
+
26835f7386ab_10873fdfa3c2ffd4949b8@sender.at.mail>
|
|
509
|
+
|
|
510
|
+
Hallo,
|
|
511
|
+
Test
|
|
512
|
+
End
|
|
442
513
|
|
|
443
|
-
|
|
444
|
-
----==_mimepart_4a914f0c911be_6f0f1ab8026659--
|
|
514
|
+
----==_mimepart_626835f733867_10873fdfa3c2ffd494636--
|
|
445
515
|
```
|
|
446
516
|
|
|
447
517
|
Mail inserts the content transfer encoding, the mime version,
|
|
448
|
-
the content-
|
|
518
|
+
the content-IDs and handles the content-type and boundary.
|
|
449
519
|
|
|
450
520
|
Mail assumes that if your text in the body is only us-ascii, that your
|
|
451
521
|
transfer encoding is 7bit and it is text/plain. You can override this
|
|
@@ -591,7 +661,7 @@ Mail.defaults do
|
|
|
591
661
|
delivery_method :test # in practice you'd do this in spec_helper.rb
|
|
592
662
|
end
|
|
593
663
|
|
|
594
|
-
describe "sending an email" do
|
|
664
|
+
RSpec.describe "sending an email" do
|
|
595
665
|
include Mail::Matchers
|
|
596
666
|
|
|
597
667
|
before(:each) do
|
|
@@ -639,6 +709,12 @@ describe "sending an email" do
|
|
|
639
709
|
# ... or any attachment
|
|
640
710
|
it { is_expected.to have_sent_email.with_attachments(any_attachment) }
|
|
641
711
|
|
|
712
|
+
# ... or attachment with filename
|
|
713
|
+
it { is_expected.to have_sent_email.with_attachments(an_attachment_with_filename('file.txt')) }
|
|
714
|
+
|
|
715
|
+
# ... or attachment with mime_type
|
|
716
|
+
it { is_expected.to have_sent_email.with_attachments(an_attachment_with_mime_type('application/pdf')) }
|
|
717
|
+
|
|
642
718
|
# ... by array of attachments
|
|
643
719
|
it { is_expected.to have_sent_email.with_attachments([my_attachment1, my_attachment2]) } #note that order is important
|
|
644
720
|
|
|
@@ -7,7 +7,9 @@ module Mail
|
|
|
7
7
|
@content_disposition_type = 'attachment'
|
|
8
8
|
parts_list.map { |p|
|
|
9
9
|
if p.mime_type == 'message/rfc822'
|
|
10
|
-
|
|
10
|
+
parts = []
|
|
11
|
+
parts << p if p.attachment?
|
|
12
|
+
parts.concat Mail.new(p.body.encoded).attachments
|
|
11
13
|
elsif p.parts.empty?
|
|
12
14
|
p if p.attachment?
|
|
13
15
|
else
|
|
@@ -74,7 +76,7 @@ module Mail
|
|
|
74
76
|
end
|
|
75
77
|
|
|
76
78
|
if hash[:body].respond_to? :force_encoding and hash[:body].respond_to? :valid_encoding?
|
|
77
|
-
if not hash[:body].valid_encoding? and default_values[:content_transfer_encoding].
|
|
79
|
+
if not hash[:body].valid_encoding? and default_values[:content_transfer_encoding].casecmp('binary').zero?
|
|
78
80
|
hash[:body] = hash[:body].dup if hash[:body].frozen?
|
|
79
81
|
hash[:body].force_encoding("BINARY")
|
|
80
82
|
end
|
|
@@ -97,10 +99,7 @@ module Mail
|
|
|
97
99
|
end
|
|
98
100
|
|
|
99
101
|
def set_mime_type(filename)
|
|
100
|
-
|
|
101
|
-
if RUBY_VERSION >= '1.9'
|
|
102
|
-
filename = filename.encode(Encoding::UTF_8) if filename.respond_to?(:encode)
|
|
103
|
-
end
|
|
102
|
+
filename = filename.encode(Encoding::UTF_8) if filename.respond_to?(:encode)
|
|
104
103
|
|
|
105
104
|
@mime_type = MiniMime.lookup_by_filename(filename)
|
|
106
105
|
@mime_type && @mime_type.content_type
|
data/lib/mail/body.rb
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
# encoding: utf-8
|
|
2
2
|
# frozen_string_literal: true
|
|
3
3
|
module Mail
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
# = Body
|
|
6
|
-
#
|
|
6
|
+
#
|
|
7
7
|
# The body is where the text of the email is stored. Mail treats the body
|
|
8
8
|
# as a single object. The body itself has no information about boundaries
|
|
9
9
|
# used in the MIME standard, it just looks at its content as either a single
|
|
10
10
|
# block of text, or (if it is a multipart message) as an array of blocks of text.
|
|
11
|
-
#
|
|
11
|
+
#
|
|
12
12
|
# A body has to be told to split itself up into a multipart message by calling
|
|
13
13
|
# #split with the correct boundary. This is because the body object has no way
|
|
14
14
|
# of knowing what the correct boundary is for itself (there could be many
|
|
15
15
|
# boundaries in a body in the case of a nested MIME text).
|
|
16
|
-
#
|
|
16
|
+
#
|
|
17
17
|
# Once split is called, Mail::Body will slice itself up on this boundary,
|
|
18
18
|
# assigning anything that appears before the first part to the preamble, and
|
|
19
19
|
# anything that appears after the closing boundary to the epilogue, then
|
|
20
20
|
# each part gets initialized into a Mail::Part object.
|
|
21
|
-
#
|
|
21
|
+
#
|
|
22
22
|
# The boundary that is used to split up the Body is also stored in the Body
|
|
23
|
-
# object for use on encoding itself back out to a string. You can
|
|
23
|
+
# object for use on encoding itself back out to a string. You can
|
|
24
24
|
# overwrite this if it needs to be changed.
|
|
25
|
-
#
|
|
25
|
+
#
|
|
26
26
|
# On encoding, the body will return the preamble, then each part joined by
|
|
27
27
|
# the boundary, followed by a closing boundary string and then the epilogue.
|
|
28
28
|
class Body
|
|
@@ -39,9 +39,9 @@ module Mail
|
|
|
39
39
|
else
|
|
40
40
|
# Do join first incase we have been given an Array in Ruby 1.9
|
|
41
41
|
if string.respond_to?(:join)
|
|
42
|
-
@raw_source =
|
|
42
|
+
@raw_source = string.join('')
|
|
43
43
|
elsif string.respond_to?(:to_s)
|
|
44
|
-
@raw_source =
|
|
44
|
+
@raw_source = string.to_s
|
|
45
45
|
else
|
|
46
46
|
raise "You can only assign a string or an object that responds_to? :join or :to_s to a body."
|
|
47
47
|
end
|
|
@@ -50,17 +50,22 @@ module Mail
|
|
|
50
50
|
set_charset
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
def init_with(coder)
|
|
54
|
+
coder.map.each { |k, v| instance_variable_set(:"@#{k}", v) }
|
|
55
|
+
@parts = Mail::PartsList.new(coder['parts'])
|
|
56
|
+
end
|
|
57
|
+
|
|
53
58
|
# Matches this body with another body. Also matches the decoded value of this
|
|
54
59
|
# body with a string.
|
|
55
|
-
#
|
|
60
|
+
#
|
|
56
61
|
# Examples:
|
|
57
|
-
#
|
|
62
|
+
#
|
|
58
63
|
# body = Mail::Body.new('The body')
|
|
59
64
|
# body == body #=> true
|
|
60
|
-
#
|
|
65
|
+
#
|
|
61
66
|
# body = Mail::Body.new('The body')
|
|
62
67
|
# body == 'The body' #=> true
|
|
63
|
-
#
|
|
68
|
+
#
|
|
64
69
|
# body = Mail::Body.new("VGhlIGJvZHk=\n")
|
|
65
70
|
# body.encoding = 'base64'
|
|
66
71
|
# body == "The body" #=> true
|
|
@@ -71,28 +76,28 @@ module Mail
|
|
|
71
76
|
super
|
|
72
77
|
end
|
|
73
78
|
end
|
|
74
|
-
|
|
79
|
+
|
|
75
80
|
# Accepts a string and performs a regular expression against the decoded text
|
|
76
|
-
#
|
|
81
|
+
#
|
|
77
82
|
# Examples:
|
|
78
|
-
#
|
|
83
|
+
#
|
|
79
84
|
# body = Mail::Body.new('The body')
|
|
80
85
|
# body =~ /The/ #=> 0
|
|
81
|
-
#
|
|
86
|
+
#
|
|
82
87
|
# body = Mail::Body.new("VGhlIGJvZHk=\n")
|
|
83
88
|
# body.encoding = 'base64'
|
|
84
89
|
# body =~ /The/ #=> 0
|
|
85
90
|
def =~(regexp)
|
|
86
91
|
self.decoded =~ regexp
|
|
87
92
|
end
|
|
88
|
-
|
|
93
|
+
|
|
89
94
|
# Accepts a string and performs a regular expression against the decoded text
|
|
90
|
-
#
|
|
95
|
+
#
|
|
91
96
|
# Examples:
|
|
92
|
-
#
|
|
97
|
+
#
|
|
93
98
|
# body = Mail::Body.new('The body')
|
|
94
99
|
# body.match(/The/) #=> #<MatchData "The">
|
|
95
|
-
#
|
|
100
|
+
#
|
|
96
101
|
# body = Mail::Body.new("VGhlIGJvZHk=\n")
|
|
97
102
|
# body.encoding = 'base64'
|
|
98
103
|
# body.match(/The/) #=> #<MatchData "The">
|
|
@@ -120,7 +125,7 @@ module Mail
|
|
|
120
125
|
def set_sort_order(order)
|
|
121
126
|
@part_sort_order = order
|
|
122
127
|
end
|
|
123
|
-
|
|
128
|
+
|
|
124
129
|
# Allows you to sort the parts according to the default sort order, or the sort order you
|
|
125
130
|
# set with :set_sort_order.
|
|
126
131
|
#
|
|
@@ -132,12 +137,6 @@ module Mail
|
|
|
132
137
|
end
|
|
133
138
|
@parts.sort!(@part_sort_order)
|
|
134
139
|
end
|
|
135
|
-
|
|
136
|
-
# Returns the raw source that the body was initialized with, without
|
|
137
|
-
# any tampering
|
|
138
|
-
def raw_source
|
|
139
|
-
@raw_source
|
|
140
|
-
end
|
|
141
140
|
|
|
142
141
|
def negotiate_best_encoding(message_encoding, allowed_encodings = nil)
|
|
143
142
|
Mail::Encodings::TransferEncoding.negotiate(message_encoding, encoding, raw_source, allowed_encodings)
|
|
@@ -165,7 +164,7 @@ module Mail
|
|
|
165
164
|
# Cannot decode, so skip normalization
|
|
166
165
|
raw_source
|
|
167
166
|
else
|
|
168
|
-
# Decode then encode to normalize and allow transforming
|
|
167
|
+
# Decode then encode to normalize and allow transforming
|
|
169
168
|
# from base64 to Q-P and vice versa
|
|
170
169
|
decoded = dec.decode(raw_source)
|
|
171
170
|
if defined?(Encoding) && charset && charset != "US-ASCII"
|
|
@@ -184,18 +183,10 @@ module Mail
|
|
|
184
183
|
Encodings.get_encoding(encoding).decode(raw_source)
|
|
185
184
|
end
|
|
186
185
|
end
|
|
187
|
-
|
|
186
|
+
|
|
188
187
|
def to_s
|
|
189
188
|
decoded
|
|
190
189
|
end
|
|
191
|
-
|
|
192
|
-
def charset
|
|
193
|
-
@charset
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def charset=( val )
|
|
197
|
-
@charset = val
|
|
198
|
-
end
|
|
199
190
|
|
|
200
191
|
def encoding(val = nil)
|
|
201
192
|
if val
|
|
@@ -214,45 +205,31 @@ module Mail
|
|
|
214
205
|
end
|
|
215
206
|
end
|
|
216
207
|
|
|
217
|
-
# Returns the
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
208
|
+
# Returns the raw source that the body was initialized with, without
|
|
209
|
+
# any tampering
|
|
210
|
+
attr_reader :raw_source
|
|
211
|
+
|
|
212
|
+
# Returns parts of the body
|
|
213
|
+
attr_reader :parts
|
|
214
|
+
|
|
215
|
+
# Returns and sets the original character encoding
|
|
216
|
+
attr_accessor :charset
|
|
217
|
+
|
|
218
|
+
# Returns and sets the preamble as a string (any text that is before the first MIME boundary)
|
|
219
|
+
attr_accessor :preamble
|
|
220
|
+
|
|
221
|
+
# Returns and sets the epilogue as a string (any text that is after the last MIME boundary)
|
|
222
|
+
attr_accessor :epilogue
|
|
223
|
+
|
|
224
|
+
# Returns and sets the boundary used by the body
|
|
225
|
+
# Allows you to change the boundary of this Body object
|
|
226
|
+
attr_accessor :boundary
|
|
221
227
|
|
|
222
|
-
# Sets the preamble to a string (adds text before the first MIME boundary)
|
|
223
|
-
def preamble=( val )
|
|
224
|
-
@preamble = val
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
# Returns the epilogue (any text that is after the last MIME boundary)
|
|
228
|
-
def epilogue
|
|
229
|
-
@epilogue
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
# Sets the epilogue to a string (adds text after the last MIME boundary)
|
|
233
|
-
def epilogue=( val )
|
|
234
|
-
@epilogue = val
|
|
235
|
-
end
|
|
236
|
-
|
|
237
228
|
# Returns true if there are parts defined in the body
|
|
238
229
|
def multipart?
|
|
239
230
|
true unless parts.empty?
|
|
240
231
|
end
|
|
241
|
-
|
|
242
|
-
# Returns the boundary used by the body
|
|
243
|
-
def boundary
|
|
244
|
-
@boundary
|
|
245
|
-
end
|
|
246
|
-
|
|
247
|
-
# Allows you to change the boundary of this Body object
|
|
248
|
-
def boundary=( val )
|
|
249
|
-
@boundary = val
|
|
250
|
-
end
|
|
251
232
|
|
|
252
|
-
def parts
|
|
253
|
-
@parts
|
|
254
|
-
end
|
|
255
|
-
|
|
256
233
|
def <<( val )
|
|
257
234
|
if @parts
|
|
258
235
|
@parts << val
|
|
@@ -295,7 +272,7 @@ module Mail
|
|
|
295
272
|
parts_regex = /
|
|
296
273
|
(?: # non-capturing group
|
|
297
274
|
\A | # start of string OR
|
|
298
|
-
\r
|
|
275
|
+
\r?\n # line break with optional CR
|
|
299
276
|
)
|
|
300
277
|
(
|
|
301
278
|
--#{Regexp.escape(boundary || "")} # boundary delimiter
|
|
@@ -312,11 +289,11 @@ module Mail
|
|
|
312
289
|
end
|
|
313
290
|
parts.map(&:first)
|
|
314
291
|
end
|
|
315
|
-
|
|
292
|
+
|
|
316
293
|
def crlf_boundary
|
|
317
294
|
"\r\n--#{boundary}\r\n"
|
|
318
295
|
end
|
|
319
|
-
|
|
296
|
+
|
|
320
297
|
def end_boundary
|
|
321
298
|
"\r\n--#{boundary}--\r\n"
|
|
322
299
|
end
|
data/lib/mail/constants.rb
CHANGED
|
@@ -16,9 +16,10 @@ module Mail
|
|
|
16
16
|
control = control.dup.force_encoding(Encoding::BINARY)
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
LAX_CRLF = /\r?\n/
|
|
20
20
|
WSP = /[#{white_space}]/
|
|
21
|
-
FWS = /#{
|
|
21
|
+
FWS = /#{LAX_CRLF}#{WSP}*/
|
|
22
|
+
UNFOLD_WS = /#{LAX_CRLF}(#{WSP})/m
|
|
22
23
|
TEXT = /[#{text}]/ # + obs-text
|
|
23
24
|
FIELD_NAME = /[#{field_name}]+/
|
|
24
25
|
FIELD_PREFIX = /\A(#{FIELD_NAME})/
|
|
@@ -26,7 +27,7 @@ module Mail
|
|
|
26
27
|
FIELD_LINE = /^[#{field_name}]+:\s*.+$/
|
|
27
28
|
FIELD_SPLIT = /^(#{FIELD_NAME})\s*:\s*(#{FIELD_BODY})?$/
|
|
28
29
|
HEADER_LINE = /^([#{field_name}]+:\s*.+)$/
|
|
29
|
-
HEADER_SPLIT = /#{
|
|
30
|
+
HEADER_SPLIT = /#{LAX_CRLF}(?!#{WSP})/
|
|
30
31
|
|
|
31
32
|
QP_UNSAFE = /[^#{qp_safe}]/
|
|
32
33
|
QP_SAFE = /[#{qp_safe}]/
|
|
@@ -34,8 +35,28 @@ module Mail
|
|
|
34
35
|
ATOM_UNSAFE = /[#{Regexp.quote aspecial}#{control}#{sp}]/n
|
|
35
36
|
PHRASE_UNSAFE = /[#{Regexp.quote aspecial}#{control}]/n
|
|
36
37
|
TOKEN_UNSAFE = /[#{Regexp.quote tspecial}#{control}#{sp}]/n
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
ENCODED_VALUE = %r{
|
|
40
|
+
\=\? # literal =?
|
|
41
|
+
([^?]+) #
|
|
42
|
+
\? # literal ?
|
|
43
|
+
([QB]) # either a "Q" or a "B"
|
|
44
|
+
\? # literal ?
|
|
45
|
+
.*? # lazily match all characters
|
|
46
|
+
\?\= # literal ?=
|
|
47
|
+
}mix # m is multi-line, i is case-insensitive, x is free-spacing
|
|
48
|
+
|
|
49
|
+
FULL_ENCODED_VALUE = %r{ # Identical to ENCODED_VALUE but captures the whole rather than components of
|
|
50
|
+
(
|
|
51
|
+
\=\? # literal =?
|
|
52
|
+
[^?]+ #
|
|
53
|
+
\? # literal ?
|
|
54
|
+
[QB] # either a "Q" or a "B"
|
|
55
|
+
\? # literal ?
|
|
56
|
+
.*? # lazily match all characters
|
|
57
|
+
\?\= # literal ?=
|
|
58
|
+
)
|
|
59
|
+
}mix # m is multi-line, i is case-insensitive, x is free-spacing
|
|
39
60
|
|
|
40
61
|
EMPTY = ''
|
|
41
62
|
SPACE = ' '
|
|
@@ -43,6 +64,7 @@ module Mail
|
|
|
43
64
|
HYPHEN = '-'
|
|
44
65
|
COLON = ':'
|
|
45
66
|
ASTERISK = '*'
|
|
67
|
+
CRLF = "\r\n"
|
|
46
68
|
CR = "\r"
|
|
47
69
|
LF = "\n"
|
|
48
70
|
CR_ENCODED = "=0D"
|