Unfortunately JMeter Mail Reader Sampler doesn't allow advanced operations. However JMeter can be extended by scripting.
So you can implement all required methods using Java Mail API and one of scripting samplers provided:
Refer to example below for deleting all messages from "Spam" folder using IMAP for Gmail:
import com.sun.mail.imap.IMAPSSLStore;
import javax.mail. *;
try {
Properties properties = props;
properties.put("mail.smtps.auth", "true");
properties.put("mail.imap.ssl.enable", "true");
Session imapsession = Session.getInstance(properties, null);
imapsession.setDebug(false);
Store imapstore = new IMAPSSLStore(imapsession, new URLName("imaps", "imap.gmail.com", 993, "", "[email protected]", "password"));
imapstore.connect();
Folder rootfolder = imapstore.getDefaultFolder();
Folder[] imapfolders = rootfolder.list("*");
for (Folder folder : imapfolders) {
if (folder.getName().equals("Spam")) {
folder.open(Folder.READ_WRITE);
log.info("Spam folder contains " + folder.getMessageCount() + " messages");
Message[] messages = folder.getMessages();
for (Message message : messages) {
message.setFlag(Flags.Flag.DELETED, true);
log.info("Marking message with subject: " + message.getSubject() + " for deletion");
}
folder.expunge();
folder.close(true);
}
}
imapstore.close();
} catch (Exception ex) {
log.error("IMAP operation failed", ex);
}
Beanshell Sampler doesn't require any extra configuration, you can just copy and paste the code above.
However Beanshell has well known performance issues and limitations so if your test assumes more or less high load it's recommended to use JSR223 Sampler and Groovy language.
See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! scripting engines comparison benchmark for more information and installation instructions for Groovy scripting engine.