Skip to content

Instantly share code, notes, and snippets.

@inertialbit
Created March 28, 2012 20:46
Show Gist options
  • Save inertialbit/2230379 to your computer and use it in GitHub Desktop.
Save inertialbit/2230379 to your computer and use it in GitHub Desktop.
Quick script to help recover garbled base64 encoded mail attachments.
# Quick script to help recover garbled base64 encoded mail attachments.
# Converts files in place.
# Usage:
# # decode files in the current directory
# ruby decode64.rb ./ file_one.jpg file_two.png file_three.gif
# # decode files in another directory
# ruby decode64.rb /path/to/else/where other.png estimate.doc
require 'base64'
dir = ARGV[0] # where files live
files = ARGV[1..-1] # base64 encoded files, maybe copied-n-pasted from Mail client
# convert decoded file
files.each do |filename|
file = File.read(File.join(dir,filename))
File.open(File.join(dir,filename), 'w+') do |new_file|
new_file.print Base64.decode64(file)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment