@kyanny's blog

My thoughts, my life. Views/opinions are my own.

TMail でメールから添付ファイルの画像を取り出しす

#!/usr/bin/env ruby
require 'rubygems'
gem 'tmail'
require 'tmail'

mail = TMail::Mail.parse(STDIN.read)
mail.parts.each do |m|
  nexf unless m.content_type != 'image/jpeg'
  m.base64_decode
  File.open('xxx_new.jpg', 'w'){ |f|
    f.write m.body
  }
end

tmail_create.rb を実行してできた xxx_mail.txt を $ ruby tmail_parse.rb < xxx_mail.txt のように食わせて実行する。

Ruby RMagick exifr TMail · GitHub

gist まとめた意味あんまなかったかもな