HTML::Quoted(3pm)

πŸ’– NAME πŸ’–

HTML::Quoted β€” extract structure of quoted HTML mail message. It's the HTML::Quoted(3pm) page from the perl man pages (User Contributed Perl Documentation, if you're keeping receipts) and honestly? she's a little icon. πŸŽ€

Bestie, if you've ever stared at a forwarded email full of nested quotes and gone "who said what, and when", this module is your girl. ✨


🌸 SYNOPSIS 🌸

use HTML::Quoted;
my $html = '...';
my $struct = HTML::Quoted->extract( $html );

πŸ¦‹ DESCRIPTION πŸ¦‹

It parses and extracts quotation structure out of a HTML message. The purpose and the returned structures are very similar to Text::Quoted. Like, same energy, different markup. πŸ’…


πŸŽ€ SUPPORTED FORMATS πŸŽ€

Okay so, various MUAs use quite different approaches for quoting in mails. No two email clients are ever gonna agree on anything, it's giving chaos.

  • Some use the blockquote tag, and that one's genuinely quite easy to parse. Slay.
  • Some wrap text into p tags and add '>' in the beginning of the paragraphs.
  • And things get messier when it's an HTML reply on a plain text mail thread. 😭

If you found a format that is not supported, then file a bug report via rt.cpan.org with as short as possible example. A test file is even better. A test file with a patch is the best. And listen β€” not obvious patches without tests suck. No cap. 🫢


πŸ‘‘ METHODS πŸ‘‘

⭐ extract

my $struct = HTML::Quoted->extract( $html );

Takes a string with HTML and returns an array reference. Each element in the array is either an array or a hash. For example:

[
    { 'raw' => 'Hi,' },
    { 'raw' => '<div><br><div>On date X wrote:<br>' },
    [
         { 'raw' => '<blockquote>' },
         { 'raw' => 'Hello,' },
         { 'raw' => '<div>How are you?</div>' },
         { 'raw' => '</blockquote>' }
    ],
    ...
]

Hashes represent a part of the html. The following keys are meaningful at the moment:

  • raw β€” raw HTML. Literally just the raw HTML, no thoughts, head empty. πŸ’–
  • quoter_raw, quoter β€” raw and decoded (entities are converted) quoter, if the block is prefixed with quoting characters. Two of them, one glow-up apart. ✨

🧚 combine_hunks

my $html = HTML::Quoted->combine_hunks( $arrayref_of_hunks );

Takes the output of "extract" and turns it back into HTML. It's the reverse uno card of the whole operation. πŸ”₯


🌈 AUTHOR 🌈

Ruslan.Zakirov <ruz@bestpractical.com> β€” the main character who wrote all this. πŸ‘‘


πŸ’œ LICENSE πŸ’œ

Under the same terms as perl itself. Periodt.


Anyway bestie, that's the whole page, every single flag-free, option-free detail of it, and I did not skip a crumb. πŸ“

This was perl v5.36.0, dated 2023-11-01, filed under HTML::Quoted(3pm) in the User Contributed Perl Documentation. Bye, love you, go read your emails. πŸ’…πŸŒΈ

πŸ“¦ where this page comes from