Java that outputs vmg format file in eml format

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

Java that outputs vmg format file in eml format
Java program that outputs Shift-JIS format in UTF-8 format at once
Format XML in Java
A bat file that uses Java in windows
Java version notation that changes in Java 10
Read Java properties file in C #
Unzip the zip file in Java
Log output to file in Java
About file copy processing in Java
Try using JSON format API in Java
Output Date in Java in ISO 8601 extended format
Read xlsx file in Java with Selenium
Sample program that returns the hash value of a file in Java
Sample to unzip gz file in Java
Read a string in a PDF file with Java
[Java] Read the file in src / main / resources
General-purpose StringConverter class that utilizes generics in Java8
google java format
Partization in Java
Changes in Java 11
Rock-paper-scissors in Java
java file creation
Pi in Java
FizzBuzz in Java
Write a class that can be ordered in Java
Include image in jar file with java static method
[Java] Get the file in the jar regardless of the environment
[Java] Get the file path in the folder with List
[.net, Java integration] Nger that executes .jar in C # .net
This and that for editing ini in Java. : inieditor-java
[Java] Explains ConcurrentModificationException that occurs in java.util.ArrayList for newcomers
How to convert a file to a byte array in Java
Java11: Run Java code in a single file as is
Gzip-compress byte array in Java and output to file
Summary of file reading method for each Java file format
The story that .java is also built in Unity 2018
A library that realizes multi-line strings in Java multiline-string
A program (Java) that outputs the sum of odd and even numbers in an array