.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "MIME::Charset 3" .TH MIME::Charset 3 2023-07-25 "perl v5.38.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME MIME::Charset \- Charset Information for MIME .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 1 \& use MIME::Charset: \& \& $charset = MIME::Charset\->new("euc\-jp"); .Ve .PP Getting charset information: .PP .Vb 4 \& $benc = $charset\->body_encoding; # e.g. "Q" \& $cset = $charset\->as_string; # e.g. "US\-ASCII" \& $henc = $charset\->header_encoding; # e.g. "S" \& $cset = $charset\->output_charset; # e.g. "ISO\-2022\-JP" .Ve .PP Translating text data: .PP .Vb 6 \& ($text, $charset, $encoding) = \& $charset\->header_encode( \& "\exc9\exc2\exc5\exaa\exc0\exde\exc3\exef\exc5\exaa". \& "\exc7\exd1\exca\exaa\exbd\exd0\exce\excf\exb4\exef", \& Charset => \*(Aqeuc\-jp\*(Aq); \& # ...returns e.g. (, "ISO\-2022\-JP", "B"). \& \& ($text, $charset, $encoding) = \& $charset\->body_encode( \& "Collectioneur path\exe9tiquement ". \& "\exe9clectique de d\exe9chets", \& Charset => \*(Aqlatin1\*(Aq); \& # ...returns e.g. (, "ISO\-8859\-1", "QUOTED\-PRINTABLE"). \& \& $len = $charset\->encoded_header_len( \& "Perl\exe8\exa8\ex80\exe8\exaa\ex9e", \& Charset => \*(Aqutf\-8\*(Aq, \& Encoding => "b"); \& # ...returns e.g. 28. .Ve .PP Manipulating module defaults: .PP .Vb 3 \& MIME::Charset::alias("csEUCKR", "euc\-kr"); \& MIME::Charset::default("iso\-8859\-1"); \& MIME::Charset::fallback("us\-ascii"); .Ve .PP Non-OO functions (may be deprecated in near future): .PP .Vb 1 \& use MIME::Charset qw(:info); \& \& $benc = body_encoding("iso\-8859\-2"); # "Q" \& $cset = canonical_charset("ANSI X3.4\-1968"); # "US\-ASCII" \& $henc = header_encoding("utf\-8"); # "S" \& $cset = output_charset("shift_jis"); # "ISO\-2022\-JP" \& \& use MIME::Charset qw(:trans); \& \& ($text, $charset, $encoding) = \& header_encode( \& "\exc9\exc2\exc5\exaa\exc0\exde\exc3\exef\exc5\exaa". \& "\exc7\exd1\exca\exaa\exbd\exd0\exce\excf\exb4\exef", \& "euc\-jp"); \& # ...returns (, "ISO\-2022\-JP", "B"); \& \& ($text, $charset, $encoding) = \& body_encode( \& "Collectioneur path\exe9tiquement ". \& "\exe9clectique de d\exe9chets", \& "latin1"); \& # ...returns (, "ISO\-8859\-1", "QUOTED\-PRINTABLE"); \& \& $len = encoded_header_len( \& "Perl\exe8\exa8\ex80\exe8\exaa\ex9e", "b", "utf\-8"); # 28 .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" MIME::Charset provides information about character sets used for MIME messages on Internet. .SS Definitions .IX Subsection "Definitions" The \fBcharset\fR is ``character set'' used in MIME to refer to a method of converting a sequence of octets into a sequence of characters. It includes both concepts of ``coded character set'' (CCS) and ``character encoding scheme'' (CES) of ISO/IEC. .PP The \fBencoding\fR is that used in MIME to refer to a method of representing a body part or a header body as sequence(s) of printable US-ASCII characters. .SS Constructor .IX Subsection "Constructor" .ie n .IP "$charset = MIME::Charset\->new([CHARSET [, OPTS]])" 4 .el .IP "\f(CW$charset\fR = MIME::Charset\->new([CHARSET [, OPTS]])" 4 .IX Item "$charset = MIME::Charset->new([CHARSET [, OPTS]])" Create charset object. .Sp OPTS may accept following key-value pair. \&\fBNOTE\fR: When Unicode/multibyte support is disabled (see "USE_ENCODE"), conversion will not be performed. So this option do not have any effects. .RS 4 .IP "Mapping => MAPTYPE" 4 .IX Item "Mapping => MAPTYPE" Whether to extend mappings actually used for charset names or not. \&\f(CW"EXTENDED"\fR uses extended mappings. \&\f(CW"STANDARD"\fR uses standardized strict mappings. Default is \f(CW"EXTENDED"\fR. .RE .RS 4 .RE .SS "Getting Information of Charsets" .IX Subsection "Getting Information of Charsets" .ie n .IP $charset\->body_encoding 4 .el .IP \f(CW$charset\fR\->body_encoding 4 .IX Item "$charset->body_encoding" .PD 0 .IP "body_encoding CHARSET" 4 .IX Item "body_encoding CHARSET" .PD Get recommended transfer-encoding of CHARSET for message body. .Sp Returned value will be one of \f(CW"B"\fR (BASE64), \f(CW"Q"\fR (QUOTED-PRINTABLE), \&\f(CW"S"\fR (shorter one of either) or \&\f(CW\*(C`undef\*(C'\fR (might not be transfer-encoded; either 7BIT or 8BIT). This may not be same as encoding for message header. .ie n .IP $charset\->as_string 4 .el .IP \f(CW$charset\fR\->as_string 4 .IX Item "$charset->as_string" .PD 0 .IP "canonical_charset CHARSET" 4 .IX Item "canonical_charset CHARSET" .PD Get canonical name for charset. .ie n .IP $charset\->decoder 4 .el .IP \f(CW$charset\fR\->decoder 4 .IX Item "$charset->decoder" Get "Encode::Encoding" object to decode strings to Unicode by charset. If charset is not specified or not known by this module, undef will be returned. .ie n .IP $charset\->dup 4 .el .IP \f(CW$charset\fR\->dup 4 .IX Item "$charset->dup" Get a copy of charset object. .ie n .IP $charset\->encoder([CHARSET]) 4 .el .IP \f(CW$charset\fR\->encoder([CHARSET]) 4 .IX Item "$charset->encoder([CHARSET])" Get "Encode::Encoding" object to encode Unicode string using compatible charset recommended to be used for messages on Internet. .Sp If optional CHARSET is specified, replace encoder (and output charset name) of \f(CW$charset\fR object with those of CHARSET, therefore, \&\f(CW$charset\fR object will be a converter between original charset and new CHARSET. .ie n .IP $charset\->header_encoding 4 .el .IP \f(CW$charset\fR\->header_encoding 4 .IX Item "$charset->header_encoding" .PD 0 .IP "header_encoding CHARSET" 4 .IX Item "header_encoding CHARSET" .PD Get recommended encoding scheme of CHARSET for message header. .Sp Returned value will be one of \f(CW"B"\fR, \f(CW"Q"\fR, \f(CW"S"\fR (shorter one of either) or \f(CW\*(C`undef\*(C'\fR (might not be encoded). This may not be same as encoding for message body. .ie n .IP $charset\->output_charset 4 .el .IP \f(CW$charset\fR\->output_charset 4 .IX Item "$charset->output_charset" .PD 0 .IP "output_charset CHARSET" 4 .IX Item "output_charset CHARSET" .PD Get a charset which is compatible with given CHARSET and is recommended to be used for MIME messages on Internet (if it is known by this module). .Sp When Unicode/multibyte support is disabled (see "USE_ENCODE"), this function will simply return the result of "canonical_charset". .SS "Translating Text Data" .IX Subsection "Translating Text Data" .ie n .IP "$charset\->body_encode(STRING [, OPTS])" 4 .el .IP "\f(CW$charset\fR\->body_encode(STRING [, OPTS])" 4 .IX Item "$charset->body_encode(STRING [, OPTS])" .PD 0 .IP "body_encode STRING, CHARSET [, OPTS]" 4 .IX Item "body_encode STRING, CHARSET [, OPTS]" .PD Get converted (if needed) data of STRING and recommended transfer-encoding of that data for message body. CHARSET is the charset by which STRING is encoded. .Sp OPTS may accept following key-value pairs. \&\fBNOTE\fR: When Unicode/multibyte support is disabled (see "USE_ENCODE"), conversion will not be performed. So these options do not have any effects. .RS 4 .IP "Detect7bit => YESNO" 4 .IX Item "Detect7bit => YESNO" Try auto-detecting 7\-bit charset when CHARSET is not given. Default is \f(CW"YES"\fR. .IP "Replacement => REPLACEMENT" 4 .IX Item "Replacement => REPLACEMENT" Specifies error handling scheme. See "Error Handling". .RE .RS 4 .Sp 3\-item list of (\fIconverted string\fR, \fIcharset for output\fR, \&\fItransfer-encoding\fR) will be returned. \&\fITransfer-encoding\fR will be either \f(CW"BASE64"\fR, \f(CW"QUOTED\-PRINTABLE"\fR, \&\f(CW"7BIT"\fR or \f(CW"8BIT"\fR. If \fIcharset for output\fR could not be determined and \fIconverted string\fR contains non-ASCII byte(s), \fIcharset for output\fR will be \f(CW\*(C`undef\*(C'\fR and \fItransfer-encoding\fR will be \f(CW"BASE64"\fR. \&\fICharset for output\fR will be \f(CW"US\-ASCII"\fR if and only if string does not contain any non-ASCII bytes. .RE .ie n .IP "$charset\->decode(STRING [,CHECK])" 4 .el .IP "\f(CW$charset\fR\->decode(STRING [,CHECK])" 4 .IX Item "$charset->decode(STRING [,CHECK])" Decode STRING to Unicode. .Sp \&\fBNote\fR: When Unicode/multibyte support is disabled (see "USE_ENCODE"), this function will die. .IP "detect_7bit_charset STRING" 4 .IX Item "detect_7bit_charset STRING" Guess 7\-bit charset that may encode a string STRING. If STRING contains any 8\-bit bytes, \f(CW\*(C`undef\*(C'\fR will be returned. Otherwise, Default Charset will be returned for unknown charset. .ie n .IP "$charset\->encode(STRING [, CHECK])" 4 .el .IP "\f(CW$charset\fR\->encode(STRING [, CHECK])" 4 .IX Item "$charset->encode(STRING [, CHECK])" Encode STRING (Unicode or non-Unicode) using compatible charset recommended to be used for messages on Internet (if this module knows it). Note that string will be decoded to Unicode then encoded even if compatible charset was equal to original charset. .Sp \&\fBNote\fR: When Unicode/multibyte support is disabled (see "USE_ENCODE"), this function will die. .ie n .IP "$charset\->encoded_header_len(STRING [, ENCODING])" 4 .el .IP "\f(CW$charset\fR\->encoded_header_len(STRING [, ENCODING])" 4 .IX Item "$charset->encoded_header_len(STRING [, ENCODING])" .PD 0 .IP "encoded_header_len STRING, ENCODING, CHARSET" 4 .IX Item "encoded_header_len STRING, ENCODING, CHARSET" .PD Get length of encoded STRING for message header (without folding). .Sp ENCODING may be one of \f(CW"B"\fR, \f(CW"Q"\fR or \f(CW"S"\fR (shorter one of either \f(CW"B"\fR or \f(CW"Q"\fR). .ie n .IP "$charset\->header_encode(STRING [, OPTS])" 4 .el .IP "\f(CW$charset\fR\->header_encode(STRING [, OPTS])" 4 .IX Item "$charset->header_encode(STRING [, OPTS])" .PD 0 .IP "header_encode STRING, CHARSET [, OPTS]" 4 .IX Item "header_encode STRING, CHARSET [, OPTS]" .PD Get converted (if needed) data of STRING and recommended encoding scheme of that data for message headers. CHARSET is the charset by which STRING is encoded. .Sp OPTS may accept following key-value pairs. \&\fBNOTE\fR: When Unicode/multibyte support is disabled (see "USE_ENCODE"), conversion will not be performed. So these options do not have any effects. .RS 4 .IP "Detect7bit => YESNO" 4 .IX Item "Detect7bit => YESNO" Try auto-detecting 7\-bit charset when CHARSET is not given. Default is \f(CW"YES"\fR. .IP "Replacement => REPLACEMENT" 4 .IX Item "Replacement => REPLACEMENT" Specifies error handling scheme. See "Error Handling". .RE .RS 4 .Sp 3\-item list of (\fIconverted string\fR, \fIcharset for output\fR, \&\fIencoding scheme\fR) will be returned. \fIEncoding scheme\fR will be either \f(CW"B"\fR, \f(CW"Q"\fR or \f(CW\*(C`undef\*(C'\fR (might not be encoded). If \fIcharset for output\fR could not be determined and \fIconverted string\fR contains non-ASCII byte(s), \fIcharset for output\fR will be \f(CW"8BIT"\fR (this is \fInot\fR charset name but a special value to represent unencodable data) and \fIencoding scheme\fR will be \f(CW\*(C`undef\*(C'\fR (should not be encoded). \&\fICharset for output\fR will be \f(CW"US\-ASCII"\fR if and only if string does not contain any non-ASCII bytes. .RE .ie n .IP "$charset\->undecode(STRING [,CHECK])" 4 .el .IP "\f(CW$charset\fR\->undecode(STRING [,CHECK])" 4 .IX Item "$charset->undecode(STRING [,CHECK])" Encode Unicode string STRING to byte string by input charset of \f(CW$charset\fR. This is equivalent to \f(CW\*(C`$charset\->decoder\->encode()\*(C'\fR. .Sp \&\fBNote\fR: When Unicode/multibyte support is disabled (see "USE_ENCODE"), this function will die. .SS "Manipulating Module Defaults" .IX Subsection "Manipulating Module Defaults" .IP "alias ALIAS [, CHARSET]" 4 .IX Item "alias ALIAS [, CHARSET]" Get/set charset alias for canonical names determined by "canonical_charset". .Sp If CHARSET is given and isn't false, ALIAS will be assigned as an alias of CHARSET. Otherwise, alias won't be changed. In both cases, current charset name that ALIAS is assigned will be returned. .IP "default [CHARSET]" 4 .IX Item "default [CHARSET]" Get/set default charset. .Sp \&\fBDefault charset\fR is used by this module when charset context is unknown. Modules using this module are recommended to use this charset when charset context is unknown or implicit default is expected. By default, it is \f(CW"US\-ASCII"\fR. .Sp If CHARSET is given and isn't false, it will be set to default charset. Otherwise, default charset won't be changed. In both cases, current default charset will be returned. .Sp \&\fBNOTE\fR: Default charset \fIshould not\fR be changed. .IP "fallback [CHARSET]" 4 .IX Item "fallback [CHARSET]" Get/set fallback charset. .Sp \&\fBFallback charset\fR is used by this module when conversion by given charset is failed and \f(CW"FALLBACK"\fR error handling scheme is specified. Modules using this module may use this charset as last resort of charset for conversion. By default, it is \f(CW"UTF\-8"\fR. .Sp If CHARSET is given and isn't false, it will be set to fallback charset. If CHARSET is \f(CW"NONE"\fR, fallback charset will be undefined. Otherwise, fallback charset won't be changed. In any cases, current fallback charset will be returned. .Sp \&\fBNOTE\fR: It \fIis\fR useful that \f(CW"US\-ASCII"\fR is specified as fallback charset, since result of conversion will be readable without charset information. .IP "recommended CHARSET [, HEADERENC, BODYENC [, ENCCHARSET]]" 4 .IX Item "recommended CHARSET [, HEADERENC, BODYENC [, ENCCHARSET]]" Get/set charset profiles. .Sp If optional arguments are given and any of them are not false, profiles for CHARSET will be set by those arguments. Otherwise, profiles won't be changed. In both cases, current profiles for CHARSET will be returned as 3\-item list of (HEADERENC, BODYENC, ENCCHARSET). .Sp HEADERENC is recommended encoding scheme for message header. It may be one of \f(CW"B"\fR, \f(CW"Q"\fR, \f(CW"S"\fR (shorter one of either) or \&\f(CW\*(C`undef\*(C'\fR (might not be encoded). .Sp BODYENC is recommended transfer-encoding for message body. It may be one of \f(CW"B"\fR, \f(CW"Q"\fR, \f(CW"S"\fR (shorter one of either) or \&\f(CW\*(C`undef\*(C'\fR (might not be transfer-encoded). .Sp ENCCHARSET is a charset which is compatible with given CHARSET and is recommended to be used for MIME messages on Internet. If conversion is not needed (or this module doesn't know appropriate charset), ENCCHARSET is \f(CW\*(C`undef\*(C'\fR. .Sp \&\fBNOTE\fR: This function in the future releases can accept more optional arguments (for example, properties to handle character widths, line folding behavior, ...). So format of returned value may probably be changed. Use "header_encoding", "body_encoding" or "output_charset" to get particular profile. .SS Constants .IX Subsection "Constants" .IP USE_ENCODE 4 .IX Item "USE_ENCODE" Unicode/multibyte support flag. Non-empty string will be set when Unicode and multibyte support is enabled. Currently, this flag will be non-empty on Perl 5.7.3 or later and empty string on earlier versions of Perl. .SS "Error Handling" .IX Subsection "Error Handling" "body_encode" and "header_encode" accept following \f(CW\*(C`Replacement\*(C'\fR options: .ie n .IP """DEFAULT""" 4 .el .IP "\f(CW""DEFAULT""\fR" 4 .IX Item """DEFAULT""" Put a substitution character in place of a malformed character. For UCM-based encodings, will be used. .ie n .IP """FALLBACK""" 4 .el .IP "\f(CW""FALLBACK""\fR" 4 .IX Item """FALLBACK""" Try \f(CW"DEFAULT"\fR scheme using \fIfallback charset\fR (see "fallback"). When fallback charset is undefined and conversion causes error, code will die on error with an error message. .ie n .IP """CROAK""" 4 .el .IP "\f(CW""CROAK""\fR" 4 .IX Item """CROAK""" Code will die on error immediately with an error message. Therefore, you should trap the fatal error with eval{} unless you really want to let it die on error. Synonym is \f(CW"STRICT"\fR. .ie n .IP """PERLQQ""" 4 .el .IP "\f(CW""PERLQQ""\fR" 4 .IX Item """PERLQQ""" .PD 0 .ie n .IP """HTMLCREF""" 4 .el .IP "\f(CW""HTMLCREF""\fR" 4 .IX Item """HTMLCREF""" .ie n .IP """XMLCREF""" 4 .el .IP "\f(CW""XMLCREF""\fR" 4 .IX Item """XMLCREF""" .PD Use \f(CW\*(C`FB_PERLQQ\*(C'\fR, \f(CW\*(C`FB_HTMLCREF\*(C'\fR or \f(CW\*(C`FB_XMLCREF\*(C'\fR scheme defined by Encode module. .IP "numeric values" 4 .IX Item "numeric values" Numeric values are also allowed. For more details see "Handling Malformed Data" in Encode. .PP If error handling scheme is not specified or unknown scheme is specified, \&\f(CW"DEFAULT"\fR will be assumed. .SS "Configuration File" .IX Subsection "Configuration File" Built-in defaults for option parameters can be overridden by configuration file: \fIMIME/Charset/Defaults.pm\fR. For more details read \fIMIME/Charset/Defaults.pm.sample\fR. .SH VERSION .IX Header "VERSION" Consult \f(CW$VERSION\fR variable. .PP Development versions of this module may be found at . .SS "Incompatible Changes" .IX Subsection "Incompatible Changes" .IP "Release 1.001" 4 .IX Item "Release 1.001" .RS 4 .PD 0 .IP \(bu 4 .PD \&\fBnew()\fR method returns an object when CHARSET argument is not specified. .RE .RS 4 .RE .IP "Release 1.005" 4 .IX Item "Release 1.005" .RS 4 .PD 0 .IP \(bu 4 .PD Restrict characters in encoded-word according to RFC 2047 section 5 (3). This also affects return value of \fBencoded_header_len()\fR method. .RE .RS 4 .RE .IP "Release 1.008.2" 4 .IX Item "Release 1.008.2" .RS 4 .PD 0 .IP \(bu 4 .PD \&\fBbody_encoding()\fR method may also returns \f(CW"S"\fR. .IP \(bu 4 Return value of \fBbody_encode()\fR method for UTF\-8 may include \&\f(CW"QUOTED\-PRINTABLE"\fR encoding item that in earlier versions was fixed to \&\f(CW"BASE64"\fR. .RE .RS 4 .RE .SH "SEE ALSO" .IX Header "SEE ALSO" Multipurpose Internet Mail Extensions (MIME). .SH AUTHOR .IX Header "AUTHOR" Hatuka*nezumi \- IKEDA Soji .SH COPYRIGHT .IX Header "COPYRIGHT" Copyright (C) 2006\-2017 Hatuka*nezumi \- IKEDA Soji. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.