2 # frozen_string_literal: true
4 require_relative File.join("..", "config", "environment")
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])
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
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
28 message&.update(:message_read => true)
30 mail = Mail.new($stdin.read
31 .encode(:universal_newline => true)
32 .encode(:crlf_newline => true))
34 message = Message.from_mail(mail, from, to)
37 UserMailer.message_notification(message).deliver if message.notify_recipient?