Class: MailManager::BounceJob
- Inherits:
-
Struct
- Object
- Struct
- MailManager::BounceJob
- Defined in:
- lib/workers/mail_manager/bounce_job.rb
Instance Attribute Summary collapse
-
#repeats_every ⇒ Object
Returns the value of attribute repeats_every.
Instance Method Summary collapse
Instance Attribute Details
#repeats_every ⇒ Object
Returns the value of attribute repeats_every
19 20 21 |
# File 'lib/workers/mail_manager/bounce_job.rb', line 19 def repeats_every @repeats_every end |
Instance Method Details
#perform ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/workers/mail_manager/bounce_job.rb', line 20 def perform = 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 = true Rails.logger.info "You have #{pop.mails.length} new bounced messages." Rails.logger.info "Downloading..." = 50 = 0 pop.mails.each_with_index do|m,i| bounce = ::MailManager::Bounce.create({ # ensure encoding will work; we don't really care about invalid characters # PG will explode if utf-8 has invalid chars :bounce_message => m.pop.encode("utf-8", invalid: :replace, undef: :replace) }) bounce.process m.delete += 1 break if > end end end if ::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 |