home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CLIX - Fazer Clix Custa Nix
/
CLIX-CD.cdr
/
mac
/
lib
/
LWP
/
Protocol
/
mailto.pm
< prev
next >
Wrap
Text File
|
1997-11-18
|
2KB
|
101 lines
#
# $Id: mailto.pm,v 1.1 1997/11/18 00:33:21 neeri Exp $
#
# This module implements the mailto protocol. It is just a simple
# frontend to the Unix sendmail program. In the long run this module
# will built using the Mail::Send module.
package LWP::Protocol::mailto;
require LWP::Protocol;
require HTTP::Request;
require HTTP::Response;
require HTTP::Status;
use Carp;
@ISA = qw(LWP::Protocol);
sub request
{
my($self, $request, $proxy, $arg, $size) = @_;
my @text = ();
# check proxy
if (defined $proxy)
{
return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
'You can not proxy with mail';
}
# check method
$method = $request->method;
if ($method ne 'POST') {
return new HTTP::Response &HTTP::Status::RC_BAD_REQUEST,
'Library does not allow method ' .
"$method for 'mailto:' URLs";
}
# check url
my $url = $request->url;
my $scheme = $url->scheme;
if ($scheme ne 'mailto') {
return new HTTP::Response &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
"LWP::file::request called for '$scheme'";
}
eval {
require Mail::Internet;
};
if($@) {
return new HTTP::Response &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
"You don't have MailTools installed";
}
unless ($ENV{SMTPHOSTS}) {
return new HTTP::Response &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
"You don't have SMTPHOSTS defined";
}
my $mail = Mail::Internet->new or
return new HTTP::Response &HTTP::Status::RC_INTERNAL_SERVER_ERROR,
"Can't get a Mail::Internet object $!";
my $addr = $url->encoded822addr;
$mail->add(To => $addr);
$mail->add(split(/[:\n]/,$request->headers_as_string));
my $content = $request->content;
if (defined $content) {
my $contRef = ref($content) ? $content : \$content;
if (ref($contRef) eq 'SCALAR') {
@text = split("\n",$$contRef);
foreach (@text) {
$_ .= "\n";
}
} elsif (ref($contRef) eq 'CODE') {
# Callback provides data
my $d;
my $stuff = "";
while (length($d = &$contRef)) {
$stuff .= $d;
}
@text = split("\n",$stuff);
foreach (@text) {
$_ .= "\n";
}
}
}
$mail->body(\@text);
$mail->smtpsend;
my $response = new HTTP::Response &HTTP::Status::RC_ACCEPTED,
'Mail accepted by sendmail';
$response->header('Content-Type', 'text/plain');
$response->content("Mail sent to <$addr>\n");
return $response;
}
1;