]> git.openstreetmap.org Git - rails.git/blob - script/deliver-message
Add a notice about the downtime
[rails.git] / script / deliver-message
1 #!/usr/bin/env ruby
2
3 require File.dirname(__FILE__) + '/../config/environment'
4 require 'tmail'
5
6 exit 0 unless recipient = ARGV[0].match(/^([cm])-(\d+)-(.*)$/)
7
8 if recipient[1] == "c"
9   comment = DiaryComment.find(recipient[2])
10   digest = comment.digest
11   from = comment.diary_entry.user
12   to = comment.user
13 else
14   message = Message.find(recipient[2])
15   digest = message.digest
16   from = message.recipient
17   to = message.sender
18   subject = message.subject.sub(/\[OpenStreetMap\] */, "")
19 end
20
21 exit 0 unless recipient[3] == digest[0,6]
22
23 mail = TMail::Mail.parse(STDIN.readlines.join)
24
25 message = Message.new(:sender => from, :recipient => to,
26                       :sent_on => Time.now.getutc,
27                       :title => subject,
28                       :body => mail.body)
29 message.save!
30
31 Notifier::deliver_message_notification(message)
32
33 exit 0