« SEPY ActionScript Editor | メイン | FLASHとのRPC PHPObject »

Postfix virtual domain で プログラムにメールを送る

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.pl ######################## #!/usr/bin/perl

# 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 より、引用されています。]

Author: yoshimax Date: 2005年6月 1日 10:04 | | Trackback (0) | Bookmark: このエントリーを含むはてなブックマーク このエントリーをはてなブックマークに追加 Save This Page この記事をクリップ! このエントリーを含むはてなブックマーク

トラックバック

このエントリーのトラックバックURL:
http://www.de4u.net/mt42/mt-tb.cgi/996

コメント

About

2005年6月 1日 10:04に投稿されたエントリーのページです。

ひとつ前の投稿は「SEPY ActionScript Editor」です。

次の投稿は「FLASHとのRPC PHPObject」です。

他にも多くのエントリーがあります。メインページアーカイブページも見てください。

Technorati

Technorati search

» ここにリンクしているブログ

2009年12月

    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

最近のコメント

アーカイブ