Class: Downloads::Commands::Attachments

Inherits:
Base
  • Object
show all
Defined in:
lib/downloads/commands/attachments.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#configuration, #local, #options, #remote

Instance Method Summary collapse

Methods inherited from Base

command_name, inherited, #initialize, usage, #usage, #valid?

Constructor Details

This class inherits a constructor from Downloads::Commands::Base

Instance Attribute Details

#streamObject

Returns the value of attribute stream.



7
8
9
# File 'lib/downloads/commands/attachments.rb', line 7

def stream
  @stream
end

Instance Method Details

#configure(argv) ⇒ Object



9
10
11
# File 'lib/downloads/commands/attachments.rb', line 9

def configure(argv)
  self.stream = ARGF
end

#runObject

TODO forward original messages from attachment emails



14
15
16
17
18
19
20
# File 'lib/downloads/commands/attachments.rb', line 14

def run
  TMail::Mail.parse(stream.read).attachments.each do |attachment|
    filename = File.join(local.directory, attachment.original_filename)
    File.open(filename, 'wb') { |file| file.write(attachment.read) }
    File.chmod(0644, filename)
  end
end