#!/usr/local/bin/perl
#
# Doug's WWW Mail Gateway 2.2
# 5/95
# All material here is Copyright 1995 Doug Stevenson.
#
# Use this script as a front end to mail in your HTML. Not every browser
# supports the mailto: URLs, so this is the next best thing. If you
# use this script, please leave credits to myself intact! :) You can
# modify it all you want, though.
#
# Documentation at:
# http://www-bprc.mps.ohio-state.edu/mailto/mailto_info.html
#
# Configurable items are just below. Also pay special attention to
# GET method arguments that this script accepts to specify defaults
# for some fields.
#
# I didn't exactly follow the RFCs on mail headers when I wrote this,
# so please send all flames my way if it breaks your mail client!!
# Also, you'll need cgi-lib.pl for the GET and POST parsing. I use
# version 1.7.
#
# Requires cgi-lib.pl which can be found at
# http://www.bio.cam.ac.uk/web/form.html
#
# PLEASE: Use this script freely, but leave credits to myself!! It's
# common decency!
#
########
#
# Changes from 1.1 to 1.2:
#
# A common modification to the script for others to make was to allow
# only a certain few mail addresses to be sent to. I changed the WWW
# Mail Gateway to allow only those mail addresses in the list @addrs
# to be mailed to - they are placed in a HTML list, with either
# the selected option being either the first one or the one that matches
# the "to" CGI variable. Thanks to Mathias Koerber
# for this suggestion.
#
# Also made one minor fix.
#
########
#
# Changes from 1.2 to 1.3:
#
# Enhancing the enhancements from 1.2. You can now specify a real name
# or some kind of identifier to go with the real mail address. This
# infomation gets put in the %addrs associative array, either explicitly
# defined, or read from a file. Read the information HTML for instructions
# on how to set this up. Also, real mail addresses may hidden from the
# user. Undefine or set to zero the variable $expose_address below.
#
########
#
# Changes from 1.3 to 1.4
#
# The next URL to be fetched after the mail is sent can be specified with
# the cgi varaible 'nexturl'.
#
# Fixed some stupid HTML mistake.
#
# Force user to enter something for the username on 'Your Email:' tag,
# if identd didn't get a username.
#
# Added Cc: field, only when %addrs is not being used.
#
########
#
# Quickie patch to 1.41
#
# Added formatted part to header entry to make it look nice and fixed a
# typo.
#
########
#
# Version 2.0 changes
#
# ALL cgi varaibles (except those reserved for mail info) are logged
# at then end of the mail received. You can put forms, hidden data,
# or whatever you want, and the info for each variable will get logged.
#
# Cleaned up a lot of spare code.
#
# IP addresses are now correctly logged instead of just hostnames.
#
# Made source retrieval optional.
#
########
#
# Changes from 2.0 to 2.1
#
# Fixed stupid HTML error for an obscure case. Probably never noticed.
#
# Reported keys are no longer reported in an apparently random order; they
# are listed in the order they were received. That was a function of perl
# hashes...changed to a list operation instead.
#
########
#
# Changes from 2.1 to 2.2
#
# Added all kinds of robust error checking and reporting. Should be
# easier to diagnose problems from the user end.
#
# New suggested sendmail flag -oi to keep sendmail from ending mail
# input on line containing . only.
#
# Added support for setting the "real" From address in the first line
# of the mail header using the -f sendmail switch. This may or may not
# be what you want, depending on the application of the script. This is
# useful for listservers that use that information for identification
# purposes or whatever. This is NOT useful if you're concerned about
# the security of your script for public usage. Your mileage will vary,
# please read the sendmail manual about the -f switch.
# Thanks to Jeff Lawrence (jlaw@irus.rri.uwo.ca) for figuring this
# one out.
#
########
#
# Doug Stevenson
# doug+@osu.edu
######################
# Configurable options
######################
# whether or not to actually allow mail to be sent -- for testing purposes
$active = 1;
# Logging flag. Logs on POST method when mail is sent.
$logging = 1;
$logfile = '/usr/local/WWW/etc/mailto_log';
# Physical script location. Define ONLY if you wish to make your version
# of this source code available with GET method and the suffix '?source'
# on the url.
$script_loc = '/usr/local/WWW/cgi-bin/mailto.pl';
# physical location of your cgi-lib.pl
$cgi_lib = '/usr/local/WWW/cgi-bin/cgi-lib.pl';
# http script location
$script_http = 'http://www-bprc.mps.ohio-state.edu/cgi-bin/mailto.pl';
# Path to sendmail and its flags. Use the first commented version and
# define $listserver = 1if you want the gateway to be used for listserver
# subscriptions -- the -f switch might be neccesary to get this to work
# correctly.
#
# sendmail options:
# -n no aliasing
# -t read message for "To:"
# -oi don't terminate message on line containing '.' alone
#$sendmail = "/usr/lib/sendmail -t -n -oi -f"; $listserver = 1;
$sendmail = "/usr/lib/sendmail -t -n -oi";
# set to 1 if you want the real addresses to be exposed from %addrs
#$expose_address = 1;
# Uncomment one of the below chunks of code to implement restricted mail
# List of address to allow ONLY - gets put in a HTML SELECT type menu.
#
#%addrs = ("orders", "orders@usaplaza.com",
# "support", "support@mipsdla.com");
# If you don't want the actual mail addresses to be visible by people
# who view source, or you don't want to mess with the source, read them
# from $mailto_addrs:
#
#$mailto_addrs = '/usr/local/WWW/etc/mailto_addrs';
#open(ADDRS,$mailto_addrs);
#while() {
# ($name,$address) = /^(.+)[ \t]+([^ ]+)\n$/;
# $name =~ s/[ \t]*$//;
# $addrs{$name} = $address;
#}
# version
$version = '2.2';
#############################
# end of configurable options
#############################
##########################
# source is self-contained
##########################
if ($ENV{'QUERY_STRING'} eq 'source' && defined($script_loc)) {
print "Content-Type: text/plain\n\n";
open(SOURCE, $script_loc) ||
&InternalError('Could not open file containing source code');
print ;
close(SOURCE);
exit(0);
}
require $cgi_lib;
&ReadParse();
#########################################################################
# method GET implies that we want to be given a FORM to fill out for mail
#########################################################################
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
# try to get as much info as possible for fields
# To: comes from $in{'to'}
# Cc: comes from $in{'cc'}
# From: comes from REMOTE_IDENT@REMOTE_HOST || $in{'from'} || REMOTE_USER
# Subject: comes from $in{'sub'}
# body comes from $in{'body'}
# we don't need no stinking gettin at mips!
# $destaddr = $in{'to'};
# $cc = $in{'cc'};
# $subject = $in{'sub'};
# $body = $in{'body'};
# $nexturl = $in{'nexturl'};
#
# if ($in{'from'}) {
# $fromaddr = $in{'from'};
# }
# # this is for NetScape pre-1.0 beta users - probably obsolete code
# elsif ($ENV{'REMOTE_USER'}) {
# $fromaddr = $ENV{'REMOTE_USER'};
# }
# # this is for Lynx users, or any HTTP/1.0 client giving From header info
# elsif ($ENV{'HTTP_FROM'}) {
# $fromaddr = $ENV{'HTTP_FROM'};
# }
# # if all else fails, make a guess
# else {
# $fromaddr = "$ENV{'REMOTE_IDENT'}\@$ENV{'REMOTE_HOST'}";
# }
#
# # Convert multiple bodies (separated by \0 according to CGI spec)
# # into one big body
# $body =~ s/\0//;
#
# # Make a list of authorized addresses if %addrs exists.
# if (%addrs) {
# $selections = '';
# foreach (sort keys %addrs) {
# if ($in{'to'} eq $addrs{$_}) {
# $selections .= "$_";
# }
# else {
# $selections .= " $_";
# }
# if ($expose_address) {
# $selections .= " <$addrs{$_}>";
# }
# }
# $selections .= " \n";
# }
#
# # give them the form
# print &PrintHeader();
# print <Doug\'s WWW Mail Gateway $version
#
#The WWW Mail Gateway $version
#
#The To : field should contain the full E-mail address
#that you want to mail to. The Your Email : field needs to
#contain your mail address so replies go to the right place. Type your
#message into the text area below. If the To : field is invalid,
#or the mail bounces for some reason, you will receive notification
#if Your Email : is set correctly. If Your Email :
#is set incorrectly, all bounced mail will be sent to the bit bucket.
#
#
#
#
#
#Information about the WWW Mail Gateway
#
#
#
#
#
#Doug Stevenson: doug+\@osu.edu
#
#file: /Techref/language/perl/mailto.pl, 15KB, , updated: 1999/2/20 10:29, local time: 2024/11/19 04:39,
©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE . Questions? <A HREF="http://massmind.org/Techref/language/perl/mailto.pl"> Doug\'s WWW Mail Gateway $version</A>
Did you find what you needed?
.