MIME::...:Param(3pm)

πŸ“¦
version 0.95 Β· 3 versions
, in ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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 is 76.

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. 1 means ON, 0 means OFF. default is 1 ✨

🌈 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 (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