Sha256: 6e89a4658791a983ee4887fa1168e56ce087bbf29f38e805635d191624377092

Contents?: true

Size: 1.15 KB

Versions: 93

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 /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

    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], File.basename(to.to_s)), 'a') { |f| "#{f.write(mail.encoded)}\r\n\r\n" }
      end
    end
    
  end
end

Version data entries

93 entries across 85 versions & 11 rubygems

Version Path
challah-0.9.0 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.6.9 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
challah-rolls-0.2.0 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
challah-0.8.3 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.6.8 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.6.7 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
otherinbox-mail-2.4.4.20121031 lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.6.6 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.6.5 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.6.4 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.6.3 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.6.2 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.6.1 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.6.0 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
challah-0.8.1 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.5.17 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.5.16 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.5.15 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb