我希望我的 Rails 应用程序能够接收传入的电子邮件并以特定方式解析它们。
传入控制器.rb
class IncomingController < ApplicationController
skip_before_action :verify_authenticity_token, only: [:create]
skip_before_action :authenticate_user!, only: [:create]
def create
# Find the user
user = User.find_by(email: params[:sender])
# Find the topic
topic = Topic.find_by(title: params[:subject])
# Assign the url to a variable after retreiving it from
url = params["body-plain"]
# If the user is nil, create and save a new user
if user.nil?
user = User.new(email: params[:sender], password: "password")
user.save!
end
# If the topic is nil, create and save a new topic
if topic.nil?
topic = Topic.new(title: params[:subject], user: user)
topic.save!
end
bookmark = topic.bookmarks.build(user: user, url: url, description: "bookmark for #{url}")
bookmark.save!
# Assuming all went well.
head 200
end
end
使用这个控制器,我只能提取 3 个值 = 用户:发件人、主题:主题和 url “body-plain”。
如何在电子邮件中添加第四个值来解析:description?