2010. 11. 29
Email::MIME::* modules aren’t very close friends
The Email::*
modules are all pretty neat, with a pleasant API. But combining them isn’t always as effortless as you’d
expect.
For my email2blog script, I use Email::Filter as the bridge between the MTA and
blosxom:
# grab email from STDIN
my $mail = Email::Filter->new;
The $mail object has nifty methods that make it very simple to accept or reject a
message.
Once I accept a message, I take out the attachments with Email::MIME::Attachment::Stripper.
The first step is to construct a stripper based on the incoming email:
# make stripper
my $strip = Email::MIME::Attachment::Stripper->new(
Email::MIME->new( $mail->simple->as_string ),
force_filename => 1
);
I’m not impressed with the hoops I have to jump through there. It should be easy for
EMA::Stripper to build its own Email::MIME object when handed an
Email::Simple object. But in fact, even Email::MIME itself doesn’t offer that
option.
Next up is taking apart the MIME email:
# strip attachments
my $msg = $strip->message;
my @attachments = $strip->attachments;
That’s pretty straightforward. $msg is an Email::MIME object, without the
attachments. To get at the plaintext body is still not very comfortable:
# extract plaintext body
my $text = first { $_->content_type =~ m{text/plain} } $msg->parts;
Maybe that’s because there may not be a text/plain part with meaningful content, but I
wouldn’t expect $msg->body to be empty after the strip operation. It is though, so that fancy
grep is necessary.
The @attachments array on the other hand is very easy to work with. It has just the things
you need, and nothing else.
All in all, the script ended up being about 60 well-spaced lines long, with most of that being taken up by sanitizing the input. The fact that I didn’t actually have to think how MIME encoding works under the hood was a big plus, and for that I’m very happy with the PEP Project.
No comments yet [ / text / blosxom / email ] permalink
First impressions
I installed Blosxom today. Getting it up and running was a piece of cake. Finding useful plugins took a little longer, but I’m happy with the current set:
- categories, meta, directorybrowse, flavourdir
- MarkDown
- SmartyPants
I stole the layout from my Perl pages.
No comments yet [ / text / blosxom ] permalink
Tidyhtml 0.01
Initial version
I’ve just written a tiny blosxom plugin that cleans up your html. It uses the 1.07_01 dev version of
HTML::Tidy, which in
turn uses libtidy.
Since this is the first ever version, I’m just going to paste it here. I’ll build a proper release later on.
# Blosxom Plugin: tidyhtml
# Author(s): Rhesa Rozendaal
# Version: 0.01
# URL: http://oss.rhesa.com/blog/text/blosxom/plugins/tidyhtml
package tidyhtml;
use strict;
# --- Configurable variables -----
my $tidy_config = {
tidy_mark => 'no',
wrap => '120',
indent => 'auto',
output_xhtml => 'yes',
char_encoding => 'utf8',
doctype => 'strict',
add_xml_decl => 'yes',
alt_text => 'photo',
};
# --------------------------------
use HTML::Tidy;
sub last {
# only operate on html content types.
return unless $blosxom::header->{-type} =~ /html/;
$blosxom::output = HTML::Tidy->new( $tidy_config )
->clean( $blosxom::output );
return;
}
sub start { 1 }
1;
No comments yet [ / text / blosxom / plugins / tidyhtml ] permalink
JavaScript-driven syntax highlighting
Based on a PerlMonks idea, I’ve added syntax highlighting on code blocks. The javascript is here, and the css here.
See this post for an example (you need javascript enabled for this).
No comments yet [ / text / blosxom ] permalink
Markdown
Markdown is neat.
No comments yet [ / text / formatting ] permalink
This time, with attachments

Let’s hear a “YAY!” :-)
No comments yet [ / text / blosxom / email ] permalink
A couple of Vim links
- Efficient Editing With vim - Jonathan McPherson
- Why, oh WHY, do those #?@! nutheads use vi?
- Search vim online tips by rating
Emacs is far too small to be a proper kitchen sink — david feuer
No comments yet [ / text / editing ] permalink
Testing my email2blog script (take 2)
Ok, so mailing works, and the file gets stored in the proper location. Now, lets see if the permissions work out.
No comments yet [ / text / blosxom / email ] permalink
Markdown sample text
This all the example text from Markdown basics.
Paragraphs, Headers, Blockquotes
A First Level Header
====================
A Second Level Header
---------------------
Now is the time for all good men to come to
the aid of their country. This is just a
regular paragraph.
The quick brown fox jumped over the lazy
dog's back.
### Header 3
> This is a blockquote.
>
> This is the second paragraph in the blockquote.
>
> ## This is an H2 in a blockquote
Phrase Emphasis
Some of these words *are emphasized*.
Some of these words _are emphasized also_.
Use two asterisks for **strong emphasis**.
Or, if you prefer, __use two underscores instead__.
Lists
bulleted:
* Candy.
* Gum.
* Booze.
numbered:
1. Red
2. Green
3. Blue
multiline:
* A list item.
With multiple paragraphs.
* Another item in the list.
Links
This is an [example link](http://example.com/).
This is an [example link](http://example.com/ "With a Title").
I get 10 times more traffic from [Google][1] than from
[Yahoo][2] or [MSN][3].
[1]: http://google.com/ "Google"
[2]: http://search.yahoo.com/ "Yahoo Search"
[3]: http://search.msn.com/ "MSN Search"
I start my morning with a cup of coffee and
[The New York Times][NY Times].
[ny times]: http://www.nytimes.com/
Images

![alt text][id]
[id]: /path/to/img.jpg "Title"
Code
I strongly recommend against using any `<blink>` tags.
I wish SmartyPants used named entities like `—`
instead of decimal-encoded entites like `—`.
If you want your page to validate under XHTML 1.0 Strict,
you've got to put paragraph tags in your blockquotes:
<blockquote>
<p>For example.</p>
</blockquote>
—
A First Level Header
A Second Level Header
Now is the time for all good men to come to the aid of their country. This is just a regular paragraph.
The quick brown fox jumped over the lazy dog’s back.
Header 3
This is a blockquote.
This is the second paragraph in the blockquote.
This is an H2 in a blockquote
Some of these words are emphasized. Some of these words are emphasized also.
Use two asterisks for strong emphasis. Or, if you prefer, use two underscores instead.
bulleted:
- Candy.
- Gum.
- Booze.
numbered:
- Red
- Green
- Blue
multiline:
-
A list item.
With multiple paragraphs.
-
Another item in the list.
This is an example link.
This is an example link.
I get 10 times more traffic from Google than from Yahoo or MSN.
I start my morning with a cup of coffee and The New York Times.


I strongly recommend against using any <blink> tags.
I wish SmartyPants used named entities like — instead of decimal-encoded entites
like —.
If you want your page to validate under XHTML 1.0 Strict, you’ve got to put paragraph tags in your blockquotes:
<blockquote>
<p>For example.</p>
</blockquote>
No comments yet [ / text / formatting ] permalink
Vim config, plugins
My preferred editor is Vim. I use a couple of plugins that make it even nicer:
My local vimrc has a couple of niceties too.
No comments yet [ / text / editing ] permalink