Skip to content

Commit

Permalink
An updated ands slightly modified patch from BJ Freeman for "allow as…
Browse files Browse the repository at this point in the history
…signment of port for the Javamail container." https://issues.apache.org/jira/browse/1967

currently no property for setting the port to read email from in the javamail container.

git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1611002 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
JacquesLeRoux committed Jul 16, 2014
1 parent 5494105 commit ba29480
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
1 change: 1 addition & 0 deletions framework/service/ofbiz-component.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ under the License.
<property name="default-listener" value="store-listener">
<property name="mail.store.protocol" value="imap"/>
<property name="mail.host" value="[host]"/>
<property name="mail.port" value="110"/>
<property name="mail.user" value="[user]"/>
<property name="mail.pass" value="[pass]"/>
<property name="mail.debug" value="false"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import javax.mail.FetchProfile;
import javax.mail.Flags;
import javax.mail.Folder;
Expand All @@ -34,23 +35,23 @@
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.URLName;
import javax.mail.internet.MimeMessage;
import javax.mail.search.FlagTerm;
import javax.mail.event.StoreEvent;
import javax.mail.event.StoreListener;
import javax.mail.internet.MimeMessage;
import javax.mail.search.FlagTerm;

import org.ofbiz.base.container.Container;
import org.ofbiz.base.container.ContainerConfig;
import org.ofbiz.base.container.ContainerException;
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.base.util.UtilValidate;
import org.ofbiz.entity.Delegator;
import org.ofbiz.entity.DelegatorFactory;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.GenericEntityException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.service.GenericServiceException;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ServiceContainer;

public class JavaMailContainer implements Container {
Expand All @@ -77,6 +78,7 @@ public class JavaMailContainer implements Container {
* @throws org.ofbiz.base.container.ContainerException
*
*/
@Override
public void init(String[] args, String name, String configFile) throws ContainerException {
this.name = name;
this.configFile = configFile;
Expand All @@ -91,6 +93,7 @@ public void init(String[] args, String name, String configFile) throws Container
* @throws org.ofbiz.base.container.ContainerException
*
*/
@Override
public boolean start() throws ContainerException {
ContainerConfig.Container cfg = ContainerConfig.getContainer(name, configFile);
String dispatcherName = ContainerConfig.getPropertyValue(cfg, "dispatcher-name", "JavaMailDispatcher");
Expand Down Expand Up @@ -141,12 +144,14 @@ public boolean start() throws ContainerException {
* @throws org.ofbiz.base.container.ContainerException
*
*/
@Override
public void stop() throws ContainerException {
// stop the poller
this.pollTimer.shutdown();
Debug.logWarning("stop JavaMail poller", module);
}

@Override
public String getName() {
return name;
}
Expand Down Expand Up @@ -229,13 +234,32 @@ protected URLName updateUrlName(URLName urlName, Properties props) {
host = props.getProperty("mail.host");
}
}


// check the port
int port1 = 0;
String strport = props.getProperty("mail." + protocol + ".port");
if (!UtilValidate.isEmpty(strport)) {
port1 = Integer.valueOf(strport).intValue();
}
if (port1==0) {
strport = props.getProperty("mail.port");
if (!UtilValidate.isEmpty(strport)) {
port1 = Integer.valueOf(props.getProperty("mail.port"))
.intValue();
}
}
// override the port if have found one.
if (port1!=0) {
port = port1;
}

if (Debug.verboseOn()) Debug.logVerbose("Update URL - " + protocol + "://" + userName + "@" + host + ":" + port + "!" + password + ";" + file, module);
return new URLName(protocol, host, port, file, userName, password);
}

class LoggingStoreListener implements StoreListener {

@Override
public void notification(StoreEvent event) {
String typeString = "";
switch (event.getMessageType()) {
Expand All @@ -261,6 +285,7 @@ public PollerTask(LocalDispatcher dispatcher, GenericValue userLogin) {
this.userLogin = userLogin;
}

@Override
public void run() {
if (UtilValidate.isNotEmpty(stores)) {
for (Map.Entry<Store, Session> entry: stores.entrySet()) {
Expand Down

0 comments on commit ba29480

Please sign in to comment.