Sha256: 9ab00477610f2d87d1ca724136a1a658a4694b13a781aef08169a2ffe554799d

Contents?: true

Size: 1.72 KB

Versions: 11

Compression:

Stored size: 1.72 KB

Contents

=begin rdoc
Author::    Chris Hauboldt (mailto:biz@lnstar.com)
Copyright:: 2009 Lone Star Internet Inc.

Worker used to pop bounces from the bounce email account and create an Bounce to process them.

Configuration:
  config/config.yml in application root

  bounce:
      email_address: bounce@example.com
      login: bounce
      password: secret
      pop_server: pop.example.com

=end
require 'net/pop'
module MailManager
  class BounceJob < Struct.new(:repeats_every)
    def perform
      found_messages = false
      ::MailManager::Lock.with_lock('mail_manager_bounce_job') do
        Rails.logger.info "Bounce Job Connecting to #{MailManager.bounce['pop_server']} with #{MailManager.bounce['login']}:#{MailManager.bounce['password']}"
        Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if MailManager.bounce['ssl']
        Net::POP3.start(MailManager.bounce['pop_server'],MailManager.bounce['port'],
        	MailManager.bounce['login'], MailManager.bounce['password']) do |pop|

          if pop.mails.empty?
            Rails.logger.info "No mail."
          else
            found_messages = true
            Rails.logger.info "You have #{pop.mails.length} new bounced messages."
            Rails.logger.info "Downloading..."

            pop.mails.each_with_index do|m,i|
              bounce = ::MailManager::Bounce.create({
                :bounce_message => m.pop
              })
              bounce.process
              m.delete
            end
          end
        end
        if found_messages
          ::Delayed::Job.enqueue ::MailManager::BounceJob.new, run_at: 10.minutes.from_now
        else
          ::Delayed::Job.enqueue ::MailManager::BounceJob.new, run_at: 120.minutes.from_now
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mail_manager-3.2.7 lib/workers/mail_manager/bounce_job.rb
mail_manager-3.2.6 lib/workers/mail_manager/bounce_job.rb
mail_manager-3.2.5 lib/workers/mail_manager/bounce_job.rb
mail_manager-3.2.4 lib/workers/mail_manager/bounce_job.rb
mail_manager-3.2.2 lib/workers/mail_manager/bounce_job.rb
mail_manager-3.2.1 lib/workers/mail_manager/bounce_job.rb
mail_manager-3.2.0 lib/workers/mail_manager/bounce_job.rb
mail_manager-3.0.0 lib/workers/mail_manager/bounce_job.rb
mail_manager-0.1.4 lib/workers/mail_manager/bounce_job.rb
mail_manager-0.1.2 lib/workers/mail_manager/bounce_job.rb
mail_manager-0.1.1 lib/workers/mail_manager/bounce_job.rb