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
classiccms-0.7.5 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.7.4 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.7.3 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
active_mailer-0.0.10 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
judge-2.0.5 vendor/bundle/ruby/2.1.0/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.7.2 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.7.1 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
active_mailer-0.0.9 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
active_mailer-0.0.8 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
active_mailer-0.0.7 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
active_mailer-0.0.6 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
classiccms-0.7.0 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
challah-1.0.0.beta vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
active_mailer-0.0.5 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
active_mailer-0.0.4 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
active_mailer-0.0.3 test/fixtures/dummyapp_rails_3.2/vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
challah-0.9.1.beta.3 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
devise_sociable-0.1.0 vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
challah-0.9.1.beta vendor/bundle/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/mail-2.4.4/lib/mail/network/delivery_methods/file_delivery.rb