mail 2.5.5 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (191) hide show
  1. checksums.yaml +5 -5
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +170 -108
  4. data/lib/mail/attachments_list.rb +13 -10
  5. data/lib/mail/body.rb +105 -91
  6. data/lib/mail/check_delivery_params.rb +30 -22
  7. data/lib/mail/configuration.rb +3 -0
  8. data/lib/mail/constants.rb +79 -0
  9. data/lib/mail/elements/address.rb +118 -174
  10. data/lib/mail/elements/address_list.rb +16 -56
  11. data/lib/mail/elements/content_disposition_element.rb +12 -22
  12. data/lib/mail/elements/content_location_element.rb +9 -17
  13. data/lib/mail/elements/content_transfer_encoding_element.rb +8 -19
  14. data/lib/mail/elements/content_type_element.rb +20 -30
  15. data/lib/mail/elements/date_time_element.rb +10 -21
  16. data/lib/mail/elements/envelope_from_element.rb +23 -31
  17. data/lib/mail/elements/message_ids_element.rb +22 -20
  18. data/lib/mail/elements/mime_version_element.rb +10 -21
  19. data/lib/mail/elements/phrase_list.rb +13 -15
  20. data/lib/mail/elements/received_element.rb +26 -21
  21. data/lib/mail/elements.rb +1 -0
  22. data/lib/mail/encodings/7bit.rb +10 -14
  23. data/lib/mail/encodings/8bit.rb +5 -18
  24. data/lib/mail/encodings/base64.rb +15 -10
  25. data/lib/mail/encodings/binary.rb +4 -22
  26. data/lib/mail/encodings/identity.rb +24 -0
  27. data/lib/mail/encodings/quoted_printable.rb +13 -7
  28. data/lib/mail/encodings/transfer_encoding.rb +47 -28
  29. data/lib/mail/encodings/unix_to_unix.rb +20 -0
  30. data/lib/mail/encodings.rb +102 -93
  31. data/lib/mail/envelope.rb +12 -19
  32. data/lib/mail/field.rb +143 -71
  33. data/lib/mail/field_list.rb +73 -19
  34. data/lib/mail/fields/bcc_field.rb +42 -48
  35. data/lib/mail/fields/cc_field.rb +29 -50
  36. data/lib/mail/fields/comments_field.rb +28 -37
  37. data/lib/mail/fields/common_address_field.rb +170 -0
  38. data/lib/mail/fields/common_date_field.rb +58 -0
  39. data/lib/mail/fields/common_field.rb +77 -0
  40. data/lib/mail/fields/common_message_id_field.rb +42 -0
  41. data/lib/mail/fields/content_description_field.rb +8 -14
  42. data/lib/mail/fields/content_disposition_field.rb +20 -44
  43. data/lib/mail/fields/content_id_field.rb +25 -51
  44. data/lib/mail/fields/content_location_field.rb +12 -25
  45. data/lib/mail/fields/content_transfer_encoding_field.rb +31 -36
  46. data/lib/mail/fields/content_type_field.rb +51 -80
  47. data/lib/mail/fields/date_field.rb +24 -52
  48. data/lib/mail/fields/from_field.rb +29 -50
  49. data/lib/mail/fields/in_reply_to_field.rb +39 -49
  50. data/lib/mail/fields/keywords_field.rb +19 -32
  51. data/lib/mail/fields/message_id_field.rb +26 -71
  52. data/lib/mail/fields/mime_version_field.rb +20 -30
  53. data/lib/mail/fields/named_structured_field.rb +11 -0
  54. data/lib/mail/fields/named_unstructured_field.rb +11 -0
  55. data/lib/mail/fields/optional_field.rb +10 -7
  56. data/lib/mail/fields/{common/parameter_hash.rb → parameter_hash.rb} +16 -13
  57. data/lib/mail/fields/received_field.rb +44 -57
  58. data/lib/mail/fields/references_field.rb +36 -49
  59. data/lib/mail/fields/reply_to_field.rb +29 -50
  60. data/lib/mail/fields/resent_bcc_field.rb +29 -50
  61. data/lib/mail/fields/resent_cc_field.rb +29 -50
  62. data/lib/mail/fields/resent_date_field.rb +6 -30
  63. data/lib/mail/fields/resent_from_field.rb +29 -50
  64. data/lib/mail/fields/resent_message_id_field.rb +6 -29
  65. data/lib/mail/fields/resent_sender_field.rb +28 -57
  66. data/lib/mail/fields/resent_to_field.rb +29 -50
  67. data/lib/mail/fields/return_path_field.rb +51 -55
  68. data/lib/mail/fields/sender_field.rb +35 -56
  69. data/lib/mail/fields/structured_field.rb +4 -30
  70. data/lib/mail/fields/subject_field.rb +10 -11
  71. data/lib/mail/fields/to_field.rb +29 -50
  72. data/lib/mail/fields/unstructured_field.rb +43 -51
  73. data/lib/mail/fields.rb +1 -0
  74. data/lib/mail/header.rb +78 -129
  75. data/lib/mail/indifferent_hash.rb +1 -0
  76. data/lib/mail/mail.rb +18 -11
  77. data/lib/mail/matchers/attachment_matchers.rb +44 -0
  78. data/lib/mail/matchers/has_sent_mail.rb +81 -4
  79. data/lib/mail/message.rb +142 -139
  80. data/lib/mail/multibyte/chars.rb +24 -180
  81. data/lib/mail/multibyte/unicode.rb +32 -27
  82. data/lib/mail/multibyte/utils.rb +27 -43
  83. data/lib/mail/multibyte.rb +56 -16
  84. data/lib/mail/network/delivery_methods/exim.rb +6 -4
  85. data/lib/mail/network/delivery_methods/file_delivery.rb +12 -10
  86. data/lib/mail/network/delivery_methods/logger_delivery.rb +34 -0
  87. data/lib/mail/network/delivery_methods/sendmail.rb +63 -21
  88. data/lib/mail/network/delivery_methods/smtp.rb +76 -50
  89. data/lib/mail/network/delivery_methods/smtp_connection.rb +4 -4
  90. data/lib/mail/network/delivery_methods/test_mailer.rb +5 -2
  91. data/lib/mail/network/retriever_methods/base.rb +9 -8
  92. data/lib/mail/network/retriever_methods/imap.rb +37 -18
  93. data/lib/mail/network/retriever_methods/pop3.rb +6 -3
  94. data/lib/mail/network/retriever_methods/test_retriever.rb +4 -2
  95. data/lib/mail/network.rb +2 -0
  96. data/lib/mail/parser_tools.rb +15 -0
  97. data/lib/mail/parsers/address_lists_parser.rb +33242 -0
  98. data/lib/mail/parsers/address_lists_parser.rl +179 -0
  99. data/lib/mail/parsers/content_disposition_parser.rb +901 -0
  100. data/lib/mail/parsers/content_disposition_parser.rl +89 -0
  101. data/lib/mail/parsers/content_location_parser.rb +822 -0
  102. data/lib/mail/parsers/content_location_parser.rl +78 -0
  103. data/lib/mail/parsers/content_transfer_encoding_parser.rb +522 -0
  104. data/lib/mail/parsers/content_transfer_encoding_parser.rl +71 -0
  105. data/lib/mail/parsers/content_type_parser.rb +1048 -0
  106. data/lib/mail/parsers/content_type_parser.rl +90 -0
  107. data/lib/mail/parsers/date_time_parser.rb +891 -0
  108. data/lib/mail/parsers/date_time_parser.rl +69 -0
  109. data/lib/mail/parsers/envelope_from_parser.rb +3675 -0
  110. data/lib/mail/parsers/envelope_from_parser.rl +89 -0
  111. data/lib/mail/parsers/message_ids_parser.rb +5161 -0
  112. data/lib/mail/parsers/message_ids_parser.rl +93 -0
  113. data/lib/mail/parsers/mime_version_parser.rb +513 -0
  114. data/lib/mail/parsers/mime_version_parser.rl +68 -0
  115. data/lib/mail/parsers/phrase_lists_parser.rb +884 -0
  116. data/lib/mail/parsers/phrase_lists_parser.rl +90 -0
  117. data/lib/mail/parsers/received_parser.rb +8782 -0
  118. data/lib/mail/parsers/received_parser.rl +91 -0
  119. data/lib/mail/parsers/rfc2045_content_transfer_encoding.rl +13 -0
  120. data/lib/mail/parsers/rfc2045_content_type.rl +25 -0
  121. data/lib/mail/parsers/rfc2045_mime.rl +16 -0
  122. data/lib/mail/parsers/rfc2183_content_disposition.rl +15 -0
  123. data/lib/mail/parsers/rfc3629_utf8.rl +19 -0
  124. data/lib/mail/parsers/rfc5234_abnf_core_rules.rl +22 -0
  125. data/lib/mail/parsers/rfc5322.rl +74 -0
  126. data/lib/mail/parsers/rfc5322_address.rl +72 -0
  127. data/lib/mail/parsers/rfc5322_date_time.rl +37 -0
  128. data/lib/mail/parsers/rfc5322_lexical_tokens.rl +60 -0
  129. data/lib/mail/parsers.rb +13 -0
  130. data/lib/mail/part.rb +11 -12
  131. data/lib/mail/parts_list.rb +90 -14
  132. data/lib/mail/smtp_envelope.rb +57 -0
  133. data/lib/mail/utilities.rb +415 -76
  134. data/lib/mail/values/unicode_tables.dat +0 -0
  135. data/lib/mail/version.rb +8 -15
  136. data/lib/mail/yaml.rb +30 -0
  137. data/lib/mail.rb +9 -32
  138. metadata +127 -79
  139. data/CHANGELOG.rdoc +0 -742
  140. data/CONTRIBUTING.md +0 -45
  141. data/Dependencies.txt +0 -3
  142. data/Gemfile +0 -32
  143. data/Rakefile +0 -21
  144. data/TODO.rdoc +0 -9
  145. data/lib/VERSION +0 -4
  146. data/lib/load_parsers.rb +0 -35
  147. data/lib/mail/core_extensions/nil.rb +0 -19
  148. data/lib/mail/core_extensions/object.rb +0 -13
  149. data/lib/mail/core_extensions/smtp.rb +0 -24
  150. data/lib/mail/core_extensions/string/access.rb +0 -145
  151. data/lib/mail/core_extensions/string/multibyte.rb +0 -78
  152. data/lib/mail/core_extensions/string.rb +0 -33
  153. data/lib/mail/fields/common/address_container.rb +0 -16
  154. data/lib/mail/fields/common/common_address.rb +0 -140
  155. data/lib/mail/fields/common/common_date.rb +0 -42
  156. data/lib/mail/fields/common/common_field.rb +0 -57
  157. data/lib/mail/fields/common/common_message_id.rb +0 -48
  158. data/lib/mail/multibyte/exceptions.rb +0 -8
  159. data/lib/mail/parsers/address_lists.rb +0 -64
  160. data/lib/mail/parsers/address_lists.treetop +0 -19
  161. data/lib/mail/parsers/content_disposition.rb +0 -535
  162. data/lib/mail/parsers/content_disposition.treetop +0 -46
  163. data/lib/mail/parsers/content_location.rb +0 -139
  164. data/lib/mail/parsers/content_location.treetop +0 -20
  165. data/lib/mail/parsers/content_transfer_encoding.rb +0 -201
  166. data/lib/mail/parsers/content_transfer_encoding.treetop +0 -18
  167. data/lib/mail/parsers/content_type.rb +0 -971
  168. data/lib/mail/parsers/content_type.treetop +0 -68
  169. data/lib/mail/parsers/date_time.rb +0 -114
  170. data/lib/mail/parsers/date_time.treetop +0 -11
  171. data/lib/mail/parsers/envelope_from.rb +0 -194
  172. data/lib/mail/parsers/envelope_from.treetop +0 -32
  173. data/lib/mail/parsers/message_ids.rb +0 -45
  174. data/lib/mail/parsers/message_ids.treetop +0 -15
  175. data/lib/mail/parsers/mime_version.rb +0 -144
  176. data/lib/mail/parsers/mime_version.treetop +0 -19
  177. data/lib/mail/parsers/phrase_lists.rb +0 -45
  178. data/lib/mail/parsers/phrase_lists.treetop +0 -15
  179. data/lib/mail/parsers/received.rb +0 -71
  180. data/lib/mail/parsers/received.treetop +0 -11
  181. data/lib/mail/parsers/rfc2045.rb +0 -421
  182. data/lib/mail/parsers/rfc2045.treetop +0 -35
  183. data/lib/mail/parsers/rfc2822.rb +0 -5397
  184. data/lib/mail/parsers/rfc2822.treetop +0 -408
  185. data/lib/mail/parsers/rfc2822_obsolete.rb +0 -3768
  186. data/lib/mail/parsers/rfc2822_obsolete.treetop +0 -241
  187. data/lib/mail/patterns.rb +0 -35
  188. data/lib/mail/version_specific/ruby_1_8.rb +0 -119
  189. data/lib/mail/version_specific/ruby_1_9.rb +0 -147
  190. data/lib/tasks/corpus.rake +0 -125
  191. data/lib/tasks/treetop.rake +0 -10
@@ -0,0 +1,78 @@
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
+ # RFC 2557 Content-Location
10
+ # https://tools.ietf.org/html/rfc2557#section-4.1
11
+ machine content_location;
12
+ alphtype int;
13
+
14
+ # Quoted String
15
+ action qstr_s { qstr_s = p }
16
+ action qstr_e { content_location.location = chars(data, qstr_s, p-1) }
17
+
18
+ # Token String
19
+ action token_string_s { token_string_s = p }
20
+ action token_string_e { content_location.location = chars(data, token_string_s, p-1) }
21
+
22
+ # No-op actions
23
+ action comment_e { }
24
+ action comment_s { }
25
+ action phrase_e { }
26
+ action phrase_s { }
27
+ action main_type_e { }
28
+ action main_type_s { }
29
+ action sub_type_e { }
30
+ action sub_type_s { }
31
+ action param_attr_e { }
32
+ action param_attr_s { }
33
+ action param_val_e { }
34
+ action param_val_s { }
35
+
36
+ include rfc2045_content_type "rfc2045_content_type.rl";
37
+
38
+ location = quoted_string | ((token | 0x3d)+ >token_string_s %token_string_e);
39
+ main := CFWS? location CFWS?;
40
+ }%%
41
+
42
+ module Mail::Parsers
43
+ module ContentLocationParser
44
+ extend Mail::ParserTools
45
+
46
+ ContentLocationStruct = Struct.new(:location, :error)
47
+
48
+ %%write data noprefix;
49
+
50
+ def self.parse(data)
51
+ data = data.dup.force_encoding(Encoding::ASCII_8BIT) if data.respond_to?(:force_encoding)
52
+
53
+ content_location = ContentLocationStruct.new(nil)
54
+ return content_location if Mail::Utilities.blank?(data)
55
+
56
+ # Parser state
57
+ disp_type_s = param_attr_s = param_attr = qstr_s = qstr = param_val_s = nil
58
+
59
+ # 5.1 Variables Used by Ragel
60
+ p = 0
61
+ eof = pe = data.length
62
+ stack = []
63
+
64
+ %%write init;
65
+ %%write exec;
66
+
67
+ if p != eof || cs < %%{ write first_final; }%%
68
+ raise Mail::Field::IncompleteParseError.new(Mail::ContentLocationElement, data, p)
69
+ end
70
+
71
+ content_location
72
+ end
73
+ end
74
+ end
75
+
76
+ ensure
77
+ $VERBOSE = original_verbose
78
+ end
@@ -0,0 +1,522 @@
1
+
2
+ # frozen_string_literal: true
3
+ require "mail/utilities"
4
+ require "mail/parser_tools"
5
+
6
+ begin
7
+ original_verbose, $VERBOSE = $VERBOSE, nil
8
+
9
+ module Mail::Parsers
10
+ module ContentTransferEncodingParser
11
+ extend Mail::ParserTools
12
+
13
+ ContentTransferEncodingStruct = Struct.new(:encoding, :error)
14
+
15
+ class << self
16
+ attr_accessor :_trans_keys
17
+ private :_trans_keys, :_trans_keys=
18
+ end
19
+ self._trans_keys = [
20
+ 0, 0, 9, 126, 10, 10,
21
+ 9, 32, 10, 10, 9,
22
+ 32, 10, 10, 9, 32,
23
+ 9, 126, 1, 244, 1, 244,
24
+ 10, 10, 9, 32, 0,
25
+ 244, 128, 191, 160, 191,
26
+ 128, 191, 128, 159, 144, 191,
27
+ 128, 191, 128, 143, 9,
28
+ 126, 9, 59, 9, 59,
29
+ 9, 40, 9, 40, 0, 0,
30
+ 0,
31
+ ]
32
+
33
+ class << self
34
+ attr_accessor :_key_spans
35
+ private :_key_spans, :_key_spans=
36
+ end
37
+ self._key_spans = [
38
+ 0, 118, 1, 24, 1, 24, 1, 24,
39
+ 118, 244, 244, 1, 24, 245, 64, 32,
40
+ 64, 32, 48, 64, 16, 118, 51, 51,
41
+ 32, 32, 0,
42
+ ]
43
+
44
+ class << self
45
+ attr_accessor :_index_offsets
46
+ private :_index_offsets, :_index_offsets=
47
+ end
48
+ self._index_offsets = [
49
+ 0, 0, 119, 121, 146, 148, 173, 175,
50
+ 200, 319, 564, 809, 811, 836, 1082, 1147,
51
+ 1180, 1245, 1278, 1327, 1392, 1409, 1528, 1580,
52
+ 1632, 1665, 1698,
53
+ ]
54
+
55
+ class << self
56
+ attr_accessor :_indicies
57
+ private :_indicies, :_indicies=
58
+ end
59
+ self._indicies = [
60
+ 0, 1, 1, 1, 2, 1, 1, 1,
61
+ 1, 1, 1, 1, 1, 1, 1, 1,
62
+ 1, 1, 1, 1, 1, 1, 1, 0,
63
+ 3, 3, 3, 3, 3, 3, 3, 4,
64
+ 1, 3, 3, 3, 3, 3, 1, 3,
65
+ 3, 3, 3, 3, 3, 3, 3, 3,
66
+ 3, 1, 1, 1, 1, 1, 1, 1,
67
+ 3, 3, 3, 3, 3, 3, 3, 3,
68
+ 3, 3, 3, 3, 3, 3, 3, 3,
69
+ 3, 3, 3, 3, 3, 3, 3, 3,
70
+ 3, 3, 1, 1, 1, 3, 3, 3,
71
+ 3, 3, 3, 3, 3, 3, 3, 3,
72
+ 3, 3, 3, 3, 3, 3, 3, 3,
73
+ 3, 3, 3, 3, 3, 3, 3, 3,
74
+ 3, 3, 3, 3, 3, 3, 1, 5,
75
+ 1, 0, 1, 1, 1, 1, 1, 1,
76
+ 1, 1, 1, 1, 1, 1, 1, 1,
77
+ 1, 1, 1, 1, 1, 1, 1, 1,
78
+ 0, 1, 6, 1, 7, 1, 1, 1,
79
+ 1, 1, 1, 1, 1, 1, 1, 1,
80
+ 1, 1, 1, 1, 1, 1, 1, 1,
81
+ 1, 1, 1, 7, 1, 8, 1, 9,
82
+ 1, 1, 1, 1, 1, 1, 1, 1,
83
+ 1, 1, 1, 1, 1, 1, 1, 1,
84
+ 1, 1, 1, 1, 1, 1, 9, 1,
85
+ 10, 1, 1, 1, 11, 1, 1, 1,
86
+ 1, 1, 1, 1, 1, 1, 1, 1,
87
+ 1, 1, 1, 1, 1, 1, 1, 10,
88
+ 12, 12, 12, 12, 12, 12, 12, 13,
89
+ 1, 12, 12, 12, 12, 12, 1, 12,
90
+ 12, 12, 12, 12, 12, 12, 12, 12,
91
+ 12, 1, 1, 1, 1, 1, 1, 1,
92
+ 12, 12, 12, 12, 12, 12, 12, 12,
93
+ 12, 12, 12, 12, 12, 12, 12, 12,
94
+ 12, 12, 12, 12, 12, 12, 12, 12,
95
+ 12, 12, 1, 1, 1, 12, 12, 12,
96
+ 12, 12, 12, 12, 12, 12, 12, 12,
97
+ 12, 12, 12, 12, 12, 12, 12, 12,
98
+ 12, 12, 12, 12, 12, 12, 12, 12,
99
+ 12, 12, 12, 12, 12, 12, 1, 14,
100
+ 14, 14, 14, 14, 14, 14, 14, 14,
101
+ 1, 14, 14, 15, 14, 14, 14, 14,
102
+ 14, 14, 14, 14, 14, 14, 14, 14,
103
+ 14, 14, 14, 14, 14, 14, 14, 14,
104
+ 14, 14, 14, 14, 14, 14, 16, 17,
105
+ 14, 14, 14, 14, 14, 14, 14, 14,
106
+ 14, 14, 14, 14, 14, 14, 14, 14,
107
+ 14, 14, 14, 14, 14, 14, 14, 14,
108
+ 14, 14, 14, 14, 14, 14, 14, 14,
109
+ 14, 14, 14, 14, 14, 14, 14, 14,
110
+ 14, 14, 14, 14, 14, 14, 14, 14,
111
+ 14, 14, 18, 14, 14, 14, 14, 14,
112
+ 14, 14, 14, 14, 14, 14, 14, 14,
113
+ 14, 14, 14, 14, 14, 14, 14, 14,
114
+ 14, 14, 14, 14, 14, 14, 14, 14,
115
+ 14, 14, 14, 14, 14, 14, 1, 1,
116
+ 1, 1, 1, 1, 1, 1, 1, 1,
117
+ 1, 1, 1, 1, 1, 1, 1, 1,
118
+ 1, 1, 1, 1, 1, 1, 1, 1,
119
+ 1, 1, 1, 1, 1, 1, 1, 1,
120
+ 1, 1, 1, 1, 1, 1, 1, 1,
121
+ 1, 1, 1, 1, 1, 1, 1, 1,
122
+ 1, 1, 1, 1, 1, 1, 1, 1,
123
+ 1, 1, 1, 1, 1, 1, 1, 1,
124
+ 19, 19, 19, 19, 19, 19, 19, 19,
125
+ 19, 19, 19, 19, 19, 19, 19, 19,
126
+ 19, 19, 19, 19, 19, 19, 19, 19,
127
+ 19, 19, 19, 19, 19, 19, 20, 21,
128
+ 21, 21, 21, 21, 21, 21, 21, 21,
129
+ 21, 21, 21, 22, 21, 21, 23, 24,
130
+ 24, 24, 25, 1, 26, 26, 26, 26,
131
+ 26, 26, 26, 26, 26, 1, 26, 26,
132
+ 27, 26, 26, 26, 26, 26, 26, 26,
133
+ 26, 26, 26, 26, 26, 26, 26, 26,
134
+ 26, 26, 26, 26, 26, 26, 26, 26,
135
+ 26, 26, 26, 28, 29, 26, 26, 26,
136
+ 26, 26, 26, 26, 26, 26, 26, 26,
137
+ 26, 26, 26, 26, 26, 26, 26, 26,
138
+ 26, 26, 26, 26, 26, 26, 26, 26,
139
+ 26, 26, 26, 26, 26, 26, 26, 26,
140
+ 26, 26, 26, 26, 26, 26, 26, 26,
141
+ 26, 26, 26, 26, 26, 26, 26, 30,
142
+ 26, 26, 26, 26, 26, 26, 26, 26,
143
+ 26, 26, 26, 26, 26, 26, 26, 26,
144
+ 26, 26, 26, 26, 26, 26, 26, 26,
145
+ 26, 26, 26, 26, 26, 26, 26, 26,
146
+ 26, 26, 26, 1, 1, 1, 1, 1,
147
+ 1, 1, 1, 1, 1, 1, 1, 1,
148
+ 1, 1, 1, 1, 1, 1, 1, 1,
149
+ 1, 1, 1, 1, 1, 1, 1, 1,
150
+ 1, 1, 1, 1, 1, 1, 1, 1,
151
+ 1, 1, 1, 1, 1, 1, 1, 1,
152
+ 1, 1, 1, 1, 1, 1, 1, 1,
153
+ 1, 1, 1, 1, 1, 1, 1, 1,
154
+ 1, 1, 1, 1, 1, 31, 31, 31,
155
+ 31, 31, 31, 31, 31, 31, 31, 31,
156
+ 31, 31, 31, 31, 31, 31, 31, 31,
157
+ 31, 31, 31, 31, 31, 31, 31, 31,
158
+ 31, 31, 31, 32, 33, 33, 33, 33,
159
+ 33, 33, 33, 33, 33, 33, 33, 33,
160
+ 34, 33, 33, 35, 36, 36, 36, 37,
161
+ 1, 38, 1, 26, 1, 1, 1, 1,
162
+ 1, 1, 1, 1, 1, 1, 1, 1,
163
+ 1, 1, 1, 1, 1, 1, 1, 1,
164
+ 1, 1, 26, 1, 26, 26, 26, 26,
165
+ 26, 26, 26, 26, 26, 26, 26, 26,
166
+ 26, 26, 26, 26, 26, 26, 26, 26,
167
+ 26, 26, 26, 26, 26, 26, 26, 26,
168
+ 26, 26, 26, 26, 26, 26, 26, 26,
169
+ 26, 26, 26, 26, 26, 26, 26, 26,
170
+ 26, 26, 26, 26, 26, 26, 26, 26,
171
+ 26, 26, 26, 26, 26, 26, 26, 26,
172
+ 26, 26, 26, 26, 26, 26, 26, 26,
173
+ 26, 26, 26, 26, 26, 26, 26, 26,
174
+ 26, 26, 26, 26, 26, 26, 26, 26,
175
+ 26, 26, 26, 26, 26, 26, 26, 26,
176
+ 26, 26, 26, 26, 26, 26, 26, 26,
177
+ 26, 26, 26, 26, 26, 26, 26, 26,
178
+ 26, 26, 26, 26, 26, 26, 26, 26,
179
+ 26, 26, 26, 26, 26, 26, 26, 26,
180
+ 26, 26, 26, 26, 1, 1, 1, 1,
181
+ 1, 1, 1, 1, 1, 1, 1, 1,
182
+ 1, 1, 1, 1, 1, 1, 1, 1,
183
+ 1, 1, 1, 1, 1, 1, 1, 1,
184
+ 1, 1, 1, 1, 1, 1, 1, 1,
185
+ 1, 1, 1, 1, 1, 1, 1, 1,
186
+ 1, 1, 1, 1, 1, 1, 1, 1,
187
+ 1, 1, 1, 1, 1, 1, 1, 1,
188
+ 1, 1, 1, 1, 1, 1, 31, 31,
189
+ 31, 31, 31, 31, 31, 31, 31, 31,
190
+ 31, 31, 31, 31, 31, 31, 31, 31,
191
+ 31, 31, 31, 31, 31, 31, 31, 31,
192
+ 31, 31, 31, 31, 32, 33, 33, 33,
193
+ 33, 33, 33, 33, 33, 33, 33, 33,
194
+ 33, 34, 33, 33, 35, 36, 36, 36,
195
+ 37, 1, 26, 26, 26, 26, 26, 26,
196
+ 26, 26, 26, 26, 26, 26, 26, 26,
197
+ 26, 26, 26, 26, 26, 26, 26, 26,
198
+ 26, 26, 26, 26, 26, 26, 26, 26,
199
+ 26, 26, 26, 26, 26, 26, 26, 26,
200
+ 26, 26, 26, 26, 26, 26, 26, 26,
201
+ 26, 26, 26, 26, 26, 26, 26, 26,
202
+ 26, 26, 26, 26, 26, 26, 26, 26,
203
+ 26, 26, 1, 31, 31, 31, 31, 31,
204
+ 31, 31, 31, 31, 31, 31, 31, 31,
205
+ 31, 31, 31, 31, 31, 31, 31, 31,
206
+ 31, 31, 31, 31, 31, 31, 31, 31,
207
+ 31, 31, 31, 1, 31, 31, 31, 31,
208
+ 31, 31, 31, 31, 31, 31, 31, 31,
209
+ 31, 31, 31, 31, 31, 31, 31, 31,
210
+ 31, 31, 31, 31, 31, 31, 31, 31,
211
+ 31, 31, 31, 31, 31, 31, 31, 31,
212
+ 31, 31, 31, 31, 31, 31, 31, 31,
213
+ 31, 31, 31, 31, 31, 31, 31, 31,
214
+ 31, 31, 31, 31, 31, 31, 31, 31,
215
+ 31, 31, 31, 31, 1, 31, 31, 31,
216
+ 31, 31, 31, 31, 31, 31, 31, 31,
217
+ 31, 31, 31, 31, 31, 31, 31, 31,
218
+ 31, 31, 31, 31, 31, 31, 31, 31,
219
+ 31, 31, 31, 31, 31, 1, 33, 33,
220
+ 33, 33, 33, 33, 33, 33, 33, 33,
221
+ 33, 33, 33, 33, 33, 33, 33, 33,
222
+ 33, 33, 33, 33, 33, 33, 33, 33,
223
+ 33, 33, 33, 33, 33, 33, 33, 33,
224
+ 33, 33, 33, 33, 33, 33, 33, 33,
225
+ 33, 33, 33, 33, 33, 33, 1, 33,
226
+ 33, 33, 33, 33, 33, 33, 33, 33,
227
+ 33, 33, 33, 33, 33, 33, 33, 33,
228
+ 33, 33, 33, 33, 33, 33, 33, 33,
229
+ 33, 33, 33, 33, 33, 33, 33, 33,
230
+ 33, 33, 33, 33, 33, 33, 33, 33,
231
+ 33, 33, 33, 33, 33, 33, 33, 33,
232
+ 33, 33, 33, 33, 33, 33, 33, 33,
233
+ 33, 33, 33, 33, 33, 33, 33, 1,
234
+ 33, 33, 33, 33, 33, 33, 33, 33,
235
+ 33, 33, 33, 33, 33, 33, 33, 33,
236
+ 1, 39, 1, 1, 1, 40, 1, 1,
237
+ 1, 1, 1, 1, 1, 1, 1, 1,
238
+ 1, 1, 1, 1, 1, 1, 1, 1,
239
+ 39, 41, 41, 41, 41, 41, 41, 41,
240
+ 42, 1, 41, 41, 41, 41, 41, 1,
241
+ 41, 41, 41, 41, 41, 41, 41, 41,
242
+ 41, 41, 1, 43, 1, 1, 1, 1,
243
+ 1, 41, 41, 41, 41, 41, 41, 41,
244
+ 41, 41, 41, 41, 41, 41, 41, 41,
245
+ 41, 41, 41, 41, 41, 41, 41, 41,
246
+ 41, 41, 41, 1, 1, 1, 41, 41,
247
+ 41, 41, 41, 41, 41, 41, 41, 41,
248
+ 41, 41, 41, 41, 41, 41, 41, 41,
249
+ 41, 41, 41, 41, 41, 41, 41, 41,
250
+ 41, 41, 41, 41, 41, 41, 41, 1,
251
+ 7, 1, 1, 1, 44, 1, 1, 1,
252
+ 1, 1, 1, 1, 1, 1, 1, 1,
253
+ 1, 1, 1, 1, 1, 1, 1, 7,
254
+ 1, 1, 1, 1, 1, 1, 1, 45,
255
+ 1, 1, 1, 1, 1, 1, 1, 1,
256
+ 1, 1, 1, 1, 1, 1, 1, 1,
257
+ 1, 1, 9, 1, 46, 1, 1, 1,
258
+ 47, 1, 1, 1, 1, 1, 1, 1,
259
+ 1, 1, 1, 1, 1, 1, 1, 1,
260
+ 1, 1, 1, 46, 1, 1, 1, 1,
261
+ 1, 1, 1, 48, 1, 1, 1, 1,
262
+ 1, 1, 1, 1, 1, 1, 1, 1,
263
+ 1, 1, 1, 1, 1, 1, 49, 1,
264
+ 9, 1, 1, 1, 50, 1, 1, 1,
265
+ 1, 1, 1, 1, 1, 1, 1, 1,
266
+ 1, 1, 1, 1, 1, 1, 1, 9,
267
+ 1, 1, 1, 1, 1, 1, 1, 51,
268
+ 1, 49, 1, 1, 1, 52, 1, 1,
269
+ 1, 1, 1, 1, 1, 1, 1, 1,
270
+ 1, 1, 1, 1, 1, 1, 1, 1,
271
+ 49, 1, 1, 1, 1, 1, 1, 1,
272
+ 53, 1, 1, 0,
273
+ ]
274
+
275
+ class << self
276
+ attr_accessor :_trans_targs
277
+ private :_trans_targs, :_trans_targs=
278
+ end
279
+ self._trans_targs = [
280
+ 1, 0, 2, 21, 8, 3, 5, 22,
281
+ 7, 24, 1, 2, 21, 8, 10, 11,
282
+ 10, 26, 13, 14, 15, 16, 17, 18,
283
+ 19, 20, 10, 11, 10, 26, 13, 14,
284
+ 15, 16, 17, 18, 19, 20, 12, 22,
285
+ 4, 21, 23, 24, 4, 23, 22, 4,
286
+ 23, 24, 6, 25, 6, 25,
287
+ ]
288
+
289
+ class << self
290
+ attr_accessor :_trans_actions
291
+ private :_trans_actions, :_trans_actions=
292
+ end
293
+ self._trans_actions = [
294
+ 0, 0, 0, 1, 2, 0, 0, 0,
295
+ 0, 0, 3, 3, 4, 5, 6, 6,
296
+ 7, 8, 6, 6, 6, 6, 6, 6,
297
+ 6, 6, 0, 0, 2, 9, 0, 0,
298
+ 0, 0, 0, 0, 0, 0, 0, 10,
299
+ 10, 0, 11, 10, 0, 2, 3, 3,
300
+ 5, 3, 0, 2, 3, 5,
301
+ ]
302
+
303
+ class << self
304
+ attr_accessor :_eof_actions
305
+ private :_eof_actions, :_eof_actions=
306
+ end
307
+ self._eof_actions = [
308
+ 0, 0, 0, 0, 0, 0, 0, 0,
309
+ 0, 0, 0, 0, 0, 0, 0, 0,
310
+ 0, 0, 0, 0, 0, 10, 0, 3,
311
+ 0, 3, 0,
312
+ ]
313
+
314
+ class << self
315
+ attr_accessor :start
316
+ end
317
+ self.start = 1
318
+ class << self
319
+ attr_accessor :first_final
320
+ end
321
+ self.first_final = 21
322
+ class << self
323
+ attr_accessor :error
324
+ end
325
+ self.error = 0
326
+
327
+ class << self
328
+ attr_accessor :en_comment_tail
329
+ end
330
+ self.en_comment_tail = 9
331
+ class << self
332
+ attr_accessor :en_main
333
+ end
334
+ self.en_main = 1
335
+
336
+ def self.parse(data)
337
+ data = data.dup.force_encoding(Encoding::ASCII_8BIT) if data.respond_to?(:force_encoding)
338
+
339
+ content_transfer_encoding = ContentTransferEncodingStruct.new("")
340
+ return content_transfer_encoding if Mail::Utilities.blank?(data)
341
+
342
+ # Parser state
343
+ encoding_s = nil
344
+
345
+ # 5.1 Variables Used by Ragel
346
+ p = 0
347
+ eof = pe = data.length
348
+ stack = []
349
+
350
+ begin
351
+ p ||= 0
352
+ pe ||= data.length
353
+ cs = start
354
+ top = 0
355
+ end
356
+
357
+ begin
358
+ testEof = false
359
+ _slen, _trans, _keys, _inds, _acts, _nacts = nil
360
+ _goto_level = 0
361
+ _resume = 10
362
+ _eof_trans = 15
363
+ _again = 20
364
+ _test_eof = 30
365
+ _out = 40
366
+ while true
367
+ if _goto_level <= 0
368
+ if p == pe
369
+ _goto_level = _test_eof
370
+ next
371
+ end
372
+ if cs == 0
373
+ _goto_level = _out
374
+ next
375
+ end
376
+ end
377
+ if _goto_level <= _resume
378
+ _keys = cs << 1
379
+ _inds = _index_offsets[cs]
380
+ _slen = _key_spans[cs]
381
+ _wide = data[p].ord
382
+ _trans = if (_slen > 0 &&
383
+ _trans_keys[_keys] <= _wide &&
384
+ _wide <= _trans_keys[_keys + 1])
385
+ _indicies[_inds + _wide - _trans_keys[_keys]]
386
+ else
387
+ _indicies[_inds + _slen]
388
+ end
389
+ cs = _trans_targs[_trans]
390
+ if _trans_actions[_trans] != 0
391
+ case _trans_actions[_trans]
392
+ when 1
393
+ begin
394
+ encoding_s = p
395
+ end
396
+ when 10
397
+ begin
398
+ content_transfer_encoding.encoding = chars(data, encoding_s, p - 1).downcase
399
+ end
400
+ when 3
401
+ begin
402
+ end
403
+ when 6
404
+ begin
405
+ end
406
+ when 2
407
+ begin
408
+ begin
409
+ stack[top] = cs
410
+ top += 1
411
+ cs = 9
412
+ _goto_level = _again
413
+ next
414
+ end
415
+ end
416
+ when 9
417
+ begin
418
+ begin
419
+ top -= 1
420
+ cs = stack[top]
421
+ _goto_level = _again
422
+ next
423
+ end
424
+ end
425
+ when 11
426
+ begin
427
+ content_transfer_encoding.encoding = chars(data, encoding_s, p - 1).downcase
428
+ end
429
+ begin
430
+ begin
431
+ stack[top] = cs
432
+ top += 1
433
+ cs = 9
434
+ _goto_level = _again
435
+ next
436
+ end
437
+ end
438
+ when 4
439
+ begin
440
+ end
441
+ begin
442
+ encoding_s = p
443
+ end
444
+ when 5
445
+ begin
446
+ end
447
+ begin
448
+ begin
449
+ stack[top] = cs
450
+ top += 1
451
+ cs = 9
452
+ _goto_level = _again
453
+ next
454
+ end
455
+ end
456
+ when 7
457
+ begin
458
+ end
459
+ begin
460
+ begin
461
+ stack[top] = cs
462
+ top += 1
463
+ cs = 9
464
+ _goto_level = _again
465
+ next
466
+ end
467
+ end
468
+ when 8
469
+ begin
470
+ end
471
+ begin
472
+ begin
473
+ top -= 1
474
+ cs = stack[top]
475
+ _goto_level = _again
476
+ next
477
+ end
478
+ end
479
+ end
480
+ end
481
+ end
482
+ if _goto_level <= _again
483
+ if cs == 0
484
+ _goto_level = _out
485
+ next
486
+ end
487
+ p += 1
488
+ if p != pe
489
+ _goto_level = _resume
490
+ next
491
+ end
492
+ end
493
+ if _goto_level <= _test_eof
494
+ if p == eof
495
+ case _eof_actions[cs]
496
+ when 10
497
+ begin
498
+ content_transfer_encoding.encoding = chars(data, encoding_s, p - 1).downcase
499
+ end
500
+ when 3
501
+ begin
502
+ end
503
+ end
504
+ end
505
+ end
506
+ if _goto_level <= _out
507
+ break
508
+ end
509
+ end
510
+ end
511
+
512
+ if p != eof || cs < 21
513
+ raise Mail::Field::IncompleteParseError.new(Mail::ContentTransferEncodingElement, data, p)
514
+ end
515
+
516
+ content_transfer_encoding
517
+ end
518
+ end
519
+ end
520
+ ensure
521
+ $VERBOSE = original_verbose
522
+ end
@@ -0,0 +1,71 @@
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 content_transfer_encoding;
10
+ alphtype int;
11
+
12
+ action encoding_s { encoding_s = p }
13
+ action encoding_e { content_transfer_encoding.encoding = chars(data, encoding_s, p-1).downcase }
14
+
15
+ # No-op actions
16
+ action comment_e { }
17
+ action comment_s { }
18
+ action phrase_e { }
19
+ action phrase_s { }
20
+ action qstr_e { }
21
+ action qstr_s { }
22
+ action param_attr_e { }
23
+ action param_attr_s { }
24
+ action param_val_e { }
25
+ action param_val_s { }
26
+ action main_type_e { }
27
+ action main_type_s { }
28
+ action sub_type_e { }
29
+ action sub_type_s { }
30
+
31
+ include rfc2045_content_transfer_encoding "rfc2045_content_transfer_encoding.rl";
32
+ main := content_transfer_encoding;
33
+ }%%
34
+
35
+ module Mail::Parsers
36
+ module ContentTransferEncodingParser
37
+ extend Mail::ParserTools
38
+
39
+ ContentTransferEncodingStruct = Struct.new(:encoding, :error)
40
+
41
+ %%write data noprefix;
42
+
43
+ def self.parse(data)
44
+ data = data.dup.force_encoding(Encoding::ASCII_8BIT) if data.respond_to?(:force_encoding)
45
+
46
+ content_transfer_encoding = ContentTransferEncodingStruct.new('')
47
+ return content_transfer_encoding if Mail::Utilities.blank?(data)
48
+
49
+ # Parser state
50
+ encoding_s = nil
51
+
52
+ # 5.1 Variables Used by Ragel
53
+ p = 0
54
+ eof = pe = data.length
55
+ stack = []
56
+
57
+ %%write init;
58
+ %%write exec;
59
+
60
+ if p != eof || cs < %%{ write first_final; }%%
61
+ raise Mail::Field::IncompleteParseError.new(Mail::ContentTransferEncodingElement, data, p)
62
+ end
63
+
64
+ content_transfer_encoding
65
+ end
66
+ end
67
+ end
68
+
69
+ ensure
70
+ $VERBOSE = original_verbose
71
+ end