MIME::EcoEncode(3pm)

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

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 is 76.
  • $mode β€” how the header behaves. 0 is an unstructured header (think Subject), 1 is a structured header (think To, Cc, From), and 2 is auto β€” Subject or Comments gets 0, everything else gets 1. Default is 2.
  • $lss β€” length of security space. Default is 25.

πŸ¦‹ 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::Param
  • MIME::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 (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