Class: BBMB::Util::PopMission

Inherits:
Object
  • Object
show all
Defined in:
lib/bbmb/util/polling_manager.rb

Constant Summary collapse

@@ptrn =
/name=(?:(?:(?<quote>['"])(?:=\?.+?\?[QB]\?)?(?<file>.*?)(\?=)?(?<!\\)\k<quote>)|(?:(?<file>.+?)(?:;|$)))/i

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#content_typeObject

Returns the value of attribute content_type.



55
56
57
# File 'lib/bbmb/util/polling_manager.rb', line 55

def content_type
  @content_type
end

#hostObject

Returns the value of attribute host.



55
56
57
# File 'lib/bbmb/util/polling_manager.rb', line 55

def host
  @host
end

#passObject

Returns the value of attribute pass.



55
56
57
# File 'lib/bbmb/util/polling_manager.rb', line 55

def pass
  @pass
end

#portObject

Returns the value of attribute port.



55
56
57
# File 'lib/bbmb/util/polling_manager.rb', line 55

def port
  @port
end

#userObject

Returns the value of attribute user.



55
56
57
# File 'lib/bbmb/util/polling_manager.rb', line 55

def user
  @user
end

Instance Method Details

#poll(&block) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/bbmb/util/polling_manager.rb', line 57

def poll(&block)
  @backup_dir = BBMB.config.backup_dir if BBMB.config.respond_to?(:backup_dir)
  @backup_dir ||= Dir.tmpdir
  options = {
                    :address    => @host,
                    :port       => @port,
                    :user_name  => @user,
                    :password   => @pass,
                    :enable_ssl => true
    }
  ::Mail.defaults do retriever_method :pop3, options  end
  all_mails = ::Mail.delivery_method.is_a?(::Mail::TestMailer) ? ::Mail::TestMailer.deliveries : ::Mail.all
  all_mails.each do |mail|
      begin
        poll_message(mail, &block)
      ensure
        time = Time.now
        name = sprintf("%s.%s.%s", @user, time.strftime("%Y%m%d%H%M%S"), time.usec)
        FileUtils.mkdir_p(@backup_dir)
        path = File.join(@backup_dir, name)
        File.open(path, 'w') { |fh| fh.puts(mail) }
        mail.mark_for_delete = true
        # mail.delete # Not necessary with gem mail, as delete_after_find is set to true by default
      end
  end
end

#poll_message(message, &block) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/bbmb/util/polling_manager.rb', line 83

def poll_message(message, &block)
  if(message.multipart?)
    message.parts.each do |part|
      poll_message(part, &block)
    end
  elsif(/text\/xml/.match(message.content_type))
    filtered_transaction(message.decoded, sprintf('pop3:%s@%s:%s', @user, @host, @port), &block)
  elsif message.attachment?
    block.call(message.filename, message.decoded)
  end
end