Module: MailRunner::InboundManagerBot

Defined in:
lib/mail_runner/inbound_manager_bot.rb

Class Method Summary collapse

Class Method Details

.deliver_mail(webhook, json_packet) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/mail_runner/inbound_manager_bot.rb', line 36

def self.deliver_mail(webhook, json_packet)
  begin
    BotHelpers::Runner.post_to_hook(webhook, json_packet)
  rescue Exception => msg 
    #interrupt exception here, so rest of inbound mail can be processed and added to queue.
    #otherwise, it will be lost.
    queued = MailRunner::QueueManagerBot.add_to_mail_queue(webhook, json_packet)
  end
end

.get_mail(mailbox) ⇒ Object

Delegation Methods###



28
29
30
# File 'lib/mail_runner/inbound_manager_bot.rb', line 28

def self.get_mail(mailbox)
  BotHelpers::Runner.get_contents_from_mailbox(mailbox) 
end

.process_inbound(mailbox, webhook, archive = nil) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mail_runner/inbound_manager_bot.rb', line 5

def self.process_inbound(mailbox, webhook, archive=nil)
  raw_mail = get_mail(mailbox)
  
  unless raw_mail.nil?
    raw_mail.each do |raw_msg|    

      mail = read_mail(raw_msg)

      json_packet = BotHelpers::Helpers.convert_raw_mail_to_json(mail)
      
      deliver_mail(webhook, json_packet)

      #Mail archived regardless of delivery errors.
      #Delayed mail processed by queue manager, so only archived once on initial pickup. 
      if archive   
        MailRunner::ArchivistBot.add_to_archive_stack(json_packet, archive)
      end
    end
  end
end

.read_mail(raw_msg) ⇒ Object



32
33
34
# File 'lib/mail_runner/inbound_manager_bot.rb', line 32

def self.read_mail(raw_msg)
  Mail.read_from_string(raw_msg)
end