Class: MailRouter
- Inherits:
-
Object
- Object
- MailRouter
- Defined in:
- lib/airmail/mail_router.rb
Class Method Summary collapse
- .info(msg) ⇒ Object
- .logger=(loggr) ⇒ Object
- .receive(original) ⇒ Object
- .record(mail, original) ⇒ Object
Instance Method Summary collapse
- #deliver(controller) ⇒ Object
- #from?(*args) ⇒ Boolean
- #has_attachment? ⇒ Boolean
-
#initialize(mail) ⇒ MailRouter
constructor
A new instance of MailRouter.
-
#route ⇒ Object
this is the app specific controller logic.
Constructor Details
#initialize(mail) ⇒ MailRouter
3 4 5 |
# File 'lib/airmail/mail_router.rb', line 3 def initialize(mail) @mail = mail end |
Class Method Details
.info(msg) ⇒ Object
64 65 66 |
# File 'lib/airmail/mail_router.rb', line 64 def info msg @logger && @logger.info(msg) end |
.logger=(loggr) ⇒ Object
68 69 70 |
# File 'lib/airmail/mail_router.rb', line 68 def logger= loggr @logger = loggr end |
.receive(original) ⇒ Object
44 45 46 47 48 49 50 51 |
# 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) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# 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 |
Instance Method Details
#deliver(controller) ⇒ Object
38 39 40 |
# File 'lib/airmail/mail_router.rb', line 38 def deliver controller controller.new(@mail).receive end |
#from?(*args) ⇒ Boolean
30 31 32 |
# File 'lib/airmail/mail_router.rb', line 30 def from? *args from end |
#has_attachment? ⇒ Boolean
34 35 36 |
# File 'lib/airmail/mail_router.rb', line 34 def @mail..size > 0 end |
#route ⇒ Object
this is the app specific controller logic
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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..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 #if not on the contact list, don't grant access to services (deliver and return) unless Contact.find_by_email(@mail.from.collect{|f| f.downcase}) (deliver AttachmentController and return) end deliver DefaultController and return end |