Skip to content

Instantly share code, notes, and snippets.

@aont
Last active December 31, 2015 08:29
Show Gist options
  • Select an option

  • Save aont/7960559 to your computer and use it in GitHub Desktop.

Select an option

Save aont/7960559 to your computer and use it in GitHub Desktop.
905SHのvMessage形式からmbox形式へ変換
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
$tel_self="09012345678"
$email_self="hoge@fuga.com"
def analyse_vcard(fin)
line = fin.gets
tel=nil
while line
tel = line[4..-1].chomp if line[0..3]=="TEL:"
return tel if line.chomp=="END:VCARD"
line = fin.gets
end
end
def analyse_vbody(fin,irmc_type,from,to)
body=""
has_from=false
has_to=false
line = fin.gets
while line
break if line.chomp=="END:VBODY"
if line.chomp=="CHARSET="
elsif line.chomp=="CHARSET=SHIFT_JIS"
body += "Content-Type: text/plain;\n charset=Shift_JIS\n"
elsif line.chomp=="ENCODING=QUOTED-PRINTABLE"
body += "Content-Transfer-Encoding: quoted-printable\n"
elsif line[0..4]=="From:"
has_from=true
if line.chomp=="From: <#{$tel_self}>" && irmc_type=="INET"
body += "From: <#{$email_self}>\n"
else
body += line
end
elsif line[0..2]=="To:"
has_to=true
if line.chomp=="To: <#{$tel_self}>" && irmc_type=="INET"
body += "To: <#{$email_self}>\n"
else
body += line
end
else
body += line
end
line = fin.gets
end
body = "To: <#{to}>\n" + body if !has_to
body = "From: <#{from}>\n" + body if !has_from
body = "From \n" + body
return body
end
def analyse_venv_body(fin,irmc_type,from,to)
body=nil
line = fin.gets
while line
body = analyse_vbody(fin,irmc_type,from,to) if line.chomp=="BEGIN:VBODY"
return body if line.chomp=="END:VENV"
line = fin.gets
end
end
def analyse_venv_to(fin,irmc_type,from)
line = fin.gets
body=nil
to=nil
while line
to = analyse_vcard(fin) if line.chomp=="BEGIN:VCARD"
body = analyse_venv_body(fin,irmc_type,from,to) if line.chomp=="BEGIN:VENV"
return body if line.chomp=="END:VENV"
line = fin.gets
end
end
def analyse_vmsg(fin)
line = fin.gets
from=nil
irmc_type=nil
while line
if line.chomp=="X-IRMC-TYPE:SMS"
irmc_type="SMS"
elsif line.chomp=="X-IRMC-TYPE:INET"
irmc_type="INET"
end
from = analyse_vcard(fin) if line.chomp=="BEGIN:VCARD"
body = analyse_venv_to(fin,irmc_type,from) if line.chomp=="BEGIN:VENV"
return body if line.chomp=="END:VMSG"
line = fin.gets
end
end
fin=$stdin
line = fin.gets
while line
body = analyse_vmsg(fin) if line.chomp=="BEGIN:VMSG"
puts body
line = fin.gets
end
@aont

aont commented Dec 14, 2013

Copy link
Copy Markdown
Author

vectorにころがってるプログラムだとうまく変換できなかったので自前で。
905SH決め打ちなので他の機種では不具合出る可能性大。

"From "のところは別の自前プログラムで動きさえすればいいやとサボっているので注意。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment