It seems like it's impossible to introduce such a PHP CLI script to IMAP server (at least I'm sure of Dovecot). Anyway, the work around I found for this problem is to use my own PHP script to insert the new mails into IMAP server and retrieve their id's and then store the id in database for future references. To be clear, email are given to my PHP CLI script by MTA, not MDA. As I said before this is done easily using .forward
file.
[UPDATE]
Unfortunately it seems this solution can not be implemented as well. The way to insert a new email to IMAP server is APPEND
command, and to have the UID
of the recently added mail server must support UIDPLUS
extension. Neither Dovecot nor Courier supports this extension at the moment! If they did it seems the server would return the UID
with a APPENDUID
response.
[UPDATE]
It is my bad since Courier does support UIDPLUS
. So this solution is valid and the one I'm going to implement.