moved imap credentials from MailingList to ImapClient
This commit is contained in:
26
src/main/java/de/srsoftware/widerhall/mail/Archiver.java
Normal file
26
src/main/java/de/srsoftware/widerhall/mail/Archiver.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package de.srsoftware.widerhall.mail;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
public class Archiver implements MessageHandler {
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Archiver.class);
|
||||
private final SmtpClient smtp;
|
||||
private final String receiver,sender;
|
||||
|
||||
public Archiver(String host, int port, String username, String password, String sender, String receiver) {
|
||||
this.sender = sender;
|
||||
this.receiver = receiver;
|
||||
SmtpClient smtp = new SmtpClient(host,port,username,password);
|
||||
this.smtp = smtp;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessageReceived(Message message) throws MessagingException {
|
||||
LOG.debug("storing {}",message.getSubject());
|
||||
}
|
||||
}
|
||||
@@ -23,11 +23,5 @@ public class Forwarder implements MessageHandler {
|
||||
@Override
|
||||
public void onMessageReceived(Message message) throws MessagingException {
|
||||
LOG.debug("forwarding {}",message.getSubject());
|
||||
|
||||
try {
|
||||
smtp.send(sender,"Stephan Richter",receiver,"Info: "+message.getSubject(),"Neue Mail eingegangen!");
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,13 +13,12 @@ import java.util.Properties;
|
||||
public class ImapClient {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ImapClient.class);
|
||||
private final JSONObject config;
|
||||
private boolean stopped = false;
|
||||
private final int port;
|
||||
private final String host, username, password, folderName;
|
||||
private boolean stopped = true;
|
||||
private IMAPFolder inbox;
|
||||
private HashSet<MessageHandler> listeners = new HashSet<>();
|
||||
|
||||
|
||||
|
||||
private class ListeningThread extends Thread {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ListeningThread.class);
|
||||
@@ -41,10 +40,6 @@ public class ImapClient {
|
||||
}
|
||||
|
||||
private void openInbox() throws MessagingException {
|
||||
String host = (String) config.get(Constants.HOST);
|
||||
String username = (String) config.get(Constants.USER);
|
||||
String password = (String) config.get(Constants.PASSWORD);
|
||||
String folderName = (String) config.get(Constants.INBOX);
|
||||
LOG.debug("Connecting and logging in…");
|
||||
Properties props = imapProps();
|
||||
Session session = Session.getInstance(props);
|
||||
@@ -105,15 +100,13 @@ public class ImapClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
public ImapClient(JSONObject config){
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
LOG.debug("Creating ListeningThread…");
|
||||
new ListeningThread().start();
|
||||
LOG.debug("Creating Heartbeat…");
|
||||
new Heartbeat().start();
|
||||
public ImapClient(String host, int port, String username, String password, String folderName) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.folderName = folderName;
|
||||
}
|
||||
|
||||
|
||||
@@ -121,4 +114,36 @@ public class ImapClient {
|
||||
listeners.add(messageHandler);
|
||||
return this;
|
||||
}
|
||||
|
||||
public String host(){
|
||||
return host;
|
||||
}
|
||||
|
||||
public String username(){
|
||||
return username;
|
||||
}
|
||||
|
||||
public String password(){
|
||||
return password;
|
||||
}
|
||||
|
||||
public int port(){
|
||||
return port;
|
||||
}
|
||||
|
||||
public String folderName(){
|
||||
return folderName;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
stopped = false;
|
||||
LOG.debug("Creating ListeningThread…");
|
||||
new ListeningThread().start();
|
||||
LOG.debug("Creating Heartbeat…");
|
||||
new Heartbeat().start();
|
||||
}
|
||||
|
||||
public void stop(){
|
||||
stopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user