Sha256: 1aab0fa10f82988b5d43e3f070092b26655135436433ef2ab7c93e67ae4f1550

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

require 'fde/mail_crawler/version'
require 'mail'

module FDE
  module MailCrawler

    class Config
      attr_accessor :address,
        :port,
        :domain,
        :user_name,
        :password,
        :authentication,
        :enable_starttls_auto

      def attributes
        {
          address: @address,
          port: @port,
          domain: @domain,
          user_name: @user_name,
          password: @password,
          authentication: @authentication,
          enable_starttls_auto: @enable_starttls_auto
        }
      end
    end

    def self.config
      @@config ||= Config.new
    end

    def self.imap_account
      @@imap_account ||= ::Mail.defaults do
        retriever_method :imap, FDE::MailCrawler.config.attributes
      end
    end

    def self.configure
      yield self.config
    end

    def self.watch(&block)
      self.crawl.each do |mail|
        yield mail
      end
    end

    def self.crawl
      FDE::MailCrawler.imap_account.all
    end

    def self.delete(message_to_delete)
      account = FDE::MailCrawler.imap_account
      account.find_and_delete do |message|
        unless message.subject == message_to_delete.subject
          message.skip_deletion
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fde-mail_crawler-0.2.1 lib/fde/mail_crawler.rb