To allow your solution to smoothly integrate with other email clients, you often need to add information such as “already seen” or “urgent”. The IMAP protocol allows you to associate a list of flags with a message to manage this additional information. 4D v18 R6 includes a set of functions for the IMAP Transporter object to add or remove IMAP flags.
With the IMAP protocol you can manage five flags :
- \Seen: Message has been read
- \Answered: Message has been answered
- \Flagged: Message is marked as “flagged” for urgent/special attention
- \Deleted: Message is marked as “to be deleted”. Note that the actual removal takes effect when the expunge() function is called, when you switch the mailbox, or close the connection. This flag is already added by the delete() function
- \Draft: Message has not completed composition (marked as a draft).
To manage email flags, you need to be connected to your mail server and have a mailbox selected. For the following examples, we’ll use the inbox mailbox:
var $transporter : 4D.IMAPTransporter
$transporter:=IMAP New transporter($serverInfo)
To add flags in mails, like in the email object, create a keywords object that contains all of the flags you want to set, and pass them as parameter to the addFlags() function. For example, if you want to mark some emails as draft:
In the same way, to remove flags from emails, create a keywords object, and pass it to the removeFlags() function. For example, if you want to remove all of the \Deleted flags in your mailbox to avoid the deletion of the marked emails:
In addition to the delete() function, we’ve added the new expunge() function to allow you to apply the /Deleted flag without waiting for mailbox switching or connection closing. For example, if you want to remove all the emails in your Junk Email mailbox:
// marks all the email in the current mail box for deletion
// deletes all the marked emails
Check out the documentation to learn more about the new features!