ユーザのホームディレクトリの .forward を以下のように書き換える。 \user, |"/home/user/mail.pl -op1 -op2" \user はそのメールボックスにメールを残す設定 それ以降はプログラムにメールを渡す -op1 -op2 はプログラムへの引数(必要なときだけ設定) #!/usr/bin/perl # 引数の読み込み while (@ARGV) { shift(@ARGV); $op{"$_"} = 1; } ### 標準入力よりメールの内容を取得する while () { ## 改行のありそうなヘッダにフラグを立てる。 # 頭に空白文字以外なら新たなフィールド if (/^\S/) {$flg = '';} # 頭の空白文字を取り値を付け足す if ($flg eq 'from') {s/^\s+//; s/\s$//; $from .= "$_";} if ($flg eq 'to') {s/^\s+//; s/\s$//; $to .= "$_";} if ($flg eq 'subj') {s/^\s+//; s/\s$//; $subj .= "$_";} # 必要なヘッダ項目の取得 if (/From:\s*(.+)/i) {$from = $1; $flg = 'from';} elsif (/To:\s*(.+)/i) {$to = $1; $flg = 'to';} elsif (/Subject:\s*(.+)/i) {$subject = $1;} # 改行のみの行でヘッダ終わり m/^\n$/ and last; } $from = &extract_address($from); $to = &extract_address($to); ($acount,$domain2) = split (/@/, $to); # メールアドレスのみを取得 sub extract_address { my ($from) = @_; if ($from =~ /.*<(.+)>/) {return $1;} # From: Foo Bar elsif ($from =~ s/\s*\(.*\)//) {return $from;} # From: foobar@com.edu (Foo Bar) else {return $from;} # From: foobar@com.edu [I hope] } # メールの本文処理 while () { print; } exit;