package com.mindprod.welcome; import java.io.EOFException; import java.io.FileReader; import java.io.FileWriter; import com.mindprod.csv.CSVReader; import com.mindprod.csv.CSVWriter; /** * Copies over email tuples that have not already * been informed, perhaps in the other newsgroup. * Works on cleaned up email addresses. * * @author Roedy Green */ public class FilterInformed { /** * * @param in name of csv file of cleanup up tuples * we plan to send welcome letters to. * @param out tuples we will actually send welcoming emails to * after ones have been removed we have already * written to, perhaps in the other group. * @param group name of group collect duplicates under, * e.g. comp.lang.java. */ public static void filterInformed(String in, String out, String group) { CSVReader r = null; CSVWriter w = null; Informed inf = null; try { r = new CSVReader(new FileReader(in)); w = new CSVWriter(new FileWriter(out)); inf = new Informed(group); try { while ( true ) { String email = r.get(); // ignore empty lines especially at end of file. if ( email == null ) { continue; } String humanName = r.get(); String originalEmail = r.get(); String account = r.get(); r.skipToNextLine(); if ( !inf.wasInformed( email ) ) { inf.markInformed( email ); w.put( email ); w.put( humanName ); w.put( originalEmail ); w.put( account ); w.nl(); } } // end while } catch ( EOFException e ) { if ( r != null ) { r.close(); } if ( w != null ) { w.close(); } if ( inf != null ) { inf.close(); } } } catch ( Exception e ) { e.printStackTrace(); } } /** * Clean up daily new posters for both comp.lang.java.help * and comp.lang.java.programmer. * * @param args not used. */ public static void main(String[] args) { filterInformed( "comp.lang.java.help.new", "emails1.txt", "comp.lang.java" ); filterInformed( "comp.lang.java.programmer.new", "emails2.txt", "comp.lang.java" ); filterInformed( "comp.lang.java.machine.new", "emails3.txt", "comp.lang.java" ); filterInformed( "comp.lang.java.security.new", "emails4.txt", "comp.lang.java" ); } // end main } // end FilterInformed