💭
- 2013/09/16初稿
- 2013/10/08スクリプトをごっそり書き直したので更新
いくらコマンドライン教徒といえども、毎度毎度サーバにログインして書くのも面倒なので、例によってメールでpostするためのスクリプトemail2blosxomを書いてみた。
まぁ全体的に自分向けに書き捨てた感じなので、もし使う場合はうまいこといじくり回してください。
以下、perldoc email2blosxom
から。
NAME
email2blosxom - A MIME message to individual file(s) converter
SYNOPSIS
email2blosxom < mailfile
DESCRIPTION
email2blosxom parses MIME message and splits into individual file(s). As its name
suggests, it's been intended to post new article for blosxom
<http://blosxom.sourceforge.net/>. However, it simplly behaves as, to say, MIME splitter.
CONFIGURATION
DATA
This script contains text template in itself, after the "__DATA__" token, in Template
Toolkit format. Substitutable variables are:
title
title text (expanded from e-mail subject)
body
body text (expanded from e-mail body)
picts
array of pictures (may be empty if no picture attached)
pict.name
file name of a picture
pict.alt
file name of a picture (identical with "pict.name", but you can overwrite by
$cleanup_text, if you want)
$output_file
Points where to put text file into. If you want some complex naming (i.e. include current
date in file name), you can set this variable calling anonymous subroutine.
our $output_file = &{sub{
... do something ...
return $filename;
}};
If the file (or something) already exists, incremental number (like
/some/path/basename-N.suffix) is automatically added.
$picture_directory
Points where to put attached picture(s) into.
The original file name (included in MIME header) will be respected, but when the file
already exists, will be treated in the same way as $output_file.
$cleanup_text
Reference to subroutine to be called just before writing new text file, to cleanup (i.e.
escaping) text.
This subroutine will be passed a hash reference.
$ref = {
'title' => title text,
'body' => body text,
'picts' => [
{
name => file name of 1st picture,
alt => identical with name,
},
.....
],
};
umask(XXXX)
You may want set umask, especially when directories to put files into are shared by other
users.
KNOWN BUGS
· This script itself doesn't have any authentication mechanism (and I have no plan to
implement.)
You MUST filter e-mails using other programs, like procmail, before passing to this
script.
· This script sees 1st MIME part as text, and other parts (if exist) as attachments. I
know thant fixing this wouldn't be a hard work. But because this behaviour seems to
be OK in practical use, I won't fix it ;-)
AUTHOR
ohkawa <http://88171.net/>
LICENSE
This software is distributed under CC BY 3.0 license.
<https://creativecommons.org/licenses/by/3.0/>