2012-10-05 72 views
3

我正在使用python的IMAPClient從IMAP服務器中檢索電子郵件。我檢索的屬性之一是BODYSTRUCTURE。但是,我找不到有關如何解釋返回值的任何文檔。以下是IMAP服務器返回的身體結構如何理解IMAP服務器返回的BODYSTRUCTURE信息?

16:12.679978 < FLAGS (NotJunk $NotJunk \Seen) BODYSTRUCTURE ((("TEXT" "PLAIN" ("CHARSET" "us-ascii") NIL NIL "QUOTED-PRINTABLE" 4888 170 NIL NIL NIL)("TEXT" "HTML" ("CHARSET" "us-ascii") NIL NIL "QUOTED-PRINTABLE" 32407 479 NIL NIL NIL) "ALTERNATIVE" ("BOUNDARY" "Apple-Mail=_3AAA7CD7-3B07-406A-83CB-2C7762C3306E") NIL NIL)("APPLICATION" "PKCS7-SIGNATURE" ("NAME" "smime.p7s") NIL NIL "BASE64" 2414 NIL ("ATTACHMENT" ("FILENAME" "smime.p7s")) NIL) "SIGNED" ("BOUNDARY" "Apple-Mail=_DF4FE6BB-F796-46D7-A593-9723F4315DD2" "MICALG" "sha1" "PROTOCOL" "application/pkcs7-signature") NIL NIL)) 

下面是與python類型解析相同的身體結構。

"BODYSTRUCTURE": [ 
    [ 
     [ 
      [ 
       "TEXT", 
       "PLAIN", 
       [ 
        "CHARSET", 
        "us-ascii" 
       ], 
       null, 
       null, 
       "QUOTED-PRINTABLE", 
       4888, 
       170, 
       null, 
       null, 
       null 
      ], 
      [ 
       "TEXT", 
       "HTML", 
       [ 
        "CHARSET", 
        "us-ascii" 
       ], 
       null, 
       null, 
       "QUOTED-PRINTABLE", 
       32407, 
       479, 
       null, 
       null, 
       null 
      ], 
      "ALTERNATIVE", 
      [ 
       "BOUNDARY", 
       "Apple-Mail=_3AAA7CD7-3B07-406A-83CB-2C7762C3306E" 
      ], 
      null, 
      null 
     ], 
     [ 
      "APPLICATION", 
      "PKCS7-SIGNATURE", 
      [ 
       "NAME", 
       "smime.p7s" 
      ], 
      null, 
      null, 
      "BASE64", 
      2414, 
      null, 
      [ 
       "ATTACHMENT", 
       [ 
        "FILENAME", 
        "smime.p7s" 
       ] 
      ], 
      null 
     ] 
    ], 
    "SIGNED", 
    [ 
     "BOUNDARY", 
     "Apple-Mail=_DF4FE6BB-F796-46D7-A593-9723F4315DD2", 
     "MICALG", 
     "sha1", 
     "PROTOCOL", 
     "application/pkcs7-signature" 
    ], 
    null, 
    null 
], 

該陣列似乎不是恆定的長度。陣列的每個元素代表什麼?

回答

5

您應該閱讀RFC 3501。取決於身體段的類型(文本vs其他),字段的長度可以改變。

詳細閱讀第73頁和第74頁。

相關問題