From xxxxx@xxxxx.com Wed Jun 21 10:22 JST 2000 Message-Id: <200006210117.xxxxx@xxxxxx.com> Date: Wed, 21 Jun 2000 10:23:44 +0900 From: ryo ikuyama <xxxxx@xxxxx.com> To: xxxxx@xxxxx.com Subject: =?ISO-2022-JP?B?GyRCRTpJVSVVJSElJCVrJE4bKEI=?= TEST Content-Length: 59584 Content-Type: multipart/mixed; boundary="U2F0LCAxNSBBcHIgMjAwMCAxMDoyMzo0NCArMDkwMA==" --U2F0LCAxNSBBcHIgMjAwMCAxMDoyMzo0NCArMDkwMA== Content-Type: text/plain; charset=ISO-2022-JP 添付ファイルのメールのテストです。 --U2F0LCAxNSBBcHIgMjAwMCAxMDoyMzo0NCArMDkwMA== Content-Type: image/jpeg; name="PIC00001.jpg" Content-Disposition: attachment; filename="PIC00001.jpg" Content-Transfer-Encoding: base64 /9j/4AAQSkZJRgABAgEAkACQAAD/4AQQSkZYWAAQ/9j/2wBDABsSFBcUERsXFhceHBsgKEIrKCUl FC4PHWqiD/DNWjPoXrRtk0LMMhZAT9K9o/tSa1hS6tfIMskQ8mNCeB9K83Hxu4nXhHqV7X4s2sMx ttXguNMugSDJF908+lbL+JrLVIy9ve2V2G6YIB9e1cLo8uiO1tH/2Q== --U2F0LCAxNSBBcHIgMjAwMCAxMDoyMzo0NCArMDkwMA== Content-Type: application/octet-stream; name="test.c" Content-Disposition: attachment; filename="test.c" Content-Transfer-Encoding: base64 LyoqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioqKioq KioqKioqKioqKioqKioqKioqKiovDQovKiAgQmV0dHkgg0qBW4Nsg4uLpJLKlZQgg3WDiYNig06D ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICovDQovKi0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0qLw0Kdm9pZCBlbmQodm9pZCkNCnsNCn0NCg== --U2F0LCAxNSBBcHIgMjAwMCAxMDoyMzo0NCArMDkwMA==-- |
メイル転送スクリプト案 現在はryo@my-machine.comからxxxxx@xxxxx.xxxと xxxxx@pdx.ne.jpにメール転送を.forwardにより単純に転送 しているが、pdxの方に添付ファイルを転送するとサーバ容量 によりエラーになってしまう。 そこで、pdxに転送するのは本文のみとし、添付ファイルは転送 しない仕組みを考えた。 .forwardの中身 現在 xxxxx@xxxxx.xxx xxxxx@pdx.ne.jp 新 xxxxx@xxxxx.xxx "| ./mailtrans.pl" ./mailtrans.plスクリプトにより添付ファイル削除後のメールを pdxに転送する。 mailtrans.plフロー ヘッダを解釈 Content-Typeを調べる ヘッダはそのまま一時ファイルに出力(変更) ヘッダからFromとSubjectを抜き出して変数に格納する。 text/plainの場合{ 本文をそのまま一時ファイルに出力 } multipart/mixedの場合{ $boundary文字列取得 $outf = OFF; $headf = ON; while(本文){ "--"$boundary"--"を見つけたら{ break; } "--"$boundaryを見つけたら{ $headf = ON; $outf = OFF; } if($headf == ON){ /Content-Typeがtext/plainなら$outf=ON; 改行のみなら$header = OFF; }else{ if($outf == ON){ 一時ファイルに出力 } } } 一時ファイルをxxxxx@pdx.ne.jpに転送 } 終了 |
#!/usr/bin/perl $sendmail = '/usr/lib/sendmail'; $forwardto = 'To: xxxxxxx@pdx.ne.jp'; $tempfile = './tempfile.txt'; &make_mail; &mail_forward; sub mail_forward { open(OUT,"| $sendmail -t") || die "Cannnot open $sendmail"; print OUT "$forwardto\n"; print OUT "$from"; print OUT "$subject"; print OUT "\n"; open(TEMP,"<$tempfile") || die "Cannot open $tempfile."; while(<TEMP>){ print OUT; } close(TEMP); close(OUT); } sub make_mail { open(TEMP,">$tempfile") || die "Cannot open $tempfile."; open(STDIN); $mainheaderf = 1; #ヘッダーフラグセット $mixf = 0; #添付ファイル有無フラグクリア $headf = 0; #途中のヘッダーフラグ $outf = 0; #出力フラグ while(<STDIN>){ if($mainheaderf){ #メインのヘッダー処理 if(/^$/){ #改行だけの行 $mainheaderf = 0; #次からは本文 } if(/^From:/){ #Fromの行 $from = $_; } if(/^Subject:/){ #Subjectの行 $subject = $_; } if(/^Content-Type:/){ #Content-Typeの行 if(/mixed/){ #添付あり $mixf = 1; ($temp,$boundary) = split("=",$_,2); $boundary =~ s/\"//g; } } }else{ #本文処理 if($mixf){ #添付ファイルありの場合 if(/^--$boundary$/){ #区切り文字列 $headf = 1; #ヘッダーの開始 $outf = 0; #出力フラグクリア } if($headf){ #ヘッダー処理 if(/^Content-Type:/){ #Content-Typeの行 if(/text\/plain/){ #text/plainなら $outf = 1; #出力フラグオン }else{ #text/plainじゃないなら $outf = 0; #出力しない } } if(/^$/){ #改行だけの行なら $headf = 0; #ヘッダー部終了 } }else{ #本文処理 if($outf){ #出力して良いなら print TEMP; #一時ファイルに格納 } } }else{ #添付ファイルなしの場合 print TEMP; #全文をそのまま一時ファイルへ } } } close(TEMP); close(STDIN); } |