Sha256: cac68e748595f2e17e16e7d8943b8113bddfc7a09cb63326e882b0b6ebae6aa4

Contents?: true

Size: 1.15 KB

Versions: 8

Compression:

Stored size: 1.15 KB

Contents

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 ~/tmp/mails then FileDelivery will create ~/tmp/mails
  # if it does not exist, and put one copy of the email in three files, called
  # "fred@test", "bob@test" and "joe@anothertest"
  # 
  # Make sure the path you specify with :location is writable by the Ruby process
  # running Mail.
  class FileDelivery

    if RUBY_VERSION >= '1.9.1'
      require 'fileutils'
    else
      require 'ftools'
    end

    def initialize(values)
      self.settings = { :location => './mails' }.merge!(values)
    end
    
    attr_accessor :settings
    
    def deliver!(mail)
      if ::File.respond_to?(:makedirs)
        ::File.makedirs settings[:location]
      else
        ::FileUtils.mkdir_p settings[:location]
      end

      mail.destinations.uniq.each do |to|
        ::File.open(::File.join(settings[:location], to), 'a') { |f| "#{f.write(mail.encoded)}\r\n\r\n" }
      end
    end
    
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
mail-2.1.5 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.1.3 lib/mail/network/delivery_methods/file_delivery.rb
kbaum-mail-2.1.2.1 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.1.2 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.1.1 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.1.0 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.0.5 lib/mail/network/delivery_methods/file_delivery.rb
mail-2.0.3 lib/mail/network/delivery_methods/file_delivery.rb