Nokia SMS to flat files

I have a Nokia phone. It's quite a simple phone compare to the androids and iPhones we have on the market but nevertheless it makes calls and sends messages. From time to time though, it gets full of sms messages and I tend to archive them to have them all in secure places.

Using Nokia suite, on a Windows PC I have access to (the machine is not mine), I can download all the messages however they are in vmg format.

I have written a small Erlang module to convert this files to plain text. I might extend this module in the future, for now, it's so small that I'll post it here. The only parameter we need to pass to the exported function, is the path to the folder the vmgs are on. It will loop through every file and create an equivalent txt with the same name in the same place.
-module(nsc_to_ascii).
-export([convert_vmg_to_txt/1]).


convert_vmg_to_txt(PathToFolder)->
%%get all the svg files in the folder
L=get_list_of_full_path(PathToFolder),
lists:map(fun(FullPath)->
B=read_file_to_binary(FullPath),
write_file(filter_file(B),get_new_extension(FullPath))
end,L).


write_file(Binary,Path)->
file:write_file(Path,Binary).

filter_file(Binary)->
filter_file(Binary,<<>>).
filter_file(<<>>,Acc)->
Acc;
filter_file(<<0,Rest/binary>>,Acc)->
filter_file(Rest,Acc);
filter_file(<<B:1/binary,Rest/binary>>,Acc)->
filter_file(Rest,<<Acc/binary,B/binary>>).

read_file_to_binary(Path)->
{ok,Binary}=file:read_file(Path),
Binary.

get_list_of_full_path(DirectoryPath)->
{ok,L}=file:list_dir(DirectoryPath),
lists:map(fun(FilePath)->
DirectoryPath++"/"++FilePath
end,L).

get_new_extension(FullPath)->
Length=length(FullPath),
case lists:sublist(FullPath,Length-2,Length) of
"vmg" -> lists:sublist(FullPath,1,Length-3)++"txt";
_ -> ""
end.

Comments

Popular posts from this blog

A case against bloom filters in bitcoin

To pray or not to pray