]> git.openstreetmap.org Git - rails.git/blob - script/deliver-message
Merge branch 'master' into openstreetbugs
[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 end
19
20 exit 0 unless recipient[3] == digest[0,6]
21
22 mail = TMail::Mail.parse(STDIN.readlines.join)
23
24 message = Message.new(:sender => from, :recipient => to,
25                       :sent_on => Time.now.getutc,
26                       :title => mail.subject.sub(/\[OpenStreetMap\] */, ""),
27                       :body => mail.body)
28 message.save!
29
30 Notifier::deliver_message_notification(message)
31
32 exit 0