1 19 20 package org.apache.james.imapserver.handler.session; 21 22 import java.io.IOException ; 23 24 import javax.mail.MessagingException ; 25 import javax.mail.internet.MimeMessage ; 26 27 import org.apache.james.imapserver.ProtocolException; 28 import org.apache.james.imapserver.client.FetchCommand; 29 import org.apache.james.imapserver.client.LoginCommand; 30 import org.apache.james.imapserver.client.SelectCommand; 31 import org.apache.james.imapserver.client.fetch.FetchBody; 32 import org.apache.james.imapserver.client.fetch.FetchHeader; 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 44 45 public class BodyFetchSessionTest extends AbstractSessionTest { 46 47 String [] onlyInbox = {USER_MAILBOX_ROOT+".INBOX"}; 48 MimeMessage [] msgs= null; 49 long[] uids = null; 50 51 public void setUp() throws MailboxException, MessagingException , IOException , MailboxManagerException { 52 super.setUp(); 53 msgs=MessageGenerator.generateSimpleMessages(4); 54 createFolders(onlyInbox); 55 appendMessagesClosed(USER_MAILBOX_ROOT+".INBOX",msgs); 57 deleteAll(USER_MAILBOX_ROOT+".INBOX"); 58 uids=addUIDMessagesOpen(USER_MAILBOX_ROOT+".INBOX",msgs); 59 } 60 61 62 public void testFetchCompleteAndSize() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 63 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 64 verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"))); 65 msgs=getMessages(USER_MAILBOX_ROOT+".INBOX"); 66 67 FetchCommand fc=new FetchCommand(msgs,1,-1); 68 fc.setFetchRfc822Size(true); 69 fc.setFetchBody(new FetchBody(true)); 70 verifyCommandOrdered(fc); 72 } 73 public void testFetchCompleteHeaderAndSize() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 74 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 75 verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"))); 76 msgs=getMessages(USER_MAILBOX_ROOT+".INBOX"); 77 FetchCommand fc=new FetchCommand(msgs,1,-1); 78 fc.setFetchRfc822Size(true); 79 FetchBody fetchBody=new FetchBody(true); 80 fetchBody.setFetchHeader(new FetchHeader()); 81 fc.setFetchBody(fetchBody); 82 verifyCommandOrdered(fc); 83 } 84 public void testFetchSomeExistingHeaderAndSize() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 85 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 86 verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"))); 87 msgs=getMessages(USER_MAILBOX_ROOT+".INBOX"); 88 FetchCommand fc=new FetchCommand(msgs,1,-1); 89 fc.setFetchRfc822Size(true); 90 FetchHeader fetchHeader=new FetchHeader(); 91 fetchHeader.setFields(new String [] {"Date","From","To"}); 92 FetchBody fetchBody=new FetchBody(true); 93 fetchBody.setFetchHeader(fetchHeader); 94 fc.setFetchBody(fetchBody); 95 verifyCommandOrdered(fc); 96 } 97 public void testFetchSomeNonExistingHeaderAndSize() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 98 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 99 verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"))); 100 msgs=getMessages(USER_MAILBOX_ROOT+".INBOX"); 101 FetchCommand fc=new FetchCommand(msgs,1,-1); 102 fc.setFetchRfc822Size(true); 103 FetchHeader fetchHeader=new FetchHeader(); 104 fetchHeader.setFields(new String [] {"Blob","Test","Oh"}); 105 FetchBody fetchBody=new FetchBody(true); 106 fetchBody.setFetchHeader(fetchHeader); 107 fc.setFetchBody(fetchBody); 108 verifyCommandOrdered(fc); 109 } 110 public void testFetchSomeNoneAndExistingHeaderAndSize() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 111 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 112 verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"))); 113 msgs=getMessages(USER_MAILBOX_ROOT+".INBOX"); 114 FetchCommand fc=new FetchCommand(msgs,1,-1); 115 fc.setFetchRfc822Size(true); 116 FetchHeader fetchHeader=new FetchHeader(); 117 fetchHeader.setFields(new String [] {"To","Message-ID","Blob","Test","Oh"}); 118 FetchBody fetchBody=new FetchBody(true); 119 fetchBody.setFetchHeader(fetchHeader); 120 fc.setFetchBody(fetchBody); 121 verifyCommandOrdered(fc); 122 } 123 124 125 public void testFetchSomeExistingHeader() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 126 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 127 verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"))); 128 msgs=getMessages(USER_MAILBOX_ROOT+".INBOX"); 129 130 FetchCommand fc=new FetchCommand(msgs,1,-1); 131 FetchHeader fetchHeader=new FetchHeader(); 132 fetchHeader.setFields(new String [] {"Date","From","To"}); 133 FetchBody fetchBody=new FetchBody(true); 134 fetchBody.setFetchHeader(fetchHeader); 135 fc.setFetchBody(fetchBody); 136 verifyCommandOrdered(fc); 137 } 138 139 public void testFetchBodyNoParenthesisOneSeqNumber() throws ProtocolException, IOException , MessagingException , MailboxManagerException { 140 verifyCommand(new LoginCommand(USER_NAME,USER_PASSWORD)); 141 verifyCommand(new SelectCommand("INBOX", msgs, getUidValidity(USER_MAILBOX_ROOT+".INBOX"))); 142 msgs=getMessages(USER_MAILBOX_ROOT+".INBOX"); 143 144 FetchCommand fc=new FetchCommand(msgs,1); 145 fc.setFetchBody(new FetchBody(true)); 146 fc.setUseParenthesis(false); 147 verifyCommandOrdered(fc); 148 149 } 150 } 151 | Popular Tags |