Skip to content

Instantly share code, notes, and snippets.

@gmaliar
Created February 11, 2019 10:29
Show Gist options
  • Save gmaliar/a90c83debb1fc024a83a134eff0f80c0 to your computer and use it in GitHub Desktop.
Save gmaliar/a90c83debb1fc024a83a134eff0f80c0 to your computer and use it in GitHub Desktop.
COMMENTS_REGEX = /^comment\+(.+)@example\.com/i
# app/mailboxes/application_mailbox.rb
class ApplicationMailbox < ActionMailbox::Base
routing COMMENTS_REGEX => :comments
end
# app/mailboxes/comments_mailbox.rb
class CommentsMailbox < ApplicationMailbox
def process
user = User.find_by(email: mail.from)
post_uuid = COMMENTS_REGEX.match(mail.to)[1]
post = Post.find_by(uuid: post_uuid)
post.comments.create(user: user, content: mail.body)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment