Skip to content

Commit

Permalink
Allow disable from filtering in config
Browse files Browse the repository at this point in the history
  • Loading branch information
drallieiv committed Jul 16, 2017
1 parent af2a23a commit 4339706
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
3 changes: 3 additions & 0 deletions KinanCity-mail/config.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# Uncomment the line below if you need to use a proxy
#proxy=http://login:pass@127.0.0.1:3128

# Uncomment the line below if you want to accept emails that does not come from pokemon.com
#disableDomainFilter=true
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.kinancity.mail.activator.LinkActivator;

import lombok.Setter;

/**
* Message Handler
*
Expand All @@ -35,11 +37,15 @@ public class KcMessageHandler implements MessageHandler {

private String recipient;
private String from;

private LinkActivator activator;

@Setter
private boolean acceptAllFrom = false;

/**
* Construct with a given Link Activator
*
* @param activator
*/
public KcMessageHandler(LinkActivator activator) {
Expand All @@ -63,7 +69,7 @@ public void recipient(String recipient) throws RejectException {
public void data(InputStream data) throws RejectException, TooMuchDataException, IOException {

// Only accept pokemon mails
if (from.endsWith(POKEMON_DOMAIN)) {
if (from.endsWith(POKEMON_DOMAIN) || acceptAllFrom) {

logger.debug("Received email from {} to {}", from, recipient);

Expand All @@ -81,10 +87,10 @@ public void data(InputStream data) throws RejectException, TooMuchDataException,
if (m.find()) {
String activationLink = m.group(0);
logger.info("Activation link found for email {} : [{}]", this.recipient, activationLink);

// Link activation, may be sync or async
activator.activateLink(new Activation(activationLink, this.recipient));

} else {
logger.error("No activation link found");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

import com.kinancity.mail.activator.LinkActivator;

import lombok.Setter;

/**
* Message Handler Factory
*
Expand All @@ -16,13 +18,18 @@ public class KcMessageHandlerFactory implements MessageHandlerFactory {

private LinkActivator activator;

@Setter
private boolean acceptAllFrom = false;

public KcMessageHandlerFactory(LinkActivator activator) {
this.activator = activator;
}

@Override
public MessageHandler create(MessageContext ctx) {
return new KcMessageHandler(activator);
KcMessageHandler handler = new KcMessageHandler(activator);
handler.setAcceptAllFrom(acceptAllFrom);
return handler;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,12 @@ public static void main(String[] args) {
wiser.setPort(25);
wiser.setHostname("localhost");

wiser.getServer().setMessageHandlerFactory(new KcMessageHandlerFactory(activator));
KcMessageHandlerFactory handlerFactory = new KcMessageHandlerFactory(activator);
boolean disableDomainFilter = config.getProperty("disableDomainFilter", "false").equals("true");
if (disableDomainFilter) {
handlerFactory.setAcceptAllFrom(true);
}
wiser.getServer().setMessageHandlerFactory(handlerFactory);
wiser.start();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public class QueueLinkActivator implements LinkActivator, Runnable {
@Setter
private boolean stop = false;

private HttpProxy httpProxy;

public QueueLinkActivator() {
client = new OkHttpClient.Builder().build();

Expand Down Expand Up @@ -150,7 +148,6 @@ public void run() {
}

public void setHttpProxy(HttpProxy httpProxy) {
this.httpProxy = httpProxy;
this.client = httpProxy.getClient();
}
}

0 comments on commit 4339706

Please sign in to comment.