Added Alt-n and Alt-p accesskeys
[clearscm.git] / maps / bin / MAPSDeliver
1 #!/usr/bin/perl
2 ################################################################################
3 #
4 # File:         $RCSfile: MAPSDeliver,v $
5 # Revision:     $Revision: 1.1 $
6 # Description:  This script simply delivers the mail. It is separated out so
7 #               it can be the only portion that is setgid to the group mail
8 #               for the purposes of being able to deliver the mail to the users
9 #               maildrop
10 # Author:       Andrew@DeFaria.com
11 # Created:      Fri Nov 29 14:17:21  2002
12 # Modified:     $Date: 2013/06/12 14:05:47 $
13 # Language:     perl
14 #
15 # (c) Copyright 2000-2006, Andrew@DeFaria.com, all rights reserved.
16 #
17 ################################################################################
18 use strict;
19 use warnings;
20
21 use English;
22 use FindBin;
23
24 # Untaint $FindBin::Bin
25 my $lib;
26
27 BEGIN {
28   if ($FindBin::Bin =~ /^(.*)$/) {
29     $lib = $1;
30   } # if
31 } # BEGIN
32
33 use lib $lib;
34
35 use MAPSFile;
36 use MAPSDB;
37 use MAPSLog;
38
39 sub DeliverMail ($$) {
40   my ($userid, $msgfileName) = @_;
41
42   # Switch to group mail
43   $EGID = getgrnam "mail";
44
45   # Untaint $userid
46   if ($userid =~ /^([-\@\w.]+)$/) {
47     $userid = $1;
48   } # if
49
50   # Open maildrop file
51   open my $maildrop, '>>', "/var/mail/$userid"
52     or return "Unable to open maildrop file (/var/mail/$userid): $!";
53
54   # Open msgfile
55   open my $msgfile, '<', $msgfileName
56     or return "Unable to open msgfile ($msgfileName): $!";
57
58   # Lock file
59   Lock $maildrop;
60
61   # Write msgfile -> $maildrop
62   print $maildrop "\n";
63   print $maildrop $_
64     while (<$msgfile>);
65
66   # Unlock the file
67   Unlock $maildrop;
68
69   # Close files
70   close $maildrop;
71   close $msgfile;
72
73   return;
74 } # DeliverMail
75
76 # Main
77 die 'User id not specified' unless $ARGV [0];
78 die 'Msgfile not specified' unless $ARGV [1];
79
80 my $userid  = shift @ARGV;
81 my $msgfile = shift @ARGV;
82
83 my $err  = DeliverMail $userid, $msgfile;
84
85 if ($err) {
86   OpenDB 'mapsadmin', 'mapsadmin';
87
88   MAPSDB::SetContext $userid;
89
90   Error $err;
91 } # if
92
93 exit 1 if $err;
94 exit 0;