Class: ETL::Processor::Pop3attachmentDownloaderProcessor
- Inherits:
-
Processor
- Object
- Processor
- ETL::Processor::Pop3attachmentDownloaderProcessor
- Defined in:
- lib/etl/processor/pop3attachment_downloader_processor.rb
Overview
Custom processor to download files via Pop3 Attachment
Instance Attribute Summary (collapse)
-
- (Object) delete
readonly
Returns the value of attribute delete.
-
- (Object) filters
readonly
Returns the value of attribute filters.
-
- (Object) host
readonly
Returns the value of attribute host.
-
- (Object) local_dir
readonly
Returns the value of attribute local_dir.
-
- (Object) port
readonly
Returns the value of attribute port.
-
- (Object) ssl
readonly
Returns the value of attribute ssl.
-
- (Object) username
readonly
Returns the value of attribute username.
Instance Method Summary (collapse)
-
- (Pop3attachmentDownloaderProcessor) initialize(control, configuration)
constructor
configuration options include:
-
host - hostname or IP address of POP3 server (required)
-
ssl - activate encryption (default false)
-
port - port number for POP3 server (default: Net::POP3.default_port or Net::POP3.default_pop3s_port)
-
delete - delete message after reading (default false)
-
filters - filter mails (default [])
-
username - username for POP3 server authentication (default: anonymous)
-
password - password for POP3 server authentication (default: nil)
-
local_dir - local output directory to save downloaded files (default: '').
-
- - (Object) process
Constructor Details
- (Pop3attachmentDownloaderProcessor) initialize(control, configuration)
configuration options include:
-
host - hostname or IP address of POP3 server (required)
-
ssl - activate encryption (default false)
-
port - port number for POP3 server (default: Net::POP3.default_port or Net::POP3.default_pop3s_port)
-
delete - delete message after reading (default false)
-
filters - filter mails (default [])
-
username - username for POP3 server authentication (default: anonymous)
-
password - password for POP3 server authentication (default: nil)
-
local_dir - local output directory to save downloaded files (default: '')
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 26 def initialize(control, configuration) @host = configuration[:host] @ssl = configuration[:ssl] || false @port = configuration[:port] || (@ssl ? Net::POP3.default_pop3s_port : Net::POP3.default_port ) @delete = configuration[:delete] || false @filters = configuration[:filters] || [] @username = configuration[:username] || 'anonymous' @password = configuration[:password] @local_dir = configuration[:local_dir] || '' end |
Instance Attribute Details
- (Object) delete (readonly)
Returns the value of attribute delete
11 12 13 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 11 def delete @delete end |
- (Object) filters (readonly)
Returns the value of attribute filters
12 13 14 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 12 def filters @filters end |
- (Object) host (readonly)
Returns the value of attribute host
8 9 10 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 8 def host @host end |
- (Object) local_dir (readonly)
Returns the value of attribute local_dir
14 15 16 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 14 def local_dir @local_dir end |
- (Object) port (readonly)
Returns the value of attribute port
10 11 12 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 10 def port @port end |
- (Object) ssl (readonly)
Returns the value of attribute ssl
9 10 11 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 9 def ssl @ssl end |
- (Object) username (readonly)
Returns the value of attribute username
13 14 15 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 13 def username @username end |
Instance Method Details
- (Object) process
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 37 def process Net::POP3.enable_ssl(OpenSSL::SSL::VERIFY_NONE) if @ssl conn = Net::POP3.new(@host, @port) conn.start(@username, @password) if !conn.mails.empty? conn.each_mail do || stringmail = .pop mail = TMail::Mail.parse(stringmail) next if mail..blank? if applyfilter(mail, @filters) mail..each do || filename = .original_filename File.open(local_file(filename), "w") {|f| f << .gets(nil) } end .delete if @delete end end end conn.finish end |