mail 2.6.6 → 2.7.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +25 -6
  3. data/Dependencies.txt +0 -1
  4. data/Gemfile +5 -8
  5. data/MIT-LICENSE +1 -1
  6. data/README.md +22 -11
  7. data/Rakefile +0 -6
  8. data/lib/mail.rb +2 -10
  9. data/lib/mail/attachments_list.rb +3 -2
  10. data/lib/mail/body.rb +3 -3
  11. data/lib/mail/core_extensions/smtp.rb +19 -16
  12. data/lib/mail/core_extensions/string.rb +0 -4
  13. data/lib/mail/elements/address.rb +9 -4
  14. data/lib/mail/elements/address_list.rb +10 -18
  15. data/lib/mail/elements/content_disposition_element.rb +8 -15
  16. data/lib/mail/elements/content_location_element.rb +5 -10
  17. data/lib/mail/elements/content_transfer_encoding_element.rb +5 -10
  18. data/lib/mail/elements/content_type_element.rb +8 -19
  19. data/lib/mail/elements/date_time_element.rb +6 -14
  20. data/lib/mail/elements/envelope_from_element.rb +14 -21
  21. data/lib/mail/elements/message_ids_element.rb +8 -12
  22. data/lib/mail/elements/mime_version_element.rb +6 -14
  23. data/lib/mail/elements/phrase_list.rb +6 -9
  24. data/lib/mail/elements/received_element.rb +9 -15
  25. data/lib/mail/encodings.rb +12 -14
  26. data/lib/mail/field.rb +7 -4
  27. data/lib/mail/fields/common/parameter_hash.rb +1 -1
  28. data/lib/mail/fields/content_type_field.rb +2 -7
  29. data/lib/mail/fields/unstructured_field.rb +2 -2
  30. data/lib/mail/header.rb +1 -0
  31. data/lib/mail/message.rb +23 -25
  32. data/lib/mail/multibyte.rb +51 -0
  33. data/lib/mail/multibyte/chars.rb +27 -27
  34. data/lib/mail/network/delivery_methods/exim.rb +10 -6
  35. data/lib/mail/network/delivery_methods/sendmail.rb +2 -6
  36. data/lib/mail/network/delivery_methods/smtp.rb +14 -6
  37. data/lib/mail/parsers.rb +16 -24
  38. data/lib/mail/parsers/address_lists_parser.rb +15321 -112
  39. data/lib/mail/parsers/address_lists_parser.rl +166 -0
  40. data/lib/mail/parsers/content_disposition_parser.rb +698 -55
  41. data/lib/mail/parsers/content_disposition_parser.rl +76 -0
  42. data/lib/mail/parsers/content_location_parser.rb +565 -23
  43. data/lib/mail/parsers/content_location_parser.rl +65 -0
  44. data/lib/mail/parsers/content_transfer_encoding_parser.rb +410 -22
  45. data/lib/mail/parsers/content_transfer_encoding_parser.rl +58 -0
  46. data/lib/mail/parsers/content_type_parser.rb +841 -54
  47. data/lib/mail/parsers/content_type_parser.rl +77 -0
  48. data/lib/mail/parsers/date_time_parser.rb +773 -26
  49. data/lib/mail/parsers/date_time_parser.rl +56 -0
  50. data/lib/mail/parsers/envelope_from_parser.rb +2051 -36
  51. data/lib/mail/parsers/envelope_from_parser.rl +76 -0
  52. data/lib/mail/parsers/message_ids_parser.rb +1494 -25
  53. data/lib/mail/parsers/message_ids_parser.rl +76 -0
  54. data/lib/mail/parsers/mime_version_parser.rb +393 -26
  55. data/lib/mail/parsers/mime_version_parser.rl +55 -0
  56. data/lib/mail/parsers/phrase_lists_parser.rb +529 -19
  57. data/lib/mail/parsers/phrase_lists_parser.rl +77 -0
  58. data/lib/mail/parsers/received_parser.rb +4711 -38
  59. data/lib/mail/parsers/received_parser.rl +78 -0
  60. data/lib/mail/parsers/rfc2045_content_transfer_encoding.rl +12 -0
  61. data/lib/mail/parsers/rfc2045_content_type.rl +24 -0
  62. data/lib/mail/parsers/rfc2045_mime.rl +15 -0
  63. data/lib/mail/parsers/rfc2183_content_disposition.rl +14 -0
  64. data/lib/mail/parsers/rfc5234_abnf_core_rules.rl +16 -0
  65. data/lib/mail/parsers/rfc5322.rl +57 -0
  66. data/lib/mail/parsers/rfc5322_address.rl +70 -0
  67. data/lib/mail/parsers/{ragel/date_time.rl → rfc5322_date_time.rl} +7 -1
  68. data/lib/mail/parsers/rfc5322_lexical_tokens.rl +56 -0
  69. data/lib/mail/part.rb +1 -1
  70. data/lib/mail/parts_list.rb +5 -6
  71. data/lib/mail/utilities.rb +4 -2
  72. data/lib/mail/version.rb +3 -3
  73. data/lib/mail/version_specific/ruby_1_8.rb +28 -2
  74. data/lib/mail/version_specific/ruby_1_9.rb +48 -8
  75. metadata +28 -45
  76. data/lib/mail/core_extensions/string/access.rb +0 -146
  77. data/lib/mail/core_extensions/string/multibyte.rb +0 -79
  78. data/lib/mail/parsers/ragel.rb +0 -18
  79. data/lib/mail/parsers/ragel/common.rl +0 -185
  80. data/lib/mail/parsers/ragel/parser_info.rb +0 -61
  81. data/lib/mail/parsers/ragel/ruby.rb +0 -40
  82. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb +0 -14864
  83. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl +0 -37
  84. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb +0 -751
  85. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl +0 -37
  86. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb +0 -614
  87. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl +0 -37
  88. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb +0 -447
  89. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl +0 -37
  90. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb +0 -825
  91. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl +0 -37
  92. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb +0 -817
  93. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl +0 -37
  94. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb +0 -2149
  95. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl +0 -37
  96. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb +0 -1570
  97. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl +0 -37
  98. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb +0 -440
  99. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl +0 -37
  100. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb +0 -564
  101. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl +0 -37
  102. data/lib/mail/parsers/ragel/ruby/machines/rb_actions.rl +0 -51
  103. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb +0 -5144
  104. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl +0 -37
  105. data/lib/mail/parsers/ragel/ruby/parser.rb.rl.erb +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fffa789ce57e01eb58d470854eef55242eae6f9c
4
- data.tar.gz: fa95a3e43e7c7b80972dd81989688ed00ef5e22c
3
+ metadata.gz: 93c47855c2c3b7c479ab1b3bfc7814fec87708c4
4
+ data.tar.gz: 7fd451474a8d296b33732d0db9184945a31d4061
5
5
  SHA512:
6
- metadata.gz: '06621968e5681c087041b046f1f52cb7316116bedf04e38ab4255118249142488f768fba638c6fc2b99eb69d15a6d84823383f073f33bc8b05a6b3be635417d7'
7
- data.tar.gz: f890a870876c79ca6014c8cccc84af35834cfc79576a2032aeef5a6f34ff183661e5fd73796b4693de53c1a288059e7733e359e7f0252548fe8c49e657f5bc7f
6
+ metadata.gz: 505cbad915ae907563530b378162b0850510f973f4ec7a5d9867ecf582900fb45dfa725c8682f2b9e1848a9cdb3497a1c313178f2fdb81c1909f63adc24bf736
7
+ data.tar.gz: 0ad2330236098fa81cac6675c17144f6b072b43d8908e57d884f833472817511ec4e7764e9bc5c7aac490e2a76680ff0c6b1bbdf95a6ec478d319b16b76686ba
data/CHANGELOG.rdoc CHANGED
@@ -1,20 +1,39 @@
1
- == Version 2.6.6 - 2017-06-09 Jeremy Daer <jeremydaer@gmail.com>
1
+ == HEAD
2
2
 
3
3
  Security:
4
4
  * #1097 – SMTP security: prevent command injection via To/From addresses. (jeremy)
5
5
 
6
- Bugs:
7
- * #689 - Fix Exim delivery method broken by #477 in 2.5.4. (jethrogb)
8
-
9
- == Version 2.6.5 - 2017-04-26 Jeremy Daer <jeremydaer@gmail.com>
10
-
11
6
  Features:
7
+ * #804 - Configurable SMTP open_timeout and read_timeout. (ankane)
8
+ * #853 - `Mail::Message#set_sort_order` overrides the default message part sort order. (rafbm)
9
+ * #650 - UTF-7 charset support. (johngrimes)
10
+ * #1065 - Require STARTTLS using :enable_starttls. (bk2204)
11
+ * #1002 - Transcoding replaces invalid chars with "�" instead of discarding them. (kjg)
12
12
  * #1053 - Ruby 2.4.0 compatibility. Fixnum+Bignum unified as Integer. (peterkovacs)
13
+ * #1094 - Core extensions removal: Drop `String#at`, `from`, `last` and `is_utf8?` since they are no longer used by Mail internals. (metcalf)
14
+ * #1095 - Core extensions removal: Drop `String#mb_chars`, `not_ascii_only?`, `constantize`, `first`, `to` to avoid monkey patching the standard library. (metcalf)
15
+
16
+ Performance:
17
+ * #1059 - Switch from mime-types to mini_mime for a much smaller memory footprint. (SamSaffron)
18
+
19
+ Compatibility:
20
+ * #464 - Improve attachment filename detection by preferring Content-Disposition filename. (lawrencepit)
21
+ * #655 - Sort attachments to the end of the parts list to work around email clients that may mistake a text attachment for the message body. (npickens)
22
+ * #982 – Faithfully preserve unfolded whitespace rather than collapsing to a single space. (jeremy)
13
23
 
14
24
  Bugs:
25
+ * #539 - Fix that whitespace-only continued headers would be incorrectly parsed as the break between headers and body. (ConradIrwin)
15
26
  * #605 - Fix Mail::Address#name for nil addresses (peterkovacs)
27
+ * #876 - Strip valid RFC-1342 separator characters between non-matching encoded-words (Caleb W. Corliss)
28
+ * #978 - Fix for invalid chars being left in a string for invalid b_value from encoding. (kjg)
29
+ * #996 - Fix that multipart/mixed emails with a delivery-status part could be interpreted as bounces. (kjg)
30
+ * #998 - Fix header parameter parsing (such as attachment names) for values encoded with a blank charset or language code. (kjg)
31
+ * #1000 - Fix header parameter parsing (such as attachment names) to transcode to UTF-8 (kjg)
16
32
  * #1003 - Fix decoding some b encoded headers on specific rubies that don't account for lack of base64 padding (kjg)
33
+ * #1020 - Don't set SMTP verify mode to nil when config was not provided. (jhass)
17
34
  * #1023 - Fix double-quoting in display names. (garethrees)
35
+ * #1032 - Fix that comparing messages changed their raw Message-ID to their parsed message_id. (bobjflong)
36
+ * #1074 - Fix that the first address in a list is dropped when a subsequent address has non-US-ASCII characters. (domininik)
18
37
 
19
38
  == Version 2.6.4 - Wed Mar 23 08:16 -0700 2016 Jeremy Daer <jeremydaer@gmail.com>
20
39
 
data/Dependencies.txt CHANGED
@@ -1,2 +1 @@
1
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 CHANGED
@@ -4,11 +4,8 @@ gemspec
4
4
 
5
5
  gem 'tlsmail', '~> 0.0.1' if RUBY_VERSION <= '1.8.6'
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
7
+
8
+ gem 'rake', '< 11.0' if RUBY_VERSION < '1.9.3'
9
+ gem 'rdoc', '< 4.3' if RUBY_VERSION < '2.0'
10
+
11
+ gem 'mini_mime', :github => 'discourse/mini_mime'
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2017 Mikel Lindsaar
1
+ Copyright (c) 2009-2016 Mikel Lindsaar
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -42,14 +42,26 @@ me a nice email :)
42
42
  Compatibility
43
43
  -------------
44
44
 
45
- Mail supports Ruby 1.8.7+, including JRuby and Rubinius.
46
-
47
- Every Mail commit is tested by Travis on [all supported Ruby versions](https://github.com/mikel/mail/blob/master/.travis.yml).
48
-
49
- Testing a specific version of mime-types (needed for Ruby 1.8.7, for example) can be done manually with:
45
+ Every Mail commit is tested by Travis on the [following platforms](https://github.com/mikel/mail/blob/master/.travis.yml)
46
+
47
+ * ruby-1.8.7 [ i686 ]
48
+ * ruby-1.9.2 [ x86_64 ]
49
+ * ruby-1.9.3 [ x86_64 ]
50
+ * ruby-2.0.0 [ x86_64 ]
51
+ * ruby-2.1.10 [ x86_64 ]
52
+ * ruby-2.2.6 [ x86_64 ]
53
+ * ruby-2.3.3 [ x86_64 ]
54
+ * ruby-2.4.0 [ x86_64 ]
55
+ * ruby-head [ x86_64 ]
56
+ * jruby [ x86_64 ]
57
+ * jruby-9.1.6.0 [ x86_64 ]
58
+ * jruby-head [ x86_64 ]
59
+ * rbx-2 [ x86_64 ]
60
+
61
+ Testing a specific mime type (needed for 1.8.7 for example) can be done manually with:
50
62
 
51
63
  ```sh
52
- BUNDLE_GEMFILE=gemfiles/mime_types_1.16.gemfile bundle && rake
64
+ BUNDLE_GEMFILE=gemfiles/mime_types_1.16.gemfile (bundle check || bundle) && rake
53
65
  ```
54
66
 
55
67
  Discussion
@@ -226,7 +238,7 @@ what you are doing.
226
238
  ### Sending an email:
227
239
 
228
240
  Mail defaults to sending via SMTP to local host port 25. If you have a
229
- sendmail or postfix daemon running on on this port, sending email is as
241
+ sendmail or postfix daemon running on this port, sending email is as
230
242
  easy as:
231
243
 
232
244
  ```ruby
@@ -339,7 +351,7 @@ mail.cc #=> 'sam@test.lindsaar.net'
339
351
  mail.subject #=> "This is the subject"
340
352
  mail.date.to_s #=> '21 Nov 1997 09:55:06 -0600'
341
353
  mail.message_id #=> '<4D6AA7EB.6490534@xxx.xxx>'
342
- mail.body.decoded #=> 'This is the body of the email...
354
+ mail.decoded #=> 'This is the body of the email...
343
355
  ```
344
356
 
345
357
  Many more methods available.
@@ -374,7 +386,7 @@ mail.attachments.each do | attachment |
374
386
  # extracting images for example...
375
387
  filename = attachment.filename
376
388
  begin
377
- File.open(images_dir + filename, "w+b", 0644) {|f| f.write attachment.body.decoded}
389
+ File.open(images_dir + filename, "w+b", 0644) {|f| f.write attachment.decoded}
378
390
  rescue => e
379
391
  puts "Unable to save data for #{filename} because #{e.message}"
380
392
  end
@@ -519,7 +531,6 @@ than mail (this should be rarely needed)
519
531
 
520
532
  ```ruby
521
533
  @mail = Mail.new
522
- file_data = File.read('path/to/myfile.pdf')
523
534
  @mail.attachments['myfile.pdf'] = { :mime_type => 'application/x-pdf',
524
535
  :content => File.read('path/to/myfile.pdf') }
525
536
  @mail.parts.first.mime_type #=> 'application/x-pdf'
@@ -689,7 +700,7 @@ License
689
700
 
690
701
  (The MIT License)
691
702
 
692
- Copyright (c) 2009-2017 Mikel Lindsaar
703
+ Copyright (c) 2009-2016 Mikel Lindsaar
693
704
 
694
705
  Permission is hereby granted, free of charge, to any person obtaining
695
706
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -19,11 +19,5 @@ RSpec::Core::RakeTask.new(:spec) do |t|
19
19
  t.rspec_opts = %w(--backtrace --color)
20
20
  end
21
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
22
  # load custom rake tasks
29
23
  Dir["#{File.dirname(__FILE__)}/tasks/**/*.rake"].sort.each { |ext| load ext }
data/lib/mail.rb CHANGED
@@ -7,13 +7,7 @@ module Mail # :doc:
7
7
 
8
8
  require 'uri'
9
9
  require 'net/smtp'
10
-
11
- begin
12
- # Use mime/types/columnar if available, for reduced memory usage
13
- require 'mime/types/columnar'
14
- rescue LoadError
15
- require 'mime/types'
16
- end
10
+ require 'mini_mime'
17
11
 
18
12
  if RUBY_VERSION <= '1.8.6'
19
13
  begin
@@ -34,15 +28,13 @@ module Mail # :doc:
34
28
  require 'mail/version'
35
29
 
36
30
  require 'mail/core_extensions/string'
37
- require 'mail/core_extensions/smtp' if RUBY_VERSION < '1.9.3'
31
+ require 'mail/core_extensions/smtp'
38
32
  require 'mail/indifferent_hash'
39
33
 
40
34
  # Only load our multibyte extensions if AS is not already loaded
41
35
  if defined?(ActiveSupport)
42
36
  require 'active_support/inflector'
43
37
  else
44
- require 'mail/core_extensions/string/access'
45
- require 'mail/core_extensions/string/multibyte'
46
38
  require 'mail/multibyte'
47
39
  end
48
40
 
@@ -60,7 +60,7 @@ module Mail
60
60
 
61
61
  if value[:mime_type]
62
62
  default_values[:content_type] = value.delete(:mime_type)
63
- @mime_type = MIME::Types[default_values[:content_type]].first
63
+ @mime_type = MiniMime.lookup_by_content_type(default_values[:content_type])
64
64
  default_values[:content_transfer_encoding] ||= guess_encoding
65
65
  end
66
66
 
@@ -99,7 +99,8 @@ module Mail
99
99
  filename = filename.encode(Encoding::UTF_8) if filename.respond_to?(:encode)
100
100
  end
101
101
 
102
- @mime_type = MIME::Types.type_for(filename).first
102
+ @mime_type = MiniMime.lookup_by_filename(filename)
103
+ @mime_type && @mime_type.content_type
103
104
  end
104
105
 
105
106
  end
data/lib/mail/body.rb CHANGED
@@ -32,7 +32,7 @@ module Mail
32
32
  @preamble = nil
33
33
  @epilogue = nil
34
34
  @charset = nil
35
- @part_sort_order = [ "text/plain", "text/enriched", "text/html" ]
35
+ @part_sort_order = [ "text/plain", "text/enriched", "text/html", "multipart/alternative" ]
36
36
  @parts = Mail::PartsList.new
37
37
  if Utilities.blank?(string)
38
38
  @raw_source = ''
@@ -115,8 +115,8 @@ module Mail
115
115
  end
116
116
 
117
117
  # Allows you to set the sort order of the parts, overriding the default sort order.
118
- # Defaults to 'text/plain', then 'text/enriched', then 'text/html' with any other content
119
- # type coming after.
118
+ # Defaults to 'text/plain', then 'text/enriched', then 'text/html', then 'multipart/alternative'
119
+ # with any other content type coming after.
120
120
  def set_sort_order(order)
121
121
  @part_sort_order = order
122
122
  end
@@ -1,25 +1,28 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
- module Net
4
- class SMTP
5
- # This is a backport of r30294 from ruby trunk because of a bug in net/smtp.
6
- # http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&amp;revision=30294
7
- #
8
- # Fixed in what will be Ruby 1.9.3 - tlsconnect also does not exist in some early versions of ruby
9
- begin
10
- alias_method :original_tlsconnect, :tlsconnect
11
3
 
12
- def tlsconnect(s)
13
- verified = false
14
- begin
15
- original_tlsconnect(s).tap { verified = true }
16
- ensure
17
- unless verified
18
- s.close rescue nil
4
+ # This is a backport of r30294 from ruby trunk because of a bug in net/smtp.
5
+ # http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&amp;revision=30294
6
+ #
7
+ # Fixed in Ruby 1.9.3 - tlsconnect also does not exist in some early versions of ruby
8
+ if RUBY_VERSION < '1.9.3'
9
+ module Net
10
+ class SMTP
11
+ begin
12
+ alias_method :original_tlsconnect, :tlsconnect
13
+
14
+ def tlsconnect(s)
15
+ verified = false
16
+ begin
17
+ original_tlsconnect(s).tap { verified = true }
18
+ ensure
19
+ unless verified
20
+ s.close rescue nil
21
+ end
19
22
  end
20
23
  end
24
+ rescue NameError
21
25
  end
22
- rescue NameError
23
26
  end
24
27
  end
25
28
  end
@@ -11,10 +11,6 @@ class String #:nodoc:
11
11
  MATCH_NON_US_ASCII = /[^\x00-\x7f]/
12
12
  end
13
13
 
14
- def not_ascii_only?
15
- !ascii_only?
16
- end
17
-
18
14
  unless method_defined?(:bytesize)
19
15
  alias :bytesize :length
20
16
  end
@@ -1,8 +1,9 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+ require 'mail/parsers/address_lists_parser'
4
+
3
5
  module Mail
4
6
  class Address
5
-
6
7
  include Mail::Utilities
7
8
 
8
9
  # Mail::Address handles all email addresses in Mail. It takes an email address string
@@ -116,11 +117,15 @@ module Mail
116
117
  Encodings.decode_encode(strip_all_comments(get_domain), @output_type) if get_domain
117
118
  end
118
119
 
119
- # Returns an array of comments that are in the email, or an empty array if there
120
+ # Returns an array of comments that are in the email, or nil if there
120
121
  # are no comments
121
122
  #
122
123
  # a = Address.new('Mikel Lindsaar (My email address) <mikel@test.lindsaar.net>')
123
124
  # a.comments #=> ['My email address']
125
+ #
126
+ # b = Address.new('Mikel Lindsaar <mikel@test.lindsaar.net>')
127
+ # b.comments #=> nil
128
+
124
129
  def comments
125
130
  parse unless @parsed
126
131
  comments = get_comments
@@ -179,11 +184,11 @@ module Mail
179
184
  @data = nil
180
185
 
181
186
  case value
182
- when Mail::Parsers::AddressStruct
187
+ when Mail::Parsers::AddressListsParser::AddressStruct
183
188
  @data = value
184
189
  when String
185
190
  unless Utilities.blank?(value)
186
- address_list = Mail::Parsers::AddressListsParser.new.parse(value)
191
+ address_list = Mail::Parsers::AddressListsParser.parse(value)
187
192
  @data = address_list.addresses.first
188
193
  end
189
194
  end
@@ -1,42 +1,34 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+ require 'mail/parsers/address_lists_parser'
4
+
3
5
  module Mail
4
6
  class AddressList # :nodoc:
7
+ attr_reader :addresses, :group_names
5
8
 
6
9
  # Mail::AddressList is the class that parses To, From and other address fields from
7
10
  # emails passed into Mail.
8
- #
11
+ #
9
12
  # AddressList provides a way to query the groups and mailbox lists of the passed in
10
13
  # string.
11
- #
14
+ #
12
15
  # It can supply all addresses in an array, or return each address as an address object.
13
- #
16
+ #
14
17
  # Mail::AddressList requires a correctly formatted group or mailbox list per RFC2822 or
15
18
  # RFC822. It also handles all obsolete versions in those RFCs.
16
- #
19
+ #
17
20
  # list = 'ada@test.lindsaar.net, My Group: mikel@test.lindsaar.net, Bob <bob@test.lindsaar.net>;'
18
21
  # a = AddressList.new(list)
19
22
  # a.addresses #=> [#<Mail::Address:14943130 Address: |ada@test.lindsaar.net...
20
23
  # a.group_names #=> ["My Group"]
21
24
  def initialize(string)
22
- @addresses_grouped_by_group = nil
23
- @address_list = Mail::Parsers::AddressListsParser.new.parse(string)
24
- end
25
-
26
- # Returns a list of address objects from the parsed line
27
- def addresses
28
- @addresses ||= @address_list.addresses.map do |address_data|
29
- Mail::Address.new(address_data)
30
- end
25
+ address_list = Parsers::AddressListsParser.parse(string)
26
+ @addresses = address_list.addresses.map { |a| Address.new(a) }
27
+ @group_names = address_list.group_names
31
28
  end
32
29
 
33
30
  def addresses_grouped_by_group
34
31
  addresses.select(&:group).group_by(&:group)
35
32
  end
36
-
37
- # Returns the names as an array of strings of all groups
38
- def group_names # :nodoc:
39
- @address_list.group_names
40
- end
41
33
  end
42
34
  end
@@ -1,27 +1,20 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+ require 'mail/parsers/content_disposition_parser'
4
+
3
5
  module Mail
4
6
  class ContentDispositionElement # :nodoc:
5
-
6
- include Mail::Utilities
7
-
8
- def initialize( string )
9
- content_disposition = Mail::Parsers::ContentDispositionParser.new.parse(cleaned(string))
7
+ attr_reader :disposition_type, :parameters
8
+
9
+ def initialize(string)
10
+ content_disposition = Mail::Parsers::ContentDispositionParser.parse(cleaned(string))
10
11
  @disposition_type = content_disposition.disposition_type
11
12
  @parameters = content_disposition.parameters
12
13
  end
13
-
14
- def disposition_type
15
- @disposition_type
16
- end
17
-
18
- def parameters
19
- @parameters
20
- end
21
-
14
+
15
+ private
22
16
  def cleaned(string)
23
17
  string =~ /(.+);\s*$/ ? $1 : string
24
18
  end
25
-
26
19
  end
27
20
  end
@@ -1,22 +1,17 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+ require 'mail/parsers/content_location_parser'
4
+
3
5
  module Mail
4
6
  class ContentLocationElement # :nodoc:
7
+ attr_reader :location
5
8
 
6
- include Mail::Utilities
7
-
8
- def initialize( string )
9
- content_location = Mail::Parsers::ContentLocationParser.new.parse(string)
10
- @location = content_location.location
11
- end
12
-
13
- def location
14
- @location
9
+ def initialize(string)
10
+ @location = Mail::Parsers::ContentLocationParser.parse(string).location
15
11
  end
16
12
 
17
13
  def to_s(*args)
18
14
  location.to_s
19
15
  end
20
-
21
16
  end
22
17
  end