How to understand the BODYSTRUCTURE information returned by IMAP servers?

Posted by Tony on Stack Overflow See other posts from Stack Overflow or by Tony
Published on 2012-10-05T00:49:52Z Indexed on 2012/10/05 3:37 UTC
Read the original article Hit count: 173

Filed under:
|
|

I'm using python's IMAPClient to retrieve email messages from IMAP server. One of the attributes I retrieve is BODYSTRUCTURE. However, I can't find any documentation on how to interpret the return values. Here's the body structure that IMAP server returns

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))

Here's the same body structure parsed to python type.

"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
],

The arrays don't seems to be constant length. What each element of the array stand for?

© Stack Overflow or respective owner

Related posts about python

Related posts about email