#!/usr/bin/perl ################################################################################ # # File: $RCSfile: MAPSDeliver,v $ # Revision: $Revision: 1.1 $ # Description: This script simply delivers the mail. It is separated out so # it can be the only portion that is setgid to the group mail # for the purposes of being able to deliver the mail to the users # maildrop # Author: Andrew@DeFaria.com # Created: Fri Nov 29 14:17:21 2002 # Modified: $Date: 2013/06/12 14:05:47 $ # Language: perl # # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved. # ################################################################################ use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; use lib "$FindBin::Bin/../../lib"; use MAPSFile; use MAPS; use MAPSLog; sub DeliverMail($$) { my ($userid, $msgfileName) = @_; # Open maildrop file open my $maildrop, '>>', "/var/mail/$userid" or return "Unable to open maildrop file (/var/mail/$userid): $!"; # Open msgfile open my $msgfile, '<', $msgfileName or return "Unable to open msgfile ($msgfileName): $!"; # Lock file Lock $maildrop; # Write msgfile -> $maildrop print $maildrop "\n\n"; print $maildrop $_ while (<$msgfile>); # Unlock the file Unlock $maildrop; # Close files close $maildrop; close $msgfile; return; } # DeliverMail # Main my ($userid, $msgfile) = @ARGV; die 'User id not specified' unless $userid; die 'Msgfile not specified' unless $msgfile; my $errmsg = DeliverMail($userid, $msgfile); if ($errmsg) { #OpenDB('maps', 'spam'); SetContext($userid); Error( userid => $userid, message => $errmsg, ); exit 1; } # if exit 0;