Sha256: 3e66c2c87093f60ff977f55225e826f16dafa6ace2abd3bc041b7b1e4b8466f1

Contents?: true

Size: 1.16 KB

Versions: 118

Compression:

Stored size: 1.16 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
  # "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

118 entries across 88 versions & 6 rubygems

Version Path
depengine-0.0.31 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.31 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.30 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.30 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.29 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.29 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.28 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.28 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.27 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.27 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.26 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.26 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.25 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.25 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.24 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.24 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.23 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.23 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.22 etc/isolate/ruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb
depengine-0.0.22 etc/isolate/jruby-1.8/gems/mail-2.2.5/lib/mail/network/delivery_methods/file_delivery.rb