MIME::...:Param(3pm)
π MIME::EcoEncode::Param β RFC 2231 Encode/Decode π
okay bestie, sit down, hydrate, because we're talking about MIME::EcoEncode::Param (that's the (3pm) one, you found it in the right place π
). This little icon implements RFC 2231 Mime Parameter Value Encoding. MIME parameters but make them international. no cap.
β¨ SYNOPSIS β¨
like, here's the whole vibe in one block:
use MIME::EcoEncode::Param;
$encoded = mime_eco_param($str, 'UTF-8'); # encode utf8 string
$encoded = mime_eco_param($str, "UTF-8'XX'"); # XX is language
$encoded = mime_eco_param($str, 'UTF-8*XX?B'); # "B" encoding
$encoded = mime_eco_param($str, 'UTF-8*XX?Q'); # "Q" encoding
$encoded = mime_eco_param($str, 'GB2312'); # euc-cn string
$encoded = mime_eco_param($str, 'EUC-KR'); # euc-kr string
$encoded = mime_eco_param($str, 'Big5'); # big5 string
$encoded = mime_eco_param($str, 'Shift_JIS'); # cp932 string
$encoded = mime_eco_param($str, 'ISO-2022-JP'); # 7bit-jis string
$encoded = mime_eco_param($str, $sbcs); # $sbcs :
# single-byte charset
# (e.g. 'ISO-8859-1')
$decoded = mime_deco_param($encoded); # decode encoded string
($decoded, $param, $charset, $lang, $value) # return array
= mime_deco_param($encoded);
so mime_eco_param is your encode girlie and mime_deco_param is your decode girlie, and they're both serving. π«Ά
πΈ DESCRIPTION πΈ
This module implements RFC 2231 Mime Parameter Value Encoding. that's it, that's the whole personality. it takes parameter values and makes them safe + portable + international. we love a standards-compliant queen. π
π Options π
encoding side, the mime_eco_param situation
$encoded = mime_eco_param($str, $charset, $lf, $bpl);
# $charset : 'UTF-8' / "UTF-8'XX'" /
# 'UTF-8*XX?B' / 'UTF-8*XX?Q' /
# 'GB2312' / 'EUC-KR' / 'Big5' /
# 'Shift_JIS' / 'ISO-2022-JP' / ...
# (default: 'UTF-8')
# Note: The others are all encoded as
# single-byte string.
# $lf : line feed (default: "\n")
# $bpl : bytes per line (default: 76)
breaking it down so you're never confused fr fr:
$strβ your string, the main character. π«Ά$charsetβ literally so many options it's giving buffet. it can be'UTF-8',"UTF-8'XX'",'UTF-8*XX?B','UTF-8*XX?Q','GB2312','EUC-KR','Big5','Shift_JIS','ISO-2022-JP', or...(there's more, iykyk). the default is'UTF-8'.
heads up bestie: the note says The others are all encoded as single-byte string. so like, all those non-UTF-8 ones are single-byte, okay? don't come for me.
$lfβ the line feed. default is"\n".$bplβ bytes per line. default is76.
decoding side, the mime_deco_param situation
$decoded = mime_deco_param($encoded, $bq_on);
# $bq_on : 1 : ON decode "B/Q" encoding
# 0 : OFF
# (default: 1)
$encodedβ the encoded string you're un-encoding. slay.$bq_onβ controls whether"B/Q"encoding gets decoded.1means ON,0means OFF. default is1β¨
π Examples π
Ex1 β RFC 2231 encoding π
use MIME::EcoEncode::Param;
my $str = " filename=\xe5\xaf\x8c\xe5\xa3\xab\xe5\xb1\xb1_2013.jpeg";
print mime_eco_param($str, "UTF-8'ja'", "\n", 33), "\n";
Ex1's output:
filename*0*=UTF-8'ja'%E5%AF%8C;
filename*1*=%E5%A3%AB%E5%B1%B1_;
filename*2=2013.jpeg
look at those *0*, *1*, *2 continuations. splitting it up so it fits. organized. β¨
Ex2 β "Q" encoding (for Windows) πͺ
use MIME::EcoEncode::Param;
my $str = " name=\xe5\xaf\x8c\xe5\xa3\xab\xe5\xb1\xb1_2013.jpeg";
print mime_eco_param($str, 'UTF-8?Q', "\n", 33), "\n";
Ex2's output:
name="=?UTF-8?Q?=E5=AF=8C=E5?=
=?UTF-8?Q?=A3=AB=E5=B1=B1=5F20?=
=?UTF-8?Q?13.jpeg?="
Ex3 β "B" encoding (for Windows) πͺ
use MIME::EcoEncode::Param;
my $str = " name=\xe5\xaf\x8c\xe5\xa3\xab\xe5\xb1\xb1_2013.jpeg";
print mime_eco_param($str, 'UTF-8?B', "\n", 33), "\n";
Ex3's output:
name="=?UTF-8?B?5a+M5aOr5bGx?=
=?UTF-8?B?XzIwMTMuanBlZw==?="
both Windows-approved. iconic behaviour honestly. π
π¦ SEE ALSO π¦
MIME::EcoEncodeβ the sister module, go say hi π«Ά
π AUTHOR π
MURATA Yasuhisa <murata@nips.ac.jp> β thank you for your service, legend π
π COPYRIGHT π
Copyright (C) 2013 MURATA Yasuhisa
β LICENSE β
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
bestie that's the free-software promise, go forth and redistribute, no gatekeeping π«
okay so that's the whole page, and this was documented with perl v5.36.0 on 2022-10-13 β so like, vintage but still eating. go encode something cute. bye bestie ππ§β¨
π¦ where this page comes from
- ubuntu noble: libmime-ecoencode-perl 0.95-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmime-ecoencode-perl 0.95-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmime-ecoencode-perl 0.95-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms