I’m trying to create a system in PHP/Zend that can gather emails from various different accounts (mainly POP and IMAP) and combine them all in one system for reasons of analysis (contents of the emails etc.)
My plan is to read the emails from the accounts and move them locally, because the system I’m designing will be called on to show the emails in their original format if the users need to view them. I’ve created a local Maildir structure using Zend_Mail_Storage_Writable_Maildir, and I’m adding the messages as they come back from each account.
I’m able to connect to the various accounts and retrieve the emails, and add them to my local Maildir account without problems. My problem is that I can’t seem to find a unique identifier to separate each message added to the Maildir account (I plan to store some of the email information for each email along with the unique identifier in a database).
Does anyone know how to get the unique identifier for a message recently added into a Zend_Mail_Storage_Writable_Maildir instance?
My basic code is as follows:
// Set config array for connecting to an email account (Hotmail, gMail etc.)
$config = array(
'host'=> 'xxxx',
'user' => 'xxxx',
'password' => 'xxxx',
'ssl' => 'SSL',
'port' => 995);
// Connect to the account and get the messages
$mail = new Zend_Mail_Storage_Pop3($config);
// Connect to the local Mairdir instance so we can add new messages
$mailWrite = new Zend_Mail_Storage_Writable_Maildir(array('dirname' => '/xxxx/xxxx/'));
// Loop through the messages and add them
foreach ($mail as $messageId => $message)
{
// ADDING THE MESSAGE WORKS FINE, BUT HOW DO I GET THE UNIQUE
// IDENTIFIER FOR THE MESSAGE I JUST ADDED?
$mailWrite->appendMessage($message);
// FYI: $messageId seems to be the message ID from the originating account; it
// starts at one and increments, so this can't be used :(
}
Thanks for any insight you may be able to offer!
Dan
You can get the unique ID of the added messages by using the
Zend_Mail_Storage_Writable_Maildir::getUniqueId()method.It will return an array of all the message’s unique ID’s from the mail directory if you do not pass an id to the function.
Here is an example:
Of note is that the return array from
getUniqueId()is 1-based instead of 0-based so just be aware of that.Also, I’m not sure if this is a bug or by design, but the unique ID returned for newly added files does not contain the message size or info string on the filename, but existing messages will.
That means, your array may look something like this:
Notice how there is no size last message yet (the one added just now with appendMessage).
Hope that helps you out.