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