Search in sources :

Example 1 with FolderListener

use of com.icegreen.greenmail.store.FolderListener in project wso2-axis2-transports by wso2.

the class GreenMailTestEnvironment method allocateAccount.

@Override
public Account allocateAccount() throws Exception {
    if (unallocatedAccounts.isEmpty()) {
        String login = "test" + accountNumber++;
        GreenMailUser user = greenMail.setUser(login + "@localhost", login, "password");
        final MailFolder inbox = greenMail.getManagers().getImapHostManager().getInbox(user);
        inbox.addListener(new FolderListener() {

            public void added(int msn) {
                StoredMessage storedMessage = (StoredMessage) inbox.getMessages().get(msn - 1);
                try {
                    OutputStream out = logManager.createLog("greenmail");
                    try {
                        storedMessage.getMimeMessage().writeTo(out);
                    } finally {
                        out.close();
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }

            public void expunged(int msn) {
            }

            public void flagsUpdated(int msn, Flags flags, Long uid) {
            }

            public void mailboxDeleted() {
            }
        });
        return new Account(user.getEmail(), user.getLogin(), user.getPassword());
    } else {
        return unallocatedAccounts.remove(0);
    }
}
Also used : FolderListener(com.icegreen.greenmail.store.FolderListener) StoredMessage(com.icegreen.greenmail.store.StoredMessage) MailFolder(com.icegreen.greenmail.store.MailFolder) OutputStream(java.io.OutputStream) GreenMailUser(com.icegreen.greenmail.user.GreenMailUser) Flags(javax.mail.Flags)

Aggregations

FolderListener (com.icegreen.greenmail.store.FolderListener)1 MailFolder (com.icegreen.greenmail.store.MailFolder)1 StoredMessage (com.icegreen.greenmail.store.StoredMessage)1 GreenMailUser (com.icegreen.greenmail.user.GreenMailUser)1 OutputStream (java.io.OutputStream)1 Flags (javax.mail.Flags)1