mail 2.6.4 → 2.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +111 -118
  3. data/lib/mail/attachments_list.rb +11 -10
  4. data/lib/mail/body.rb +73 -84
  5. data/lib/mail/check_delivery_params.rb +54 -10
  6. data/lib/mail/configuration.rb +2 -0
  7. data/lib/mail/constants.rb +27 -5
  8. data/lib/mail/elements/address.rb +61 -50
  9. data/lib/mail/elements/address_list.rb +11 -19
  10. data/lib/mail/elements/content_disposition_element.rb +9 -16
  11. data/lib/mail/elements/content_location_element.rb +6 -11
  12. data/lib/mail/elements/content_transfer_encoding_element.rb +6 -11
  13. data/lib/mail/elements/content_type_element.rb +16 -23
  14. data/lib/mail/elements/date_time_element.rb +7 -15
  15. data/lib/mail/elements/envelope_from_element.rb +22 -23
  16. data/lib/mail/elements/message_ids_element.rb +18 -13
  17. data/lib/mail/elements/mime_version_element.rb +7 -15
  18. data/lib/mail/elements/phrase_list.rb +12 -10
  19. data/lib/mail/elements/received_element.rb +27 -19
  20. data/lib/mail/encodings/7bit.rb +9 -14
  21. data/lib/mail/encodings/8bit.rb +2 -21
  22. data/lib/mail/encodings/base64.rb +11 -12
  23. data/lib/mail/encodings/binary.rb +3 -22
  24. data/lib/mail/encodings/identity.rb +24 -0
  25. data/lib/mail/encodings/quoted_printable.rb +6 -6
  26. data/lib/mail/encodings/transfer_encoding.rb +38 -29
  27. data/lib/mail/encodings/unix_to_unix.rb +3 -1
  28. data/lib/mail/encodings.rb +81 -54
  29. data/lib/mail/envelope.rb +11 -14
  30. data/lib/mail/field.rb +119 -98
  31. data/lib/mail/field_list.rb +60 -7
  32. data/lib/mail/fields/bcc_field.rb +34 -52
  33. data/lib/mail/fields/cc_field.rb +28 -49
  34. data/lib/mail/fields/comments_field.rb +27 -37
  35. data/lib/mail/fields/common_address_field.rb +170 -0
  36. data/lib/mail/fields/common_date_field.rb +58 -0
  37. data/lib/mail/fields/common_field.rb +77 -0
  38. data/lib/mail/fields/common_message_id_field.rb +42 -0
  39. data/lib/mail/fields/content_description_field.rb +7 -14
  40. data/lib/mail/fields/content_disposition_field.rb +13 -38
  41. data/lib/mail/fields/content_id_field.rb +24 -51
  42. data/lib/mail/fields/content_location_field.rb +11 -25
  43. data/lib/mail/fields/content_transfer_encoding_field.rb +31 -31
  44. data/lib/mail/fields/content_type_field.rb +50 -80
  45. data/lib/mail/fields/date_field.rb +23 -52
  46. data/lib/mail/fields/from_field.rb +28 -49
  47. data/lib/mail/fields/in_reply_to_field.rb +38 -49
  48. data/lib/mail/fields/keywords_field.rb +18 -31
  49. data/lib/mail/fields/message_id_field.rb +25 -71
  50. data/lib/mail/fields/mime_version_field.rb +19 -30
  51. data/lib/mail/fields/named_structured_field.rb +11 -0
  52. data/lib/mail/fields/named_unstructured_field.rb +11 -0
  53. data/lib/mail/fields/optional_field.rb +9 -7
  54. data/lib/mail/fields/{common/parameter_hash.rb → parameter_hash.rb} +13 -11
  55. data/lib/mail/fields/received_field.rb +43 -57
  56. data/lib/mail/fields/references_field.rb +35 -49
  57. data/lib/mail/fields/reply_to_field.rb +28 -49
  58. data/lib/mail/fields/resent_bcc_field.rb +28 -49
  59. data/lib/mail/fields/resent_cc_field.rb +28 -49
  60. data/lib/mail/fields/resent_date_field.rb +5 -30
  61. data/lib/mail/fields/resent_from_field.rb +28 -49
  62. data/lib/mail/fields/resent_message_id_field.rb +5 -29
  63. data/lib/mail/fields/resent_sender_field.rb +27 -56
  64. data/lib/mail/fields/resent_to_field.rb +28 -49
  65. data/lib/mail/fields/return_path_field.rb +50 -54
  66. data/lib/mail/fields/sender_field.rb +34 -55
  67. data/lib/mail/fields/structured_field.rb +3 -30
  68. data/lib/mail/fields/subject_field.rb +9 -11
  69. data/lib/mail/fields/to_field.rb +28 -49
  70. data/lib/mail/fields/unstructured_field.rb +32 -47
  71. data/lib/mail/header.rb +71 -110
  72. data/lib/mail/mail.rb +2 -10
  73. data/lib/mail/matchers/attachment_matchers.rb +15 -0
  74. data/lib/mail/matchers/has_sent_mail.rb +21 -1
  75. data/lib/mail/message.rb +113 -117
  76. data/lib/mail/multibyte/chars.rb +23 -180
  77. data/lib/mail/multibyte/unicode.rb +10 -10
  78. data/lib/mail/multibyte/utils.rb +26 -43
  79. data/lib/mail/multibyte.rb +55 -16
  80. data/lib/mail/network/delivery_methods/exim.rb +8 -11
  81. data/lib/mail/network/delivery_methods/file_delivery.rb +13 -16
  82. data/lib/mail/network/delivery_methods/logger_delivery.rb +34 -0
  83. data/lib/mail/network/delivery_methods/sendmail.rb +32 -35
  84. data/lib/mail/network/delivery_methods/smtp.rb +76 -54
  85. data/lib/mail/network/delivery_methods/smtp_connection.rb +4 -9
  86. data/lib/mail/network/delivery_methods/test_mailer.rb +8 -9
  87. data/lib/mail/network/retriever_methods/base.rb +8 -8
  88. data/lib/mail/network/retriever_methods/imap.rb +20 -7
  89. data/lib/mail/network/retriever_methods/pop3.rb +5 -3
  90. data/lib/mail/network/retriever_methods/test_retriever.rb +3 -2
  91. data/lib/mail/network.rb +1 -0
  92. data/lib/mail/parser_tools.rb +15 -0
  93. data/lib/mail/parsers/address_lists_parser.rb +33225 -116
  94. data/lib/mail/parsers/address_lists_parser.rl +179 -0
  95. data/lib/mail/parsers/content_disposition_parser.rb +882 -49
  96. data/lib/mail/parsers/content_disposition_parser.rl +89 -0
  97. data/lib/mail/parsers/content_location_parser.rb +809 -23
  98. data/lib/mail/parsers/content_location_parser.rl +78 -0
  99. data/lib/mail/parsers/content_transfer_encoding_parser.rb +509 -21
  100. data/lib/mail/parsers/content_transfer_encoding_parser.rl +71 -0
  101. data/lib/mail/parsers/content_type_parser.rb +1037 -56
  102. data/lib/mail/parsers/content_type_parser.rl +90 -0
  103. data/lib/mail/parsers/date_time_parser.rb +877 -25
  104. data/lib/mail/parsers/date_time_parser.rl +69 -0
  105. data/lib/mail/parsers/envelope_from_parser.rb +3669 -40
  106. data/lib/mail/parsers/envelope_from_parser.rl +89 -0
  107. data/lib/mail/parsers/message_ids_parser.rb +5146 -25
  108. data/lib/mail/parsers/message_ids_parser.rl +93 -0
  109. data/lib/mail/parsers/mime_version_parser.rb +497 -26
  110. data/lib/mail/parsers/mime_version_parser.rl +68 -0
  111. data/lib/mail/parsers/phrase_lists_parser.rb +870 -22
  112. data/lib/mail/parsers/phrase_lists_parser.rl +90 -0
  113. data/lib/mail/parsers/received_parser.rb +8776 -43
  114. data/lib/mail/parsers/received_parser.rl +91 -0
  115. data/lib/mail/parsers/rfc2045_content_transfer_encoding.rl +13 -0
  116. data/lib/mail/parsers/rfc2045_content_type.rl +25 -0
  117. data/lib/mail/parsers/rfc2045_mime.rl +16 -0
  118. data/lib/mail/parsers/rfc2183_content_disposition.rl +15 -0
  119. data/lib/mail/parsers/rfc3629_utf8.rl +19 -0
  120. data/lib/mail/parsers/rfc5234_abnf_core_rules.rl +22 -0
  121. data/lib/mail/parsers/rfc5322.rl +74 -0
  122. data/lib/mail/parsers/rfc5322_address.rl +72 -0
  123. data/lib/mail/parsers/{ragel/date_time.rl → rfc5322_date_time.rl} +8 -1
  124. data/lib/mail/parsers/rfc5322_lexical_tokens.rl +60 -0
  125. data/lib/mail/parsers.rb +11 -25
  126. data/lib/mail/part.rb +6 -10
  127. data/lib/mail/parts_list.rb +62 -6
  128. data/lib/mail/smtp_envelope.rb +57 -0
  129. data/lib/mail/utilities.rb +357 -74
  130. data/lib/mail/version.rb +2 -2
  131. data/lib/mail/yaml.rb +30 -0
  132. data/lib/mail.rb +5 -35
  133. metadata +111 -66
  134. data/CHANGELOG.rdoc +0 -787
  135. data/CONTRIBUTING.md +0 -60
  136. data/Dependencies.txt +0 -2
  137. data/Gemfile +0 -11
  138. data/Rakefile +0 -29
  139. data/TODO.rdoc +0 -9
  140. data/lib/mail/core_extensions/smtp.rb +0 -25
  141. data/lib/mail/core_extensions/string/access.rb +0 -146
  142. data/lib/mail/core_extensions/string/multibyte.rb +0 -79
  143. data/lib/mail/core_extensions/string.rb +0 -21
  144. data/lib/mail/fields/common/address_container.rb +0 -17
  145. data/lib/mail/fields/common/common_address.rb +0 -136
  146. data/lib/mail/fields/common/common_date.rb +0 -36
  147. data/lib/mail/fields/common/common_field.rb +0 -61
  148. data/lib/mail/fields/common/common_message_id.rb +0 -49
  149. data/lib/mail/multibyte/exceptions.rb +0 -9
  150. data/lib/mail/parsers/ragel/common.rl +0 -185
  151. data/lib/mail/parsers/ragel/parser_info.rb +0 -61
  152. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb +0 -14864
  153. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl +0 -37
  154. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb +0 -751
  155. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl +0 -37
  156. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb +0 -614
  157. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl +0 -37
  158. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb +0 -447
  159. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl +0 -37
  160. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb +0 -825
  161. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl +0 -37
  162. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb +0 -817
  163. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl +0 -37
  164. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb +0 -2149
  165. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl +0 -37
  166. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb +0 -1570
  167. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl +0 -37
  168. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb +0 -440
  169. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl +0 -37
  170. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb +0 -564
  171. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl +0 -37
  172. data/lib/mail/parsers/ragel/ruby/machines/rb_actions.rl +0 -51
  173. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb +0 -5144
  174. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl +0 -37
  175. data/lib/mail/parsers/ragel/ruby/parser.rb.rl.erb +0 -37
  176. data/lib/mail/parsers/ragel/ruby.rb +0 -40
  177. data/lib/mail/parsers/ragel.rb +0 -18
  178. data/lib/mail/version_specific/ruby_1_8.rb +0 -126
  179. data/lib/mail/version_specific/ruby_1_9.rb +0 -223
@@ -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
@@ -1,34 +1,522 @@
1
+
1
2
  # frozen_string_literal: true
2
- module Mail::Parsers
3
- class ContentTransferEncodingParser
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)
4
14
 
5
- def parse(s)
6
- content_transfer_encoding = ContentTransferEncodingStruct.new("")
7
- if Mail::Utilities.blank?(s)
8
- return content_transfer_encoding
15
+ class << self
16
+ attr_accessor :_trans_keys
17
+ private :_trans_keys, :_trans_keys=
9
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
+ ]
10
32
 
11
- actions, error = Ragel.parse(:content_transfer_encoding, s)
12
- if error
13
- raise Mail::Field::ParseError.new(Mail::ContentTransferEncodingElement, s, error)
33
+ class << self
34
+ attr_accessor :_key_spans
35
+ private :_key_spans, :_key_spans=
14
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
+ ]
15
43
 
16
- encoding_s = nil
17
- actions.each_slice(2) do |action_id, p|
18
- action = Mail::Parsers::Ragel::ACTIONS[action_id]
19
- case action
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
+ ]
20
54
 
21
- # Encoding
22
- when :encoding_s then encoding_s = p
23
- when :encoding_e
24
- content_transfer_encoding.encoding = s[encoding_s..(p-1)].downcase
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
+ ]
25
274
 
26
- else
27
- raise Mail::Field::ParseError.new(Mail::ContentTransferEncodingElement, s, "Failed to process unknown action: #{action}")
28
- end
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
29
324
  end
325
+ self.error = 0
30
326
 
31
- content_transfer_encoding
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
32
518
  end
33
519
  end
520
+ ensure
521
+ $VERBOSE = original_verbose
34
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