tilde.news/script/parse_inbound_mail

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

2013-06-25 18:58:52 +00:00
#!/usr/bin/env ruby
ENV["RAILS_ENV"] ||= "production"
APP_PATH = File.expand_path("../../config/application", __FILE__)
require File.expand_path("../../config/boot", __FILE__)
2013-06-25 18:58:52 +00:00
require APP_PATH
Rails.application.require_environment!
# postfix exit codes
EX_NOUSER = 67
EX_TEMPFAIL = 75
EX_UNAVAILABLE = 69
message = ""
until $stdin.eof?
message += $stdin.gets.to_s
end
2018-03-14 17:04:03 +00:00
parser = EmailParser.new(ARGV[1], ARGV[0], message)
if parser.been_here?
# avoid looping, quietly
2013-06-25 18:58:52 +00:00
exit
elsif !parser.sending_user
warn "no active user with mailing list token #{parser.user_token}"
2013-06-25 18:58:52 +00:00
# if this looks like a user token but invalid, generate a bounce to be
# helpful. otherwise supress it to avoid talking back to spammers
exit(parser.user_token ? EX_NOUSER : 0)
2013-06-25 18:58:52 +00:00
elsif !parser.email
warn "error parsing e-mail"
2013-06-25 18:58:52 +00:00
exit EX_UNAVAILABLE
elsif !parser.parent
warn "no valid comment or story being replied to"
2013-06-25 18:58:52 +00:00
exit EX_NOUSER
2023-09-14 13:29:11 +00:00
elsif parser.body.blank?
warn "no valid text/plain body found"
2013-06-25 18:58:52 +00:00
exit EX_UNAVAILABLE
end
c = Comment.new
c.user_id = parser.sending_user.id
c.comment = parser.body
c.is_from_email = true
2013-06-25 18:58:52 +00:00
if parser.parent.is_a?(Comment)
c.story_id = parser.parent.story_id
c.parent_comment_id = parser.parent.id
2013-06-25 18:58:52 +00:00
else
c.story_id = parser.parent.id
2013-06-25 18:58:52 +00:00
end
if c.save
exit
else
warn c.errors.inspect
2013-06-25 18:58:52 +00:00
exit EX_UNAVAILABLE
end