Move command line mail handling into separate function
This commit is contained in:
parent
46275fa564
commit
4817ab6452
1 changed files with 51 additions and 48 deletions
|
@ -3,7 +3,12 @@ require "mail"
|
|||
namespace :foodsoft do
|
||||
desc "Parse incoming email on stdin (options: RECIPIENT=f.1.2.a1b2c3d3e5)"
|
||||
task :parse_reply_email => :environment do
|
||||
m = /(?<foodcoop>[^@]*)\.(?<message_id>\d+)\.(?<user_id>\d+)\.(?<hash>\w+)(@(?<hostname>.*))?/.match(ENV['RECIPIENT'])
|
||||
hande_mail(ENV['RECIPIENT'], STDIN.read)
|
||||
end
|
||||
end
|
||||
|
||||
def hande_mail(recipient, received_email)
|
||||
m = /(?<foodcoop>[^@]*)\.(?<message_id>\d+)\.(?<user_id>\d+)\.(?<hash>\w+)(@(?<hostname>.*))?/.match(recipient)
|
||||
|
||||
raise "RECIPIENT is missing or has an invalid format" if m.nil?
|
||||
raise "Foodcoop '#{m[:foodcoop]}' could not be found" unless FoodsoftConfig.foodcoops.include? m[:foodcoop]
|
||||
|
@ -18,7 +23,6 @@ namespace :foodsoft do
|
|||
hash = original_message.mail_hash_for_user user
|
||||
raise "Hash does not match expectations" unless hash.casecmp(m[:hash]) == 0
|
||||
|
||||
received_email = STDIN.read
|
||||
mail = Mail.new received_email
|
||||
|
||||
mail_part = nil
|
||||
|
@ -52,7 +56,6 @@ namespace :foodsoft do
|
|||
Resque.enqueue(MessageNotifier, FoodsoftConfig.scope, "message_deliver", message.id)
|
||||
rake_say "Handled reply email from #{user.display}."
|
||||
end
|
||||
end
|
||||
|
||||
# Helper
|
||||
def rake_say(message)
|
||||
|
|
Loading…
Reference in a new issue