com.icegreen.greenmail.imap.ImapHostManager Java Examples

The following examples show how to use com.icegreen.greenmail.imap.ImapHostManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserManagerTest.java    From greenmail with Apache License 2.0 6 votes vote down vote up
@Test
public void testListUsers() throws UserException {
    ImapHostManager imapHostManager = new ImapHostManagerImpl(new InMemoryStore());
    UserManager userManager = new UserManager(imapHostManager);

    assertEquals(0, userManager.listUser().size());

    GreenMailUser u1 = userManager.createUser("[email protected]", "foo", "pwd");

    assertEquals(1, userManager.listUser().size());
    assertTrue(userManager.listUser().contains(u1));

    GreenMailUser u2 = userManager.createUser("[email protected]", "foo2", "pwd");
    assertEquals(2, userManager.listUser().size());
    assertTrue(userManager.listUser().contains(u1));
    assertTrue(userManager.listUser().contains(u2));
}
 
Example #2
Source File: UserManagerTest.java    From greenmail with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteUserShouldDeleteMail() throws Exception {
    ImapHostManager imapHostManager = new ImapHostManagerImpl(new InMemoryStore());
    UserManager userManager = new UserManager(imapHostManager);

    GreenMailUser user = userManager.createUser("[email protected]", "foo", "pwd");
    assertEquals(1, userManager.listUser().size());

    imapHostManager.createPrivateMailAccount(user);
    MailFolder otherfolder = imapHostManager.createMailbox(user, "otherfolder");
    MailFolder inbox = imapHostManager.getFolder(user, ImapConstants.INBOX_NAME);

    ServerSetup ss = ServerSetupTest.IMAP;
    MimeMessage m1 = GreenMailUtil.createTextEmail("there@localhost", "here@localhost", "sub1", "msg1", ss);
    MimeMessage m2 = GreenMailUtil.createTextEmail("there@localhost", "here@localhost", "sub1", "msg1", ss);

    inbox.store(m1);
    otherfolder.store(m2);
 
    userManager.deleteUser(user);
    assertTrue(imapHostManager.getAllMessages().isEmpty());
}
 
Example #3
Source File: UserImpl.java    From greenmail with Apache License 2.0 5 votes vote down vote up
public UserImpl(String email, String login, String password, ImapHostManager imapHostManager) {
    this.email = email;
    cachedHashCode = email.hashCode();
    cachedHashCodeAsString = String.valueOf(cachedHashCode);
    this.login = login;
    this.password = password;
    this.imapHostManager = imapHostManager;
}
 
Example #4
Source File: GreenMail.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Override
public void purgeEmailFromAllMailboxes() throws FolderException {
    ImapHostManager imaphost = getManagers().getImapHostManager();
    InMemoryStore store = (InMemoryStore) imaphost.getStore();
    Collection<MailFolder> mailboxes = store.listMailboxes("*");
    for (MailFolder folder : mailboxes) {
        folder.deleteAllMessages();
    }
}
 
Example #5
Source File: UserManagerTest.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Test
public void testFindByEmailAndLogin() throws UserException {
    ImapHostManager imapHostManager = new ImapHostManagerImpl(new InMemoryStore());
    UserManager userManager = new UserManager(imapHostManager);
    GreenMailUser u1 = userManager.createUser("[email protected]", "foo", "pwd");

    assertEquals(u1, userManager.getUserByEmail(u1.getEmail()));
    assertEquals(u1, userManager.getUser(u1.getLogin()));

    GreenMailUser u2 = userManager.createUser("[email protected]", "foo2", "pwd");
    assertEquals(u1, userManager.getUserByEmail(u1.getEmail()));
    assertEquals(u2, userManager.getUserByEmail(u2.getEmail()));
    assertEquals(u1, userManager.getUser(u1.getLogin()));
    assertEquals(u2, userManager.getUser(u2.getLogin()));
}
 
Example #6
Source File: UserManagerTest.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreateAndDeleteUser() throws UserException {
    ImapHostManager imapHostManager = new ImapHostManagerImpl(new InMemoryStore());
    UserManager userManager = new UserManager(imapHostManager);

    assertTrue(userManager.listUser().isEmpty());

    GreenMailUser user = userManager.createUser("[email protected]", "foo", "pwd");
    assertEquals(1, userManager.listUser().size());

    userManager.deleteUser(user);
    assertTrue(userManager.listUser().isEmpty());
}
 
Example #7
Source File: UserManagerTest.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoAuthRequired() {
    ImapHostManager imapHostManager = new ImapHostManagerImpl(new InMemoryStore());
    UserManager userManager = new UserManager(imapHostManager);
    userManager.setAuthRequired(false);

    assertTrue(userManager.test("foo@localhost", null));
    assertEquals(1, userManager.listUser().size());
}
 
Example #8
Source File: UserManagerTest.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoAuthRequiredWithExistingUser() throws UserException {
    ImapHostManager imapHostManager = new ImapHostManagerImpl(new InMemoryStore());
    UserManager userManager = new UserManager(imapHostManager);
    userManager.setAuthRequired(false);

    userManager.createUser("[email protected]", "foo", null);
    assertFalse(userManager.listUser().isEmpty());
    assertTrue(userManager.test("foo", null));
}
 
Example #9
Source File: UserManagerTest.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Test
public void testAuthRequired() {
    ImapHostManager imapHostManager = new ImapHostManagerImpl(new InMemoryStore());
    UserManager userManager = new UserManager(imapHostManager);
    userManager.setAuthRequired(true);

    assertFalse(userManager.test("foo@localhost", null));
    assertTrue(userManager.listUser().isEmpty());
}
 
Example #10
Source File: UserManagerTest.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Test
public void testAuthRequiredWithExistingUser() throws UserException {
    ImapHostManager imapHostManager = new ImapHostManagerImpl(new InMemoryStore());
    UserManager userManager = new UserManager(imapHostManager);
    userManager.setAuthRequired(true);
    userManager.createUser("[email protected]", "foo", "bar");

    assertFalse(userManager.listUser().isEmpty());
    assertTrue(userManager.test("foo", "bar"));
}
 
Example #11
Source File: AbstractTest.java    From smtp-connection-pool with Apache License 2.0 4 votes vote down vote up
protected ImapHostManager getImapHostManager(){
  return greenMail.getManagers().getImapHostManager();
}
 
Example #12
Source File: Managers.java    From greenmail with Apache License 2.0 4 votes vote down vote up
public ImapHostManager getImapHostManager() {
    return imapHostManager;
}
 
Example #13
Source File: SmtpManager.java    From greenmail with Apache License 2.0 4 votes vote down vote up
public SmtpManager(ImapHostManager imapHostManager, UserManager userManager) {
    this.imapHostManager = imapHostManager;
    this.userManager = userManager;
    incomingQueue = new Incoming();
    notifyList = Collections.synchronizedList(new ArrayList<CountDownLatch>());
}
 
Example #14
Source File: UserManager.java    From greenmail with Apache License 2.0 4 votes vote down vote up
public UserManager(ImapHostManager imapHostManager) {
    this.imapHostManager = imapHostManager;
}
 
Example #15
Source File: UserManager.java    From greenmail with Apache License 2.0 4 votes vote down vote up
public ImapHostManager getImapHostManager() {
    return imapHostManager;
}