openstreetmap-website/script/deliver-message
Tom Hughes 23b8672bc9 Add support for processing incoming mail messages in reply to message
notifications and diary comment notifications, turning the maill messages
into reply messages through the site messaging system.
2009-11-05 23:16:20 +00:00

32 lines
782 B
Ruby
Executable file

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
require 'mailread'
exit 0 unless recipient = ARGV[0].match(/^([cm])-(\d+)-(.*)$/)
if recipient[1] == "c"
comment = DiaryComment.find(recipient[2])
digest = comment.digest
from = comment.diary_entry.user
to = comment.user
else
message = Message.find(recipient[2])
digest = message.digest
from = message.recipient
to = message.sender
end
exit 0 unless recipient[3] == digest[0,6]
mail = Mail.new(STDIN)
message = Message.new(:sender => from, :recipient => to,
:sent_on => Time.now.getutc,
:title => mail["Subject"],
:body => mail.body.join("\n"))
message.save!
Notifier::deliver_message_notification(message)
exit 0