# -*-Perl-*- 
#######################################################################
# This software has been created by Genome Research Limited (GRL).    # 
# GRL hereby grants permission to use, copy, modify and distribute    # 
# this software and its documentation for non-commercial purposes     # 
# without fee at the user's own risk on the basis set out below.      #
# GRL neither undertakes nor accepts any duty whether contractual or  # 
# otherwise in connection with the software, its use or the use of    # 
# any derivative, and makes no representations or warranties, express #
# or implied, concerning the software, its suitability, fitness for   #
# a particular purpose or non-infringement.                           #
# In no event shall the authors of the software or GRL be responsible # 
# or liable for any loss or damage whatsoever arising in any way      # 
# directly or indirectly out of the use of this software or its       # 
# derivatives, even if advised of the possibility of such damage.     #
# Our software can be freely distributed under the conditions set out # 
# above, and must contain this copyright notice.                      #
#######################################################################
# 
# Mail
#      - tools for sending mail. 
# 
# 
# $Id: Mail.pm,v 1.7 1998/01/20 15:38:08 as1 Exp $
#
# $Log: Mail.pm,v $
# Revision 1.7  1998/01/20  15:38:08  as1
# Added a newline before message, this is because if a body of text
# starts with capital letter and followed by a colon it is interpreted
# as part of the header.
#
# Revision 1.6  1998/01/19  09:55:59  as1
# Added primitive documentation (usage:)
#
# Revision 1.5  1997/04/28  08:45:05  dn1
# moved copyright
#
# Revision 1.4  1997/04/24  10:24:07  dn1
# Added copyright
#
# Revision 1.3  1996/06/07  11:08:38  dmh
# Removes single quotes in message bodies.
#
# Revision 1.2  1996/05/28  15:01:01  dmh
# No change - fiddliing with RCS
#
# Revision 1.1  1996/05/28  14:58:52  dmh
# Initial revision
#
#
#
#
#######################################################################
# This software has been created by Genome Research Limited (GRL).    # 
# GRL hereby grants permission to use, copy, modify and distribute    # 
# this software and its documentation for non-commercial purposes     # 
# without fee at the user's own risk on the basis set out below.      #
# GRL neither undertakes nor accepts any duty whether contractual or  # 
# otherwise in connection with the software, its use or the use of    # 
# any derivative, and makes no representations or warranties, express #
# or implied, concerning the software, its suitability, fitness for   #
# a particular purpose or non-infringement.                           #
# In no event shall the authors of the software or GRL be responsible # 
# or liable for any loss or damage whatsoever arising in any way      # 
# directly or indirectly out of the use of this software or its       # 
# derivatives, even if advised of the possibility of such damage.     #
# Our software can be freely distributed under the conditions set out # 
# above, and must contain this copyright notice.                      #
#######################################################################

#
# Example of usage:
#
# 	use Mail;
#
#	Mail::sendMail(-to => as1, -subject => hello, -message => message);

package Mail;


sub sendMail {

    my %args = @_;

    my $error_ref = $args{'-errors'} || undef;
    
    my $recipient;
    unless($recipient = $args{'-to'}) {
	$$error_ref .=  "No recipient defined via \'-to\' in Mail::sendMail\n" if defined $error_ref;
	return 1;
    }

    my $subject = $args{'-subject'} || 'No Subject';
    my $message = $args{'-message'} || 'No Message';

    $message = "Subject: $subject\nTo: $recipient\n\n$message\n";
    $message =~ s/\'//g; # Single quotes screw things up.

    system ("echo '$message' | mail $recipient");

    if ($?) {
	$$error_ref .=  "Error forking mail program\n" if defined $error_ref;
	return 1;

    }

    0;

}



1;
