Sha256: 349671e9e6272abe083f6fc4472e7842608b01ffc4f6ce377fa856a37dd9ccff

Contents?: true

Size: 1.09 KB

Versions: 4

Compression:

Stored size: 1.09 KB

Contents

module MList
  class Server
    attr_reader :list_manager, :email_server
    
    def initialize(config)
      @list_manager = config[:list_manager]
      @email_server = config[:email_server]
      @email_server.receiver(self)
    end
    
    def receive_email(email)
      lists = list_manager.lists(email)
      if lists.empty?
        list_manager.no_lists_found(email)
      elsif email.bounce?
        process_bounce(lists.first, email)
      else
        process_post(lists, email)
      end
    end
    
    def mail_list(list)
      MailList.find_or_create_by_list(list, @email_server)
    end
    
    protected
      def process_bounce(list, email)
        list.bounce(email)
      end
      
      def process_post(lists, email)
        lists.each do |list|
          next if email.been_here?(list)
          if list.subscriber?(email.from_address)
            if list.active?
              mail_list(list).process_email(email)
            else
              list.inactive_post(email)
            end
          else
            list.non_subscriber_post(email)
          end
        end
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
aiwilliams-mlist-0.1.1 lib/mlist/server.rb
aiwilliams-mlist-0.1.2 lib/mlist/server.rb
aiwilliams-mlist-0.1.3 lib/mlist/server.rb
aiwilliams-mlist-0.1.4 lib/mlist/server.rb