Just write to a file between the tag of each message to make it eml format, Simple thing. See the following page for how it was made. How to retrieve carrier emails from Android smartphones
vmg contains multiple message data surrounded by tags. Regarding tags, I referred to the following. Convert VMG file with PowerShell and read it with Excel
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.FileNotFoundException;
class vmg2Eml{
public static void main(String args[]){
String input_maildata_filename;
if(args.length <= 0){
System.out.println("Enter the file name on the command line");
return;
} else {
input_maildata_filename = args[0];
}
try{
int line_number = 0;
File file = new File(input_maildata_filename);
if (!file.exists()){
System.out.println("There is no file");
return;
}
FileInputStream FIS = new FileInputStream(file);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(FIS,"UTF-8"));
String data;
String strBegin = "BEGIN:VBODY";
String strEnd = "END:VBODY";
Boolean Has2Write = false;
int mail_number = 0;
PrintWriter printwriter = null;
FileOutputStream FOS2write = null;
while ((data = bufferedReader.readLine()) != null) {
int isBegin = data.indexOf(strBegin);
int isEnd = data.indexOf(strEnd);
if(isBegin != -1){
Has2Write = true;
data = bufferedReader.readLine();
mail_number++;
String filename2write = String.format("%05d",mail_number) + ".eml";
File file2write = new File(filename2write);
FOS2write = new FileOutputStream(file2write);
printwriter = new PrintWriter(new BufferedWriter(new OutputStreamWriter(FOS2write,"UTF-8")));
}
if(isEnd != -1){
Has2Write = false;
printwriter.close();
}
if(printwriter != null && Has2Write){
printwriter.println(data);
}
}
bufferedReader.close();
}catch(FileNotFoundException e){
System.out.println(e);
}catch(IOException e){
System.out.println(e);
}
}
}
//System.out.println(data);
Recommended Posts