]> git.openstreetmap.org Git - rails.git/blob - script/deliver-message
Migrate the database on `vagrant up`.
[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   date = diary_comment.created_at
11   from = comment.diary_entry.user
12   to = comment.user
13 else
14   message = Message.find(recipient[2])
15   digest = message.digest
16   date = message.sent_on
17   from = message.recipient
18   to = message.sender
19 end
20
21 exit 0 unless recipient[3] == digest[0,6]
22 exit 0 if date < 1.month.ago
23
24 message.update_attribute(:message_read, true) if message
25
26 mail = Mail.new(STDIN.readlines.join)
27
28 message = Message.from_mail(mail, from, to)
29 message.save!
30
31 Notifier.message_notification(message).deliver
32
33 exit 0