Skip to content

Commit

Permalink
Merge pull request #388 from telekom/fix/imap-connector-delete-message
Browse files Browse the repository at this point in the history
Fix/imap connector delete message
  • Loading branch information
martingrossmann authored Jan 19, 2024
2 parents 3aa3c15 + cd7aef7 commit 5506b56
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 264 deletions.
14 changes: 9 additions & 5 deletions docs/src/docs/modules/mail-connector.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ The `POP3MailConnector` provides access to a POP3 server. Emails are read and pr
POP3MailConnector pop3MailConnector = new POP3MailConnector();
// wait until the email with subject 'test' arrived in the InboxFolder
EmailQuery query = new EmailQuery().setSearchTerm(new SubjectTerm(subject));
SubjectTerm subjectTerm = new SubjectTerm(subject);
EmailQuery query = new EmailQuery().setSearchTerm(subjectTerm);
Email email = pop3MailConnector.query(query).findFirst().get();
// delete all emails with this subject from the server while setting timeout and max number of polls explicitly
Expand All @@ -103,10 +104,13 @@ Email email = pop3MailConnector.query(query).findFirst().get();
// delete mails matching the given criteria
String recipient = email.getRecipients().get(0));
String subject = email.getSubject();
String messageId = null;
pop3MailConnector.deleteMessage(recipient, RecipientType.TO, subject, messageId);
SearchTerm searchTerm = new AndTerm(new SearchTerm[]{
subjectTerm,
new RecipientTerm(RecipientType.TO, new InternetAddress(recipient))
});
pop3MailConnector.deleteMessage(searchTerm);
----

.Working with attachments
Expand Down Expand Up @@ -286,7 +290,7 @@ connector.query(query)
----

== MailUtils
This helper class contains methods which facilitate reoccurring tasks when working with mails, e.g. encrypting, decrypting, and comparing mails.
This helper class contains methods which facilitate reoccurring tasks when working with mails, e.g. encrypting, decrypting and comparing mails.

.Encryption, Decryption and Comparison
[source,java]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,24 @@
*/
package eu.tsystems.mms.tic.testframework.mailconnector.imap;

import eu.tsystems.mms.tic.testframework.common.PropertyManager;
import eu.tsystems.mms.tic.testframework.exceptions.SystemException;
import eu.tsystems.mms.tic.testframework.logging.Loggable;
import eu.tsystems.mms.tic.testframework.mailconnector.util.AbstractInboxConnector;

import java.util.Properties;

import jakarta.mail.Flags;
import jakarta.mail.Folder;
import jakarta.mail.Message;
import jakarta.mail.MessagingException;
import jakarta.mail.NoSuchProviderException;
import jakarta.mail.Store;

import java.util.Properties;


/**
* MailConnector using the IMAP Protocol. Creates a session with values from mailconnection.properties.
*
* @author mibu
*/
public class ImapMailConnector extends AbstractInboxConnector implements Loggable {
public class ImapMailConnector extends AbstractInboxConnector {

/**
* Constructor, creates a ImapMailConnector object.
Expand All @@ -54,14 +52,14 @@ public ImapMailConnector() {
* Called from constructor. Initializes the ImapMailConnector.
*/
private void init() {
setServer(PropertyManager.getProperty("IMAP_SERVER", null));
setPort(PropertyManager.getProperty("IMAP_SERVER_PORT", null));
setInboxFolder(PropertyManager.getProperty("IMAP_FOLDER_INBOX", null));
setUsername(PropertyManager.getProperty("IMAP_USERNAME", null));
setPassword(PropertyManager.getProperty("IMAP_PASSWORD", null));
setSslEnabled(PropertyManager.getBooleanProperty("IMAP_SSL_ENABLED", true));
setServer(PROPERTY_MANAGER.getProperty("IMAP_SERVER", null));
setPort(PROPERTY_MANAGER.getProperty("IMAP_SERVER_PORT", null));
setInboxFolder(PROPERTY_MANAGER.getProperty("IMAP_FOLDER_INBOX", null));
setUsername(PROPERTY_MANAGER.getProperty("IMAP_USERNAME", null));
setPassword(PROPERTY_MANAGER.getProperty("IMAP_PASSWORD", null));
setSslEnabled(PROPERTY_MANAGER.getBooleanProperty("IMAP_SSL_ENABLED", true));

setDebug(PropertyManager.getBooleanProperty("DEBUG_SETTING", false));
setDebug(PROPERTY_MANAGER.getBooleanProperty("DEBUG_SETTING", false));
}

/**
Expand Down Expand Up @@ -108,9 +106,6 @@ private void pMarkAllMailsAsSeen() throws SystemException {
message.setFlag(Flags.Flag.SEEN, true);
}
store.close();
} catch (final NoSuchProviderException e) {
log().error(e.getMessage());
throw new SystemException(e);
} catch (final MessagingException e) {
log().error(e.getMessage());
throw new SystemException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/
package eu.tsystems.mms.tic.testframework.mailconnector.pop3;

import eu.tsystems.mms.tic.testframework.common.PropertyManager;
import eu.tsystems.mms.tic.testframework.mailconnector.util.AbstractInboxConnector;

import java.util.Properties;

/**
Expand All @@ -44,15 +44,15 @@ public POP3MailConnector() {
* Called from constructor. Initializes the ImapMailConnector.
*/
private void init() {
setServer(PropertyManager.getProperty("POP3_SERVER", null));
setPort(PropertyManager.getProperty("POP3_SERVER_PORT", null));
setInboxFolder(PropertyManager.getProperty("POP3_FOLDER_INBOX", null));
setUsername(PropertyManager.getProperty("POP3_USERNAME", null));
setPassword(PropertyManager.getProperty("POP3_PASSWORD", null));
setServer(PROPERTY_MANAGER.getProperty("POP3_SERVER", null));
setPort(PROPERTY_MANAGER.getProperty("POP3_SERVER_PORT", null));
setInboxFolder(PROPERTY_MANAGER.getProperty("POP3_FOLDER_INBOX", null));
setUsername(PROPERTY_MANAGER.getProperty("POP3_USERNAME", null));
setPassword(PROPERTY_MANAGER.getProperty("POP3_PASSWORD", null));

// Password may needs to be encoded
setDebug(PropertyManager.getBooleanProperty("DEBUG_SETTING", false));
setSslEnabled(PropertyManager.getBooleanProperty("POP3_SSL_ENABLED", true));
setDebug(PROPERTY_MANAGER.getBooleanProperty("DEBUG_SETTING", false));
setSslEnabled(PROPERTY_MANAGER.getBooleanProperty("POP3_SSL_ENABLED", true));
}

/**
Expand Down
Loading

0 comments on commit 5506b56

Please sign in to comment.