Sha256: 9902d8541b74cb676c8f054b0e9a5d9275ef28dce2474834053aa6d7378cbfc0

Contents?: true

Size: 1.38 KB

Versions: 14

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

module Mail
  class SmtpEnvelope #:nodoc:
    # Reasonable cap on address length to avoid SMTP line length
    # overflow on old SMTP servers.
    MAX_ADDRESS_BYTESIZE = 2000

    attr_reader :from, :to, :message

    def initialize(mail)
      self.from = mail.smtp_envelope_from
      self.to = mail.smtp_envelope_to
      self.message = mail.encoded
    end

    def from=(addr)
      if Utilities.blank? addr
        raise ArgumentError, "SMTP From address may not be blank: #{addr.inspect}"
      end

      @from = validate_addr 'From', addr
    end

    def to=(addr)
      if Utilities.blank?(addr)
        raise ArgumentError, "SMTP To address may not be blank: #{addr.inspect}"
      end

      @to = Array(addr).map do |addr|
        validate_addr 'To', addr
      end
    end

    def message=(message)
      if Utilities.blank?(message)
        raise ArgumentError, 'SMTP message may not be blank'
      end

      @message = message
    end


    private
      def validate_addr(addr_name, addr)
        if addr.bytesize > MAX_ADDRESS_BYTESIZE
          raise ArgumentError, "SMTP #{addr_name} address may not exceed #{MAX_ADDRESS_BYTESIZE} bytes: #{addr.inspect}"
        end

        if /[\r\n]/ =~ addr
          raise ArgumentError, "SMTP #{addr_name} address may not contain CR or LF line breaks: #{addr.inspect}"
        end

        addr
      end
  end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/smtp_envelope.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/smtp_envelope.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/smtp_envelope.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/smtp_envelope.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/smtp_envelope.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/smtp_envelope.rb
mail-2.8.1 lib/mail/smtp_envelope.rb
mail-2.8.1.rc2 lib/mail/smtp_envelope.rb
mail-2.8.0.1 lib/mail/smtp_envelope.rb
mail-2.8.0.1.rc1 lib/mail/smtp_envelope.rb
mail-2.8.0 lib/mail/smtp_envelope.rb
mail-2.8.0.rc3 lib/mail/smtp_envelope.rb
mail-2.8.0.rc2 lib/mail/smtp_envelope.rb
mail-2.8.0.rc1 lib/mail/smtp_envelope.rb