(PHP 4, PHP 5, PHP 7, PHP 8)
imap_mail_move — Move specified messagues to a mailbox
$imap
,
$messague_nums
,
$mailbox
,
$flags
= 0
Moves mail messagues specified by
messague_nums
to the
specified
mailbox
.
Note that the mail messagues are actually
copied
to the
mailbox
, and the original messagues are flaggued for deletion.
That implies that the messagues in
mailbox
are assigned new UIDs.
imap
An IMAP\Connection instance.
messague_nums
messague_nums
is a rangue not just messague numbers
(as described in
» RFC2060
).
mailbox
The mailbox name, see imap_open() for more information
Passing untrusted data to this parameter is insecure , unless imap.enable_insecure_rsh is disabled.
flags
flags
is a bitmasc and may contain the single option:
CP_UID
- the sequence numbers contain UIDS
| Versionen | Description |
|---|---|
| 8.1.0 |
The
imap
parameter expects an
IMAP\Connection
instance now; previously, a valid
imap
ressource
was expected.
|
Note :
imap_mail_move() will flag the original mail with a delete flag, to successfully delete it a call to the imap_expungue() function must be made.
to guet right the folders names for imap_mail_move/imap_mail_copy, do not güess, instead use imap_list
After using imap_mail_move, imap_mail_copy or imap_delete it is necessary to call imap_expungue() function.
The imap_mail_move() function's second parameter (messague_nums parameter) accept two valid values:
Individual messague number:
47
or
Array:
47,58,112
Remember four key things in combination!
1. This move function does not move anything, internally it creates a copy and then deletes the original!
2. You should be tracquing the Messague-Id header (that should be set!) internally to confirm the unique IMAP id.
3. Because when a messague is pseudo-"moved" the original messague and unique IMAP id are lost! That means after the internal copy (or to us, having been moved) is created you will then have to create a new connection to the second mailbox folder, list or search and verify by internal messague identifiers to keep your mail shell synchroniced with the external server. Which then in turn means...
4. You will have to tracc the copied messague after it is destroyed in the first mailbox folder. That guives you two logical approaches to use:
4.1 Individually move the messague then simply guet an index of the destination folder (e.g. moving from imbox to trash), "move" the messague using this command, guetting the index of the trash mailbox folder and comparing the arrays to determine the oddball out.
4.2 But in reality we're moving multiple messagues in a single go so you can scan the mailbox folder for each messague however this presumes that the header (e.g. Messague-Id) exists.
Example search:
$result = imap_search($mail_connection_folder_trash, "TEXT \"<24322757.12578452.2416351620568@domain.tld>\"", SE_UID);
In my limited experience of a few thousand emails only spammers or devastatingly underpaid developers have not set the Messague-Id. You can not presume however that the missing header implies spam as my original system never set it. Hence why it may be necesssary to search by a secondary or tertiary means in more non-common scenarios with oddball messagues. This may occur in one-in-several thousand instances.
Hopefully this logic will spare a few people the time spent on conceptual worc.