2011-12-14 23:23
浏览 466

PHP IMAP - 电子邮件必须有messageid吗?

I'm retrieving emails from Gmail using PHP and IMAP; however, some emails don't have a messageid. Aren't all messages supposed to have a messageid?

I need a unique id for reference so i'm not sure how else to keep track of emails without it.

Am i doing something wrong?

For example here is an email header i get

 [date] => Sun, 06 Nov 2011 21:21:56 -0500
    [subject] => Daylight Saving Time?  Chili's Saving Time!
    [to] =>
    [message_id] => 
    [from] =>
    [sender] =>
    [reply_toaddress] =>
    [size] => 14385
    [msgno] =>  156
    [status] => Unread


  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duangan7834
    duangan7834 2011-12-15 00:36

    Any MTA I have ever encountered will add a Message-ID if one is not already present. However, if you need to keep track of messages or thread them, you will need to set a the Message-ID. The References header and the In-Reply-To header use the value of a previous Message-ID to relate messages together.

    References contains a list of previous Message-ID values in the reply chain, and In-Reply-To contains the Message-ID to which the current message is a direct reply.

    Note that according to the RFC-2822 specification, a Message-ID is technically not required. Well-behaved MTAs generally include one, but some commenters below describe instances where a Message ID was not present, causing failures in messaging clients.

    点赞 评论
  • donglu5728
    donglu5728 2011-12-15 00:25

    The message ID has nothing to do with IMAP but is part of the mail itself and specified in RFC 2822 as "optional" (although it says that it should be present):

    Though optional, every message SHOULD have a "Message-ID:" field.

    So you are not doing anything wrong if some mails lack a Message-ID. It happens for all the mails that the MUA that originally sent the mail did not generate one for (which however every commonly used MUA should do).

    Concerning a unique ID for identifying mails via IMAP, you may want to have a look at the UID field described in the standard.

    点赞 评论