The 2001 Perl Advent Calendar
[about] | [archives] | [contact] | [home]

On the 22nd day of Advent my True Language brought to me..
Text::Autoformat

What is it with email? Why is it that no-one can format it correctly? How many times have you got an email where the whole thing was on one line because the sender's client didn't chop the message up into 72char length lines? Or had someone apply creative formatting to the message with a terrible cut and paste? It'd be nice if you could get a program to smarten up text like this...to make it more readable. Of course correcting these kinds of problems is more than simply trivial.

One of the major problems with reformatting is that email contains quoted text and simply reformatting it naive manner simply doesn't work - you end up with the quotation delimiters being reformatted as if they were any other words and ending up in the middle of lines. Text::Autoformat is a module that has a good stab at reformatting the text to look less disorganised. The great thing is that Text::Autoformat is clever (or at least cunning) and knows what to do with email quoting and wraps the text without the quotes and then adds and removes quotes until the original format was there again.

This isn't the only situation Text::Autoformat knows how to deal with; It has a whole plethora of other reformatting options from reordering numbered lists to providing full justification if you really want it. Text::Autoformat isn't always able to determine the correct thing to do with any input (that problem is Hard,) so sometimes it screws up. Nine times out of ten however, you end up with text that looks a lot better than when you applied it.

  • Template::Plugin::Autoformat