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