Skip to content

Instantly share code, notes, and snippets.

@jhbruhn
Created April 5, 2012 09:52
Show Gist options
  • Save jhbruhn/2309635 to your computer and use it in GitHub Desktop.
Save jhbruhn/2309635 to your computer and use it in GitHub Desktop.
MailParse from mail tingi Thunderbörd
package org.hans.uwe.werner;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class MailParse {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// data.txt contains the Mail Data
String s = readFile("data.txt");
String[] emailStrings = getEmails(s);
for(String emailString : emailStrings){
System.out.println(emailString);
}
}
private static String[] getEmails(String s){
ArrayList<String> stringsArrayList = new ArrayList<String>();
String[] strings = s.split("=");
for(String string : strings){
if(string.contains("@") && string.contains(".")){
string = (String) string.subSequence(0, string.indexOf(")"));
stringsArrayList.add(string);
}
}
return stringsArrayList.toArray(new String[stringsArrayList.size()]);
}
private static String readFile(String path){
File file = new File(path);
FileInputStream fStream = null;
try {
fStream = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(new DataInputStream(fStream)));
String string = "";
String data = "";
try {
while((string = reader.readLine()) != null)
{
data += string;
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return data;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment