MIME::EcoEncode(3pm)
MIME::EcoEncode(3pm) β bestie, it's from the User Contributed Perl Documentation corner of the universe, and it's about to change how you do MIME headers forever. π
πΈ NAME πΈ
MIME::EcoEncode β MIME Encoding (Economical). Yes, economical. It said what it said. π
β¨ SYNOPSIS β¨
Okay so here's the whole vibe in one block, no cap:
use MIME::EcoEncode;
$encoded = mime_eco($str, 'UTF-8'); # encode utf8 string
$encoded = mime_eco($str, 'UTF-8?B'); # ditto ("B" encoding)
$encoded = mime_eco($str, 'UTF-8?Q'); # ditto ("Q" encoding)
$encoded = mime_eco($str, 'UTF-8*XX'); # XX is RFC2231's language
$encoded = mime_eco($str, 'UTF-8*XX?B'); # ditto ("B" encoding)
$encoded = mime_eco($str, 'UTF-8*XX?Q'); # ditto ("Q" encoding)
$encoded = mime_eco($str, 'GB2312'); # encode euc-cn string
$encoded = mime_eco($str, 'EUC-KR'); # encode euc-kr string
$encoded = mime_eco($str, 'Big5'); # encode big5 string
$encoded = mime_eco($str, 'Shift_JIS'); # encode cp932 string
$encoded = mime_eco($str, 'ISO-2022-JP'); # encode 7bit-jis string
$encoded = mime_eco($str, $sbcs); # $sbcs :
# single-byte charset
# (e.g. 'ISO-8859-1')
$decoded = mime_deco($encoded); # decode encoded string
# (for single charset)
($decoded, $charset, $language) # return array
= mime_deco($encoded); # (for single charset)
use Encode;
$decoded = mime_deco($encoded, \&cb); # cb is callback subroutine
# (for multiple charsets)
# Example of callback subroutine
sub cb {
my ($encoded_word, $charset, $language, $decoded_word) = @_;
encode_utf8(decode($charset, $decoded_word));
}
So like β mime_eco takes it in, mime_deco takes it out, and if you've got a whole squad of charsets you pass a callback. It's giving main character energy for real. π«Ά
π DESCRIPTION π
This module implements RFC 2047 Mime Header Encoding. That's the whole assignment. Periodt. π
π₯ Options π₯
Here's the full signature situation, verbatim, because I'm not about to paraphrase parameters on you:
$encoded = mime_eco($str, $charset, $lf, $bpl, $mode, $lss);
# $charset : 'UTF-8' / 'UTF-8?Q' / 'UTF-8*XX' /
# 'GB2312' / 'EUC-KR' / 'Big5' /
# 'Shift_JIS' / 'ISO-2022-JP' / ...
# (default: 'UTF-8')
# Note: "B" encoding is all defaults.
# The others are all encoded as
# single-byte string.
# $lf : line feed (default: "\n")
# $bpl : bytes per line (default: 76)
# $mode : 0 : unstructured header (e.g. Subject)
# 1 : structured header (e.g. To, Cc, From)
# 2 : auto (Subject or Comments ? 0 : 1)
# (default: 2)
# $lss : length of security space (default: 25)
And because I love you, here's the same tea, one sip at a time: π
$charsetβ your charset, bestie. Could be'UTF-8','UTF-8?Q','UTF-8*XX','GB2312','EUC-KR','Big5','Shift_JIS','ISO-2022-JP', or whatever else. Default is'UTF-8'. Little note from the source:"B"encoding is all defaults, and all the others get encoded as a single-byte string.$lfβ the line feed. Default is"\n".$bplβ bytes per line. Default is76.$modeβ how the header behaves.0is an unstructured header (thinkSubject),1is a structured header (thinkTo,Cc,From), and2is auto βSubjectorCommentsgets0, everything else gets1. Default is2.$lssβ length of security space. Default is25.
π¦ Examples π¦
Honestly? The receipts are right here. Watch.
Ex1 β normal (structured header)
use MIME::EcoEncode;
my $str = "From: Sakura <sakura\@example.jp> (\xe6\xa1\x9c)\n";
print mime_eco($str);
Ex1's output:
From: Sakura <sakura@example.jp> (=?UTF-8?B?5qGc?=)
Ex2 β "Q" encoding + RFC2231's language
use MIME::EcoEncode;
my $str = "From: Sakura <sakura\@example.jp> (\xe6\xa1\x9c)\n";
print mime_eco($str, 'UTF-8*ja-JP?Q');
Ex2's output:
From: Sakura <sakura@example.jp> (=?UTF-8*ja-JP?Q?=E6=A1=9C?=)
Ex3 β continuous spaces
use MIME::EcoEncode;
my $str = "From: Sakura <sakura\@example.jp> (\xe6\xa1\x9c)\n";
print mime_eco($str);
Ex3's output:
From: Sakura <sakura@example.jp> (=?UTF-8?B?5qGc?=)
Ex4 β unstructured header (1)
use MIME::EcoEncode;
my $str = "Subject: Sakura (\xe6\xa1\x9c)\n";
print mime_eco($str);
Ex4's output:
Subject: Sakura =?UTF-8?B?KOahnCk=?=
Ex5 β unstructured header (2)
use MIME::EcoEncode;
my $str = "Subject: \xe6\xa1\x9c Sakura\n";
print mime_eco($str);
Ex5's output:
Subject: =?UTF-8?B?5qGc?= Sakura
Ex6 β 7bit-jis string
use Encode;
use MIME::EcoEncode;
my $str = "Subject: \xe6\xa1\x9c Sakura\n";
print mime_eco(encode('7bit-jis', decode_utf8($str)), 'ISO-2022-JP');
Ex6's output:
Subject: =?ISO-2022-JP?B?GyRCOnkbKEI=?= Sakura
Six examples, zero notes skipped. We ate. ππ₯
π SEE ALSO π
MIME::EcoEncode::ParamMIME::EcoEncode::Fold
For more information, please visit http://www.nips.ac.jp/~murata/mimeeco/ β go look, iykyk. π
π AUTHOR π
MURATA Yasuhisa <murata@nips.ac.jp> β the icon, the legend. π
π COPYRIGHT π
Copyright (C) 2011-2013 MURATA Yasuhisa
π LICENSE π
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Slay, honestly. π«Ά
And that's the whole page, bestie β shipped as perl v5.36.0, dated 2022-10-13, straight out of MIME::EcoEncode(3pm). Go encode something cute. πβ¨ππ¦
π¦ 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