多段のリメーラーができた。今朝書いた。
多段のリメーラーにする変更はとても簡単だ。これが新しいperlのスクリプトだ。
--------- cut here ---------
while (<>) {
last if /^$/ ;
$subject = $_ if /^Subject:/ ;
if (/^Request-Remailing-To:/) {
chop ;
s/^.*:// ;
$addressee = $_ ;
}
}
#open( OUTPUT, ">foo" ) || die "Cannot open 'foo'." ;
open( OUTPUT, "| /usr/lib/sendmail " . $addressee ) ;
select( OUTPUT ) ;
print "To:" . $addressee . "\n" ;
print "From: nobody\n" ;
print $subject ;
print "Remailed-By: Eric Hughes <hughes@soda.berkeley.edu>\n" ;
#
# check to see if there are header lines in the body to collapse
# into the full header.
#
if ( $_ = <> ) {
if (/^##$/) {
# do nothing if the pasting token appears
# the rest of the body will be directly appended
# this allows for extra header lines to be added
} else {
# normal line
print "\n" ;
print $_ ;
}
} else {
# empty body
exit ;
}
while (<>) {
} continue {
print ;
}
--------- cut here ---------
短い説明。‘print “\n” ;’ の行を、新しいif文の中に移した。if文は本文を1行読み、本文がなければスクリプトを止める。読んだ行が、”##” の2文字だけの行かどうかを調べる。”##” はANSI Cのトークン連結の演算子だ。連結がなければ、ヘッダーの終わりを示す空行を出力し、本文の1行目を出力する。連結があれば、条件の中では何もしない。そのため、本文はヘッダーの末尾にそのまま付け足され、ヘッダーが書き換えられたあとに、ヘッダーの行を追加できる。
新しいスクリプトを入れたあと、自分宛てに送った見本のメッセージがこれだ。
--------- cut here ---------
To: hughes
Subject: multiple hops
Request-Remailing-To: hughes
##
X-Hop: 1
Request-Remailing-To: hughes
##
X-Hop: 2
Request-Remailing-To: hughes
##
X-Hop: 3
This is a test message of multiple hops.
Eric
--------- cut here ---------
これを自分宛てに送ると、4通のメールが届いた。1通目は実際の手紙で、これはいまもふつうに届いていて、選り分けられていない。次の2通は1回目と2回目の送り直しで、X-Hop: 1と2が付いていた。最後のメッセージが最後の1通で、ヘッダーにX-Hop: 3があり、ふつうに届いた。
各段階で、ヘッダーが書き換えられ、新しいRequest-Remailing-To:の行が差し込まれた。そのメールが届くと、また書き換えられ、新しい送り直しの依頼が付く。この手順は、メールの大きさの実用上の限界、50Kかそこらまで広げられる。
この仕組みそれだけでは、まったく安全ではないことに注意してほしい。だが、メッセージの本文をそれぞれ先に暗号化しておき、ヘッダーの書き換えの前にメッセージを復号するようにすれば、経路の指示の全体を、詮索する目から隠せる。
それが次の課題だ。
エリック
