Rewrite Email Without Worrying
Encoding and Email
Talking about encoding is sort of tiresome, and I think everybody has heard enough of it. Talking is about email is pretty tiresome, too, and I know I have had enough. So, here's a very, very brief overview of why the two things are annoying together.
There are many systems for picking a set of symbols and assigning them numerical values. These are character sets. Unicode is the current favorite. In unicode, for example, the character numbered 0x2603 is a snowman (☃). There are also systems for writing out strings of characters to bytes so you can put them in a file system. These are encodings. UTF-8 is a popular way to do this for unicode, but not the only way. Some character sets already fit in 8-bit bytes, so they are their own encoding. Latin-1 is a good example. MacCyrillic is also an example.
Rougly speaking, in email, character set and encoding are conflated and called charset. If you declare your message's charset to be UTF-8, it means that it's UTF-8 encoded Unicode. In general, this conflation does not lead to problems. The problem is that email has to be encoded to 7-bit octets -- that is, bytes where the high bit is always off. The process by which this is done is called encoding (content transfer encoding).
So, say you're operating a mailing list and you need to attach footers to a message. First you have to decode from 7-bit to 8-bit and then from 8-bit to characters. Then you can tack on your footer, then you have to do the reverse encoding dance.
Hiding the Encoding Process
MIME::Visitor does its best to get rid of the whole mess.
So, with just a few lines of code, we hide all the annoying bits of encoding and decoding, letting you just focus on the content you want to play with. It has a number of other ways to handle messages, and it does work to ensure that it never rewrites parts that haven't been changed.
Unwrapped to code you'd have to write, the above is something like:
The most glaring problem with MIME::Visitor is that it works with MIME::Entity objects instead of Email::MIME objects, which are generally more common in my toolchain. When MIME::Visitor was written, access to get and set the Unicode content of a text part wasn't very good. It's better now, so this may get fixed soon!