IMAP Connection
Note
IMAP connection is available since Process2024.0.0
To set up a connection to a server
-
From the connection properties form, fill in the definition of the connection: the label, possibly a description, the connection’s attachment organization and the System name.
-
Enter the connection settings :
- Server
- Port Number: The default port for an IMAP connection is 143 and 993 for an IMAPS connection
- Username by which Process will connect to the server
- Password by which Process will connect to the server
- Protocol : 3 choices : IMAP, IMAPS (IMAP with SSL) and STARTTLS (IMAP with TLS)
Message status is managed by flags:
- ANSWERED: indicates whether this message has received a reply.
- DELETED: this flag indicates that a message has been deleted. Closing the connection deletes all messages marked for deletion.
- DRAFT: indicates whether the message is a draft.
- NEW : indicates that the message is new. (Clients cannot alter this flag.)
- READ : indicates that the message has been read. This flag is implicitly set by the implementation when the message content is returned.
Example: agent with every available methods
import java.util.Collection;
import com.axemble.vdoc.sdk.modules.IPortalModule;
import com.axemble.vdoc.sdk.exceptions.PortalModuleException;
import com.axemble.vdoc.sdk.enums.IIMAPFlag;
import com.axemble.vdoc.sdk.interfaces.IConnectionDefinition;
import com.axemble.vdoc.sdk.interfaces.IContext;
import com.axemble.vdoc.sdk.interfaces.IAgentProcessingContext;
import com.axemble.vdoc.sdk.interfaces.IStoppableAgentProcessing;
import com.axemble.vdoc.sdk.interfaces.imap.IIMAPClient;
import com.axemble.vdoc.sdk.interfaces.imap.IIMAPFolder;
import com.axemble.vdoc.sdk.interfaces.imap.IIMAPMessage;
import com.axemble.vdoc.sdk.interfaces.imap.IIMAPBodyPart;
public class AgentTest implements IStoppableAgentProcessing {
@Override
public void execute(IAgentProcessingContext iAgentProcessingContext) {
IPortalModule portalModule = Modules.getPortalModule();
IContext sysadminContext = portalModule.getSysadminContext();
IConnectionDefinition<?> testIMAP;
try {
testIMAP = portalModule.getConnectionDefinition(sysadminContext, "TestIMAP");
} catch (PortalModuleException e) {
throw new RuntimeException(e);
}
try (IIMAPClient client = (IIMAPClient)testIMAP.getConnection()) {
IIMAPFolder rootFolder = client.getDefaultFolder();
IIMAPFolder inboxFolder = client.getFolder("INBOX");
inboxFolder.countTotalMessage();
inboxFolder.countUnreadMessage();
inboxFolder.countNewMessage();
inboxFolder.getFolderName();
inboxFolder.getFullFolderName();
for (IIMAPMessage message : inboxFolder.getMessages()) {
message.getRecipients();
message.getFrom();
message.getTextContent();
message.getReceivedDate();
message.getSubject();
message.getSentDate();
message.setFlag(IIMAPFlag.DELETED, true);
message.getFlagValue(IIMAPFlag.ANSWERED);
for (IIMAPBodyPart attachment : message.getAttachments()) {
attachment.getSize();
attachment.getContent();
attachment.getFileName();
attachment.getContentType();
attachment.getDescription();
attachment.getInputStream();
}
}
Collection<IIMAPMessage> messagesByFlag = inboxFolder.getMessagesByFlag(IIMAPFlag.READ, false);
IIMAPFolder customFolder = client.getFolder("CUSTOM_FOLDER");
client.moveMessages(messagesByFlag, customFolder);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}