mail 2.6.6 → 2.7.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.
Files changed (160) hide show
  1. checksums.yaml +5 -5
  2. data/MIT-LICENSE +1 -1
  3. data/README.md +74 -90
  4. data/lib/mail/attachments_list.rb +8 -4
  5. data/lib/mail/body.rb +50 -38
  6. data/lib/mail/check_delivery_params.rb +8 -6
  7. data/lib/mail/configuration.rb +2 -0
  8. data/lib/mail/constants.rb +1 -1
  9. data/lib/mail/core_extensions/smtp.rb +19 -16
  10. data/lib/mail/core_extensions/string.rb +0 -4
  11. data/lib/mail/elements/address.rb +28 -22
  12. data/lib/mail/elements/address_list.rb +10 -18
  13. data/lib/mail/elements/content_disposition_element.rb +8 -15
  14. data/lib/mail/elements/content_location_element.rb +5 -10
  15. data/lib/mail/elements/content_transfer_encoding_element.rb +5 -10
  16. data/lib/mail/elements/content_type_element.rb +8 -19
  17. data/lib/mail/elements/date_time_element.rb +6 -14
  18. data/lib/mail/elements/envelope_from_element.rb +14 -21
  19. data/lib/mail/elements/message_ids_element.rb +8 -12
  20. data/lib/mail/elements/mime_version_element.rb +6 -14
  21. data/lib/mail/elements/phrase_list.rb +6 -9
  22. data/lib/mail/elements/received_element.rb +9 -15
  23. data/lib/mail/encodings/7bit.rb +5 -15
  24. data/lib/mail/encodings/8bit.rb +2 -21
  25. data/lib/mail/encodings/base64.rb +11 -12
  26. data/lib/mail/encodings/binary.rb +3 -22
  27. data/lib/mail/encodings/identity.rb +24 -0
  28. data/lib/mail/encodings/quoted_printable.rb +6 -6
  29. data/lib/mail/encodings/transfer_encoding.rb +38 -29
  30. data/lib/mail/encodings/unix_to_unix.rb +3 -1
  31. data/lib/mail/encodings.rb +99 -43
  32. data/lib/mail/envelope.rb +1 -1
  33. data/lib/mail/field.rb +96 -59
  34. data/lib/mail/fields/bcc_field.rb +2 -2
  35. data/lib/mail/fields/cc_field.rb +1 -1
  36. data/lib/mail/fields/comments_field.rb +1 -1
  37. data/lib/mail/fields/common/common_address.rb +32 -7
  38. data/lib/mail/fields/common/common_field.rb +1 -10
  39. data/lib/mail/fields/common/parameter_hash.rb +1 -1
  40. data/lib/mail/fields/content_description_field.rb +1 -1
  41. data/lib/mail/fields/content_disposition_field.rb +3 -3
  42. data/lib/mail/fields/content_id_field.rb +2 -2
  43. data/lib/mail/fields/content_location_field.rb +1 -1
  44. data/lib/mail/fields/content_transfer_encoding_field.rb +1 -1
  45. data/lib/mail/fields/content_type_field.rb +4 -9
  46. data/lib/mail/fields/date_field.rb +2 -3
  47. data/lib/mail/fields/from_field.rb +1 -1
  48. data/lib/mail/fields/in_reply_to_field.rb +1 -1
  49. data/lib/mail/fields/keywords_field.rb +1 -1
  50. data/lib/mail/fields/message_id_field.rb +1 -1
  51. data/lib/mail/fields/mime_version_field.rb +1 -1
  52. data/lib/mail/fields/optional_field.rb +4 -1
  53. data/lib/mail/fields/received_field.rb +1 -1
  54. data/lib/mail/fields/references_field.rb +1 -1
  55. data/lib/mail/fields/reply_to_field.rb +1 -1
  56. data/lib/mail/fields/resent_bcc_field.rb +1 -1
  57. data/lib/mail/fields/resent_cc_field.rb +1 -1
  58. data/lib/mail/fields/resent_date_field.rb +0 -1
  59. data/lib/mail/fields/resent_from_field.rb +1 -1
  60. data/lib/mail/fields/resent_message_id_field.rb +1 -1
  61. data/lib/mail/fields/resent_sender_field.rb +1 -1
  62. data/lib/mail/fields/resent_to_field.rb +1 -1
  63. data/lib/mail/fields/return_path_field.rb +1 -1
  64. data/lib/mail/fields/sender_field.rb +1 -1
  65. data/lib/mail/fields/subject_field.rb +1 -1
  66. data/lib/mail/fields/to_field.rb +1 -1
  67. data/lib/mail/fields/unstructured_field.rb +21 -4
  68. data/lib/mail/header.rb +10 -8
  69. data/lib/mail/mail.rb +2 -10
  70. data/lib/mail/matchers/has_sent_mail.rb +21 -1
  71. data/lib/mail/message.rb +78 -68
  72. data/lib/mail/multibyte/chars.rb +29 -28
  73. data/lib/mail/multibyte/unicode.rb +10 -10
  74. data/lib/mail/multibyte.rb +64 -15
  75. data/lib/mail/network/delivery_methods/logger_delivery.rb +37 -0
  76. data/lib/mail/network/delivery_methods/sendmail.rb +8 -5
  77. data/lib/mail/network/delivery_methods/smtp.rb +58 -49
  78. data/lib/mail/network/delivery_methods/smtp_connection.rb +9 -1
  79. data/lib/mail/network/retriever_methods/imap.rb +18 -5
  80. data/lib/mail/network/retriever_methods/pop3.rb +3 -1
  81. data/lib/mail/network.rb +1 -0
  82. data/lib/mail/parser_tools.rb +15 -0
  83. data/lib/mail/parsers/address_lists_parser.rb +33207 -104
  84. data/lib/mail/parsers/address_lists_parser.rl +172 -0
  85. data/lib/mail/parsers/content_disposition_parser.rb +876 -49
  86. data/lib/mail/parsers/content_disposition_parser.rl +82 -0
  87. data/lib/mail/parsers/content_location_parser.rb +803 -23
  88. data/lib/mail/parsers/content_location_parser.rl +71 -0
  89. data/lib/mail/parsers/content_transfer_encoding_parser.rb +501 -19
  90. data/lib/mail/parsers/content_transfer_encoding_parser.rl +64 -0
  91. data/lib/mail/parsers/content_type_parser.rb +1023 -48
  92. data/lib/mail/parsers/content_type_parser.rl +83 -0
  93. data/lib/mail/parsers/date_time_parser.rb +870 -24
  94. data/lib/mail/parsers/date_time_parser.rl +62 -0
  95. data/lib/mail/parsers/envelope_from_parser.rb +3569 -34
  96. data/lib/mail/parsers/envelope_from_parser.rl +82 -0
  97. data/lib/mail/parsers/message_ids_parser.rb +2839 -25
  98. data/lib/mail/parsers/message_ids_parser.rl +82 -0
  99. data/lib/mail/parsers/mime_version_parser.rb +491 -26
  100. data/lib/mail/parsers/mime_version_parser.rl +61 -0
  101. data/lib/mail/parsers/phrase_lists_parser.rb +860 -18
  102. data/lib/mail/parsers/phrase_lists_parser.rl +83 -0
  103. data/lib/mail/parsers/received_parser.rb +8764 -37
  104. data/lib/mail/parsers/received_parser.rl +84 -0
  105. data/lib/mail/parsers/rfc2045_content_transfer_encoding.rl +13 -0
  106. data/lib/mail/parsers/rfc2045_content_type.rl +25 -0
  107. data/lib/mail/parsers/rfc2045_mime.rl +16 -0
  108. data/lib/mail/parsers/rfc2183_content_disposition.rl +15 -0
  109. data/lib/mail/parsers/rfc3629_utf8.rl +19 -0
  110. data/lib/mail/parsers/rfc5234_abnf_core_rules.rl +22 -0
  111. data/lib/mail/parsers/rfc5322.rl +59 -0
  112. data/lib/mail/parsers/rfc5322_address.rl +72 -0
  113. data/lib/mail/parsers/{ragel/date_time.rl → rfc5322_date_time.rl} +8 -1
  114. data/lib/mail/parsers/rfc5322_lexical_tokens.rl +60 -0
  115. data/lib/mail/parsers.rb +16 -24
  116. data/lib/mail/part.rb +3 -3
  117. data/lib/mail/parts_list.rb +5 -6
  118. data/lib/mail/utilities.rb +59 -28
  119. data/lib/mail/version.rb +2 -2
  120. data/lib/mail/version_specific/ruby_1_8.rb +40 -3
  121. data/lib/mail/version_specific/ruby_1_9.rb +61 -9
  122. data/lib/mail.rb +3 -16
  123. metadata +44 -53
  124. data/CHANGELOG.rdoc +0 -803
  125. data/CONTRIBUTING.md +0 -60
  126. data/Dependencies.txt +0 -2
  127. data/Gemfile +0 -14
  128. data/Rakefile +0 -29
  129. data/TODO.rdoc +0 -9
  130. data/lib/mail/core_extensions/string/access.rb +0 -146
  131. data/lib/mail/core_extensions/string/multibyte.rb +0 -79
  132. data/lib/mail/multibyte/exceptions.rb +0 -9
  133. data/lib/mail/parsers/ragel/common.rl +0 -185
  134. data/lib/mail/parsers/ragel/parser_info.rb +0 -61
  135. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb +0 -14864
  136. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl +0 -37
  137. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb +0 -751
  138. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl +0 -37
  139. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb +0 -614
  140. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl +0 -37
  141. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb +0 -447
  142. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl +0 -37
  143. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb +0 -825
  144. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl +0 -37
  145. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb +0 -817
  146. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl +0 -37
  147. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb +0 -2149
  148. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl +0 -37
  149. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb +0 -1570
  150. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl +0 -37
  151. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb +0 -440
  152. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl +0 -37
  153. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb +0 -564
  154. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl +0 -37
  155. data/lib/mail/parsers/ragel/ruby/machines/rb_actions.rl +0 -51
  156. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb +0 -5144
  157. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl +0 -37
  158. data/lib/mail/parsers/ragel/ruby/parser.rb.rl.erb +0 -37
  159. data/lib/mail/parsers/ragel/ruby.rb +0 -40
  160. data/lib/mail/parsers/ragel.rb +0 -18
data/CONTRIBUTING.md DELETED
@@ -1,60 +0,0 @@
1
- Contributing to Mail
2
- ====================
3
-
4
- Hi there, I welcome pull requests! Here are some thoughts on how to get your
5
- pull request merged quickly:
6
-
7
- 1. Check the Reference RFCs, they are in the References directory, so no excuses.
8
- 2. Check for a ticket on GitHub, maybe someone else has the problem too
9
- 3. Make a fork of my GitHub repository
10
- 4. Run the specs. We only take pull requests with passing tests, and it's great
11
- to know that you have a clean slate: `bundle && bundle exec rake`
12
- 5. Add a spec for your change. Only refactoring and documentation changes
13
- require no new specs. If you are adding functionality or fixing a bug, we need
14
- a spec!
15
- 6. Test the spec _at_ _least_ against MRI-1.9.3 and MRI-1.8.7
16
- 7. Update the README if needed to reflect your change / addition
17
- 8. Update the CHANGELOG and give yourself credit
18
- 9. With all specs passing push your changes back to your fork
19
- 10. Send me a pull request.
20
- - If it needs any changes, please push or force push to the same branch you made the pull request from. GitHub will just update the pull request with your changes.
21
-
22
- Note, specs that break MRI 1.8.7 or 1.9.3 will not be accepted.
23
-
24
- At this point you're waiting on us. We like to at least comment on, if not
25
- accept, pull requests within three business days (and, typically, one business
26
- day). We may suggest some changes or improvements or alternatives.
27
-
28
- Some things that will increase the chance that your pull request is accepted,
29
- taken straight from the Ruby on Rails guide:
30
-
31
- * Tell me you have tested it against more than one version of Ruby, RVM is great for
32
- this. I test against 7 rubies before I push into master.
33
- * Use good, idiomatic, structured and modular code
34
- * Include tests that fail without your code, and pass with it
35
- * Update the documentation, the surrounding one, examples elsewhere, guides,
36
- whatever is affected by your contribution
37
-
38
- Syntax:
39
-
40
- * Two spaces, no tabs.
41
- * No trailing whitespace. Blank lines should not have any space.
42
- * Prefer &&/|| over and/or.
43
- * MyClass.my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
44
- * a = b and not a=b.
45
- * Follow the conventions you see used in the source already.
46
-
47
- And in case we didn't emphasize it enough: we love specs!
48
-
49
- ### Testing against mime-types versions:
50
-
51
- Use [appraisal](https://github.com/thoughtbot/appraisal) to run against all supported versions of mime-types.
52
-
53
- 1. Run `(bundle check || bundle) && appraisal` so that all the 'appraised' gemfiles are bundled.
54
- 2. Run either `appraisal rake` or `rake appraisal` to run all the tests.
55
-
56
- To run only one 'appraised' gemfile, run. e.g. `BUNDLE_GEMFILE=gemfiles/mime_types_edge.gemfile (bundle check || bundle) && rake`
57
-
58
- To change the appraisals, modify the `Appraisals` file, run `appraisal`, commit the generated gemfiles, and modify the .travis.yml matrix.
59
-
60
- To run on all rubies / gemfiles, just like TravisCI, see [WWTD](https://github.com/grosser/wwtd).
data/Dependencies.txt DELETED
@@ -1,2 +0,0 @@
1
- tlsmail: if ruby < 1.8.6... we could make it optional, or embed it in Mail
2
- mime/types: I think we embed a simplified version, or help maintain it, it is old (2006)
data/Gemfile DELETED
@@ -1,14 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
4
-
5
- gem 'tlsmail', '~> 0.0.1' if RUBY_VERSION <= '1.8.6'
6
- gem 'jruby-openssl', :platforms => :jruby
7
- gem 'rake', '< 11.0', :platforms => :ruby_18
8
- gem 'rdoc', '< 4.3', :platforms => [ :ruby_18, :ruby_19 ]
9
- gem 'mime-types', '< 2.0', :platforms => [ :ruby_18, :ruby_19 ]
10
-
11
- # For gems not required to run tests
12
- group :local_development, :test do
13
- gem 'appraisal', '~> 1.0' unless RUBY_VERSION < '1.9'
14
- end
data/Rakefile DELETED
@@ -1,29 +0,0 @@
1
- if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
2
- ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __FILE__)
3
- end
4
- require 'rubygems'
5
- require 'bundler/setup'
6
-
7
- require 'rake/testtask'
8
- require 'rspec/core/rake_task'
9
-
10
- desc "Build a gem file"
11
- task :build do
12
- system "gem build mail.gemspec"
13
- end
14
-
15
- task :default => :spec
16
-
17
- RSpec::Core::RakeTask.new(:spec) do |t|
18
- t.ruby_opts = '-w'
19
- t.rspec_opts = %w(--backtrace --color)
20
- end
21
-
22
- begin
23
- require "appraisal"
24
- rescue LoadError, SyntaxError
25
- warn "Appraisal is only available in test/development on Ruby 1.9+"
26
- end
27
-
28
- # load custom rake tasks
29
- Dir["#{File.dirname(__FILE__)}/tasks/**/*.rake"].sort.each { |ext| load ext }
data/TODO.rdoc DELETED
@@ -1,9 +0,0 @@
1
- == Not really in any order:
2
-
3
- * Add multibyte handling to fields, if they get a multibyte string, try encoding it into
4
- UTF-8 B first, if this fails, throw an error.
5
-
6
- * Cleanup the treetop parsers......... do I _really_ need that many entrance files?
7
-
8
- * Simplify the relationship of Headers and Fields. Doing too much of the Field work
9
- in the Header class on instantiating fields. Header should just say "Field, do it!"
@@ -1,146 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- # This is not loaded if ActiveSupport is already loaded
5
-
6
- # This is an almost cut and paste from ActiveSupport v3.0.6, copied in here so that Mail
7
- # itself does not depend on ActiveSupport to avoid versioning conflicts
8
-
9
- class String
10
- unless '1.9'.respond_to?(:force_encoding)
11
- # Returns the character at the +position+ treating the string as an array (where 0 is the first character).
12
- #
13
- # Examples:
14
- # "hello".at(0) # => "h"
15
- # "hello".at(4) # => "o"
16
- # "hello".at(10) # => ERROR if < 1.9, nil in 1.9
17
- def at(position)
18
- mb_chars[position, 1].to_s
19
- end
20
-
21
- # Returns the remaining of the string from the +position+ treating the string as an array (where 0 is the first character).
22
- #
23
- # Examples:
24
- # "hello".from(0) # => "hello"
25
- # "hello".from(2) # => "llo"
26
- # "hello".from(10) # => "" if < 1.9, nil in 1.9
27
- def from(position)
28
- mb_chars[position..-1].to_s
29
- end
30
-
31
- # Returns the beginning of the string up to the +position+ treating the string as an array (where 0 is the first character).
32
- #
33
- # Examples:
34
- # "hello".to(0) # => "h"
35
- # "hello".to(2) # => "hel"
36
- # "hello".to(10) # => "hello"
37
- def to(position)
38
- mb_chars[0..position].to_s
39
- end
40
-
41
- # Returns the first character of the string or the first +limit+ characters.
42
- #
43
- # Examples:
44
- # "hello".first # => "h"
45
- # "hello".first(2) # => "he"
46
- # "hello".first(10) # => "hello"
47
- def first(limit = 1)
48
- if limit == 0
49
- ''
50
- elsif limit >= size
51
- self
52
- else
53
- mb_chars[0...limit].to_s
54
- end
55
- end
56
-
57
- # Returns the last character of the string or the last +limit+ characters.
58
- #
59
- # Examples:
60
- # "hello".last # => "o"
61
- # "hello".last(2) # => "lo"
62
- # "hello".last(10) # => "hello"
63
- def last(limit = 1)
64
- if limit == 0
65
- ''
66
- elsif limit >= size
67
- self
68
- else
69
- mb_chars[(-limit)..-1].to_s
70
- end
71
- end
72
- else
73
- def at(position)
74
- self[position]
75
- end
76
-
77
- def from(position)
78
- self[position..-1]
79
- end
80
-
81
- def to(position)
82
- self[0..position]
83
- end
84
-
85
- def first(limit = 1)
86
- if limit == 0
87
- ''
88
- elsif limit >= size
89
- self
90
- else
91
- to(limit - 1)
92
- end
93
- end
94
-
95
- def last(limit = 1)
96
- if limit == 0
97
- ''
98
- elsif limit >= size
99
- self
100
- else
101
- from(-limit)
102
- end
103
- end
104
- end
105
-
106
- if Module.method(:const_get).arity == 1
107
- # Tries to find a constant with the name specified in the argument string:
108
- #
109
- # "Module".constantize # => Module
110
- # "Test::Unit".constantize # => Test::Unit
111
- #
112
- # The name is assumed to be the one of a top-level constant, no matter whether
113
- # it starts with "::" or not. No lexical context is taken into account:
114
- #
115
- # C = 'outside'
116
- # module M
117
- # C = 'inside'
118
- # C # => 'inside'
119
- # "C".constantize # => 'outside', same as ::C
120
- # end
121
- #
122
- # NameError is raised when the name is not in CamelCase or the constant is
123
- # unknown.
124
- def constantize
125
- names = self.split('::')
126
- names.shift if names.empty? || names.first.empty?
127
-
128
- constant = Object
129
- names.each do |name|
130
- constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
131
- end
132
- constant
133
- end
134
- else
135
- def constantize #:nodoc:
136
- names = self.split('::')
137
- names.shift if names.empty? || names.first.empty?
138
-
139
- constant = Object
140
- names.each do |name|
141
- constant = constant.const_defined?(name, false) ? constant.const_get(name) : constant.const_missing(name)
142
- end
143
- constant
144
- end
145
- end
146
- end
@@ -1,79 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- # This is not loaded if ActiveSupport is already loaded
5
-
6
- # This is an almost cut and paste from ActiveSupport v3.0.6, copied in here so that Mail
7
- # itself does not depend on ActiveSupport to avoid versioning conflicts
8
-
9
- require 'mail/multibyte'
10
-
11
- class String
12
- if RUBY_VERSION >= "1.9"
13
- # == Multibyte proxy
14
- #
15
- # +mb_chars+ is a multibyte safe proxy for string methods.
16
- #
17
- # In Ruby 1.8 and older it creates and returns an instance of the Mail::Multibyte::Chars class which
18
- # encapsulates the original string. A Unicode safe version of all the String methods are defined on this proxy
19
- # class. If the proxy class doesn't respond to a certain method, it's forwarded to the encapsuled string.
20
- #
21
- # name = 'Claus Müller'
22
- # name.reverse # => "rell??M sualC"
23
- # name.length # => 13
24
- #
25
- # name.mb_chars.reverse.to_s # => "rellüM sualC"
26
- # name.mb_chars.length # => 12
27
- #
28
- # In Ruby 1.9 and newer +mb_chars+ returns +self+ because String is (mostly) encoding aware. This means that
29
- # it becomes easy to run one version of your code on multiple Ruby versions.
30
- #
31
- # == Method chaining
32
- #
33
- # All the methods on the Chars proxy which normally return a string will return a Chars object. This allows
34
- # method chaining on the result of any of these methods.
35
- #
36
- # name.mb_chars.reverse.length # => 12
37
- #
38
- # == Interoperability and configuration
39
- #
40
- # The Chars object tries to be as interchangeable with String objects as possible: sorting and comparing between
41
- # String and Char work like expected. The bang! methods change the internal string representation in the Chars
42
- # object. Interoperability problems can be resolved easily with a +to_s+ call.
43
- #
44
- # For more information about the methods defined on the Chars proxy see Mail::Multibyte::Chars. For
45
- # information about how to change the default Multibyte behaviour see Mail::Multibyte.
46
- def mb_chars
47
- if Mail::Multibyte.proxy_class.consumes?(self)
48
- Mail::Multibyte.proxy_class.new(self)
49
- else
50
- self
51
- end
52
- end
53
-
54
- def is_utf8? #:nodoc
55
- case encoding
56
- when Encoding::UTF_8
57
- valid_encoding?
58
- when Encoding::ASCII_8BIT, Encoding::US_ASCII
59
- dup.force_encoding(Encoding::UTF_8).valid_encoding?
60
- else
61
- false
62
- end
63
- end
64
- else
65
- def mb_chars
66
- if Mail::Multibyte.proxy_class.wants?(self)
67
- Mail::Multibyte.proxy_class.new(self)
68
- else
69
- self
70
- end
71
- end
72
-
73
- # Returns true if the string has UTF-8 semantics (a String used for purely byte resources is unlikely to have
74
- # them), returns false otherwise.
75
- def is_utf8?
76
- Mail::Multibyte::Chars.consumes?(self)
77
- end
78
- end
79
- end
@@ -1,9 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- module Mail #:nodoc:
5
- module Multibyte #:nodoc:
6
- # Raised when a problem with the encoding was found.
7
- class EncodingError < StandardError; end
8
- end
9
- end
@@ -1,185 +0,0 @@
1
- %%{
2
-
3
- machine common;
4
-
5
- action comment_begin { fcall comment_tail; }
6
- action comment_exit { fret; }
7
-
8
- # RFC5322: address_lists, date_time, message_ids, phrase_lists, received
9
-
10
- obs_NO_WS_CTL = 0x01..0x08 | 0x0b | 0x0c | 0x0e..0x1f | 0x7f;
11
- LF = "\n";
12
- CR = "\r";
13
- CRLF = "\r\n";
14
- WSP = 0x09 | 0x20;
15
- obs_ctext = obs_NO_WS_CTL;
16
- VCHAR = 0x21..0x7e;
17
- obs_qp = "\\" (0x00 | obs_NO_WS_CTL | LF | CR);
18
- obs_FWS = (CRLF? WSP)+;
19
- ctext = 0x21..0x27 | 0x2a..0x5b | 0x5d..0x7e | obs_ctext;
20
- quoted_pair = ("\\" (VCHAR | WSP)) | obs_qp;
21
- FWS = (WSP* CRLF WSP+) | (CRLF WSP+) | obs_FWS;
22
- ALPHA = [a-zA-Z];
23
- DIGIT = [0-9];
24
- DQUOTE = '"';
25
- obs_qtext = obs_NO_WS_CTL;
26
- atext = ALPHA | DIGIT | "!" | "#" | "$" | "%" | "&" |
27
- "'" | "*" | "+" | "-" | "/" | "=" | "?" | "^" |
28
- "_" | "`" | "{" | "|" | "}" | "~";
29
- qtext = 0x21 | 0x23..0x5b | 0x5d..0x7e | obs_qtext;
30
- obs_dtext = obs_NO_WS_CTL | quoted_pair;
31
- qcontent = qtext | quoted_pair;
32
-
33
- # Handle recursive comments
34
- ccontent = ctext | quoted_pair | "(" @comment_begin;
35
- comment_tail := ((FWS? ccontent)* >comment_s) FWS? ")" @comment_exit;
36
- comment = "(" @comment_begin %comment_e;
37
- CFWS = ((FWS? comment)+ FWS?) | FWS;
38
-
39
- quoted_string = CFWS?
40
- (DQUOTE
41
- (((FWS? qcontent)* FWS?) >qstr_s %qstr_e)
42
- DQUOTE)
43
- CFWS?;
44
-
45
- atom = CFWS? atext+ CFWS?;
46
- word = atom | quoted_string;
47
-
48
- # phrase_lists
49
- obs_phrase = (word | "." | "@")+;
50
- phrase = (obs_phrase | word+) >phrase_s %phrase_e;
51
- phrase_lists = phrase ("," FWS* phrase)*;
52
-
53
- # address_lists
54
-
55
- # local_part:
56
- domain_text = (DQUOTE (FWS? qcontent)+ FWS? DQUOTE) | atext+;
57
- local_dot_atom_text = ("."* domain_text "."*)+;
58
- local_dot_atom = CFWS?
59
- (local_dot_atom_text >local_dot_atom_s %local_dot_atom_pre_comment_e)
60
- CFWS?;
61
- obs_local_part = word ("." word)*;
62
- local_part = (local_dot_atom >local_dot_atom_s %local_dot_atom_e |
63
- (quoted_string %local_quoted_string_e) |
64
- obs_local_part);
65
-
66
- # Treetop parser behavior was to ignore addresses missing '@' inside of angle
67
- # brackets. This construction preserves that behavior.
68
- local_part_no_capture = (local_dot_atom | quoted_string | obs_local_part);
69
-
70
- # domain:
71
- dot_atom_text = "."* domain_text ("."* domain_text)*;
72
- dtext = 0x21..0x5a | 0x5e..0x7e | obs_dtext;
73
- dot_atom = CFWS? dot_atom_text (CFWS? >(comment_after_address,1));
74
- domain_literal = CFWS? "[" (FWS? dtext)* FWS? "]" CFWS?;
75
- obs_domain = atom ("." atom)*;
76
- domain = (dot_atom | domain_literal | obs_domain) >domain_s %domain_e;
77
-
78
- # addr_spec:
79
-
80
- # The %(end_addr,N) priority resolves uncertainty when whitespace
81
- # after an addr_spec could cause it to be interpreted as a
82
- # display name: "bar@example.com ,..."
83
-
84
- addr_spec_in_angle_brackets =
85
- (local_part "@" domain) %(end_addr,1) |
86
- local_part_no_capture %(end_addr,0);
87
-
88
- addr_spec_no_angle_brackets =
89
- (local_part "@" domain) %(end_addr,1) |
90
- local_part %(end_addr,0);
91
-
92
- # angle_addr:
93
- obs_domain_list = (CFWS | ",")* "@" domain ("," CFWS? ("@" domain)?)*;
94
- obs_route = (obs_domain_list ":") >obs_domain_list_s %obs_domain_list_e;
95
- obs_angle_addr = CFWS? "<" obs_route? addr_spec_in_angle_brackets ">" CFWS?;
96
-
97
- angle_addr = CFWS? ("<" >angle_addr_s) addr_spec_in_angle_brackets ">" CFWS? |
98
- obs_angle_addr;
99
-
100
- # Address
101
- display_name = phrase;
102
- name_addr = display_name? %(end_addr,2) angle_addr;
103
- mailbox = (name_addr | addr_spec_no_angle_brackets) >address_s %address_e;
104
- obs_mbox_list = (CFWS? ",")* mailbox ("," (mailbox | CFWS)?)*;
105
- mailbox_list = (mailbox (("," | ";") mailbox)*) | obs_mbox_list;
106
- obs_group_list = (CFWS? ",")+ CFWS?;
107
- group_list = mailbox_list | CFWS | obs_group_list;
108
- group = (display_name >group_name_s %group_name_e) ":"
109
- (group_list?) ";" CFWS?;
110
- address = group | mailbox;
111
- #obs_addr_list = (CFWS? ",")* address ("," (address | CFWS)?)*;
112
- address_lists = address? %(comment_after_address,0)
113
- (FWS* ("," | ";") FWS* address?)*;
114
-
115
- # message_ids
116
- obs_id_left = local_part;
117
- id_left = dot_atom_text | obs_id_left;
118
- # id_right modifications to support multiple '@' in msg_id.
119
- msg_id_atext = ALPHA | DIGIT | "!" | "#" | "$" | "%" | "&" | "'" | "*" |
120
- "+" | "-" | "/" | "=" | "?" | "^" | "_" | "`" | "{" | "|" |
121
- "}" | "~" | "@";
122
- msg_id_dot_atom_text = (msg_id_atext+ "."?)+;
123
- obs_id_right = domain;
124
- no_fold_literal = "[" (dtext)* "]";
125
- id_right = msg_id_dot_atom_text | no_fold_literal | obs_id_right;
126
- msg_id = (CFWS)?
127
- (("<" id_left "@" id_right ">") >msg_id_s %msg_id_e)
128
- (CFWS)?;
129
- message_ids = msg_id (CFWS? msg_id)*;
130
-
131
- include date_time "date_time.rl";
132
- date_time = (day_of_week ",")?
133
- (date >date_s %date_e) <: (time >time_s %time_e) CFWS?;
134
-
135
- # Added CFWS? to increase robustness
136
- # (qmail likes to include a comment style string...?)
137
- received_token = word | angle_addr | addr_spec_no_angle_brackets | domain;
138
- received = ((CFWS? received_token*) >received_tokens_s %received_tokens_e)
139
- ";" date_time;
140
-
141
- # RFC2045: mime_version, content_type, content_transfer_encoding
142
- mime_version = CFWS?
143
- (DIGIT+ >major_digits_s %major_digits_e)
144
- comment? "." comment?
145
- (DIGIT+ >minor_digits_s %minor_digits_e)
146
- CFWS?;
147
-
148
- token = 0x21..0x27 | 0x2a..0x2b | 0x2c..0x2e |
149
- 0x30..0x39 | 0x41..0x5a | 0x5e..0x7e;
150
- value = (quoted_string | (token -- '"' | 0x3d)+) >param_val_s %param_val_e;
151
- attribute = (token+) >param_attr_s %param_attr_e;
152
- parameter = CFWS? attribute "=" value CFWS?;
153
-
154
- ietf_token = token+;
155
- custom_x_token = 'x'i "-" token+;
156
- extension_token = ietf_token | custom_x_token;
157
- discrete_type = 'text'i | 'image'i | 'audio'i | 'video'i |
158
- 'application'i | extension_token;
159
- composite_type = 'message'i | 'multipart'i | extension_token;
160
- iana_token = token+;
161
- main_type = (discrete_type | composite_type) >main_type_s %main_type_e;
162
- sub_type = (extension_token | iana_token) >sub_type_s %sub_type_e;
163
- content_type = main_type "/" sub_type (((CFWS? ";"+) | CFWS) parameter CFWS?)*;
164
-
165
- encoding = ('7bits' | '8bits' | '7bit' | '8bit' | 'binary' |
166
- 'quoted-printable' | 'base64' | ietf_token |
167
- custom_x_token) >encoding_s %encoding_e;
168
- content_transfer_encoding = CFWS? encoding CFWS? ";"? CFWS?;
169
-
170
- # RFC2183: content_disposition
171
- # TODO: recognize filename, size, creation date, etc.
172
- disposition_type = 'inline'i | 'attachment'i | extension_token | '';
173
- content_disposition = (disposition_type >disp_type_s %disp_type_e)
174
- (CFWS? ";" parameter CFWS?)*;
175
-
176
- # Envelope From
177
- ctime_date = day_name " "+ month " "+ day " " time_of_day " " year;
178
- null_sender = ('<>' ' '{0,1});
179
- envelope_from = (addr_spec_no_angle_brackets | null_sender) >address_s %address_e " "
180
- (ctime_date >ctime_date_s %ctime_date_e);
181
-
182
- # content_location
183
- location = quoted_string | ((token | 0x3d)+ >token_string_s %token_string_e);
184
- content_location = CFWS? location CFWS?;
185
- }%%
@@ -1,61 +0,0 @@
1
- module Mail
2
- module Parsers
3
- module Ragel
4
- ACTIONS = [
5
- :addr_spec,
6
- :address_e,
7
- :address_s,
8
- :angle_addr_s,
9
- :comment_e,
10
- :comment_s,
11
- :ctime_date_e,
12
- :ctime_date_s,
13
- :date_e,
14
- :date_s,
15
- :disp_type_e,
16
- :disp_type_s,
17
- :domain_e,
18
- :domain_s,
19
- :encoding_e,
20
- :encoding_s,
21
- :group_name_e,
22
- :group_name_s,
23
- :local_dot_atom_e,
24
- :local_dot_atom_pre_comment_e,
25
- :local_dot_atom_s,
26
- :local_quoted_string_e,
27
- :main_type_e,
28
- :main_type_s,
29
- :major_digits_e,
30
- :major_digits_s,
31
- :minor_digits_e,
32
- :minor_digits_s,
33
- :msg_id_e,
34
- :msg_id_s,
35
- :obs_domain_list_e,
36
- :obs_domain_list_s,
37
- :param_attr_e,
38
- :param_attr_s,
39
- :param_val_e,
40
- :param_val_s,
41
- :phrase_e,
42
- :phrase_s,
43
- :qstr_e,
44
- :qstr_s,
45
- :received_tokens_e,
46
- :received_tokens_s,
47
- :sub_type_e,
48
- :sub_type_s,
49
- :time_e,
50
- :time_s,
51
- :token_string_e,
52
- :token_string_s
53
- ]
54
-
55
- FIELD_PARSERS = %w[ address_lists phrase_lists
56
- date_time received message_ids envelope_from
57
- mime_version content_type content_disposition
58
- content_transfer_encoding content_location ]
59
- end
60
- end
61
- end