1 36 package org.columba.ristretto.message; 37 38 import java.io.File ; 39 import java.io.IOException ; 40 import java.util.regex.Matcher ; 41 import java.util.regex.Pattern ; 42 43 import junit.framework.TestCase; 44 45 import org.columba.ristretto.io.FileSource; 46 import org.columba.ristretto.io.Source; 47 import org.columba.ristretto.parser.MessageParser; 48 import org.columba.ristretto.parser.ParserException; 49 50 public class ColumbaMailParserTest extends TestCase { 51 52 private static final Pattern mailboxPattern = Pattern.compile("(\r?\n?From [^\r\n]+\r?\n)"); 53 54 58 public ColumbaMailParserTest(String arg0) { 59 super(arg0); 60 } 61 62 public void testMailboxes() { 63 try { 64 testMailBox(new File ("src/mail/test/org/columba/mail/message/testsuite.mbox")); 65 } catch (ParserException e) { 66 e.printStackTrace(); 67 } catch (IOException e) { 68 e.printStackTrace(); 69 } 70 } 71 72 protected void testMailBox( File mailboxFile ) throws ParserException, IOException { 73 FileSource source = new FileSource( mailboxFile ); 74 Matcher matcher = mailboxPattern.matcher( source ); 75 matcher.find(); 76 int lastStart = matcher.end(); 77 Message message; 78 Source messageSource; 79 80 while( matcher.find() ) { 81 messageSource = (Source) source.subSequence(lastStart, matcher.start()); 82 message = MessageParser.parse( messageSource ); 83 System.out.println( message.getHeader().toString() ); 84 lastStart = matcher.end(); 85 } 86 87 message = MessageParser.parse( (Source) source.subSequence(lastStart, source.length() -2 ) ); 88 89 } 90 91 } 92 | Popular Tags |