{"id":7429,"date":"2022-12-20T19:38:04","date_gmt":"2022-12-20T22:38:04","guid":{"rendered":"http:\/\/lode.uno\/linux-man\/index.php\/2022\/12\/20\/mimewords-man3\/"},"modified":"2022-12-20T19:38:04","modified_gmt":"2022-12-20T22:38:04","slug":"mimewords-man3","status":"publish","type":"post","link":"https:\/\/lode.uno\/linux-man\/2022\/12\/20\/mimewords-man3\/","title":{"rendered":"MIME::Words (man3)"},"content":{"rendered":"<h1 align=\"center\">MIME::Words<\/h1>\n<p> <a href=\"#NAME\">NAME<\/a><br \/> <a href=\"#SYNOPSIS\">SYNOPSIS<\/a><br \/> <a href=\"#DESCRIPTION\">DESCRIPTION<\/a><br \/> <a href=\"#PUBLIC INTERFACE\">PUBLIC INTERFACE<\/a><br \/> <a href=\"#SEE ALSO\">SEE ALSO<\/a><br \/> <a href=\"#NOTES\">NOTES<\/a><br \/> <a href=\"#AUTHOR\">AUTHOR<\/a> <\/p>\n<hr>\n<h2>NAME <a name=\"NAME\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">MIME::Words \u2212 deal with RFC 2047 encoded words<\/p>\n<h2>SYNOPSIS <a name=\"SYNOPSIS\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Before reading further, you should see MIME::Tools to make sure that you understand where this module fits into the grand scheme of things. Go on, do it now. I\u2019ll wait.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Ready? Ok&#8230;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">use MIME::Words qw(:all); <br \/> ### Decode the string into another string, forgetting the charsets: <br \/> $decoded = decode_mimewords( <br \/> &#8216;To: =?ISO\u22128859\u22121?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>&#8216;, <br \/> ); <br \/> ### Split string into array of decoded [DATA,CHARSET] pairs: <br \/> @decoded = decode_mimewords( <br \/> &#8216;To: =?ISO\u22128859\u22121?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>&#8216;, <br \/> ); <br \/> ### Encode a single unsafe word: <br \/> $encoded = encode_mimeword(&#8220;xABFranxE7oisxBB&#8221;); <br \/> ### Encode a string, trying to find the unsafe words inside it: <br \/> $encoded = encode_mimewords(&#8220;Me and xABFranxE7oisxBB in town&#8221;);<\/p>\n<h2>DESCRIPTION <a name=\"DESCRIPTION\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Fellow Americans, you probably won\u2019t know what the hell this module is for. Europeans, Russians, et al, you probably do. &#8220;:\u2212)&#8221;.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For example, here\u2019s a valid <small>MIME<\/small> header you might get:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">From: =?US\u2212ASCII?Q?Keith_Moore?= <moore@cs.utk.edu> <br \/> To: =?ISO\u22128859\u22121?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk> <br \/> CC: =?ISO\u22128859\u22121?Q?Andr=E9_?= Pirard <PIRARD@vm1.ulg.ac.be> <br \/> Subject: =?ISO\u22128859\u22121?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= <br \/> =?ISO\u22128859\u22122?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?= <br \/> =?US\u2212ASCII?Q?.._cool!?=<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">The fields basically decode to (sorry, I can only approximate the Latin characters with 7 bit sequences \/o and \u2019e):<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">From: Keith Moore <moore@cs.utk.edu> <br \/> To: Keld J\/orn Simonsen <keld@dkuug.dk> <br \/> CC: Andr&#8217;e Pirard <PIRARD@vm1.ulg.ac.be> <br \/> Subject: If you can read this you understand the example&#8230; cool!<\/p>\n<h2>PUBLIC INTERFACE <a name=\"PUBLIC INTERFACE\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">decode_mimewords <small>ENCODED<\/small><\/p>\n<p style=\"margin-left:17%;\"><i>Function.<\/i> Go through the string looking for <small>RFC<\/small> 2047\u2212style &#8220;Q&#8221; (quoted-printable, sort of) or &#8220;B&#8221; (base64) encoding, and decode them.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b>In an array context,<\/b> splits the <small>ENCODED<\/small> string into a list of decoded &#8220;[DATA, CHARSET]&#8221; pairs, and returns that list. Unencoded data are returned in a 1\u2212element array &#8220;[DATA]&#8221;, giving an effective <small>CHARSET<\/small> of &#8220;undef&#8221;.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">$enc = &#8216;=?ISO\u22128859\u22121?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>&#8216;; <br \/> foreach (decode_mimewords($enc)) { <br \/> print &#8220;&#8221;, ($_\u2212>[1] || &#8216;US\u2212ASCII&#8217;), &#8220;: &#8220;, $_\u2212>[0], &#8220;n&#8221;; <br \/> }<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b>In a scalar context,<\/b> joins the &#8220;data&#8221; elements of the above list together, and returns that. <i>Warning: this is information-lossy,<\/i> and probably <i>not<\/i> what you want, but if you know that all charsets in the <small>ENCODED<\/small> string are identical, it might be useful to you. (Before you use this, please see &#8220;unmime&#8221; in MIME::WordDecoder, which is probably what you want.)<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">In the event of a syntax error, $@ will be set to a description of the error, but parsing will continue as best as possible (so as to get <i>something<\/i> back when decoding headers). $@ will be false if no error was detected.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">Any arguments past the <small>ENCODED<\/small> string are taken to define a hash of options:<\/p>\n<p style=\"margin-left:11%;\">encode_mimeword <small>RAW,<\/small> [ <small>ENCODING<\/small> ], [ <small>CHARSET<\/small> ]<\/p>\n<p style=\"margin-left:17%;\"><i>Function.<\/i> Encode a single <small>RAW<\/small> &#8220;word&#8221; that has unsafe characters. The &#8220;word&#8221; will be encoded in its entirety.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">### Encode &#8220;<<Franc,ois>>&#8221;: <br \/> $encoded = encode_mimeword(&#8220;xABFranxE7oisxBB&#8221;);<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">You may specify the <small>ENCODING<\/small> (&#8220;Q&#8221; or &#8220;B&#8221;), which defaults to &#8220;Q&#8221;. You may specify the <small>CHARSET,<\/small> which defaults to &#8220;iso\u22128859\u22121&#8221;.<\/p>\n<p style=\"margin-left:11%;\">encode_mimewords <small>RAW,<\/small> [ <small>OPTS<\/small> ]<\/p>\n<p style=\"margin-left:17%;\"><i>Function.<\/i> Given a <small>RAW<\/small> string, try to find and encode all &#8220;unsafe&#8221; sequences of characters:<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">### Encode a string with some unsafe &#8220;words&#8221;: <br \/> $encoded = encode_mimewords(&#8220;Me and xABFranxE7oisxBB&#8221;);<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\">Returns the encoded string. Any arguments past the <small>RAW<\/small> string are taken to define a hash of options: <br \/> Charset<\/p>\n<p style=\"margin-left:23%;\">Encode all unsafe stuff with this charset. Default is \u2019 <small>ISO\u22128859\u22121<\/small> \u2019, a.k.a. &#8220;Latin\u22121&#8221;.<\/p>\n<p style=\"margin-left:17%;\">Encoding<\/p>\n<p style=\"margin-left:23%;\">The encoding to use, &#8220;q&#8221; or &#8220;b&#8221;. The default is &#8220;q&#8221;.<\/p>\n<p style=\"margin-left:17%; margin-top: 1em\"><b>Warning:<\/b> this is a quick-and-dirty solution, intended for character sets which overlap <small>ASCII.<\/small> <b>It does not comply with the <small>RFC 2047<\/small> rules regarding the use of encoded words in message headers<\/b>. You may want to roll your own variant, using &#8220;encode_mimeword()&#8221;, for your application. <i>Thanks to Jan Kasprzak for reminding me about this problem.<\/i><\/p>\n<h2>SEE ALSO <a name=\"SEE ALSO\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">MIME::Base64, MIME::QuotedPrint, MIME::Tools<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">For other implementations of this or similar functionality (particularly, ones with proper <small>UTF8<\/small> support), see:<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Encode::MIME::Header, MIME::EncWords, MIME::AltWords<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">At some future point, one of these implementations will likely replace MIME::Words and MIME::Words will become deprecated.<\/p>\n<h2>NOTES <a name=\"NOTES\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Exports its principle functions by default, in keeping with MIME::Base64 and MIME::QuotedPrint.<\/p>\n<h2>AUTHOR <a name=\"AUTHOR\"><\/a> <\/h2>\n<p style=\"margin-left:11%; margin-top: 1em\">Eryq (<i>eryq@zeegee.com<\/i>), ZeeGee Software Inc (<i>http:\/\/www.zeegee.com<\/i>). Dianne Skoll (dfs@roaringpenguin.com) http:\/\/www.roaringpenguin.com<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">All rights reserved. This program is free software; you can redistribute it and\/or modify it under the same terms as Perl itself.<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Thanks also to&#8230;<\/p>\n<p style=\"margin-left:11%; margin-top: 1em\">Kent Boortz For providing the idea, and the baseline <br \/> RFC\u22121522\u2212decoding code! <br \/> KJJ at PrimeNet For requesting that this be split into <br \/> its own module. <br \/> Stephane Barizien For reporting a nasty bug.<\/p>\n<hr>\n","protected":false},"excerpt":{"rendered":"<p>  MIME::Words \u2212 deal with RFC 2047 encoded words <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3007,3741],"class_list":["post-7429","post","type-post","status-publish","format-standard","hentry","category-sin-categoria","tag-man3","tag-mimewords"],"gutentor_comment":0,"_links":{"self":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/comments?post=7429"}],"version-history":[{"count":0,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/posts\/7429\/revisions"}],"wp:attachment":[{"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/media?parent=7429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/categories?post=7429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lode.uno\/linux-man\/wp-json\/wp\/v2\/tags?post=7429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}