Created
February 11, 2019 10:29
-
-
Save gmaliar/a90c83debb1fc024a83a134eff0f80c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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