mail 2.5.5 → 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 +170 -108
- data/lib/mail/attachments_list.rb +13 -10
- data/lib/mail/body.rb +105 -91
- data/lib/mail/check_delivery_params.rb +30 -22
- data/lib/mail/configuration.rb +3 -0
- data/lib/mail/constants.rb +79 -0
- data/lib/mail/elements/address.rb +118 -174
- data/lib/mail/elements/address_list.rb +16 -56
- data/lib/mail/elements/content_disposition_element.rb +12 -22
- data/lib/mail/elements/content_location_element.rb +9 -17
- data/lib/mail/elements/content_transfer_encoding_element.rb +8 -19
- data/lib/mail/elements/content_type_element.rb +20 -30
- data/lib/mail/elements/date_time_element.rb +10 -21
- data/lib/mail/elements/envelope_from_element.rb +23 -31
- data/lib/mail/elements/message_ids_element.rb +22 -20
- data/lib/mail/elements/mime_version_element.rb +10 -21
- data/lib/mail/elements/phrase_list.rb +13 -15
- data/lib/mail/elements/received_element.rb +26 -21
- data/lib/mail/elements.rb +1 -0
- data/lib/mail/encodings/7bit.rb +10 -14
- data/lib/mail/encodings/8bit.rb +5 -18
- data/lib/mail/encodings/base64.rb +15 -10
- data/lib/mail/encodings/binary.rb +4 -22
- data/lib/mail/encodings/identity.rb +24 -0
- data/lib/mail/encodings/quoted_printable.rb +13 -7
- data/lib/mail/encodings/transfer_encoding.rb +47 -28
- data/lib/mail/encodings/unix_to_unix.rb +20 -0
- data/lib/mail/encodings.rb +102 -93
- data/lib/mail/envelope.rb +12 -19
- data/lib/mail/field.rb +143 -71
- data/lib/mail/field_list.rb +73 -19
- data/lib/mail/fields/bcc_field.rb +42 -48
- data/lib/mail/fields/cc_field.rb +29 -50
- data/lib/mail/fields/comments_field.rb +28 -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 +8 -14
- data/lib/mail/fields/content_disposition_field.rb +20 -44
- data/lib/mail/fields/content_id_field.rb +25 -51
- data/lib/mail/fields/content_location_field.rb +12 -25
- data/lib/mail/fields/content_transfer_encoding_field.rb +31 -36
- data/lib/mail/fields/content_type_field.rb +51 -80
- data/lib/mail/fields/date_field.rb +24 -52
- data/lib/mail/fields/from_field.rb +29 -50
- data/lib/mail/fields/in_reply_to_field.rb +39 -49
- data/lib/mail/fields/keywords_field.rb +19 -32
- data/lib/mail/fields/message_id_field.rb +26 -71
- data/lib/mail/fields/mime_version_field.rb +20 -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 +10 -7
- data/lib/mail/fields/{common/parameter_hash.rb → parameter_hash.rb} +16 -13
- data/lib/mail/fields/received_field.rb +44 -57
- data/lib/mail/fields/references_field.rb +36 -49
- data/lib/mail/fields/reply_to_field.rb +29 -50
- data/lib/mail/fields/resent_bcc_field.rb +29 -50
- data/lib/mail/fields/resent_cc_field.rb +29 -50
- data/lib/mail/fields/resent_date_field.rb +6 -30
- data/lib/mail/fields/resent_from_field.rb +29 -50
- data/lib/mail/fields/resent_message_id_field.rb +6 -29
- data/lib/mail/fields/resent_sender_field.rb +28 -57
- data/lib/mail/fields/resent_to_field.rb +29 -50
- data/lib/mail/fields/return_path_field.rb +51 -55
- data/lib/mail/fields/sender_field.rb +35 -56
- data/lib/mail/fields/structured_field.rb +4 -30
- data/lib/mail/fields/subject_field.rb +10 -11
- data/lib/mail/fields/to_field.rb +29 -50
- data/lib/mail/fields/unstructured_field.rb +43 -51
- data/lib/mail/fields.rb +1 -0
- data/lib/mail/header.rb +78 -129
- data/lib/mail/indifferent_hash.rb +1 -0
- data/lib/mail/mail.rb +18 -11
- data/lib/mail/matchers/attachment_matchers.rb +44 -0
- data/lib/mail/matchers/has_sent_mail.rb +81 -4
- data/lib/mail/message.rb +142 -139
- data/lib/mail/multibyte/chars.rb +24 -180
- data/lib/mail/multibyte/unicode.rb +32 -27
- data/lib/mail/multibyte/utils.rb +27 -43
- data/lib/mail/multibyte.rb +56 -16
- data/lib/mail/network/delivery_methods/exim.rb +6 -4
- data/lib/mail/network/delivery_methods/file_delivery.rb +12 -10
- data/lib/mail/network/delivery_methods/logger_delivery.rb +34 -0
- data/lib/mail/network/delivery_methods/sendmail.rb +63 -21
- data/lib/mail/network/delivery_methods/smtp.rb +76 -50
- data/lib/mail/network/delivery_methods/smtp_connection.rb +4 -4
- data/lib/mail/network/delivery_methods/test_mailer.rb +5 -2
- data/lib/mail/network/retriever_methods/base.rb +9 -8
- data/lib/mail/network/retriever_methods/imap.rb +37 -18
- data/lib/mail/network/retriever_methods/pop3.rb +6 -3
- data/lib/mail/network/retriever_methods/test_retriever.rb +4 -2
- data/lib/mail/network.rb +2 -0
- data/lib/mail/parser_tools.rb +15 -0
- data/lib/mail/parsers/address_lists_parser.rb +33242 -0
- data/lib/mail/parsers/address_lists_parser.rl +179 -0
- data/lib/mail/parsers/content_disposition_parser.rb +901 -0
- data/lib/mail/parsers/content_disposition_parser.rl +89 -0
- data/lib/mail/parsers/content_location_parser.rb +822 -0
- data/lib/mail/parsers/content_location_parser.rl +78 -0
- data/lib/mail/parsers/content_transfer_encoding_parser.rb +522 -0
- data/lib/mail/parsers/content_transfer_encoding_parser.rl +71 -0
- data/lib/mail/parsers/content_type_parser.rb +1048 -0
- data/lib/mail/parsers/content_type_parser.rl +90 -0
- data/lib/mail/parsers/date_time_parser.rb +891 -0
- data/lib/mail/parsers/date_time_parser.rl +69 -0
- data/lib/mail/parsers/envelope_from_parser.rb +3675 -0
- data/lib/mail/parsers/envelope_from_parser.rl +89 -0
- data/lib/mail/parsers/message_ids_parser.rb +5161 -0
- data/lib/mail/parsers/message_ids_parser.rl +93 -0
- data/lib/mail/parsers/mime_version_parser.rb +513 -0
- data/lib/mail/parsers/mime_version_parser.rl +68 -0
- data/lib/mail/parsers/phrase_lists_parser.rb +884 -0
- data/lib/mail/parsers/phrase_lists_parser.rl +90 -0
- data/lib/mail/parsers/received_parser.rb +8782 -0
- 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/rfc5322_date_time.rl +37 -0
- data/lib/mail/parsers/rfc5322_lexical_tokens.rl +60 -0
- data/lib/mail/parsers.rb +13 -0
- data/lib/mail/part.rb +11 -12
- data/lib/mail/parts_list.rb +90 -14
- data/lib/mail/smtp_envelope.rb +57 -0
- data/lib/mail/utilities.rb +415 -76
- data/lib/mail/values/unicode_tables.dat +0 -0
- data/lib/mail/version.rb +8 -15
- data/lib/mail/yaml.rb +30 -0
- data/lib/mail.rb +9 -32
- metadata +127 -79
- data/CHANGELOG.rdoc +0 -742
- data/CONTRIBUTING.md +0 -45
- data/Dependencies.txt +0 -3
- data/Gemfile +0 -32
- data/Rakefile +0 -21
- data/TODO.rdoc +0 -9
- data/lib/VERSION +0 -4
- data/lib/load_parsers.rb +0 -35
- data/lib/mail/core_extensions/nil.rb +0 -19
- data/lib/mail/core_extensions/object.rb +0 -13
- data/lib/mail/core_extensions/smtp.rb +0 -24
- data/lib/mail/core_extensions/string/access.rb +0 -145
- data/lib/mail/core_extensions/string/multibyte.rb +0 -78
- data/lib/mail/core_extensions/string.rb +0 -33
- data/lib/mail/fields/common/address_container.rb +0 -16
- data/lib/mail/fields/common/common_address.rb +0 -140
- data/lib/mail/fields/common/common_date.rb +0 -42
- data/lib/mail/fields/common/common_field.rb +0 -57
- data/lib/mail/fields/common/common_message_id.rb +0 -48
- data/lib/mail/multibyte/exceptions.rb +0 -8
- data/lib/mail/parsers/address_lists.rb +0 -64
- data/lib/mail/parsers/address_lists.treetop +0 -19
- data/lib/mail/parsers/content_disposition.rb +0 -535
- data/lib/mail/parsers/content_disposition.treetop +0 -46
- data/lib/mail/parsers/content_location.rb +0 -139
- data/lib/mail/parsers/content_location.treetop +0 -20
- data/lib/mail/parsers/content_transfer_encoding.rb +0 -201
- data/lib/mail/parsers/content_transfer_encoding.treetop +0 -18
- data/lib/mail/parsers/content_type.rb +0 -971
- data/lib/mail/parsers/content_type.treetop +0 -68
- data/lib/mail/parsers/date_time.rb +0 -114
- data/lib/mail/parsers/date_time.treetop +0 -11
- data/lib/mail/parsers/envelope_from.rb +0 -194
- data/lib/mail/parsers/envelope_from.treetop +0 -32
- data/lib/mail/parsers/message_ids.rb +0 -45
- data/lib/mail/parsers/message_ids.treetop +0 -15
- data/lib/mail/parsers/mime_version.rb +0 -144
- data/lib/mail/parsers/mime_version.treetop +0 -19
- data/lib/mail/parsers/phrase_lists.rb +0 -45
- data/lib/mail/parsers/phrase_lists.treetop +0 -15
- data/lib/mail/parsers/received.rb +0 -71
- data/lib/mail/parsers/received.treetop +0 -11
- data/lib/mail/parsers/rfc2045.rb +0 -421
- data/lib/mail/parsers/rfc2045.treetop +0 -35
- data/lib/mail/parsers/rfc2822.rb +0 -5397
- data/lib/mail/parsers/rfc2822.treetop +0 -408
- data/lib/mail/parsers/rfc2822_obsolete.rb +0 -3768
- data/lib/mail/parsers/rfc2822_obsolete.treetop +0 -241
- data/lib/mail/patterns.rb +0 -35
- data/lib/mail/version_specific/ruby_1_8.rb +0 -119
- data/lib/mail/version_specific/ruby_1_9.rb +0 -147
- data/lib/tasks/corpus.rake +0 -125
- data/lib/tasks/treetop.rake +0 -10
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'mail/utilities'
|
3
|
+
require 'mail/parser_tools'
|
4
|
+
|
5
|
+
begin
|
6
|
+
original_verbose, $VERBOSE = $VERBOSE, nil
|
7
|
+
|
8
|
+
%%{
|
9
|
+
machine date_time;
|
10
|
+
alphtype int;
|
11
|
+
|
12
|
+
# Received Tokens
|
13
|
+
action received_tokens_s { received_tokens_s = p }
|
14
|
+
action received_tokens_e { received.info = chars(data, received_tokens_s, p-1) }
|
15
|
+
|
16
|
+
# Date
|
17
|
+
action date_s { date_s = p }
|
18
|
+
action date_e { received.date = chars(data, date_s, p-1).strip }
|
19
|
+
|
20
|
+
# Time
|
21
|
+
action time_s { time_s = p }
|
22
|
+
action time_e { received.time = chars(data, time_s, p-1) }
|
23
|
+
|
24
|
+
# No-op actions
|
25
|
+
action address_s {}
|
26
|
+
action address_e {}
|
27
|
+
action angle_addr_s {}
|
28
|
+
action ctime_date_s {}
|
29
|
+
action ctime_date_e {}
|
30
|
+
action comment_e {}
|
31
|
+
action comment_s {}
|
32
|
+
action phrase_s {}
|
33
|
+
action phrase_e {}
|
34
|
+
action domain_e {}
|
35
|
+
action domain_s {}
|
36
|
+
action local_dot_atom_e {}
|
37
|
+
action local_dot_atom_pre_comment_e {}
|
38
|
+
action local_dot_atom_pre_comment_s {}
|
39
|
+
action local_dot_atom_s {}
|
40
|
+
action qstr_e {}
|
41
|
+
action qstr_s {}
|
42
|
+
action local_quoted_string_s {}
|
43
|
+
action local_quoted_string_e {}
|
44
|
+
action obs_domain_list_s {}
|
45
|
+
action obs_domain_list_e {}
|
46
|
+
action group_name_s {}
|
47
|
+
action group_name_e {}
|
48
|
+
action msg_id_s {}
|
49
|
+
action msg_id_e {}
|
50
|
+
|
51
|
+
include rfc5322 "rfc5322.rl";
|
52
|
+
main := received;
|
53
|
+
}%%
|
54
|
+
|
55
|
+
module Mail::Parsers
|
56
|
+
module ReceivedParser
|
57
|
+
extend Mail::ParserTools
|
58
|
+
|
59
|
+
ReceivedStruct = Struct.new(:date, :time, :info, :error)
|
60
|
+
|
61
|
+
%%write data noprefix;
|
62
|
+
|
63
|
+
def self.parse(data)
|
64
|
+
data = data.dup.force_encoding(Encoding::ASCII_8BIT) if data.respond_to?(:force_encoding)
|
65
|
+
|
66
|
+
raise Mail::Field::NilParseError.new(Mail::ReceivedElement) if data.nil?
|
67
|
+
|
68
|
+
# Parser state
|
69
|
+
received = ReceivedStruct.new
|
70
|
+
received_tokens_s = date_s = time_s = nil
|
71
|
+
|
72
|
+
# 5.1 Variables Used by Ragel
|
73
|
+
p = 0
|
74
|
+
eof = pe = data.length
|
75
|
+
stack = []
|
76
|
+
|
77
|
+
%%write init;
|
78
|
+
%%write exec;
|
79
|
+
|
80
|
+
if p != eof || cs < %%{ write first_final; }%%
|
81
|
+
raise Mail::Field::IncompleteParseError.new(Mail::ReceivedElement, data, p)
|
82
|
+
end
|
83
|
+
|
84
|
+
received
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
ensure
|
90
|
+
$VERBOSE = original_verbose
|
91
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
%%{
|
2
|
+
# RFC 2045 Section 6.1: Content-Transfer-Encoding Header Field
|
3
|
+
# https://tools.ietf.org/html/rfc2045#section-6.1
|
4
|
+
machine rfc2045_content_transfer_encoding;
|
5
|
+
alphtype int;
|
6
|
+
|
7
|
+
include rfc2045_content_type "rfc2045_content_type.rl";
|
8
|
+
|
9
|
+
encoding = ('7bits' | '8bits' | '7bit' | '8bit' | 'binary' |
|
10
|
+
'quoted-printable' | 'base64' | ietf_token |
|
11
|
+
custom_x_token) >encoding_s %encoding_e;
|
12
|
+
content_transfer_encoding = CFWS? encoding CFWS? ";"? CFWS?;
|
13
|
+
}%%
|
@@ -0,0 +1,25 @@
|
|
1
|
+
%%{
|
2
|
+
# RFC 2045 Section 5.1: Content-Type Header Field
|
3
|
+
# https://tools.ietf.org/html/rfc2045#section-5.1
|
4
|
+
# Previously: https://tools.ietf.org/html/rfc1049#section-3
|
5
|
+
machine rfc2045_content_type;
|
6
|
+
alphtype int;
|
7
|
+
|
8
|
+
include rfc5322_lexical_tokens "rfc5322_lexical_tokens.rl";
|
9
|
+
|
10
|
+
token = 0x21..0x27 | 0x2a..0x2b | 0x2c..0x2e | 0x30..0x39 | 0x41..0x5a | 0x5e..0x7e;
|
11
|
+
value = (quoted_string | (token -- '"' | 0x3d)+) >param_val_s %param_val_e;
|
12
|
+
attribute = (token+) >param_attr_s %param_attr_e;
|
13
|
+
parameter = CFWS? attribute "=" value CFWS?;
|
14
|
+
|
15
|
+
ietf_token = token+;
|
16
|
+
custom_x_token = 'x'i "-" token+;
|
17
|
+
extension_token = ietf_token | custom_x_token;
|
18
|
+
discrete_type = 'text'i | 'image'i | 'audio'i | 'video'i |
|
19
|
+
'application'i | extension_token;
|
20
|
+
composite_type = 'message'i | 'multipart'i | extension_token;
|
21
|
+
iana_token = token+;
|
22
|
+
main_type = (discrete_type | composite_type) >main_type_s %main_type_e;
|
23
|
+
sub_type = (extension_token | iana_token) >sub_type_s %sub_type_e;
|
24
|
+
content_type = main_type "/" sub_type (((CFWS? ";"+) | CFWS) parameter CFWS?)*;
|
25
|
+
}%%
|
@@ -0,0 +1,16 @@
|
|
1
|
+
%%{
|
2
|
+
# RFC 2045 MIME
|
3
|
+
# https://tools.ietf.org/html/rfc2045
|
4
|
+
machine rfc2045_mime;
|
5
|
+
alphtype int;
|
6
|
+
|
7
|
+
include rfc5322_lexical_tokens "rfc5322_lexical_tokens.rl";
|
8
|
+
|
9
|
+
# 4. MIME-Version Header Field
|
10
|
+
# https://tools.ietf.org/html/rfc2045#section-4
|
11
|
+
mime_version = CFWS?
|
12
|
+
(DIGIT+ >major_digits_s %major_digits_e)
|
13
|
+
comment? "." comment?
|
14
|
+
(DIGIT+ >minor_digits_s %minor_digits_e)
|
15
|
+
CFWS?;
|
16
|
+
}%%
|
@@ -0,0 +1,15 @@
|
|
1
|
+
%%{
|
2
|
+
# RFC 2183 The Content-Disposition Header Field
|
3
|
+
# https://tools.ietf.org/html/rfc2183#section-2
|
4
|
+
#
|
5
|
+
# TODO: recognize filename, size, creation date, etc.
|
6
|
+
machine rfc2183_content_disposition;
|
7
|
+
alphtype int;
|
8
|
+
|
9
|
+
include rfc2045_content_type "rfc2045_content_type.rl";
|
10
|
+
|
11
|
+
disposition_type = 'inline'i | 'attachment'i | extension_token;
|
12
|
+
disposition_parm = parameter;
|
13
|
+
disposition = (disposition_type >disp_type_s %disp_type_e)
|
14
|
+
(";" disposition_parm)*;
|
15
|
+
}%%
|
@@ -0,0 +1,19 @@
|
|
1
|
+
%%{
|
2
|
+
# RFC 3629 4. Syntax of UTF-8 Byte Sequences
|
3
|
+
# https://tools.ietf.org/html/rfc3629#section-4
|
4
|
+
machine rfc3629_utf8;
|
5
|
+
alphtype int;
|
6
|
+
|
7
|
+
utf8_tail = 0x80..0xBF;
|
8
|
+
|
9
|
+
utf8_2byte = 0xC2..0xDF utf8_tail;
|
10
|
+
utf8_3byte = 0xE0 0xA0..0xBF utf8_tail |
|
11
|
+
0xE1..0xEC utf8_tail utf8_tail |
|
12
|
+
0xED 0x80..0x9F utf8_tail |
|
13
|
+
0xEE..0xEF utf8_tail utf8_tail;
|
14
|
+
utf8_4byte = 0xF0 0x90..0xBF utf8_tail utf8_tail |
|
15
|
+
0xF1..0xF3 utf8_tail utf8_tail utf8_tail |
|
16
|
+
0xF4 0x80..0x8F utf8_tail utf8_tail;
|
17
|
+
|
18
|
+
utf8_non_ascii = utf8_2byte | utf8_3byte | utf8_4byte;
|
19
|
+
}%%
|
@@ -0,0 +1,22 @@
|
|
1
|
+
%%{
|
2
|
+
# RFC 5234 B.1. Core Rules
|
3
|
+
# https://tools.ietf.org/html/rfc5234#appendix-B.1
|
4
|
+
machine rfc5234_abnf_core_rules;
|
5
|
+
alphtype int;
|
6
|
+
|
7
|
+
include rfc3629_utf8 "rfc3629_utf8.rl";
|
8
|
+
|
9
|
+
LF = "\n";
|
10
|
+
CR = "\r";
|
11
|
+
CRLF = "\r\n";
|
12
|
+
SP = " ";
|
13
|
+
HTAB = "\t";
|
14
|
+
WSP = SP | HTAB;
|
15
|
+
DQUOTE = '"';
|
16
|
+
DIGIT = [0-9];
|
17
|
+
ALPHA = [a-zA-Z];
|
18
|
+
|
19
|
+
# RFC6532 extension for UTF-8 content
|
20
|
+
rfc5234_VCHAR = 0x21..0x7e;
|
21
|
+
VCHAR = rfc5234_VCHAR | utf8_non_ascii;
|
22
|
+
}%%
|
@@ -0,0 +1,74 @@
|
|
1
|
+
%%{
|
2
|
+
# RFC 5322 Internet Message Format
|
3
|
+
# https://tools.ietf.org/html/rfc5322
|
4
|
+
#
|
5
|
+
# RFC 6854 Update to Internet Message Format to Allow Group Syntax in the "From:" and "Sender:" Header Fields
|
6
|
+
# https://tools.ietf.org/html/rfc6854
|
7
|
+
machine rfc5322;
|
8
|
+
alphtype int;
|
9
|
+
|
10
|
+
include rfc5234_abnf_core_rules "rfc5234_abnf_core_rules.rl";
|
11
|
+
|
12
|
+
# 3.2. Lexical Tokens
|
13
|
+
include rfc5322_lexical_tokens "rfc5322_lexical_tokens.rl";
|
14
|
+
|
15
|
+
# 3.3. Date and Time Specification
|
16
|
+
include rfc5322_date_time "rfc5322_date_time.rl";
|
17
|
+
|
18
|
+
# 3.4. Address Specification
|
19
|
+
include rfc5322_address "rfc5322_address.rl";
|
20
|
+
|
21
|
+
# 3.5. Overall Message Syntax
|
22
|
+
#rfc5322_text = 0x01..0x09 | "\v" | "\f" | 0x0e..0x1f;
|
23
|
+
#text = rfc5322_text | utf8_non_ascii; # RFC6532 for UTF-8
|
24
|
+
#obs_body = ((LF* CR* ((0x00 | text) LF* CR*)*) | CRLF)*
|
25
|
+
#body = ((text{,998} CRLF)* text{,998}) | obs_body;
|
26
|
+
#message = (fields | obs_fields) (CRLF body)?;
|
27
|
+
|
28
|
+
|
29
|
+
# 3.6. Field Definitions
|
30
|
+
|
31
|
+
# 3.6.4. Identification Fields
|
32
|
+
obs_id_left = local_part;
|
33
|
+
obs_id_right = domain;
|
34
|
+
no_fold_literal = "[" (dtext)* "]";
|
35
|
+
|
36
|
+
msg_id_atext = rfc5322_atext | ":" | "," | "." | " ";
|
37
|
+
|
38
|
+
id_left = msg_id_atext+ | obs_id_left;
|
39
|
+
id_left_ns = ( msg_id_atext - ( " " | "," ) )+;
|
40
|
+
|
41
|
+
# id_right modifications to support multiple '@' in msg_id.
|
42
|
+
id_right = ( msg_id_atext | "@" )+ | no_fold_literal | obs_id_right;
|
43
|
+
id_right_ns = ( msg_id_atext - ( " " | "," ) | "@" )+ | no_fold_literal;
|
44
|
+
|
45
|
+
# Handle various message-id formats:
|
46
|
+
# <id_left@id_right>
|
47
|
+
# <id_left@id_right...
|
48
|
+
# <id_left@>
|
49
|
+
# <id_left>
|
50
|
+
# <id_left...
|
51
|
+
# id_left@id_right
|
52
|
+
# id_left
|
53
|
+
# Handle comma-separated message_ids.
|
54
|
+
msg_id = (CFWS)? (
|
55
|
+
(("<" id_left "@" id_right? ">") >msg_id_s %msg_id_e) |
|
56
|
+
(("<" id_left "@" id_right? :>> "...") >msg_id_s %msg_id_e) |
|
57
|
+
(("<" id_left ">") >msg_id_s %msg_id_e) |
|
58
|
+
(("<" id_left :>> "..." ) >msg_id_s %msg_id_e) |
|
59
|
+
((id_left_ns ("@" id_right_ns)? ) >msg_id_s %msg_id_e)
|
60
|
+
) (CFWS)? <: ","?;
|
61
|
+
message_ids = msg_id**;
|
62
|
+
|
63
|
+
|
64
|
+
# 3.6.7 Trace Fields
|
65
|
+
# Added CFWS? to increase robustness (qmail likes to include a comment)
|
66
|
+
received_token = word | angle_addr | addr_spec_no_angle_brackets | domain;
|
67
|
+
received = ((CFWS? received_token*) >received_tokens_s %received_tokens_e)
|
68
|
+
";" date_time;
|
69
|
+
|
70
|
+
# Envelope From
|
71
|
+
ctime_date = day_name " "+ month " "+ day " " time_of_day " " year;
|
72
|
+
null_sender = ('<>' ' '{0,1});
|
73
|
+
envelope_from = (addr_spec_no_angle_brackets | null_sender) >address_s %address_e (" " (ctime_date >ctime_date_s %ctime_date_e))?;
|
74
|
+
}%%
|
@@ -0,0 +1,72 @@
|
|
1
|
+
%%{
|
2
|
+
# RFC 5322 Internet Message Format
|
3
|
+
# Section 3.4. Address Specification
|
4
|
+
# https://tools.ietf.org/html/rfc5322#section-3.4
|
5
|
+
machine rfc5322_address;
|
6
|
+
alphtype int;
|
7
|
+
|
8
|
+
include rfc5234_abnf_core_rules "rfc5234_abnf_core_rules.rl";
|
9
|
+
include rfc5322_lexical_tokens "rfc5322_lexical_tokens.rl";
|
10
|
+
|
11
|
+
# local_part:
|
12
|
+
domain_text = (DQUOTE (FWS? qcontent)+ FWS? DQUOTE) | atext+;
|
13
|
+
local_dot_atom_text = ("."* domain_text "."*)+;
|
14
|
+
local_dot_atom = CFWS?
|
15
|
+
(local_dot_atom_text >local_dot_atom_s %local_dot_atom_pre_comment_e)
|
16
|
+
CFWS?;
|
17
|
+
obs_local_part = word ("." word)*;
|
18
|
+
local_part = (local_dot_atom >local_dot_atom_s %local_dot_atom_e |
|
19
|
+
(quoted_string %local_quoted_string_e) |
|
20
|
+
obs_local_part);
|
21
|
+
|
22
|
+
# Treetop parser behavior was to ignore addresses missing '@' inside of angle
|
23
|
+
# brackets. This construction preserves that behavior.
|
24
|
+
local_part_no_capture = (local_dot_atom | quoted_string | obs_local_part);
|
25
|
+
|
26
|
+
# domain:
|
27
|
+
domain_dot_atom_text = "."* domain_text ("."* domain_text)*;
|
28
|
+
obs_dtext = obs_NO_WS_CTL | quoted_pair;
|
29
|
+
rfc5322_dtext = 0x21..0x5a | 0x5e..0x7e | obs_dtext;
|
30
|
+
dtext = rfc5322_dtext | utf8_non_ascii; # RFC6532 for UTF-8
|
31
|
+
domain_dot_atom = CFWS? domain_dot_atom_text (CFWS? >(comment_after_address,1));
|
32
|
+
domain_literal = CFWS? "[" (FWS? dtext)* FWS? "]" CFWS?;
|
33
|
+
obs_domain = atom ("." atom)*;
|
34
|
+
domain = (domain_dot_atom | domain_literal | obs_domain) >domain_s %domain_e;
|
35
|
+
|
36
|
+
# 3.4.1. Addr-Spec Specification
|
37
|
+
|
38
|
+
# The %(end_addr,N) priority resolves uncertainty when whitespace
|
39
|
+
# after an addr_spec could cause it to be interpreted as a
|
40
|
+
# display name: "bar@example.com ,..."
|
41
|
+
|
42
|
+
addr_spec_in_angle_brackets =
|
43
|
+
(local_part "@" domain) %(end_addr,1) |
|
44
|
+
local_part_no_capture %(end_addr,0);
|
45
|
+
|
46
|
+
addr_spec_no_angle_brackets =
|
47
|
+
(local_part "@" domain) %(end_addr,1) |
|
48
|
+
local_part %(end_addr,0);
|
49
|
+
|
50
|
+
# angle_addr:
|
51
|
+
obs_domain_list = (CFWS | ",")* "@" domain ("," CFWS? ("@" domain)?)*;
|
52
|
+
obs_route = (obs_domain_list ":") >obs_domain_list_s %obs_domain_list_e;
|
53
|
+
obs_angle_addr = CFWS? "<" obs_route? addr_spec_in_angle_brackets ">" CFWS?;
|
54
|
+
|
55
|
+
angle_addr = CFWS? ("<" >angle_addr_s) addr_spec_in_angle_brackets ">" CFWS? |
|
56
|
+
obs_angle_addr;
|
57
|
+
|
58
|
+
# 3.4. Address Specification
|
59
|
+
display_name = phrase;
|
60
|
+
name_addr = display_name? %(end_addr,2) angle_addr;
|
61
|
+
mailbox = (name_addr | addr_spec_no_angle_brackets) >address_s %address_e;
|
62
|
+
obs_mbox_list = (CFWS? ",")* mailbox ("," (mailbox | CFWS)?)*;
|
63
|
+
mailbox_list = (mailbox (("," | ";") mailbox)*) | obs_mbox_list;
|
64
|
+
obs_group_list = (CFWS? ",")+ CFWS?;
|
65
|
+
group_list = mailbox_list | CFWS | obs_group_list;
|
66
|
+
group = (display_name >group_name_s %group_name_e) ":"
|
67
|
+
(group_list?) ";" CFWS?;
|
68
|
+
address = group | mailbox;
|
69
|
+
#obs_addr_list = (CFWS? ",")* address ("," (address | CFWS)?)*;
|
70
|
+
address_lists = address? %(comment_after_address,0)
|
71
|
+
(FWS* ("," | ";") FWS* address?)*;
|
72
|
+
}%%
|
@@ -0,0 +1,37 @@
|
|
1
|
+
%%{
|
2
|
+
# RFC 5322 Internet Message Format
|
3
|
+
# Section 3.3. Date and Time Specification
|
4
|
+
# https://tools.ietf.org/html/rfc5322#section-3.3
|
5
|
+
machine rfc5322_date_time;
|
6
|
+
alphtype int;
|
7
|
+
|
8
|
+
include rfc5322_lexical_tokens "rfc5322_lexical_tokens.rl";
|
9
|
+
|
10
|
+
# day_of_week
|
11
|
+
day_name = "Mon" | "Tue" | "Wed" | "Thu" | "Fri" | "Sat" | "Sun";
|
12
|
+
obs_day_of_week = CFWS? day_name CFWS?;
|
13
|
+
day_of_week = (FWS? day_name) | obs_day_of_week;
|
14
|
+
|
15
|
+
# date
|
16
|
+
obs_day = CFWS? (DIGIT | (DIGIT DIGIT)) CFWS?;
|
17
|
+
day = (FWS? DIGIT DIGIT? FWS) | obs_day;
|
18
|
+
month = "Jan" | "Feb" | "Mar" | "Apr" | "May" | "Jun" | "Jul" | "Aug" | "Sep" | "Oct" | "Nov" | "Dec";
|
19
|
+
obs_year = CFWS? (DIGIT DIGIT DIGIT*) CFWS?;
|
20
|
+
year = FWS DIGIT DIGIT DIGIT DIGIT FWS | obs_year;
|
21
|
+
date = day month year;
|
22
|
+
|
23
|
+
# time
|
24
|
+
obs_hour = CFWS? (DIGIT DIGIT) CFWS?;
|
25
|
+
hour = DIGIT DIGIT | obs_hour;
|
26
|
+
obs_minute = CFWS? (DIGIT DIGIT) CFWS?;
|
27
|
+
minute = DIGIT DIGIT | obs_minute;
|
28
|
+
obs_second = CFWS? (DIGIT DIGIT) CFWS?;
|
29
|
+
second = DIGIT DIGIT | obs_second;
|
30
|
+
obs_zone = "UT" | "GMT" | "EST" | "EDT" | "CST" | "CDT" | "MST" | "MDT" | "PST" | "PDT" | 0x41..0x49 | 0x4B..0x5A | 0x61..0x69 | 0x6B..0x7A;
|
31
|
+
time_of_day = hour ":" minute (":" second)?;
|
32
|
+
zone = FWS ((("+" | "-") DIGIT DIGIT DIGIT DIGIT) | obs_zone);
|
33
|
+
time = time_of_day zone;
|
34
|
+
|
35
|
+
date_time = (day_of_week ",")?
|
36
|
+
(date >date_s %date_e) <: (time >time_s %time_e) CFWS?;
|
37
|
+
}%%
|
@@ -0,0 +1,60 @@
|
|
1
|
+
%%{
|
2
|
+
# RFC 5322 Internet Message Format
|
3
|
+
# Section 3.2. Lexical Tokens
|
4
|
+
# https://tools.ietf.org/html/rfc5322#section-3.2
|
5
|
+
machine rfc5322_lexical_tokens;
|
6
|
+
alphtype int;
|
7
|
+
|
8
|
+
include rfc5234_abnf_core_rules "rfc5234_abnf_core_rules.rl";
|
9
|
+
|
10
|
+
# 3.2.1. Quoted characters
|
11
|
+
obs_NO_WS_CTL = 0x01..0x08 | "\v" | "\f" | 0x0e..0x1f | 0x7f;
|
12
|
+
obs_qp = "\\" (0x00 | obs_NO_WS_CTL | LF | CR);
|
13
|
+
quoted_pair = ("\\" (VCHAR | WSP)) | obs_qp;
|
14
|
+
|
15
|
+
# 3.2.2. Folding White Space and Comments
|
16
|
+
obs_FWS = (CRLF? WSP)+;
|
17
|
+
FWS = (WSP* CRLF WSP+) | (CRLF WSP+) | obs_FWS;
|
18
|
+
|
19
|
+
obs_ctext = obs_NO_WS_CTL;
|
20
|
+
rfc5322_ctext = 0x21..0x27 | 0x2a..0x5b | 0x5d..0x7e | obs_ctext;
|
21
|
+
ctext = rfc5322_ctext | utf8_non_ascii; # RFC6532 for UTF-8
|
22
|
+
|
23
|
+
# Recursive comments
|
24
|
+
action comment_begin { fcall comment_tail; }
|
25
|
+
action comment_exit { fret; }
|
26
|
+
ccontent = ctext | quoted_pair | "(" @comment_begin;
|
27
|
+
comment_tail := ((FWS? ccontent)* >comment_s) FWS? ")" @comment_exit;
|
28
|
+
comment = "(" @comment_begin %comment_e;
|
29
|
+
CFWS = ((FWS? comment)+ FWS?) | FWS;
|
30
|
+
|
31
|
+
# 3.2.3. Atom
|
32
|
+
rfc5322_atext = ALPHA | DIGIT | "!" | "#" | "$" | "%" | "&" |
|
33
|
+
"'" | "*" | "+" | "-" | "/" | "=" | "?" | "^" |
|
34
|
+
"_" | "`" | "{" | "|" | "}" | "~";
|
35
|
+
atext = rfc5322_atext | utf8_non_ascii; # RFC6532 for UTF-8
|
36
|
+
atom = CFWS? atext+ CFWS?;
|
37
|
+
dot_atom_text = atext ("." atext)*;
|
38
|
+
dot_atom = CFWS? dot_atom_text CFWS?;
|
39
|
+
|
40
|
+
# 3.2.4. Quoted Strings
|
41
|
+
obs_qtext = obs_NO_WS_CTL;
|
42
|
+
rfc5322_qtext = 0x21 | 0x23..0x5b | 0x5d..0x7e | obs_qtext;
|
43
|
+
qtext = rfc5322_qtext | utf8_non_ascii; # RFC6532 for UTF-8
|
44
|
+
|
45
|
+
qcontent = qtext | quoted_pair;
|
46
|
+
quoted_string = CFWS?
|
47
|
+
(DQUOTE
|
48
|
+
(((FWS? qcontent)* FWS?) >qstr_s %qstr_e)
|
49
|
+
DQUOTE)
|
50
|
+
CFWS?;
|
51
|
+
|
52
|
+
# 3.2.5. Miscellaneous Tokens
|
53
|
+
word = atom | quoted_string;
|
54
|
+
|
55
|
+
obs_phrase = (word | "." | "@")+;
|
56
|
+
phrase = (obs_phrase | word+) >phrase_s %phrase_e;
|
57
|
+
|
58
|
+
# Not part of RFC, used for keywords per 3.6.5 Information Fields
|
59
|
+
phrase_lists = phrase ("," FWS* phrase)*;
|
60
|
+
}%%
|
data/lib/mail/parsers.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'mail/parsers/address_lists_parser'
|
4
|
+
require 'mail/parsers/content_disposition_parser'
|
5
|
+
require 'mail/parsers/content_location_parser'
|
6
|
+
require 'mail/parsers/content_transfer_encoding_parser'
|
7
|
+
require 'mail/parsers/content_type_parser'
|
8
|
+
require 'mail/parsers/date_time_parser'
|
9
|
+
require 'mail/parsers/envelope_from_parser'
|
10
|
+
require 'mail/parsers/message_ids_parser'
|
11
|
+
require 'mail/parsers/mime_version_parser'
|
12
|
+
require 'mail/parsers/phrase_lists_parser'
|
13
|
+
require 'mail/parsers/received_parser'
|
data/lib/mail/part.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
require 'mail/constants'
|
4
|
+
require 'mail/utilities'
|
5
|
+
|
2
6
|
module Mail
|
3
7
|
class Part < Message
|
4
|
-
|
5
8
|
# Creates a new empty Content-ID field and inserts it in the correct order
|
6
9
|
# into the Header. The ContentIdField object will automatically generate
|
7
10
|
# a unique content ID if you try and encode it or output it to_s without
|
@@ -18,15 +21,9 @@ module Mail
|
|
18
21
|
header.has_content_id?
|
19
22
|
end
|
20
23
|
|
21
|
-
def inline_content_id
|
22
|
-
# TODO: Deprecated in 2.2.2 - Remove in 2.3
|
23
|
-
STDERR.puts("Part#inline_content_id is deprecated, please call Part#cid instead")
|
24
|
-
cid
|
25
|
-
end
|
26
|
-
|
27
24
|
def cid
|
28
25
|
add_content_id unless has_content_id?
|
29
|
-
uri_escape(unbracket(content_id))
|
26
|
+
Utilities.uri_escape(Utilities.unbracket(content_id))
|
30
27
|
end
|
31
28
|
|
32
29
|
def url
|
@@ -34,7 +31,7 @@ module Mail
|
|
34
31
|
end
|
35
32
|
|
36
33
|
def inline?
|
37
|
-
header[:content_disposition].disposition_type == 'inline' if header[:content_disposition]
|
34
|
+
header[:content_disposition].disposition_type == 'inline' if header[:content_disposition].respond_to?(:disposition_type)
|
38
35
|
end
|
39
36
|
|
40
37
|
def add_required_fields
|
@@ -94,15 +91,17 @@ module Mail
|
|
94
91
|
def get_return_values(key)
|
95
92
|
if delivery_status_data[key].is_a?(Array)
|
96
93
|
delivery_status_data[key].map { |a| a.value }
|
97
|
-
|
94
|
+
elsif !delivery_status_data[key].nil?
|
98
95
|
delivery_status_data[key].value
|
96
|
+
else
|
97
|
+
nil
|
99
98
|
end
|
100
99
|
end
|
101
100
|
|
102
101
|
# A part may not have a header.... so, just init a body if no header
|
103
102
|
def parse_message
|
104
|
-
header_part, body_part = raw_source.split(/#{
|
105
|
-
if header_part =~ HEADER_LINE
|
103
|
+
header_part, body_part = raw_source.split(/#{Constants::LAX_CRLF}#{Constants::WSP}*#{Constants::LAX_CRLF}/m, 2)
|
104
|
+
if header_part =~ Constants::HEADER_LINE
|
106
105
|
self.header = header_part
|
107
106
|
self.body = body_part
|
108
107
|
else
|
data/lib/mail/parts_list.rb
CHANGED
@@ -1,8 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'delegate'
|
3
|
+
|
1
4
|
module Mail
|
2
|
-
class PartsList < Array
|
5
|
+
class PartsList < DelegateClass(Array)
|
6
|
+
attr_reader :parts
|
7
|
+
|
8
|
+
def initialize(*args)
|
9
|
+
@parts = Array.new(*args)
|
10
|
+
super @parts
|
11
|
+
end
|
12
|
+
|
13
|
+
# The #encode_with and #to_yaml methods are just implemented
|
14
|
+
# for the sake of backward compatibility ; the delegator does
|
15
|
+
# not correctly delegate these calls to the delegated object
|
16
|
+
def encode_with(coder) # :nodoc:
|
17
|
+
coder.represent_object(nil, @parts)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_yaml(options = {}) # :nodoc:
|
21
|
+
@parts.to_yaml(options)
|
22
|
+
end
|
3
23
|
|
4
24
|
def attachments
|
5
|
-
Mail::AttachmentsList.new(
|
25
|
+
Mail::AttachmentsList.new(@parts)
|
6
26
|
end
|
7
27
|
|
8
28
|
def collect
|
@@ -14,8 +34,6 @@ module Mail
|
|
14
34
|
to_a
|
15
35
|
end
|
16
36
|
end
|
17
|
-
|
18
|
-
undef :map
|
19
37
|
alias_method :map, :collect
|
20
38
|
|
21
39
|
def map!
|
@@ -26,29 +44,87 @@ module Mail
|
|
26
44
|
raise NoMethodError, "#collect! is not defined, please call #collect and create a new PartsList"
|
27
45
|
end
|
28
46
|
|
47
|
+
def inspect_structure(parent_id = '')
|
48
|
+
enum_for(:map).with_index { |part, i|
|
49
|
+
i = i + 1 # Use 1-based indexes since this is for humans to read
|
50
|
+
id = parent_id.empty? ? "#{i}" : "#{parent_id}.#{i}"
|
51
|
+
if part.content_type == "message/rfc822"
|
52
|
+
sub_list = Mail.new(part.body).parts
|
53
|
+
else
|
54
|
+
sub_list = part.parts
|
55
|
+
end
|
56
|
+
id + '. ' + part.inspect +
|
57
|
+
if sub_list.any?
|
58
|
+
"\n" + sub_list.inspect_structure(id)
|
59
|
+
end.to_s
|
60
|
+
}.join("\n")
|
61
|
+
end
|
62
|
+
|
63
|
+
def recursive_each(&block)
|
64
|
+
each do |part|
|
65
|
+
if part.content_type == "message/rfc822"
|
66
|
+
sub_list = Mail.new(part.body).parts
|
67
|
+
else
|
68
|
+
sub_list = part.parts
|
69
|
+
end
|
70
|
+
|
71
|
+
yield part
|
72
|
+
|
73
|
+
sub_list.recursive_each(&block)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def recursive_size
|
78
|
+
i = 0
|
79
|
+
recursive_each {|p| i += 1 }
|
80
|
+
i
|
81
|
+
end
|
82
|
+
|
83
|
+
def recursive_delete_if
|
84
|
+
delete_if { |part|
|
85
|
+
if part.content_type == "message/rfc822"
|
86
|
+
sub_list = Mail.new(part.body).parts
|
87
|
+
else
|
88
|
+
sub_list = part.parts
|
89
|
+
end
|
90
|
+
(yield part).tap {
|
91
|
+
if sub_list.any?
|
92
|
+
sub_list.recursive_delete_if {|part| yield part }
|
93
|
+
end
|
94
|
+
}
|
95
|
+
}
|
96
|
+
end
|
97
|
+
|
98
|
+
def delete_attachments
|
99
|
+
recursive_delete_if { |part|
|
100
|
+
part.attachment?
|
101
|
+
}
|
102
|
+
end
|
103
|
+
|
29
104
|
def sort
|
30
|
-
self.class.new(
|
105
|
+
self.class.new(@parts.sort)
|
31
106
|
end
|
32
107
|
|
33
108
|
def sort!(order)
|
34
|
-
|
109
|
+
# stable sort should be used to maintain the relative order as the parts are added
|
110
|
+
i = 0;
|
111
|
+
sorted = @parts.sort_by do |a|
|
35
112
|
# OK, 10000 is arbitrary... if anyone actually wants to explicitly sort 10000 parts of a
|
36
113
|
# single email message... please show me a use case and I'll put more work into this method,
|
37
114
|
# in the meantime, it works :)
|
38
|
-
get_order_value(a, order)
|
115
|
+
get_order_value(a, order) << (i += 1)
|
39
116
|
end
|
40
|
-
|
41
|
-
sorted.each { |p|
|
117
|
+
@parts.clear
|
118
|
+
sorted.each { |p| @parts << p }
|
42
119
|
end
|
43
120
|
|
44
121
|
private
|
45
122
|
|
46
123
|
def get_order_value(part, order)
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
end
|
124
|
+
is_attachment = part.respond_to?(:attachment?) && part.attachment?
|
125
|
+
has_content_type = part.respond_to?(:content_type) && !part[:content_type].nil?
|
126
|
+
|
127
|
+
[is_attachment ? 1 : 0, (has_content_type ? order.index(part[:content_type].string.downcase) : nil) || 10000]
|
52
128
|
end
|
53
129
|
|
54
130
|
end
|