mail 2.6.5 → 2.7.0.rc1

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 (108) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.rdoc +28 -1
  3. data/Dependencies.txt +0 -1
  4. data/Gemfile +5 -8
  5. data/MIT-LICENSE +1 -1
  6. data/README.md +5 -5
  7. data/Rakefile +0 -6
  8. data/lib/mail/attachments_list.rb +3 -2
  9. data/lib/mail/body.rb +3 -3
  10. data/lib/mail/check_delivery_params.rb +47 -10
  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/chars.rb +27 -27
  33. data/lib/mail/multibyte.rb +51 -0
  34. data/lib/mail/network/delivery_methods/file_delivery.rb +4 -8
  35. data/lib/mail/network/delivery_methods/sendmail.rb +2 -4
  36. data/lib/mail/network/delivery_methods/smtp.rb +16 -11
  37. data/lib/mail/network/delivery_methods/smtp_connection.rb +2 -6
  38. data/lib/mail/network/delivery_methods/test_mailer.rb +5 -8
  39. data/lib/mail/parsers/address_lists_parser.rb +15321 -112
  40. data/lib/mail/parsers/address_lists_parser.rl +166 -0
  41. data/lib/mail/parsers/content_disposition_parser.rb +698 -55
  42. data/lib/mail/parsers/content_disposition_parser.rl +76 -0
  43. data/lib/mail/parsers/content_location_parser.rb +565 -23
  44. data/lib/mail/parsers/content_location_parser.rl +65 -0
  45. data/lib/mail/parsers/content_transfer_encoding_parser.rb +410 -22
  46. data/lib/mail/parsers/content_transfer_encoding_parser.rl +58 -0
  47. data/lib/mail/parsers/content_type_parser.rb +841 -54
  48. data/lib/mail/parsers/content_type_parser.rl +77 -0
  49. data/lib/mail/parsers/date_time_parser.rb +773 -26
  50. data/lib/mail/parsers/date_time_parser.rl +56 -0
  51. data/lib/mail/parsers/envelope_from_parser.rb +2051 -36
  52. data/lib/mail/parsers/envelope_from_parser.rl +76 -0
  53. data/lib/mail/parsers/message_ids_parser.rb +1494 -25
  54. data/lib/mail/parsers/message_ids_parser.rl +76 -0
  55. data/lib/mail/parsers/mime_version_parser.rb +393 -26
  56. data/lib/mail/parsers/mime_version_parser.rl +55 -0
  57. data/lib/mail/parsers/phrase_lists_parser.rb +529 -19
  58. data/lib/mail/parsers/phrase_lists_parser.rl +77 -0
  59. data/lib/mail/parsers/received_parser.rb +4711 -38
  60. data/lib/mail/parsers/received_parser.rl +78 -0
  61. data/lib/mail/parsers/rfc2045_content_transfer_encoding.rl +12 -0
  62. data/lib/mail/parsers/rfc2045_content_type.rl +24 -0
  63. data/lib/mail/parsers/rfc2045_mime.rl +15 -0
  64. data/lib/mail/parsers/rfc2183_content_disposition.rl +14 -0
  65. data/lib/mail/parsers/rfc5234_abnf_core_rules.rl +16 -0
  66. data/lib/mail/parsers/rfc5322.rl +57 -0
  67. data/lib/mail/parsers/rfc5322_address.rl +70 -0
  68. data/lib/mail/parsers/{ragel/date_time.rl → rfc5322_date_time.rl} +7 -1
  69. data/lib/mail/parsers/rfc5322_lexical_tokens.rl +56 -0
  70. data/lib/mail/parsers.rb +16 -24
  71. data/lib/mail/part.rb +1 -1
  72. data/lib/mail/parts_list.rb +5 -6
  73. data/lib/mail/utilities.rb +4 -2
  74. data/lib/mail/version.rb +3 -3
  75. data/lib/mail/version_specific/ruby_1_8.rb +28 -2
  76. data/lib/mail/version_specific/ruby_1_9.rb +48 -8
  77. data/lib/mail.rb +2 -10
  78. metadata +28 -45
  79. data/lib/mail/core_extensions/string/access.rb +0 -146
  80. data/lib/mail/core_extensions/string/multibyte.rb +0 -79
  81. data/lib/mail/parsers/ragel/common.rl +0 -185
  82. data/lib/mail/parsers/ragel/parser_info.rb +0 -61
  83. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb +0 -14864
  84. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl +0 -37
  85. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb +0 -751
  86. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl +0 -37
  87. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb +0 -614
  88. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl +0 -37
  89. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb +0 -447
  90. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl +0 -37
  91. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb +0 -825
  92. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl +0 -37
  93. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb +0 -817
  94. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl +0 -37
  95. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb +0 -2149
  96. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl +0 -37
  97. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb +0 -1570
  98. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl +0 -37
  99. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb +0 -440
  100. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl +0 -37
  101. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb +0 -564
  102. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl +0 -37
  103. data/lib/mail/parsers/ragel/ruby/machines/rb_actions.rl +0 -51
  104. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb +0 -5144
  105. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl +0 -37
  106. data/lib/mail/parsers/ragel/ruby/parser.rb.rl.erb +0 -37
  107. data/lib/mail/parsers/ragel/ruby.rb +0 -40
  108. data/lib/mail/parsers/ragel.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a4283c0737ab7bc528ff6a60317c46e1a2ff0f92
4
- data.tar.gz: 8f98051e95f99f1622283e76919404d08027b7ff
3
+ metadata.gz: 93c47855c2c3b7c479ab1b3bfc7814fec87708c4
4
+ data.tar.gz: 7fd451474a8d296b33732d0db9184945a31d4061
5
5
  SHA512:
6
- metadata.gz: 63514c34ddad591e76cb6704122775906f4d603aad4e90024ec88f17d7f19a78129dfe15d561b2f9e3807bdb074e6269dbdcb09d95656da2399b143e58681cd2
7
- data.tar.gz: a05cbc7af1c553e062d405b024390c17b03649f280c1c171b278b373401c1843657dc25e316f5041a44fdd3aba19f2a7a44b9d33d0ca9074bab06ed6c86b068d
6
+ metadata.gz: 505cbad915ae907563530b378162b0850510f973f4ec7a5d9867ecf582900fb45dfa725c8682f2b9e1848a9cdb3497a1c313178f2fdb81c1909f63adc24bf736
7
+ data.tar.gz: 0ad2330236098fa81cac6675c17144f6b072b43d8908e57d884f833472817511ec4e7764e9bc5c7aac490e2a76680ff0c6b1bbdf95a6ec478d319b16b76686ba
data/CHANGELOG.rdoc CHANGED
@@ -1,12 +1,39 @@
1
- == Version 2.6.5 - 2017-04-26 Jeremy Daer <jeremydaer@gmail.com>
1
+ == HEAD
2
+
3
+ Security:
4
+ * #1097 – SMTP security: prevent command injection via To/From addresses. (jeremy)
2
5
 
3
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)
4
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)
5
23
 
6
24
  Bugs:
25
+ * #539 - Fix that whitespace-only continued headers would be incorrectly parsed as the break between headers and body. (ConradIrwin)
7
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)
8
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)
9
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)
10
37
 
11
38
  == Version 2.6.4 - Wed Mar 23 08:16 -0700 2016 Jeremy Daer <jeremydaer@gmail.com>
12
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
@@ -51,6 +51,7 @@ Every Mail commit is tested by Travis on the [following platforms](https://githu
51
51
  * ruby-2.1.10 [ x86_64 ]
52
52
  * ruby-2.2.6 [ x86_64 ]
53
53
  * ruby-2.3.3 [ x86_64 ]
54
+ * ruby-2.4.0 [ x86_64 ]
54
55
  * ruby-head [ x86_64 ]
55
56
  * jruby [ x86_64 ]
56
57
  * jruby-9.1.6.0 [ x86_64 ]
@@ -237,7 +238,7 @@ what you are doing.
237
238
  ### Sending an email:
238
239
 
239
240
  Mail defaults to sending via SMTP to local host port 25. If you have a
240
- 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
241
242
  easy as:
242
243
 
243
244
  ```ruby
@@ -350,7 +351,7 @@ mail.cc #=> 'sam@test.lindsaar.net'
350
351
  mail.subject #=> "This is the subject"
351
352
  mail.date.to_s #=> '21 Nov 1997 09:55:06 -0600'
352
353
  mail.message_id #=> '<4D6AA7EB.6490534@xxx.xxx>'
353
- mail.body.decoded #=> 'This is the body of the email...
354
+ mail.decoded #=> 'This is the body of the email...
354
355
  ```
355
356
 
356
357
  Many more methods available.
@@ -385,7 +386,7 @@ mail.attachments.each do | attachment |
385
386
  # extracting images for example...
386
387
  filename = attachment.filename
387
388
  begin
388
- 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}
389
390
  rescue => e
390
391
  puts "Unable to save data for #{filename} because #{e.message}"
391
392
  end
@@ -530,7 +531,6 @@ than mail (this should be rarely needed)
530
531
 
531
532
  ```ruby
532
533
  @mail = Mail.new
533
- file_data = File.read('path/to/myfile.pdf')
534
534
  @mail.attachments['myfile.pdf'] = { :mime_type => 'application/x-pdf',
535
535
  :content => File.read('path/to/myfile.pdf') }
536
536
  @mail.parts.first.mime_type #=> 'application/x-pdf'
@@ -700,7 +700,7 @@ License
700
700
 
701
701
  (The MIT License)
702
702
 
703
- Copyright (c) 2009-2017 Mikel Lindsaar
703
+ Copyright (c) 2009-2016 Mikel Lindsaar
704
704
 
705
705
  Permission is hereby granted, free of charge, to any person obtaining
706
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 }
@@ -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,21 +1,58 @@
1
1
  # frozen_string_literal: true
2
2
  module Mail
3
- module CheckDeliveryParams
4
- def check_delivery_params(mail)
5
- if Utilities.blank?(mail.smtp_envelope_from)
6
- raise ArgumentError.new('An SMTP From address is required to send a message. Set the message smtp_envelope_from, return_path, sender, or from address.')
3
+ module CheckDeliveryParams #:nodoc:
4
+ class << self
5
+ def check(mail)
6
+ [ check_from(mail.smtp_envelope_from),
7
+ check_to(mail.smtp_envelope_to),
8
+ check_message(mail) ]
7
9
  end
8
10
 
9
- if Utilities.blank?(mail.smtp_envelope_to)
10
- raise ArgumentError.new('An SMTP To address is required to send a message. Set the message smtp_envelope_to, to, cc, or bcc address.')
11
+ def check_from(addr)
12
+ if Utilities.blank?(addr)
13
+ raise ArgumentError, "SMTP From address may not be blank: #{addr.inspect}"
14
+ end
15
+
16
+ check_addr 'From', addr
17
+ end
18
+
19
+ def check_to(addrs)
20
+ if Utilities.blank?(addrs)
21
+ raise ArgumentError, "SMTP To address may not be blank: #{addrs.inspect}"
22
+ end
23
+
24
+ Array(addrs).map do |addr|
25
+ check_addr 'To', addr
26
+ end
11
27
  end
12
28
 
13
- message = mail.encoded if mail.respond_to?(:encoded)
14
- if Utilities.blank?(message)
15
- raise ArgumentError.new('An encoded message is required to send an email')
29
+ def check_addr(addr_name, addr)
30
+ validate_smtp_addr addr do |error_message|
31
+ raise ArgumentError, "SMTP #{addr_name} address #{error_message}: #{addr.inspect}"
32
+ end
16
33
  end
17
34
 
18
- [mail.smtp_envelope_from, mail.smtp_envelope_to, message]
35
+ def validate_smtp_addr(addr)
36
+ if addr.bytesize > 2048
37
+ yield 'may not exceed 2kB'
38
+ end
39
+
40
+ if /[\r\n]/ =~ addr
41
+ yield 'may not contain CR or LF line breaks'
42
+ end
43
+
44
+ addr
45
+ end
46
+
47
+ def check_message(message)
48
+ message = message.encoded if message.respond_to?(:encoded)
49
+
50
+ if Utilities.blank?(message)
51
+ raise ArgumentError, 'An encoded message is required to send an email'
52
+ end
53
+
54
+ message
55
+ end
19
56
  end
20
57
  end
21
58
  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
@@ -1,18 +1,13 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+ require 'mail/parsers/content_transfer_encoding_parser'
4
+
3
5
  module Mail
4
6
  class ContentTransferEncodingElement
5
-
6
- include Mail::Utilities
7
-
7
+ attr_reader :encoding
8
+
8
9
  def initialize(string)
9
- content_transfer_encoding = Mail::Parsers::ContentTransferEncodingParser.new.parse(string)
10
- @encoding = content_transfer_encoding.encoding
10
+ @encoding = Mail::Parsers::ContentTransferEncodingParser.parse(string).encoding
11
11
  end
12
-
13
- def encoding
14
- @encoding
15
- end
16
-
17
12
  end
18
13
  end
@@ -1,32 +1,21 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+ require 'mail/parsers/content_type_parser'
4
+
3
5
  module Mail
4
6
  class ContentTypeElement # :nodoc:
5
-
6
- include Mail::Utilities
7
-
8
- def initialize( string )
9
- content_type = Mail::Parsers::ContentTypeParser.new.parse(cleaned(string))
7
+ attr_reader :main_type, :sub_type, :parameters
8
+
9
+ def initialize(string)
10
+ content_type = Mail::Parsers::ContentTypeParser.parse(cleaned(string))
10
11
  @main_type = content_type.main_type
11
12
  @sub_type = content_type.sub_type
12
13
  @parameters = content_type.parameters
13
14
  end
14
-
15
- def main_type
16
- @main_type
17
- end
18
-
19
- def sub_type
20
- @sub_type
21
- end
22
-
23
- def parameters
24
- @parameters
25
- end
26
-
15
+
16
+ private
27
17
  def cleaned(string)
28
18
  string =~ /(.+);\s*$/ ? $1 : string
29
19
  end
30
-
31
20
  end
32
21
  end
@@ -1,23 +1,15 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+ require 'mail/parsers/date_time_parser'
4
+
3
5
  module Mail
4
6
  class DateTimeElement # :nodoc:
5
-
6
- include Mail::Utilities
7
-
8
- def initialize( string )
9
- date_time = Mail::Parsers::DateTimeParser.new.parse(string)
7
+ attr_reader :date_string, :time_string
8
+
9
+ def initialize(string)
10
+ date_time = Mail::Parsers::DateTimeParser.parse(string)
10
11
  @date_string = date_time.date_string
11
12
  @time_string = date_time.time_string
12
13
  end
13
-
14
- def date_string
15
- @date_string
16
- end
17
-
18
- def time_string
19
- @time_string
20
- end
21
-
22
14
  end
23
15
  end
@@ -1,40 +1,33 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+ require 'mail/parsers/envelope_from_parser'
4
+ require 'date'
5
+
3
6
  module Mail
4
7
  class EnvelopeFromElement
5
-
6
- include Mail::Utilities
7
-
8
- def initialize( string )
9
- @envelope_from = Mail::Parsers::EnvelopeFromParser.new.parse(string)
10
- @address = @envelope_from.address
11
- @date_time = ::DateTime.parse(@envelope_from.ctime_date)
12
- end
13
-
14
- def date_time
15
- @date_time
16
- end
17
-
18
- def address
19
- @address
8
+ attr_reader :date_time, :address
9
+
10
+ def initialize(string)
11
+ envelope_from = Mail::Parsers::EnvelopeFromParser.parse(string)
12
+ @address = envelope_from.address
13
+ @date_time = ::DateTime.parse(envelope_from.ctime_date)
20
14
  end
21
-
15
+
22
16
  # RFC 4155:
23
17
  # a timestamp indicating the UTC date and time when the message
24
18
  # was originally received, conformant with the syntax of the
25
19
  # traditional UNIX 'ctime' output sans timezone (note that the
26
20
  # use of UTC precludes the need for a timezone indicator);
27
21
  def formatted_date_time
28
- if @date_time.respond_to?(:ctime)
29
- @date_time.ctime
22
+ if date_time.respond_to?(:ctime)
23
+ date_time.ctime
30
24
  else
31
- @date_time.strftime '%a %b %e %T %Y'
25
+ date_time.strftime '%a %b %e %T %Y'
32
26
  end
33
27
  end
34
28
 
35
29
  def to_s
36
- "#{@address} #{formatted_date_time}"
30
+ "#{address} #{formatted_date_time}"
37
31
  end
38
-
39
32
  end
40
33
  end
@@ -1,26 +1,22 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
+ require 'mail/parsers/message_ids_parser'
4
+
3
5
  module Mail
4
6
  class MessageIdsElement
5
-
6
- include Mail::Utilities
7
+ attr_reader :message_ids
7
8
 
8
9
  def initialize(string)
9
- raise Mail::Field::ParseError.new(Mail::MessageIdsElement, string, 'nil is invalid') if string.nil?
10
- @message_ids = Mail::Parsers::MessageIdsParser.new.parse(string).message_ids.map { |msg_id| clean_msg_id(msg_id) }
11
- end
12
-
13
- def message_ids
14
- @message_ids
10
+ @message_ids = Mail::Parsers::MessageIdsParser.parse(string).message_ids.map { |msg_id| clean_msg_id(msg_id) }
15
11
  end
16
12
 
17
13
  def message_id
18
- @message_ids.first
14
+ message_ids.first
19
15
  end
20
16
 
21
- def clean_msg_id( val )
22
- val =~ /.*<(.*)>.*/ ; $1
17
+ private
18
+ def clean_msg_id(val)
19
+ val =~ /.*<(.*)>.*/ ? $1 : val
23
20
  end
24
-
25
21
  end
26
22
  end