1 19 import java.io.BufferedReader ; 20 import java.io.File ; 21 import java.io.FileReader ; 22 23 import org.columba.api.command.IWorkerStatusController; 24 import org.columba.mail.folder.IMailbox; 25 import org.columba.mail.folder.mailboximport.AbstractMailboxImporter; 26 27 public class MBOXMailImportFilter extends AbstractMailboxImporter { 28 29 public MBOXMailImportFilter() { 30 super(); 31 } 32 33 public MBOXMailImportFilter(IMailbox destinationFolder, File [] sourceFiles) { 34 super(destinationFolder, sourceFiles); 35 } 36 37 public int getType() { 38 return TYPE_FILE; 39 } 40 41 public void importMailboxFile(File file, IWorkerStatusController worker, 42 IMailbox destFolder) throws Exception { 43 44 boolean success = false; 45 46 StringBuffer strbuf = new StringBuffer (); 47 48 BufferedReader in = new BufferedReader (new FileReader (file)); 49 String str; 50 51 while ((str = in.readLine()) != null) { 53 if (worker.cancelled()) 55 return; 56 57 if (!str.startsWith("From ") || (str.length() == 0)) { 60 strbuf.append(str + "\n"); 61 } else { 62 63 65 if (strbuf.length() != 0) { 66 68 saveMessage(strbuf.toString(), worker, 69 getDestinationFolder()); 70 71 success = true; 72 73 } 74 strbuf = new StringBuffer (); 75 76 } 77 78 } 79 80 if (success && (strbuf.length() > 0)) { 83 saveMessage(strbuf.toString(), worker, getDestinationFolder()); 84 } 85 86 in.close(); 87 } 88 89 94 public String getDescription() { 95 return "Example MBOX import filter"; 96 } 97 } 98 | Popular Tags |