开发者

imap headers of a quoted mail

I'm sending an email with some xheader.

When the recipient of the email replays to that email, i want to parse it, and get the content of that xheader from the mail i get by replay.

unfortunately, when i'm parsing the email i get back, i don't see my xheader. (I printed the whole email, and the xheader is not there)

How can i do that in PHP with Zend Framework (i'm using Zend_Mail_Storage_Imap)?

Code:

    $mail = new Zend_Mail_Storage_Imap(array(
    'host' => 'pop.gmail.com',
    'user' => 'a@gmail.com',
    'password' => 'a',
开发者_开发知识库    'ssl' => 'SSL'
));
$count = $mail->countMessages();
$message = $mail->getMessage($count);   
print_r($message);

    //go through the message
    foreach(new RecursiveIteratorIterator($message) as $part){
        echo '*****************<br/>';
        print_r($part);
        echo '<br/>*****************<br/>';         
        //match parts content type to text/html - the one that maches is the message HTML body
        if (preg_match('/.*text\/html.*/', $part->contentType)){
            $body = $part->getContent();
        }

        $headers = $part->getHeaders();
        if (isset($headers['X-aHeader'])){
            echo $headers['X-aHeader'];
        }

Thanks, Boris.


Pekka gets points for the correct response here - X-headers in an original message will not necessarily be retained for any replies to that message. But, you're using Gmail, so you have another potential option.

Gmail allows plus addressing, so username@gmail.com will also receive mail for username+extra@gmail.com. If your X-aHeader content is alphanumeric, you can append it to your email address (e.g. a+headerdata@gmail.com). If your header content isn't alphanumeric, I'd recommend caching what you would put in the header locally on your system, and provide a uniqid as the email plus-address. When you receive a reply, you can use that uniqid to look up the data you cached locally.

This is a common technique for uniquely identifying recipients who reply to emails, or who perhaps bounce messages.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜