Sometimes you need to save certain emails in dedicated mailboxes and other times you want to delete certain emails to keep up your INBOX tidy. The three new functions we’ve added to the IMAP transporter, copy(), move(), and delete() make this a breeze!
move or copy emails
To move an email, you need to be connected to your mail server and have a mailbox selected. For the following examples, we’ll use the inbox mailbox:
$transporter:=IMAP New transporter($serverInfo)
$boxInfo:=$transporter.selectBox("inbox")
To move all of the emails whose subject contains “4D new feature:” from your current mailbox (“inbox”) to a mailbox named “New features”, use the move() function:
$mailIds:=$transporter.searchMails("subject \"4D new feature:\"")
// Move emails from selected mailbox to destination mailbox
$status:=$transporter.move($mailIds; "New features")
The mails are no longer displayed in the inbox mailbox but rather, in the New features mailbox. Of course, you can also keep them in both mailboxes with the copy() function:
// Copy emails from selected mailbox to destination mailbox
$status:=$transporter.copy($mailIds; "New features")
Delete emails
If you want to delete all of the emails in your “Junk Email” mailbox, just select this mailbox and use the IMAP all keyword with the delete() function:
$boxInfo:=$transporter.selectBox("Junk Email")
// delete all the email in the current mail box
$status:=$transporter.delete(IMAP all)
Note that the delete() function only flags the message as deleted. It won’t be deleted from the IMAP server until you switch the mailbox or close the connection.
Download the HDI above to see the new functions in action!