Class: 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
-
#delete ⇒ Object
readonly
Returns the value of attribute delete.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#local_dir ⇒ Object
readonly
Returns the value of attribute local_dir.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#ssl ⇒ Object
readonly
Returns the value of attribute ssl.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(control, configuration) ⇒ Pop3attachmentDownloaderProcessor
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: ”).
- #process ⇒ Object
Constructor Details
#initialize(control, configuration) ⇒ Pop3attachmentDownloaderProcessor
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
#delete ⇒ Object (readonly)
Returns the value of attribute delete.
11 12 13 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 11 def delete @delete end |
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
12 13 14 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 12 def filters @filters end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 8 def host @host end |
#local_dir ⇒ Object (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 |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 10 def port @port end |
#ssl ⇒ Object (readonly)
Returns the value of attribute ssl.
9 10 11 |
# File 'lib/etl/processor/pop3attachment_downloader_processor.rb', line 9 def ssl @ssl end |
#username ⇒ Object (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
#process ⇒ Object
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 |