Skip to content

Commit

Permalink
Minor cleanups (javadoc, sonar) and minor integration of #294
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelmay committed Apr 5, 2020
1 parent 7186491 commit a68af5c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,18 @@ public boolean isReadonly() {

public int[] getExpunged() {
synchronized (expungedMsns) {
int[] expungedMsns = new int[this.expungedMsns.size()];
for (int i = 0; i < expungedMsns.length; i++) {
int[] expungedMsnsArray = new int[this.expungedMsns.size()];
for (int i = 0; i < expungedMsnsArray.length; i++) {
int msn = this.expungedMsns.get(i);
expungedMsns[i] = msn;
expungedMsnsArray[i] = msn;
}
this.expungedMsns.clear();

// TODO - renumber any cached ids (for now we assume the modifiedFlags has been cleared)\
if (!(modifiedFlags.isEmpty() && !sizeChanged)) {
throw new IllegalStateException("Need to do this properly...");
}
return expungedMsns;
return expungedMsnsArray;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void deleteMailbox(MailFolder folder) throws FolderException {
}

@Override
public void renameMailbox(MailFolder existingFolder, String newName) throws FolderException {
public void renameMailbox(MailFolder existingFolder, String newName) {
HierarchicalFolder toRename = (HierarchicalFolder) existingFolder;
HierarchicalFolder parent = toRename.getParent();

Expand Down Expand Up @@ -112,16 +112,16 @@ public void renameMailbox(MailFolder existingFolder, String newName) throws Fold
}

private HierarchicalFolder getInboxOrUserRootFolder(HierarchicalFolder folder) {
final HierarchicalFolder inboxFolder = findParentByName(folder, ImapConstants.INBOX_NAME);
final HierarchicalFolder inboxFolder = findParentByName(folder);
if(null==inboxFolder) {
return folder.getParent();
}
return inboxFolder.getParent();
}

private HierarchicalFolder findParentByName(HierarchicalFolder folder, String name) {
private HierarchicalFolder findParentByName(HierarchicalFolder folder) {
HierarchicalFolder currentFolder = folder;
while (null != currentFolder && !name.equals(currentFolder.getName())) {
while (null != currentFolder && !ImapConstants.INBOX_NAME.equals(currentFolder.getName())) {
currentFolder = currentFolder.getParent();
}
return currentFolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
import org.slf4j.LoggerFactory;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

public class UserManager {
private static final Logger log = LoggerFactory.getLogger(UserManager.class);
/**
* User list by their trimmed, lowercased user names
* User list by their trimmed, lower-cased user names
*/
private Map<String, GreenMailUser> loginToUser = Collections.synchronizedMap(new HashMap<String, GreenMailUser>());
private Map<String, GreenMailUser> emailToUser = Collections.synchronizedMap(new HashMap<String, GreenMailUser>());
private Map<String, GreenMailUser> loginToUser = new ConcurrentHashMap<>();
private Map<String, GreenMailUser> emailToUser = new ConcurrentHashMap<>();
private ImapHostManager imapHostManager;
private boolean authRequired = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static GreenMailUtil instance() {
/**
* Writes the content of an input stream to an output stream
*
* @throws IOException
* @throws IOException on io error.
*/
public static void copyStream(final InputStream src, OutputStream dest) throws IOException {
byte[] buffer = new byte[1024];
Expand Down Expand Up @@ -129,7 +129,7 @@ public static int getLineCount(String str) {
public static String getBody(Part msg) {
String all = getWholeMessage(msg);
int i = all.indexOf("\r\n\r\n");
return i < 0 ? "" /* empty body */ : all.substring(i + 4, all.length());
return i < 0 ? "" /* empty body */ : all.substring(i + 4);
}

/**
Expand Down Expand Up @@ -333,7 +333,7 @@ public static MimeMultipart createMultipartWithAttachment(String msg, final byte

DataSource ds = new DataSource() {
@Override
public InputStream getInputStream() throws IOException {
public InputStream getInputStream() {
return new ByteArrayInputStream(attachment);
}

Expand Down Expand Up @@ -363,6 +363,12 @@ public String getName() {
}
}

/**
* Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.
*
* @param setup the setup type, such as <code>ServerSetup.IMAP</code>
* @return the JavaMail session.
*/
public static Session getSession(final ServerSetup setup) {
return getSession(setup, null);
}
Expand All @@ -375,10 +381,20 @@ public static Session getSession(final ServerSetup setup) {
* @return the JavaMail session.
*/
public static Session getSession(final ServerSetup setup, Properties mailProps) {
Properties props = setup.configureJavaMailSessionProperties(mailProps, false);
return getSession(setup, mailProps, false);
}

/**
* Gets a JavaMail Session for given server type such as IMAP and additional props for JavaMail.
*
* @param setup the setup type, such as <code>ServerSetup.IMAP</code>
* @param mailProps additional mail properties.
* @param debug sets JavaMail debug properties.
* @return the JavaMail session.
*/
public static Session getSession(final ServerSetup setup, Properties mailProps, boolean debug) {
Properties props = setup.configureJavaMailSessionProperties(mailProps, debug);
log.debug("Mail session properties are {}", props);

return Session.getInstance(props, null);
}

Expand Down

0 comments on commit a68af5c

Please sign in to comment.