From 81c8051b4447cbd853c1a12fa11346fa9ef2429b Mon Sep 17 00:00:00 2001 From: Iwein Fuld Date: Mon, 26 Jan 2009 18:56:28 +0000 Subject: [PATCH] OPEN - issue INT-540: AbstractMailReceiver needs to have authenticator property http://jira.springframework.org/browse/INT-540 added javaMailAuthenticator property. If not set passing a null Authenticator to getInstance(props, auth) will have the exact same behavior as before. --- .../mail/AbstractMailReceiver.java | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java index 54b549352d..e80dba18c8 100755 --- a/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java +++ b/org.springframework.integration.mail/src/main/java/org/springframework/integration/mail/AbstractMailReceiver.java @@ -18,6 +18,7 @@ package org.springframework.integration.mail; import java.util.Properties; +import javax.mail.Authenticator; import javax.mail.FetchProfile; import javax.mail.Flags; import javax.mail.Folder; @@ -40,6 +41,7 @@ import org.springframework.util.Assert; * @author Arjen Poutsma * @author Jonas Partner * @author Mark Fisher + * @author Iwein Fuld */ public abstract class AbstractMailReceiver implements MailReceiver, DisposableBean { @@ -61,6 +63,7 @@ public abstract class AbstractMailReceiver implements MailReceiver, DisposableBe private final Object initializationMonitor = new Object(); + private Authenticator javaMailAuthenticator; public AbstractMailReceiver(URLName urlName) { Assert.notNull(urlName, "urlName must not be null"); @@ -72,11 +75,17 @@ public abstract class AbstractMailReceiver implements MailReceiver, DisposableBe this.url = new URLName(url); } - public void setJavaMailProperties(Properties javaMailProperties) { this.javaMailProperties = javaMailProperties; } + /** + * Optional, sets the Authenticator to be used to obtain a session + */ + public void setJavaMailAuthenticator(Authenticator javaMailAuthenticator) { + this.javaMailAuthenticator = javaMailAuthenticator; + } + public void setMaxFetchSize(int maxFetchSize) { this.maxFetchSize = maxFetchSize; } @@ -98,7 +107,7 @@ public abstract class AbstractMailReceiver implements MailReceiver, DisposableBe private void openSession() throws MessagingException { if (this.session == null) { - this.session = Session.getInstance(this.javaMailProperties); + this.session = Session.getInstance(this.javaMailProperties, this.javaMailAuthenticator); } if (this.store == null) { this.store = this.session.getStore(this.url); @@ -173,7 +182,7 @@ public abstract class AbstractMailReceiver implements MailReceiver, DisposableBe * Fetches the specified messages from this receiver's folder. Default * implementation {@link Folder#fetch(Message[], FetchProfile) fetches} * every {@link javax.mail.FetchProfile.Item}. - * + * * @param messages the messages to fetch * @throws MessagingException in case of JavMail errors */ @@ -186,9 +195,9 @@ public abstract class AbstractMailReceiver implements MailReceiver, DisposableBe } /** - * Deletes the given messages from this receiver's folder. Only invoked - * when {@link #setDeleteMessages(boolean)} is true. - * + * Deletes the given messages from this receiver's folder. Only invoked when + * {@link #setDeleteMessages(boolean)} is true. + * * @param messages the messages to delete * @throws MessagingException in case of JavaMail errors */