2013-06-13 18:11:10 -04:00
|
|
|
#
|
|
|
|
# Connects to a mailbox and checks for replies
|
|
|
|
#
|
|
|
|
require 'net/pop'
|
|
|
|
require_dependency 'email/receiver'
|
2014-02-24 01:01:37 -05:00
|
|
|
require_dependency 'email/sender'
|
|
|
|
require_dependency 'email/message_builder'
|
2013-06-13 18:11:10 -04:00
|
|
|
|
|
|
|
module Jobs
|
2013-08-07 13:25:05 -04:00
|
|
|
class PollMailbox < Jobs::Scheduled
|
2014-02-05 18:14:41 -05:00
|
|
|
every 5.minutes
|
2013-06-13 18:11:10 -04:00
|
|
|
sidekiq_options retry: false
|
2014-02-24 01:01:37 -05:00
|
|
|
include Email::BuildEmailHelper
|
2013-06-13 18:11:10 -04:00
|
|
|
|
|
|
|
def execute(args)
|
|
|
|
if SiteSetting.pop3s_polling_enabled?
|
|
|
|
poll_pop3s
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-02-28 07:05:09 -05:00
|
|
|
def handle_mail(mail)
|
|
|
|
begin
|
|
|
|
Email::Receiver.new(mail).process
|
|
|
|
rescue Email::Receiver::UserNotSufficientTrustLevelError => e
|
|
|
|
# inform the user about the rejection
|
|
|
|
@message = Mail::Message.new(mail)
|
|
|
|
clientMessage = RejectionMailer.send_trust_level(@message.from, @message.body)
|
|
|
|
email_sender = Email::Sender.new(clientMessage, :email_reject_trust_level)
|
|
|
|
email_sender.send
|
|
|
|
rescue Email::Receiver::ProcessingError
|
|
|
|
# all other ProcessingErrors are ok to be dropped
|
|
|
|
rescue StandardError => e
|
|
|
|
# Inform Admins about error
|
|
|
|
GroupMessage.create(Group[:admins].name, :email_error_notification,
|
|
|
|
{limit_once_per: false, message_params: {source: mail, error: e}})
|
|
|
|
ensure
|
|
|
|
mail.delete
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-06-13 18:11:10 -04:00
|
|
|
def poll_pop3s
|
|
|
|
Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE)
|
|
|
|
Net::POP3.start(SiteSetting.pop3s_polling_host,
|
|
|
|
SiteSetting.pop3s_polling_port,
|
|
|
|
SiteSetting.pop3s_polling_username,
|
|
|
|
SiteSetting.pop3s_polling_password) do |pop|
|
|
|
|
unless pop.mails.empty?
|
|
|
|
pop.each do |mail|
|
2014-02-28 07:05:09 -05:00
|
|
|
handle_mail mail.pop
|
2013-06-13 18:11:10 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|