]> git.openstreetmap.org Git - rails.git/blob - script/deliver-message
Merge remote-tracking branch 'openstreetmap/pull/1395'
[rails.git] / script / deliver-message
1 #!/usr/bin/env ruby
2
3 require File.dirname(__FILE__) + "/../config/environment"
4
5 if recipient = ARGV[0].match(/^c-(\d+)-(\d+)-(.*)$/)
6   comment = DiaryComment.find(recipient[1])
7   digest = comment.digest
8   date = comment.created_at
9   from = User.find(recipient[2])
10   to = comment.user
11   token = recipient[3]
12 elsif recipient = ARGV[0].match(/^m-(\d+)-(.*)$/)
13   message = Message.find(recipient[1])
14   digest = message.digest
15   date = message.sent_on
16   from = message.recipient
17   to = message.sender
18   token = recipient[2]
19 else
20   exit 0
21 end
22
23 exit 0 unless token == digest[0, 6]
24 exit 0 if date < 1.month.ago
25
26 message.update_attribute(:message_read, true) if message
27
28 mail = Mail.new(STDIN.readlines.join)
29
30 message = Message.from_mail(mail, from, to)
31 message.save!
32
33 Notifier.message_notification(message).deliver
34
35 exit 0