#!/usr/bin/perl -w

# email_link - display an obfuscated email address

# History:
#   2005/02/14 DT   Add f(ilter) option.
#   2005/02/05 DT   Start

require 5;

require "./form.pl";

# get the query into usable form
$rfield = &form_function;

if (defined $rfield->{'d'}
    && defined $rfield->{'e'}
    && defined $rfield->{'n'}) {
    my $domain = shift @{$rfield->{'d'}};
    my $email = shift @{$rfield->{'e'}};
    my $filter = shift @{$rfield->{'f'}} || '';
    my $name = shift @{$rfield->{'n'}};

    if ($filter) {
        my $filter_len = length $filter;
        $filter = <<"EOF";
<p>In order to get through the spam filter, you must include the string
<b>$filter</b> anywhere in the <b>Subject:</b> line of your message.
Any message NOT containing that exact $filter_len-character ASCII string
somewhere in the Subject: line will be summarily discarded.</p>
EOF
    }

    print <<"EOF";
Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><head>
 <title>email to $name</title>
</head><body>
<h1 align=center>email to $name</h1>
<p>To send a message to $name, use the following address:</p>
<blockquote><table cellspacing=0 cellpadding=0><tr>
 <td>$name</td>
 <td>&nbsp;&lt;</td>
 <td>$email</td>
 <td>@</td>
 <td>$domain</td>
 <td>&gt;</td>
</tr></table></blockquote>
<p>The above address has been deliberately obfuscated to frustrate spammers,
and a simple copy-and-paste will probably not work.
You must retype the address as shown into your mail program.</p>
$filter
<p>Use your browser's "back" button to return.</p>
</body></html>
EOF
#'
} else {
    error ("invalid request");
}

sub error {
    my ($string) = @_;

    print <<"EOF";
Content-type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html><body>
<h1 align=center>ERROR</h1>
$string
</body></html>
EOF
}
