MIME::...e::Fold(3pm)
π MIME::EcoEncode::Fold β folding multi-byte string π
okay bestie, pull up a chair because we're about to talk about the MIME::EcoEncode::Fold module (it lives in the MIME::...e::Fold(3pm) section of the perl docs, iykyk) and it is lowkey a lifesaver. β¨
πΈ SYNOPSIS πΈ
like, here's the whole vibe in one block, no notes:
use MIME::EcoEncode::Fold;
$folded = mime_eco_fold($str, 'UTF-8'); # fold utf8 string
$folded = mime_eco_fold($str, 'GB2312'); # fold euc-cn string
$folded = mime_eco_fold($str, 'EUC-KR'); # fold euc-kr string
$folded = mime_eco_fold($str, 'Big5'); # fold big5 string
$folded = mime_eco_fold($str, 'Shift_JIS'); # fold cp932 string
$folded = mime_eco_fold($str, 'ISO-2022-JP'); # fold 7bit-jis string
$folded = mime_eco_fold($str, $sbcs); # $sbcs :
# single-byte charset
# (e.g. 'ISO-8859-1')
that's it. that's the whole API. we love a one-function icon. π
β¨ DESCRIPTION β¨
so basically? this is a module for folding multi-byte string. π
here's the tea: when a line of the e-mail text is long, the SMTP server may insert line feed code, and then the multi-byte string might break π. absolutely not on our watch. this module was written in order to prevent exactly that. no cap, it's out here protecting your multibyte characters from getting chopped mid-character like a bad haircut.
π¦ Options π¦
one function, four args, let's get into it:
$folded = mime_eco_fold($str, $charset, $lf, $bpl);
# $charset : 'UTF-8' / 'GB2312' / 'EUC-KR' / 'Big5' /
# 'Shift_JIS' / 'ISO-2022-JP' / ...
# (default: 'UTF-8')
# Note: The others are all folded as
# single-byte string.
# $lf : line feed (default: "\n ")
# $bpl : bytes per line (default: 990)
# Note: 990 is postfix's default.
breaking that down for my besties:
$strβ the string you're folding, obviously. the main character. π$charsetβ'UTF-8'/'GB2312'/'EUC-KR'/'Big5'/'Shift_JIS'/'ISO-2022-JP'/ ... and the default is'UTF-8'. β Note: the others are all folded as single-byte string. don't forget that part!!$lfβ the line feed. default is"\n "(that's a newline and a space, she's subtle β¨).$bplβ bytes per line. default is990. π Note:990is postfix's default, so if you were wondering where that number came from... now you know.
π§ Examples π§
okay let's see her in action, this is the good part:
Ex1
use MIME::EcoEncode::Fold;
my $str =<<"END";
This document specifies an Internet standards track protocol for the
Internet community, and requests discussion and suggestions for
improvements.
END
print mime_eco_fold($str, 'UTF-8', undef, 50);
look at that β undef for the line feed so we get the default, and 50 bytes per line because we're being dramatic about it. π
Ex1's output:
This document specifies an Internet standards trac
k protocol for the
Internet community, and requests discussion and su
ggestions for
improvements.
see how it chopped right at the byte limit and just... kept going on a fresh line with a lil space in front? that's the fold, bestie. she ate and left no crumbs. π₯ (and yes, <italic>trac</italic> + <italic>k</italic> getting split across lines is exactly the point β the byte boundary falls wherever it falls, that's just how $bpl works.)
π SEE ALSO π
MIME::EcoEncodeβ her sibling, her ride-or-die, go say hi π«Ά
π AUTHOR π
MURATA Yasuhisa <murata@nips.ac.jp>
(hi king, thank you for your service π)
π 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. slay, open source behavior fr fr. β¨
and that's the whole page, pookies! go fold some multibyte strings and stay unbroken π πΈ
this lil doc drop was brought to you by perl v5.36.0, dated 2022-10-13, straight out of the User Contributed Perl Documentation β¨ β catch you in the MIME::...e::Fold(3pm) section, mwah π
π¦ 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