File: check_delivery_params.rb

package info (click to toggle)
ruby-mail 2.8.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 5,704 kB
  • sloc: ruby: 73,709; makefile: 3
file content (65 lines) | stat: -rw-r--r-- 1,940 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true
#
# This whole class and associated specs is deprecated and will go away in the version 3 release of mail.
module Mail
  module CheckDeliveryParams #:nodoc:
    class << self

      extend Gem::Deprecate

      def check(mail)
        envelope = Mail::SmtpEnvelope.new(mail)
        [ envelope.from,
          envelope.to,
          envelope.message ]
      end
      deprecate :check, 'Mail::SmtpEnvelope.new created in commit c106bebea066782a72e4f24dd37b532d95773df7', 2023, 6

      def check_from(addr)
        mail = Mail.new(from: 'deprecated@example.com', to: 'deprecated@example.com')
        Mail::SmtpEnvelope.new(mail).send(:validate_addr, 'From', addr)
      end
      deprecate :check_from, :none, 2023, 6

      def check_to(addrs)
        mail = Mail.new(from: 'deprecated@example.com', to: 'deprecated@example.com')
        Array(addrs).map do |addr|
          Mail::SmtpEnvelope.new(mail).send(:validate_addr, 'To', addr)
        end
      end
      deprecate :check_to, :none, 2023, 6

      def check_addr(addr_name, addr)
        mail = Mail.new(from: 'deprecated@example.com', to: 'deprecated@example.com')
        Mail::SmtpEnvelope.new(mail).send(:validate_addr, addr_name, addr)
      end
      deprecate :check_addr, :none, 2023, 6

      def validate_smtp_addr(addr)
        if addr
          if addr.bytesize > 2048
            yield 'may not exceed 2kB'
          end

          if /[\r\n]/ =~ addr
            yield 'may not contain CR or LF line breaks'
          end
        end

        addr
      end
      deprecate :validate_smtp_addr, :none, 2023, 6

      def check_message(message)
        message = message.encoded if message.respond_to?(:encoded)

        if Utilities.blank?(message)
          raise ArgumentError, 'An encoded message is required to send an email'
        end

        message
      end
      deprecate :check_message, :none, 2023, 6
    end
  end
end