Skip to content

Instantly share code, notes, and snippets.

@kou1okada
Created December 10, 2014 22:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kou1okada/e1cfc5f749fe048c5e2c to your computer and use it in GitHub Desktop.
Save kou1okada/e1cfc5f749fe048c5e2c to your computer and use it in GitHub Desktop.
SoftBank Mail backup (.mbk) to .eml splitter
#!/usr/bin/env ruby
#
# mbk2eml.rb - mbk to eml splitter
#
# The .mbk file is the backup file of SoftBank Mail.
# This script splits .mbk file to .eml file.
# The .mbk files can be found from below directory.
# /storage/emulated/0/private/SBMAIL/MBK/
#
# SoftBank mail
# https://play.google.com/store/apps/details?id=jp.softbank.mb.mail&hl=ja
#
require 'time'
stamp = nil
s = stat = ""
i = 0
open(ARGV[0], "r"){|fp|
while fp.gets
stat = :vbodybegin if $_ =~ /^BEGIN:VBODY\r\n$/
stat = :vbodyend if $_ =~ /^END:VBODY\r\n$/
case stat
when :vbodyend
fn = "#{i}.eml"
p fn
open(fn, "w") {|fp|
fp.write(s)
}
File.utime(stamp, stamp, fn) unless stamp.nil?
stamp = nil
i += 1
s = stat = ""
when :vbodybegin
stat = :vbody1
when :vbody1
if $_ =~ /^Date: /
stamp = Time.parse $_[6..-1]
p $_[6..-1]
p stamp
end
s += $_
when :vbody2
s += $_
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment