Do diffence

[hack] ./bin/qmail-remote 활용 본문

OLD

[hack] ./bin/qmail-remote 활용

고포릿 2006. 12. 19. 13:15
#!/usr/bin/perl

# 스탠다드 입력으로 메일 내용을 읽어들인다.
undef $/;
$inputdata = <STDIN>;
$/ = "\n";
$inputdata =~ /Subject: (.*)/;
$subject = $1;
$inputdata =~ /Received: from.*\(([0-9.]+)\)/;
$ip = $1;

# 시간을 구한다.
$now_string = localtime;

# 로그를 기록한다.
$logfile = "/var/log/qmail/remote.log";
open FH, ">>$logfile";
flock(FH,2);

# 반송메일을 드롭한다.
if ($subject =~ /(failure notice)/i) {
   $inputdata =~ /(no mailbox here by that name)/i;
   if ($1 eq "no mailbox here by that name") {
       print FH "Droped!!(Nouser)\t$now_string\tIP:$ip\tTo:$ARGV[2]\tFrom:$ARGV[1]\tSubject:$subject\n";
       close FH;
       exit 2;
   } else {
       print FH "Droped!!(failure notice)\t$now_string\tIP:$ip\tTo:$ARGV[2]\tFrom:$ARGV[1]\tSubject:$subject - Other\n";
       close FH;
   }
} else {
   print FH "OK!!\t\t\t$now_string\tIP:$ip\tTo:$ARGV[2]\tFrom:$ARGV[1]\tSubject:$subject\n";
   close FH;
}

# 원래 qmail-remote 프로그램을 실행시킨다.
open (MAIL, "| /var/qmail/bin/qmail-remote-original $ARGV[0] $ARGV[1] $ARGV[2]");
print MAIL $inputdata;
close MAIL;