Sha256: 84a8b25dcaf9502136d3ca231d466ce14471b45949521bb4cdbfc1b27a7fb5b5

Contents?: true

Size: 1.26 KB

Versions: 14

Compression:

Stored size: 1.26 KB

Contents

# frozen_string_literal: true
require 'mail/smtp_envelope'

module Mail
  # FileDelivery class delivers emails into multiple files based on the destination
  # address.  Each file is appended to if it already exists.
  # 
  # So if you have an email going to fred@test, bob@test, joe@anothertest, and you
  # set your location path to /path/to/mails then FileDelivery will create the directory
  # if it does not exist, and put one copy of the email in three files, called
  # by their message id
  # 
  # Make sure the path you specify with :location is writable by the Ruby process
  # running Mail.
  class FileDelivery
    require 'fileutils'

    attr_accessor :settings

    def initialize(values)
      self.settings = { :location => './mails', :extension => '' }.merge!(values)
    end

    def deliver!(mail)
      envelope = Mail::SmtpEnvelope.new(mail)

      if ::File.respond_to?(:makedirs)
        ::File.makedirs settings[:location]
      else
        ::FileUtils.mkdir_p settings[:location]
      end

      envelope.to.uniq.each do |to|
        path = ::File.join(settings[:location], File.basename(to.to_s+settings[:extension]))

        ::File.open(path, 'a') do |f|
          f.write envelope.message
          f.write "\r\n\r\n"
        end
      end
    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/network/delivery_methods/file_delivery.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/file_delivery.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/file_delivery.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/file_delivery.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/file_delivery.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/mail-2.8.1/lib/mail/network/delivery_methods/file_delivery.rb
mail-2.8.1 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.8.1.rc2 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.8.0.1 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.8.0.1.rc1 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.8.0 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.8.0.rc3 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.8.0.rc2 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.8.0.rc1 lib/mail/network/delivery_methods/file_delivery.rb