sorted methods alphabetically
Signed-off-by: Stephan Richter <s.richter@srsoftware.de>
This commit is contained in:
@@ -33,28 +33,40 @@ public class ImapClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListeningThread doStop() {
|
||||
stopped = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ListeningThread dropListeners() {
|
||||
listeners.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (!stopped) {
|
||||
try {
|
||||
sleep(5000);
|
||||
} catch (InterruptedException interruptedException) {
|
||||
interruptedException.printStackTrace();
|
||||
}
|
||||
try {
|
||||
openInbox();
|
||||
} catch (MessagingException e){
|
||||
LOG.warn("Connection problem:",e);
|
||||
problemListener.onImapException(e);
|
||||
}
|
||||
|
||||
private void handle(Message message) throws MessagingException {
|
||||
LOG.debug("Handling {}",message.getSubject());
|
||||
for (MessageHandler listener : listeners) listener.onMessageReceived(message);
|
||||
}
|
||||
|
||||
private void handleMessages() throws MessagingException {
|
||||
LOG.debug("Reading email of {}:",username);
|
||||
if (!inbox.isOpen()) inbox.open(IMAPFolder.READ_WRITE);
|
||||
for (Message message : inbox.getMessages()){
|
||||
if (message.isSet(Flags.Flag.SEEN)) continue;
|
||||
handle(message);
|
||||
Folder folder = message.getFolder();
|
||||
if (!folder.isOpen()) folder.open(Folder.READ_WRITE);
|
||||
message.setFlag(Flags.Flag.SEEN,true);
|
||||
}
|
||||
}
|
||||
|
||||
private Properties imapProps() {
|
||||
Properties props = new Properties();
|
||||
props.put(Constants.PROTOCOL,Constants.IMAPS);
|
||||
return props;
|
||||
}
|
||||
|
||||
private void openInbox() throws MessagingException {
|
||||
LOG.debug("Connecting and logging in…");
|
||||
Properties props = imapProps();
|
||||
@@ -73,40 +85,33 @@ public class ImapClient {
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMessages() throws MessagingException {
|
||||
LOG.debug("Reading email of {}:",username);
|
||||
if (!inbox.isOpen()) inbox.open(IMAPFolder.READ_WRITE);
|
||||
for (Message message : inbox.getMessages()){
|
||||
if (message.isSet(Flags.Flag.SEEN)) continue;
|
||||
handle(message);
|
||||
Folder folder = message.getFolder();
|
||||
if (!folder.isOpen()) folder.open(Folder.READ_WRITE);
|
||||
message.setFlag(Flags.Flag.SEEN,true);
|
||||
@Override
|
||||
public void run() {
|
||||
while (!stopped) {
|
||||
try {
|
||||
sleep(5000);
|
||||
} catch (InterruptedException interruptedException) {
|
||||
interruptedException.printStackTrace();
|
||||
}
|
||||
try {
|
||||
openInbox();
|
||||
} catch (MessagingException e){
|
||||
LOG.warn("Connection problem:",e);
|
||||
problemListener.onImapException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handle(Message message) throws MessagingException {
|
||||
LOG.debug("Handling {}",message.getSubject());
|
||||
for (MessageHandler listener : listeners) listener.onMessageReceived(message);
|
||||
}
|
||||
|
||||
private Properties imapProps() {
|
||||
Properties props = new Properties();
|
||||
props.put(Constants.PROTOCOL,Constants.IMAPS);
|
||||
return props;
|
||||
}
|
||||
|
||||
public ListeningThread doStop() {
|
||||
stopped = true;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
private class Heartbeat extends Thread{
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Heartbeat.class);
|
||||
private boolean stopped = false;
|
||||
|
||||
public Heartbeat doStop() {
|
||||
stopped = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while (!stopped){
|
||||
@@ -123,11 +128,6 @@ public class ImapClient {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Heartbeat doStop() {
|
||||
stopped = true;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public ImapClient(String host, int port, String username, String password, String folderName,ProblemListener listener) {
|
||||
@@ -165,27 +165,15 @@ public class ImapClient {
|
||||
inbox.expunge();
|
||||
}
|
||||
|
||||
public String folderName(){
|
||||
return folderName;
|
||||
}
|
||||
|
||||
|
||||
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 ImapClient move(Message message, String destinationFolder) throws MessagingException {
|
||||
if (listeningThread == null || listeningThread.stopped) throw new IllegalStateException("IMAP client not connected!");
|
||||
var source = message.getFolder();
|
||||
@@ -200,6 +188,14 @@ public class ImapClient {
|
||||
return this;
|
||||
}
|
||||
|
||||
public String password(){
|
||||
return password;
|
||||
}
|
||||
|
||||
public int port(){
|
||||
return port;
|
||||
}
|
||||
|
||||
|
||||
public ImapClient start() {
|
||||
stop();
|
||||
@@ -225,4 +221,8 @@ public class ImapClient {
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public String username(){
|
||||
return username;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user