class MailRouter
Public Class Methods
info(msg)
click to toggle source
# File lib/airmail/mail_router.rb, line 64 def info msg @logger && @logger.info(msg) end
logger=(loggr)
click to toggle source
# File lib/airmail/mail_router.rb, line 68 def logger= loggr @logger = loggr end
new(mail)
click to toggle source
# File lib/airmail/mail_router.rb, line 3 def initialize(mail) @mail = mail end
receive( original )
click to toggle source
# File lib/airmail/mail_router.rb, line 44 def receive( original ) mail = Mail::Message.new( original ) record(mail, original) self.new(mail).route mail end
record(mail, original)
click to toggle source
# File lib/airmail/mail_router.rb, line 53 def record(mail, original) Message.create!( from: mail.from.first, #reference_id: mail. to: mail.to, subject: mail.subject, original: original, taxonomy: 'log' ) end
Public Instance Methods
deliver(controller)
click to toggle source
# File lib/airmail/mail_router.rb, line 38 def deliver controller controller.new(@mail).receive end
from?(*args)
click to toggle source
# File lib/airmail/mail_router.rb, line 30 def from? *args from end
has_attachment?()
click to toggle source
# File lib/airmail/mail_router.rb, line 34 def has_attachment? @mail.attachments.size > 0 end
route()
click to toggle source
# File lib/airmail/mail_router.rb, line 7 def route #this is the app specific controller logic MailRouter.info("Receiving email '#{@mail.subject}' from #{@mail.from}, #{@mail.to} with #{@mail.attachments.count} attachments") @mail.attachments.each do |attach| MailRouter.info(">> #{attach.filename}")#(#{a.content_type.to_s})") end #TODO catch mailerdaemon stuff #TODO circular loops? throttle speed #if from? :mailerdaemon, :root (deliver MailDemoController and return) if @mail.to.join(" ") =~ /demo.*@amendment.io/ if has_attachment? #if not on the contact list, don't grant access to services (deliver ThanksForPlayingController and return) unless Contact.find_by_email(@mail.from.collect{|f| f.downcase}) (deliver AttachmentController and return) end deliver DefaultController and return end