]> git.openstreetmap.org Git - rails.git/blob - script/deliver-message
Add frozen_string_literal comments to ruby files
[rails.git] / script / deliver-message
1 #!/usr/bin/env ruby
2 # frozen_string_literal: true
3
4 require_relative File.join("..", "config", "environment")
5
6 if recipient = ARGV[0].match(/^c-(\d+)-(\d+)-(.*)$/)
7   comment = DiaryComment.find(recipient[1])
8   expected_token = comment.notification_token(recipient[2])
9   date = comment.created_at
10   from = comment.diary_entry.subscribers.find(recipient[2])
11   to = comment.user
12   token = recipient[3]
13 elsif recipient = ARGV[0].match(/^m-(\d+)-(.*)$/)
14   message = Message.find(recipient[1])
15   expected_token = message.notification_token
16   date = message.sent_on
17   from = message.recipient
18   to = message.sender
19   token = recipient[2]
20 else
21   exit 0
22 end
23
24 exit 0 unless ActiveSupport::SecurityUtils.secure_compare(token, expected_token)
25 exit 0 unless from.active?
26 exit 0 if date < 1.month.ago
27
28 message&.update(:message_read => true)
29
30 mail = Mail.new($stdin.read
31                      .encode(:universal_newline => true)
32                      .encode(:crlf_newline => true))
33
34 message = Message.from_mail(mail, from, to)
35 message.save!
36
37 UserMailer.message_notification(message).deliver if message.notify_recipient?
38
39 exit 0