Class: ETL::Processor::ImapattachmentDownloaderProcessor
- Defined in:
- lib/etl/processor/imapattachment_downloader_processor.rb
Overview
Custom processor to download files via Imap Attachment
Instance Attribute Summary collapse
-
#delete ⇒ Object
readonly
Returns the value of attribute delete.
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
-
#folder ⇒ Object
readonly
Returns the value of attribute folder.
-
#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) ⇒ ImapattachmentDownloaderProcessor
constructor
configuration options include: * host - hostname or IP address of IMAP server (required) * ssl - activate encryption (default false) * port - port number for IMAP server (default: 220 or 993) * delete - delete message after reading (default false) * filters - filter mails (default []) * folder - folder to select mails from (default INBOX) * username - username for IMAP server authentication (default: anonymous) * password - password for IMAP server authentication (default: nil) * local_dir - local output directory to save downloaded files (default: ”).
- #process ⇒ Object
Constructor Details
#initialize(control, configuration) ⇒ ImapattachmentDownloaderProcessor
configuration options include:
-
host - hostname or IP address of IMAP server (required)
-
ssl - activate encryption (default false)
-
port - port number for IMAP server (default: 220 or 993)
-
delete - delete message after reading (default false)
-
filters - filter mails (default [])
-
folder - folder to select mails from (default INBOX)
-
username - username for IMAP server authentication (default: anonymous)
-
password - password for IMAP server authentication (default: nil)
-
local_dir - local output directory to save downloaded files (default: ”)
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/etl/processor/imapattachment_downloader_processor.rb', line 28 def initialize(control, configuration) @host = configuration[:host] @ssl = configuration[:ssl] || false @port = configuration[:port] || (@ssl ? 993 : 220 ) @delete = configuration[:delete] || false @filters = configuration[:filters] || [] @folder = configuration[:folder] || 'INBOX' @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/imapattachment_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/imapattachment_downloader_processor.rb', line 12 def filters @filters end |
#folder ⇒ Object (readonly)
Returns the value of attribute folder.
13 14 15 |
# File 'lib/etl/processor/imapattachment_downloader_processor.rb', line 13 def folder @folder end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
8 9 10 |
# File 'lib/etl/processor/imapattachment_downloader_processor.rb', line 8 def host @host end |
#local_dir ⇒ Object (readonly)
Returns the value of attribute local_dir.
15 16 17 |
# File 'lib/etl/processor/imapattachment_downloader_processor.rb', line 15 def local_dir @local_dir end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
10 11 12 |
# File 'lib/etl/processor/imapattachment_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/imapattachment_downloader_processor.rb', line 9 def ssl @ssl end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
14 15 16 |
# File 'lib/etl/processor/imapattachment_downloader_processor.rb', line 14 def username @username end |
Instance Method Details
#process ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/etl/processor/imapattachment_downloader_processor.rb', line 40 def process conn = Net::IMAP.new(@host, @port, @ssl) conn.login(@username, @password) conn.select(@folder) conn.uid_search(["NOT", "DELETED"]).each do |msguuid| mail = TMail::Mail.parse( conn.uid_fetch(msguuid, 'RFC822').first.attr['RFC822'] ) 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 conn.store(msguuid, "+FLAGS", [:Deleted]) if @delete end end conn.expunge conn.close end |