forked from greenmail-mail-test/greenmail
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
greenmail-mail-test#293 - make GreenMail more configurable
- Loading branch information
Thomas Frühbeck
committed
Nov 10, 2019
1 parent
5bf443e
commit d3ea847
Showing
11 changed files
with
379 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,11 +6,20 @@ | |
*/ | ||
package com.icegreen.greenmail.imap; | ||
|
||
import com.icegreen.greenmail.store.*; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.StringTokenizer; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
import com.icegreen.greenmail.store.FolderException; | ||
import com.icegreen.greenmail.store.InMemoryStore; | ||
import com.icegreen.greenmail.store.MailFolder; | ||
import com.icegreen.greenmail.store.Store; | ||
import com.icegreen.greenmail.store.StoredMessage; | ||
import com.icegreen.greenmail.user.GreenMailUser; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* An initial implementation of an ImapHost. By default, uses, | ||
* the {@link com.icegreen.greenmail.store.InMemoryStore} implementation of {@link com.icegreen.greenmail.store.Store}. | ||
|
@@ -19,10 +28,9 @@ | |
* @author Darrell DeBoer <[email protected]> | ||
* @version $Revision: 109034 $ | ||
*/ | ||
public class ImapHostManagerImpl | ||
implements ImapHostManager, ImapConstants { | ||
private Store store; | ||
private MailboxSubscriptions subscriptions; | ||
public class ImapHostManagerImpl implements ImapHostManager, ImapConstants { | ||
protected Store store; | ||
protected MailboxSubscriptions subscriptions; | ||
|
||
/** | ||
* Hack constructor which creates an in-memory store, and creates a console logger. | ||
|
@@ -37,6 +45,11 @@ public ImapHostManagerImpl(Store store) { | |
subscriptions = new MailboxSubscriptions(); | ||
} | ||
|
||
public ImapHostManagerImpl(Store store, MailboxSubscriptions subscriptions) { | ||
this.store = store; | ||
this.subscriptions = subscriptions; | ||
} | ||
|
||
@Override | ||
public List<StoredMessage> getAllMessages() { | ||
List<StoredMessage> ret = new ArrayList<>(); | ||
|
@@ -76,7 +89,7 @@ public MailFolder getFolder(GreenMailUser user, String mailboxName, boolean must | |
return folder; | ||
} | ||
|
||
private MailFolder checkViewable(MailFolder folder) { | ||
protected MailFolder checkViewable(MailFolder folder) { | ||
// TODO implement this. | ||
return folder; | ||
} | ||
|
@@ -217,7 +230,7 @@ public Collection<MailFolder> listMailboxes(GreenMailUser user, | |
* | ||
* @see com.icegreen.greenmail.imap.ImapHostManager#listMailboxes | ||
*/ | ||
private Collection<MailFolder> listMailboxes(GreenMailUser user, | ||
protected Collection<MailFolder> listMailboxes(GreenMailUser user, | ||
String mailboxPattern, | ||
boolean subscribedOnly) | ||
throws FolderException { | ||
|
@@ -273,7 +286,7 @@ public void unsubscribe(GreenMailUser user, String mailboxName) | |
* | ||
* @return String of absoluteName, null if not valid selection | ||
*/ | ||
private String getQualifiedMailboxName(GreenMailUser user, String mailboxName) { | ||
protected String getQualifiedMailboxName(GreenMailUser user, String mailboxName) { | ||
String userNamespace = user.getQualifiedMailboxName(); | ||
|
||
if ("INBOX".equalsIgnoreCase(mailboxName)) { | ||
|
@@ -298,8 +311,8 @@ private String getQualifiedMailboxName(GreenMailUser user, String mailboxName) { | |
* TODO make this a proper class | ||
* TODO persist | ||
*/ | ||
private static class MailboxSubscriptions { | ||
private Map<String, List<String>> userSubs = new HashMap<>(); | ||
public static class MailboxSubscriptions { | ||
protected Map<String, List<String>> userSubs = new ConcurrentHashMap<>(); | ||
|
||
/** | ||
* Subscribes the user to the store. | ||
|
@@ -309,7 +322,7 @@ private static class MailboxSubscriptions { | |
* @param folder The store to subscribe | ||
* @throws FolderException ??? doesn't yet. | ||
*/ | ||
void subscribe(GreenMailUser user, MailFolder folder) | ||
public void subscribe(GreenMailUser user, MailFolder folder) | ||
throws FolderException { | ||
getUserSubs(user).add(folder.getFullName()); | ||
} | ||
|
@@ -322,7 +335,7 @@ void subscribe(GreenMailUser user, MailFolder folder) | |
* @param folder The store to unsubscribe | ||
* @throws FolderException ?? doesn't yet | ||
*/ | ||
void unsubscribe(GreenMailUser user, MailFolder folder) | ||
public void unsubscribe(GreenMailUser user, MailFolder folder) | ||
throws FolderException { | ||
getUserSubs(user).remove(folder.getFullName()); | ||
} | ||
|
@@ -334,11 +347,11 @@ void unsubscribe(GreenMailUser user, MailFolder folder) | |
* @param folder The store to test. | ||
* @return <code>true</code> if the user is subscribed. | ||
*/ | ||
boolean isSubscribed(GreenMailUser user, MailFolder folder) { | ||
public boolean isSubscribed(GreenMailUser user, MailFolder folder) { | ||
return getUserSubs(user).contains(folder.getFullName()); | ||
} | ||
|
||
private List<String> getUserSubs(GreenMailUser user) { | ||
protected List<String> getUserSubs(GreenMailUser user) { | ||
List<String> subs = userSubs.get(user.getLogin()); | ||
if (subs == null) { | ||
subs = new ArrayList<>(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.