{
    "mode": "perldoc",
    "parameter": "Encode::MIME::Header",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Encode%3A%3AMIME%3A%3AHeader/json",
    "generated": "2026-06-12T06:21:11Z",
    "synopsis": "use Encode qw(encode decode);\nmy $mimestr = encode(\"MIME-Header\", \"Sample:Text \\N{U+263A}\");\n# $mimestr is \"=?UTF-8?B?U2FtcGxlOlRleHQg4pi6?=\"\nmy $mimeqstr = encode(\"MIME-Q\", \"Sample:Text \\N{U+263A}\");\n# $mimeqstr is \"=?UTF-8?Q?Sample=3AText=E2=98=BA?=\"\nmy $str = decode(\"MIME-Header\",\n\"=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\\r\\n \" .\n\"=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\n);\n# $str is \"If you can read this you understand the example.\"\nuse Encode qw(decode :fallbacks);\nuse Encode::MIME::Header;\nlocal $Encode::MIME::Header::STRICTDECODE = 1;\nmy $strictstring = decode(\"MIME-Header\", $mimestring, FBCROAK);\n# use strict decoding and croak on errors",
    "sections": {
        "NAME": {
            "content": "Encode::MIME::Header -- MIME encoding for an unstructured email header\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Encode qw(encode decode);\n\nmy $mimestr = encode(\"MIME-Header\", \"Sample:Text \\N{U+263A}\");\n# $mimestr is \"=?UTF-8?B?U2FtcGxlOlRleHQg4pi6?=\"\n\nmy $mimeqstr = encode(\"MIME-Q\", \"Sample:Text \\N{U+263A}\");\n# $mimeqstr is \"=?UTF-8?Q?Sample=3AText=E2=98=BA?=\"\n\nmy $str = decode(\"MIME-Header\",\n\"=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\\r\\n \" .\n\"=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\n);\n# $str is \"If you can read this you understand the example.\"\n\nuse Encode qw(decode :fallbacks);\nuse Encode::MIME::Header;\nlocal $Encode::MIME::Header::STRICTDECODE = 1;\nmy $strictstring = decode(\"MIME-Header\", $mimestring, FBCROAK);\n# use strict decoding and croak on errors\n",
            "subsections": []
        },
        "ABSTRACT": {
            "content": "This module implements RFC 2047 <https://tools.ietf.org/html/rfc2047> MIME encoding for an\nunstructured field body of the email header. It can also be used for RFC 822\n<https://tools.ietf.org/html/rfc822> 'text' token. However, it cannot be used directly for the\nwhole header with the field name or for the structured header fields like From, To, Cc,\nMessage-Id, etc... There are 3 encoding names supported by this module: \"MIME-Header\", \"MIME-B\"\nand \"MIME-Q\".\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "Decode method takes an unstructured field body of the email header (or RFC 822\n<https://tools.ietf.org/html/rfc822> 'text' token) as its input and decodes each MIME\nencoded-word from input string to a sequence of bytes according to RFC 2047\n<https://tools.ietf.org/html/rfc2047> and RFC 2231 <https://tools.ietf.org/html/rfc2231>.\nSubsequently, each sequence of bytes with the corresponding MIME charset is decoded with the\nEncode module and finally, one output string is returned. Text parts of the input string which\ndo not contain MIME encoded-word stay unmodified in the output string. Folded newlines between\ntwo consecutive MIME encoded-words are discarded, others are preserved in the output string.\n\"MIME-B\" can decode Base64 variant, \"MIME-Q\" can decode Quoted-Printable variant and\n\"MIME-Header\" can decode both of them. If Encode module does not support particular MIME charset\nor chosen variant then an action based on CHECK flags is performed (by default, the MIME\nencoded-word is not decoded).\n\nEncode method takes a scalar string as its input and uses strict UTF-8 encoder for encoding it\nto UTF-8 bytes. Then a sequence of UTF-8 bytes is encoded into MIME encoded-words (\"MIME-Header\"\nand \"MIME-B\" use a Base64 variant while \"MIME-Q\" uses a Quoted-Printable variant) where each\nMIME encoded-word is limited to 75 characters. MIME encoded-words are separated by \"CRLF SPACE\"\nand joined to one output string. Output string is suitable for unstructured field body of the\nemail header.\n\nBoth encode and decode methods propagate CHECK flags when encoding and decoding the MIME\ncharset.\n",
            "subsections": []
        },
        "BUGS": {
            "content": "Versions prior to 2.22 (part of Encode 2.83) have a malfunctioning decoder and encoder. The MIME\nencoder infamously inserted additional spaces or discarded white spaces between consecutive MIME\nencoded-words, which led to invalid MIME headers produced by this module. The MIME decoder had a\ntendency to discard white spaces, incorrectly interpret data or attempt to decode Base64 MIME\nencoded-words as Quoted-Printable. These problems were fixed in version 2.22. It is highly\nrecommended not to use any version prior 2.22!\n\nVersions prior to 2.24 (part of Encode 2.87) ignored CHECK flags. The MIME encoder used not\nstrict utf8 encoder for input Unicode strings which could lead to invalid UTF-8 sequences. MIME\ndecoder used also not strict utf8 decoder and additionally called the decode method with a\n\"Encode::FBPERLQQ\" flag (thus user-specified CHECK flags were ignored). Moreover, it\nautomatically croaked when a MIME encoded-word contained unknown encoding. Since version 2.24,\nthis module uses strict UTF-8 encoder and decoder. And CHECK flags are correctly propagated.\n\nSince version 2.22 (part of Encode 2.83), the MIME encoder should be fully compliant to RFC 2047\n<https://tools.ietf.org/html/rfc2047> and RFC 2231 <https://tools.ietf.org/html/rfc2231>. Due to\nthe aforementioned bugs in previous versions of the MIME encoder, there is a *less strict*\ncompatible mode for the MIME decoder which is used by default. It should be able to decode MIME\nencoded-words encoded by pre 2.22 versions of this module. However, note that this is not\ncorrect according to RFC 2047 <https://tools.ietf.org/html/rfc2047>.\n\nIn default *not strict* mode the MIME decoder attempts to decode every substring which looks\nlike a MIME encoded-word. Therefore, the MIME encoded-words do not need to be separated by white\nspace. To enforce a correct *strict* mode, set variable $Encode::MIME::Header::STRICTDECODE to\n1 e.g. by localizing:\n\nuse Encode::MIME::Header;\nlocal $Encode::MIME::Header::STRICTDECODE = 1;\n",
            "subsections": []
        },
        "AUTHORS": {
            "content": "Pali <pali@cpan.org>\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "Encode, RFC 822 <https://tools.ietf.org/html/rfc822>, RFC 2047\n<https://tools.ietf.org/html/rfc2047>, RFC 2231 <https://tools.ietf.org/html/rfc2231>\n",
            "subsections": []
        }
    },
    "summary": "Encode::MIME::Header -- MIME encoding for an unstructured email header",
    "flags": [],
    "examples": [],
    "see_also": []
}