]> 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
5 exit 0 unless recipient = ARGV[0].match(/^([cm])-(\d+)-(.*)$/)
6
7 if recipient[1] == "c"
8   comment = DiaryComment.find(recipient[2])
9   digest = comment.digest
10   from = comment.diary_entry.user
11   to = comment.user
12 else
13   message = Message.find(recipient[2])
14   digest = message.digest
15   from = message.recipient
16   to = message.sender
17 end
18
19 exit 0 unless recipient[3] == digest[0,6]
20
21 mail = Mail.new(STDIN.readlines.join)
22
23 if mail.multipart?
24   body = mail.html_part || mail.text_part
25 else
26   body = mail
27 end
28
29 message = Message.new({
30   :sender => from,
31   :recipient => to,
32   :sent_on => mail.date.new_offset(0),
33   :title => mail.subject.sub(/\[OpenStreetMap\] */, ""),
34   :body => body.decoded
35 }, :without_protection => true)
36 message.save!
37
38 Notifier.message_notification(message).deliver
39
40 exit 0