简体   繁体   English

带引号的邮件的imap标头

[英]imap headers of a quoted mail

I'm sending an email with some xheader. 我正在发送带有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. 当电子邮件的收件人重播到该电子邮件时,我想解析它,并从我通过重播获得的邮件中获取该xheader的内容。

unfortunately, when i'm parsing the email i get back, i don't see my xheader. 不幸的是,当我解析电子邮件时,我回来了,我看不到我的xheader。 (I printed the whole email, and the xheader is not there) (我打印了整个电子邮件,但xheader不存在)

How can i do that in PHP with Zend Framework (i'm using Zend_Mail_Storage_Imap)? 我如何在使用Zend Framework的PHP中做到这一点(我正在使用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. Pekka在此处获得正确响应的分数-原始邮件中的X-header对于该邮件的任何回复都不一定会保留。 But, you're using Gmail, so you have another potential option. 但是,您使用的是Gmail,因此还有另一种可能的选择。

Gmail allows plus addressing, so username@gmail.com will also receive mail for username+extra@gmail.com. Gmail允许加上地址,因此username@gmail.com也将收到用户名+extra@gmail.com的邮件。 If your X-aHeader content is alphanumeric, you can append it to your email address (eg a+headerdata@gmail.com). 如果您的X-aHeader内容是字母数字,则可以将其附加到您的电子邮件地址(例如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. 如果你的头内容是不是字母数字,我建议你缓存放什么在头在您的系统,并提供uniqid作为邮件加地址。 When you receive a reply, you can use that uniqid to look up the data you cached locally. 收到答复后,您可以使用该uniqid查找本地缓存的数据。

This is a common technique for uniquely identifying recipients who reply to emails, or who perhaps bounce messages. 这是一种用于唯一标识回复电子邮件或退回邮件的收件人的常用技术。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM