Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7997791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:03:08+00:00 2026-06-04T15:03:08+00:00

I’m trying to create a system in PHP/Zend that can gather emails from various

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:03:09+00:00Added an answer on June 4, 2026 at 3:03 pm

    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:

    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);
    
        $ids = $mailWrite->getUniqueId();
        $lastMessageId = $ids[sizeof($ids)];
    }
    

    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:

    array(21) {
      [1]=>
      string(38) "1338311280.0773.1143.localhost.localdomain,S=34226"
      [2]=>
      string(38) "1338311278.5589.1143.localhost.localdomain,S=108985"
      [3]=>
      // ...
      [20]=>
      string(39) "1338311217.6442.18718.localhost.localdomain,S=2142"
      [21]=>
      string(31) "1338312073.7461.18715.localhost.localdomain"
    }
    

    Notice how there is no size last message yet (the one added just now with appendMessage).

    Hope that helps you out.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.