MIME::...e::Fold(3pm)

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

πŸ’– 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 is 990. πŸ“ Note: 990 is 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 (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