1 19 20 package org.apache.james.imapserver.handler.session; 21 22 import java.io.IOException ; 23 24 import javax.mail.Flags ; 25 import javax.mail.MessagingException ; 26 import javax.mail.Flags.Flag; 27 import javax.mail.internet.MimeMessage ; 28 29 import org.apache.james.imapserver.ProtocolException; 30 import org.apache.james.imapserver.client.FetchCommand; 31 import org.apache.james.imapserver.client.LoginCommand; 32 import org.apache.james.imapserver.client.SelectCommand; 33 import org.apache.james.imapserver.store.MailboxException; 34 import org.apache.james.imapserver.util.MessageGenerator; 35 import org.apache.james.mailboxmanager.MailboxManagerException; 36 37 public class UidFlagSizeFetchSessionTest extends AbstractSessionTest { 38 39 String [] folders = {USER_MAILBOX_ROOT + ".INBOX",USER_MAILBOX_ROOT + ".test",USER_MAILBOX_ROOT + ".test1",USER_MAILBOX_ROOT + ".test1.test1a",USER_MAILBOX_ROOT + ".test1.test1b",USER_MAILBOX_ROOT + ".test2.test2a",USER_MAILBOX_ROOT + ".test2.test2b"}; 40 String [] onlyInbox = {USER_MAILBOX_ROOT + ".INBOX"}; 41 MimeMessage [] msgs= null; 42 long[] uids = null; 43 44 public void setUp() throws MailboxException, MessagingException , IOException , MailboxManagerException { 45 super.setUp(); 46 msgs=MessageGenerator.generateSimpleMessages(10); 47 createFolders(onlyInbox); 48 appendMessagesClosed(USER_MAILBOX_ROOT+".INBOX",msgs); 50 deleteAll(USER_MAILBOX_ROOT+".INBOX"); 51 uids=addUIDMessagesOpen(USER_MAILBOX_ROOT+".INBOX",msgs); 52 } 53 54 public void testEmptyFetchInRange() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 55 56 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 57 verifyCommand(new SelectCommand(USER_MAILBOX_ROOT+".INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"))); 58 59 verifyCommand(new FetchCommand(msgs,1,-1)); 60 verifyCommand(new FetchCommand(msgs,1,5)); 61 verifyCommand(new FetchCommand(msgs,5,-1)); 62 verifyCommand(new FetchCommand(msgs,2,2)); 63 } 64 65 public void testEmptyFetchOutOfRange() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 66 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 67 verifyCommand(new SelectCommand(USER_MAILBOX_ROOT+".INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"))); 68 69 verifyCommand(new FetchCommand(msgs,0,2)); 70 verifyCommand(new FetchCommand(msgs,3,2)); 71 verifyCommand(new FetchCommand(msgs,3,12)); 72 } 73 74 public void testFetchUids() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 75 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 76 verifyCommand(new SelectCommand(USER_MAILBOX_ROOT+".INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"))); 77 78 FetchCommand fc=new FetchCommand(msgs,1,-1); 79 fc.setUids(uids); 80 verifyCommand(fc); 81 82 } 83 84 public void testFetchUidsFlags() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 85 useFolder(USER_MAILBOX_ROOT+".INBOX"); 87 appendMessagesClosed(USER_MAILBOX_ROOT+".INBOX",MessageGenerator.generateSimpleMessages(5)); 88 setFlags(USER_MAILBOX_ROOT+".INBOX", 12, 12, new Flags (Flags.Flag.SEEN), true, false); 89 setFlags(USER_MAILBOX_ROOT+".INBOX", 14, 14, new Flags (Flags.Flag.SEEN), true, false); 90 msgs=getMessages(USER_MAILBOX_ROOT+".INBOX"); 91 uids=getUids(USER_MAILBOX_ROOT+".INBOX"); 92 93 94 95 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 96 SelectCommand sc=new SelectCommand(USER_MAILBOX_ROOT+".INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX")); 97 assertEquals(sc.getRecentCount(),5); 98 verifyCommand(sc); 99 100 FetchCommand fc=new FetchCommand(msgs,1,-1); 101 fc.setUids(uids); 102 fc.setFetchFlags(true); 103 verifyCommand(fc); 104 freeFolder(USER_MAILBOX_ROOT+".INBOX"); 105 106 } 107 108 public void testRfc822Size() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 109 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 110 verifyCommand(new SelectCommand(USER_MAILBOX_ROOT+".INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"))); 111 msgs=getMessages(USER_MAILBOX_ROOT+".INBOX"); 112 FetchCommand fc=new FetchCommand(msgs,1,-1); 113 fc.setFetchRfc822Size(true); 114 verifyCommand(fc); 115 } 116 117 } 118 | Popular Tags |