qmail+vpopmail+ezmlm から postfix+mysql+dovecot+mailman
にメールサーバの構成を変更したのは良いけど、プログラムへの
渡し方がわからなかったのでメモ。
(とりあえず、動いているけど、もっと素敵な記述がないのかな。。)
yoshimax-aliases
movie "|/home/yoshimax/local/keitaimovie/store.pl"
#postmap /etc/postfix/yoshimax-aliases
yoshimax-aliases.cf
movie@dreamxxxx.jp movie
#postmap /etc/postfix/yoshimax-aliases.cf
main.cf
alias_maps = hash:/usr/local/mailman/data/aliases,
hash:/etc/postfix/yoshimax-aliases
virtual_alias_maps = mysql:/etc/postfix/mysql-aliases.cf,
hash:/usr/local/mailm\
an/data/virtual-mailman, hash:/etc/postfix/yoshimax-aliases.cf
普通に標準入力で渡されるので、
それなりに処理する。
添付ファイルを保存するのは、以下のような感じ。
# store keitai movie
# (c)dreamedge project
use strict;
use MIME::Parser;
use Time::Piece;
use FileHandle;
my $t = localtime;
# movie store directory
my $outputdir = '/home/yoshimax/local/keitaimovie/data/';
# Parse
my $parser = new MIME::Parser;
$parser->output_under('/tmp');
my $entity = $parser->parse(\*STDIN) or die;
my ($mail_body, $filename, $body);
# HEAD
my $mail_from = $entity->head->get('from');
my $mail_date = $entity->head->get('date');
my $mail_subject = $entity->head->get('subject');
if ($entity->is_multipart){
my $count = $entity->parts;
for (my $i = 0; $i < $count; $i++) {
#!!text or binary
my ($type, $subtype) = split('/', $entity->parts($i)->head->mime_type);
if ($type =~ /^(text|message)$/) { # text
$mail_body .= $entity->parts($i)->bodyhandle->as_string;
} else {
# devide file name
my $sPath = $entity->parts($i)->bodyhandle->path;
my($sHead, $sExt);
if ($sPath =~ /(.+)(\.\w+)$/) {
($sHead, $sExt) = ($1, $2);
}else {
($sHead, $sExt) = ($sPath, "");
}
my $filename = $t->ymd('') . $t->hms('') . $sExt;
my $path = $outputdir . $filename;
my $fh = new FileHandle "> $path";
if (defined $fh) {
print $fh $entity->parts($i)->bodyhandle->as_string;
undef $fh; # automatically closes the file
}
}
}
}
[ この記事は、trispot.net より、引用されています。]

コメント