Sha256: 30ac4cf2d9adeeb0b651892d80bdc066ee0fd8a09a3d34d5d7fc715fe5b79f4c

Contents?: true

Size: 555 Bytes

Versions: 13

Compression:

Stored size: 555 Bytes

Contents

#
# extract-attachments.rb  -- Extracts attachment(s) from the message.
#
# Usage: ruby extract-attachments.rb mail mail...
#

require 'tmail'

def main
  idx = 1
  ARGV.each do |fname|
    TMail::Mail.load(fname).parts.each do |m|
      m.base64_decode
      File.open("#{idx}.#{ext(m)}", 'w') {|f|
        f.write m.body
      }
      idx += 1
    end
  end
end

CTYPE_TO_EXT = {
  'image/jpeg' => 'jpeg',
  'image/gif'  => 'gif',
  'image/png'  => 'png',
  'image/tiff' => 'tiff'
}

def ext( mail )
  CTYPE_TO_EXT[mail.content_type] || 'txt'
end

main

Version data entries

13 entries across 13 versions & 7 rubygems

Version Path
japetheape-tmail-1.2.3.4 sample/extract-attachements.rb
ledermann-tmail-1.2.5 sample/extract-attachements.rb
lonbaker-tmail-1.2.3.1 sample/extract-attachements.rb
valodzka-tmail-1.2.3.2 sample/extract-attachements.rb
valodzka-tmail-1.2.3.3 sample/extract-attachements.rb
valodzka-valodzka-tmail-1.2.3.2 sample/extract-attachements.rb
sa-tmail-1.2.5.1 sample/extract-attachements.rb
tmail-1.2.3.1 sample/extract-attachements.rb
tmail-1.1.1 sample/extract-attachements.rb
tmail-1.2.0 sample/extract-attachements.rb
tmail-1.2.2 sample/extract-attachements.rb
tmail-1.2.3 sample/extract-attachements.rb
tmail-1.2.1 sample/extract-attachements.rb