]> git.openstreetmap.org Git - rails.git/blob - script/deliver-message
Strip trailing whitespace from lines before joining them.
[rails.git] / script / deliver-message
1 #!/usr/bin/env ruby
2
3 require File.dirname(__FILE__) + '/../config/environment'
4 require 'mailread'
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 = Mail.new(STDIN)
23
24 message = Message.new(:sender => from, :recipient => to,
25                       :sent_on => Time.now.getutc,
26                       :title => mail["Subject"],
27                       :body => mail.body.map { |l| l.rstrip }.join("\n"))
28 message.save!
29
30 Notifier::deliver_message_notification(message)
31
32 exit 0