Skip to content

Commit 5506b56

Browse files
Merge pull request #388 from telekom/fix/imap-connector-delete-message
Fix/imap connector delete message
2 parents 3aa3c15 + cd7aef7 commit 5506b56

File tree

6 files changed

+156
-264
lines changed

6 files changed

+156
-264
lines changed

docs/src/docs/modules/mail-connector.adoc

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ The `POP3MailConnector` provides access to a POP3 server. Emails are read and pr
9292
POP3MailConnector pop3MailConnector = new POP3MailConnector();
9393
9494
// wait until the email with subject 'test' arrived in the InboxFolder
95-
EmailQuery query = new EmailQuery().setSearchTerm(new SubjectTerm(subject));
95+
SubjectTerm subjectTerm = new SubjectTerm(subject);
96+
EmailQuery query = new EmailQuery().setSearchTerm(subjectTerm);
9697
Email email = pop3MailConnector.query(query).findFirst().get();
9798
9899
// delete all emails with this subject from the server while setting timeout and max number of polls explicitly
@@ -103,10 +104,13 @@ Email email = pop3MailConnector.query(query).findFirst().get();
103104
104105
// delete mails matching the given criteria
105106
String recipient = email.getRecipients().get(0));
106-
String subject = email.getSubject();
107-
String messageId = null;
108107
109-
pop3MailConnector.deleteMessage(recipient, RecipientType.TO, subject, messageId);
108+
SearchTerm searchTerm = new AndTerm(new SearchTerm[]{
109+
subjectTerm,
110+
new RecipientTerm(RecipientType.TO, new InternetAddress(recipient))
111+
});
112+
113+
pop3MailConnector.deleteMessage(searchTerm);
110114
----
111115

112116
.Working with attachments
@@ -286,7 +290,7 @@ connector.query(query)
286290
----
287291

288292
== MailUtils
289-
This helper class contains methods which facilitate reoccurring tasks when working with mails, e.g. encrypting, decrypting, and comparing mails.
293+
This helper class contains methods which facilitate reoccurring tasks when working with mails, e.g. encrypting, decrypting and comparing mails.
290294

291295
.Encryption, Decryption and Comparison
292296
[source,java]

mail-connector/src/main/java/eu/tsystems/mms/tic/testframework/mailconnector/imap/ImapMailConnector.java

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,24 @@
2121
*/
2222
package eu.tsystems.mms.tic.testframework.mailconnector.imap;
2323

24-
import eu.tsystems.mms.tic.testframework.common.PropertyManager;
2524
import eu.tsystems.mms.tic.testframework.exceptions.SystemException;
26-
import eu.tsystems.mms.tic.testframework.logging.Loggable;
2725
import eu.tsystems.mms.tic.testframework.mailconnector.util.AbstractInboxConnector;
26+
27+
import java.util.Properties;
28+
2829
import jakarta.mail.Flags;
2930
import jakarta.mail.Folder;
3031
import jakarta.mail.Message;
3132
import jakarta.mail.MessagingException;
32-
import jakarta.mail.NoSuchProviderException;
3333
import jakarta.mail.Store;
3434

35-
import java.util.Properties;
36-
3735

3836
/**
3937
* MailConnector using the IMAP Protocol. Creates a session with values from mailconnection.properties.
4038
*
4139
* @author mibu
4240
*/
43-
public class ImapMailConnector extends AbstractInboxConnector implements Loggable {
41+
public class ImapMailConnector extends AbstractInboxConnector {
4442

4543
/**
4644
* Constructor, creates a ImapMailConnector object.
@@ -54,14 +52,14 @@ public ImapMailConnector() {
5452
* Called from constructor. Initializes the ImapMailConnector.
5553
*/
5654
private void init() {
57-
setServer(PropertyManager.getProperty("IMAP_SERVER", null));
58-
setPort(PropertyManager.getProperty("IMAP_SERVER_PORT", null));
59-
setInboxFolder(PropertyManager.getProperty("IMAP_FOLDER_INBOX", null));
60-
setUsername(PropertyManager.getProperty("IMAP_USERNAME", null));
61-
setPassword(PropertyManager.getProperty("IMAP_PASSWORD", null));
62-
setSslEnabled(PropertyManager.getBooleanProperty("IMAP_SSL_ENABLED", true));
55+
setServer(PROPERTY_MANAGER.getProperty("IMAP_SERVER", null));
56+
setPort(PROPERTY_MANAGER.getProperty("IMAP_SERVER_PORT", null));
57+
setInboxFolder(PROPERTY_MANAGER.getProperty("IMAP_FOLDER_INBOX", null));
58+
setUsername(PROPERTY_MANAGER.getProperty("IMAP_USERNAME", null));
59+
setPassword(PROPERTY_MANAGER.getProperty("IMAP_PASSWORD", null));
60+
setSslEnabled(PROPERTY_MANAGER.getBooleanProperty("IMAP_SSL_ENABLED", true));
6361

64-
setDebug(PropertyManager.getBooleanProperty("DEBUG_SETTING", false));
62+
setDebug(PROPERTY_MANAGER.getBooleanProperty("DEBUG_SETTING", false));
6563
}
6664

6765
/**
@@ -108,9 +106,6 @@ private void pMarkAllMailsAsSeen() throws SystemException {
108106
message.setFlag(Flags.Flag.SEEN, true);
109107
}
110108
store.close();
111-
} catch (final NoSuchProviderException e) {
112-
log().error(e.getMessage());
113-
throw new SystemException(e);
114109
} catch (final MessagingException e) {
115110
log().error(e.getMessage());
116111
throw new SystemException(e);

mail-connector/src/main/java/eu/tsystems/mms/tic/testframework/mailconnector/pop3/POP3MailConnector.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
*/
2222
package eu.tsystems.mms.tic.testframework.mailconnector.pop3;
2323

24-
import eu.tsystems.mms.tic.testframework.common.PropertyManager;
2524
import eu.tsystems.mms.tic.testframework.mailconnector.util.AbstractInboxConnector;
25+
2626
import java.util.Properties;
2727

2828
/**
@@ -44,15 +44,15 @@ public POP3MailConnector() {
4444
* Called from constructor. Initializes the ImapMailConnector.
4545
*/
4646
private void init() {
47-
setServer(PropertyManager.getProperty("POP3_SERVER", null));
48-
setPort(PropertyManager.getProperty("POP3_SERVER_PORT", null));
49-
setInboxFolder(PropertyManager.getProperty("POP3_FOLDER_INBOX", null));
50-
setUsername(PropertyManager.getProperty("POP3_USERNAME", null));
51-
setPassword(PropertyManager.getProperty("POP3_PASSWORD", null));
47+
setServer(PROPERTY_MANAGER.getProperty("POP3_SERVER", null));
48+
setPort(PROPERTY_MANAGER.getProperty("POP3_SERVER_PORT", null));
49+
setInboxFolder(PROPERTY_MANAGER.getProperty("POP3_FOLDER_INBOX", null));
50+
setUsername(PROPERTY_MANAGER.getProperty("POP3_USERNAME", null));
51+
setPassword(PROPERTY_MANAGER.getProperty("POP3_PASSWORD", null));
5252

5353
// Password may needs to be encoded
54-
setDebug(PropertyManager.getBooleanProperty("DEBUG_SETTING", false));
55-
setSslEnabled(PropertyManager.getBooleanProperty("POP3_SSL_ENABLED", true));
54+
setDebug(PROPERTY_MANAGER.getBooleanProperty("DEBUG_SETTING", false));
55+
setSslEnabled(PROPERTY_MANAGER.getBooleanProperty("POP3_SSL_ENABLED", true));
5656
}
5757

5858
/**

0 commit comments

Comments
 (0)