Improve the interface of FoodsoftMailReceiver
This commit is contained in:
parent
e9bae618ed
commit
e017a1196e
3 changed files with 24 additions and 19 deletions
|
@ -4,11 +4,14 @@ class BounceMailReceiver
|
|||
/bounce\+(?<local>.*)=(?<domain>[^=]+)/
|
||||
end
|
||||
|
||||
def received(match, data)
|
||||
address = "#{match[:local]}@#{match[:domain]}"
|
||||
def initialize(match)
|
||||
@address = "#{match[:local]}@#{match[:domain]}"
|
||||
end
|
||||
|
||||
def received(data)
|
||||
mail = Mail.new data
|
||||
subject = mail.subject || 'Unknown bounce error'
|
||||
MailDeliveryStatus.create email: address,
|
||||
MailDeliveryStatus.create email: @address,
|
||||
message: subject,
|
||||
attachment_mime: 'message/rfc822',
|
||||
attachment_data: data
|
||||
|
|
|
@ -17,7 +17,7 @@ class FoodsoftMailReceiver < MidiSmtpServer::Smtpd
|
|||
|
||||
@@registered_classes.each do |klass|
|
||||
klass_m = klass.regexp.match(m[:address])
|
||||
return klass.new.received klass_m, data if klass_m
|
||||
return klass.new(klass_m).received(data) if klass_m
|
||||
end
|
||||
|
||||
raise "invalid format for recipient"
|
||||
|
|
|
@ -6,16 +6,18 @@ class MessagesMailReceiver
|
|||
/(?<message_id>\d+)\.(?<user_id>\d+)\.(?<hash>\w+)/
|
||||
end
|
||||
|
||||
def received(match, data)
|
||||
original_message = Message.find_by_id(match[:message_id])
|
||||
user = User.find_by_id(match[:user_id])
|
||||
def initialize(match)
|
||||
@message = Message.find_by_id(match[:message_id])
|
||||
@user = User.find_by_id(match[:user_id])
|
||||
|
||||
raise "Message could not be found" if original_message.nil?
|
||||
raise "User could not be found" if user.nil?
|
||||
raise "Message could not be found" if @message.nil?
|
||||
raise "User could not be found" if @user.nil?
|
||||
|
||||
hash = original_message.mail_hash_for_user user
|
||||
hash = @message.mail_hash_for_user(@user)
|
||||
raise "Hash does not match expectations" unless hash.casecmp(match[:hash]) == 0
|
||||
end
|
||||
|
||||
def received(data)
|
||||
mail = Mail.new data
|
||||
|
||||
mail_part = nil
|
||||
|
@ -41,18 +43,18 @@ class MessagesMailReceiver
|
|||
|
||||
body = EmailReplyTrimmer.trim(body)
|
||||
|
||||
message = user.send_messages.new body: body,
|
||||
group: original_message.group,
|
||||
private: original_message.private,
|
||||
received_email: received_email,
|
||||
message = @user.send_messages.new body: body,
|
||||
group: @message.group,
|
||||
private: @message.private,
|
||||
received_email: data,
|
||||
subject: mail.subject.gsub("[#{FoodsoftConfig[:name]}] ", "")
|
||||
if original_message.reply_to
|
||||
message.reply_to_message = original_message.reply_to_message
|
||||
if @message.reply_to
|
||||
message.reply_to_message = @message.reply_to_message
|
||||
else
|
||||
message.reply_to_message = original_message
|
||||
message.reply_to_message = @message
|
||||
end
|
||||
message.add_recipients original_message.recipients
|
||||
message.add_recipients [original_message.sender]
|
||||
message.add_recipients @message.recipients
|
||||
message.add_recipients [@message.sender]
|
||||
|
||||
message.save!
|
||||
Resque.enqueue(MessageNotifier, FoodsoftConfig.scope, "message_deliver", message.id)
|
||||
|
|
Loading…
Reference in a new issue