package com.fsck.k9.endtoend.framework;

import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.ServerSetup;

/**
 * Configuration and management of a pair of stub servers for use by an account.
 */
public class StubMailServer {
    private static final ServerSetup IMAP_SERVER_SETUP = new ServerSetup(10143, "127.0.0.2", ServerSetup.PROTOCOL_IMAP);
    private static final ServerSetup SMTP_SERVER_SETUP = new ServerSetup(10587, "127.0.0.2", ServerSetup.PROTOCOL_SMTP);

    /**
     * Stub server that speaks SMTP, IMAP etc., that K-9 can talk to.
     */
    private GreenMail greenmail;

    public StubMailServer() {

        greenmail = new GreenMail(new ServerSetup[]{IMAP_SERVER_SETUP, SMTP_SERVER_SETUP});
        greenmail.setUser(UserForImap.TEST_USER.emailAddress, UserForImap.TEST_USER.loginUsername, UserForImap.TEST_USER.password);
        greenmail.start();
    }

    public String getSmtpBindAddress() {
        return SMTP_SERVER_SETUP.getBindAddress();
    }

    public int getSmtpPort() {
        return SMTP_SERVER_SETUP.getPort();
    }

    public String getImapBindAddress() {
        return IMAP_SERVER_SETUP.getBindAddress();
    }

    public int getImapPort() {
        return IMAP_SERVER_SETUP.getPort();
    }

    public void stop() {
        greenmail.stop();
    }
}


@@ -34,16 +34,115 @@
 ework;%0A%0A
+import android.util.Log;%0A%0Aimport com.fsck.k9.K9;%0Aimport com.icegreen.greenmail.user.GreenMailUser;%0A
 import c
@@ -841,25 +841,63 @@
         
-greenmail
+GreenMailUser user = greenmail%0A                
 .setUser
@@ -969,16 +969,40 @@
 sername,
+%0A                       
  UserFor
@@ -1026,16 +1026,358 @@
 ssword);
+%0A%0A        for (String mailbox : new String%5B%5D %7B%22Drafts%22, %22Spam%22%7D) %7B%0A            Log.d(K9.LOG_TAG, %22creating mailbox %22+mailbox);%0A            try %7B%0A                greenmail.getManagers().getImapHostManager().createMailbox(user, mailbox);%0A            %7D catch (Exception e) %7B%0A                throw new RuntimeException(e);%0A            %7D%0A        %7D
 %0A       

Create test mailboxes