procmail�Ƃ́A���[���̐U�蕪�����s�Ȃ��c�[���ł��B
�U�蕪���ɂ̓��V�s(�]���̏���)��ݒ肷�邱�Ƃɂ��A���܂��܂ȓ]���������w�肷�邱�Ƃ��o���܂��B
# yum -y install procmail |
procmail �̃p�X���m�F # which procmail /usr/bin/procmail �ݒ�t�@�C���C��(�lj�) # vi /etc/postfix/main.cf �F �F #mailbox_command = /some/where/procmail #mailbox_command = /some/where/procmail -a "$EXTENSION" ���L�� 1 �s��lj�(procmail �̃p�X�͏�L���s����) mailbox_command = /usr/bin/procmail postfiix���ċN������ �yFC1 ���� Fedora15 / CentOS4 / CentOS5 / CentOS6 �̏ꍇ�z # /etc/rc.d/init.d/postfix restart �yFedora16�ȍ~ �̏ꍇ�z # systemctl restart postfix.service |
�t�H���[�h�t�@�C���̐ݒ� # vi /home/linux/.forward "|IFS=' ' && exec /usr/bin/procmail -f- || exit 75 #linux" �Ō��#�̌��Ɏ����̃A�J�E���g(���[�U�����w�肵�܂�) �쐬�����t�H���[�h�t�@�C���̏��L�ҁE�O���[�v�ݒ� # chown linux:linux /home/linux/.forward ���V�s��ݒ�(#�Ŏn�܂镔���̓R�����g�s�ɂȂ�܂�) # vi /home/linux/.procmailrc PATH=/bin:/usr/bin:/usr/sbin # procmail���g�p����p�X LOGFILE=$HOME/procmail.log # ���O�t�@�C���� LOCKFILE=$HOME/.lockfile # ���b�N�t�@�C���� MAILDIR=$HOME/Maildir/ # ���[���i�[�ꏊ DEFAULT=$MAILDIR # ���V�s�Ƀ}�b�`���Ȃ������ꍇ�̊i�[�ꏊ ### Subject:��"test"���܂܂�Ă����ꍇ�̓J�[�{���R�s�[���� ### (���[���{�b�N�X�Ɏ�M���[�����c��) ### [email protected] �� [email protected]�ɓ]�� :0 c * ^Subject: .*test.* ! [email protected],[email protected] �쐬�������V�s�ݒ�t�@�C���̏��L�ҁE�O���[�v�ݒ� # chown linux:linux /home/linux/.procmailrc �u.forward�v�u.procmailrc�v�ݒ�t�@�C���̏��L�ҁE�O���[�v�͊Y�����郆�[�U���ł��鎖�ɒ��� # ls -la /home/linux/.forward -rw-r--r-- 1 linux linux 64 8�� 3 11:53 /home/linux/.forward # ls -la /home/linux/.procmailrc -rw-r--r-- 1 linux linux 152 8�� 3 11:53 /home/linux/.procmailrc �� �� �� ���L�� �O���[�v ���[�U |
�N���C�A���g���[���\�t�g�ŁA������"test"�Ǝw�肵�A�A�J�E���g"linux"�փ��[�����Ă݂܂��傤�B
���V�s�Ɏw�肵���[email protected]��[email protected]���ɁA�]������܂��B
�t�H���[�h�t�@�C�����e�̊m�F # cat /home/linux/.forward "|IFS=' ' && exec /usr/bin/procmail -f- || exit 75 #linux" ���V�s�ݒ�t�@�C�����ȉ��̗l�ɂ��� # vi /home/linux/.procmailrc PATH=/bin:/usr/bin:/usr/sbin # procmail���g�p����p�X LOGFILE=$HOME/procmail.log # ���O�t�@�C���� LOCKFILE=$HOME/.lockfile # ���b�N�t�@�C���� MAILDIR=$HOME/Maildir/ # ���[���i�[�ꏊ DEFAULT=$MAILDIR # ���V�s�Ƀ}�b�`���Ȃ������ꍇ�̊i�[�ꏊ ### ���[�����͂�����J�X�^�}�C�Ycgi�����s���� ���L��"c"(�J�[�{���R�s�[)�������Ă��鎖�ɒ��� "c"�������ƁA�]����ɃI���W�i���̃��[���͔j������Ă��܂��܂��B :0 c |$HOME/maildelivery.cgi |
�J�X�^�}�C�Ycgi�̍쐬 # vi /home/linux/maildelivery.cgi #!/usr/local/bin/perl #=================================================================== # MailDelivery Version 1.0 # Copyright (c) First home server construction. # http://kajuhome.com/ #=================================================================== #==============�C�Ӑݒ�(��������)================ # ���o�l�̃A�h���X $sender='[email protected]'; # �]���������A�h���X��ݒ� @transaddr = ('[email protected]','[email protected]') ; # �]���������{���̕����� $transcnt = 400 ; # ���e��HTML���[�������ł��]������(1:Yes / 0:No) $transhtm = 0; #==============�C�Ӑݒ�(�����܂�)================ ################################################# # sendmail�̎��s���W���[�� $sendmail = '/usr/sbin/sendmail'; # Perl�ėp���W require '/usr/lib/perl-lib.pl'; # BASE�ϊ����C�u����(MIME�G���R�[�h) require "/usr/lib/mimew.pl"; ## BASE�ϊ����C�u����(MIME �f�R�[�h) require "/usr/lib/mimer.pl"; # ���[���t�@�C��(�ꎞ���[�N) $tmp_file = "$ENV{'HOME'}/maildelivery.tmp"; ################################################# push(@INC,'/usr/lib/perl5/network_modules/modules'); require MIME; @tmp=<>; open(TMP,">$tmp_file"); print TMP @tmp; close(TMP); my $FH = Symbol::gensym(); open($FH, "< $tmp_file"); my $mime = MIME->new(File => $FH); $mime->decode_message( Convert => "euc", Uudecode => 1, Suffix => [qw(gif png jpeg jpg txt text html htm doc)], ); # �w�b�_�����擾 @header = $mime->header(); # �w�b�_�e����擾 $subject = $mime->header('Subject'); $from = $mime->header('From'); $to = $mime->header('To'); $cc = $mime->header('Cc'); $date = $mime->header('Date'); # �{�f�B�����擾 $content = $mime->content(); # plain�^�C�v�̃f�[�^��S�ē��� @plain = $mime->content('plain'); # html�^�C�v�̃f�[�^��S�ē��� @html = $mime->content('html'); # ========== plain ========== $tmp_plain = ""; foreach $plain(@plain){ $tmp_plain .= $plain; } $tmp_plain =~ s/ //g; # ========== html ========== $tmp_html = ""; foreach $html(@html){ $tmp_html .= $html; } $tmp_html =~ s/ //g; @send_body = (); if("" ne $tmp_plain){ @send_body = @plain; }elsif("" ne $tmp_html){ if($transhtm eq "1"){ @send_body = @html; }else{ push(@send_body,"�I�I�@�g�s�l�k���[���ׁ̈A�]�����Ă��܂���@�I�I"); } }else{ push(@send_body,"�I�I�@�{��������܂���@�I�I"); } $plain_tmp = ""; foreach $send_body(@send_body){ $plain_tmp .= $send_body; } $edt_mail_body = &ksubstr($plain_tmp, 0, $transcnt); # ���[���{�� @mbody=(); push(@mbody,"�ȉ��̃��[����[$to]�ɓ͂��܂����B\n"); push(@mbody,"------------------------------------------------------------\n"); push(@mbody," ���o�l�F$from\n"); push(@mbody," �����F$subject\n"); push(@mbody,"��M�����F$date\n"); push(@mbody,"\n"); push(@mbody,"[�{��]\n"); push(@mbody,"$edt_mail_body\n"); push(@mbody,"------------------------------------------------------------\n"); push(@mbody,"��)�{���͐擪���[$transcnt]�����]�����Ă��܂��B\n"); # ���[���^�C�g���G���R�[�h $msub = &mimeencode("[kaju mail] New mail arrived"); foreach $transaddr ( @transaddr ) { # sendmail�N�� open(MAIL,"| $sendmail -t"); print MAIL "To: $transaddr\n"; print MAIL "From: $sender\n"; print MAIL "Subject: $msub\n"; print MAIL "MIME-Version: 1.0\n"; print MAIL "Content-type: text/plain; charset=ISO-2022-JP\n"; print MAIL "Content-Transfer-Encoding: 7bit\n"; print MAIL "X-Mailer: kaju original\n\n"; foreach $mbody(@mbody) { &jcode'convert(*mbody, 'jis'); print MAIL $mbody; } close(MAIL); } close($FH); unlink($tmp_file); exit 0; __END__ �쐬����cgi�X�N���v�g�Ɏ��s���t�^ # chmod 700 /home/linux/maildelivery.cgi �쐬����cgi�X�N���v�g�̏��L���ݒ� # chown linux /home/linux/maildelivery.cgi |
*�F�ulinux�v���[�U�ł̎g�p���Ƃ��āA�_�E�����[�h�����umaildelivery.tar�v�t�@�C�����u/root/�v�ɂ���Ƃ��܂��B ���[�U�f�B���N�g���Ɉړ� # cd /home/linux/ tar�t�@�C����W�J # tar xvf /root/maildelivery.tar ���L�ҁE�O���[�v�̕ύX # chown linux:linux maildelivery.cgi �t�@�C���̊m�F # ls -l maildelivery.cgi -rwx------ 1 linux linux 4110 8�� 3 11:11 maildelivery.cgi |
�쐬�����A�J�E���g���Ƀ��[�����͂��ƁA�J�X�^�}�C�Y���ꂽ���[�����w�肵���A�h���X�ɓ͂��܂��B