2 ################################################################################
5 # Description: This script is a generalized notify trigger. It takes one
6 # parameter, a message file. The format of this file is similar
7 # to an email message. Environment variables will be substituted.
9 # This trigger is typically added, perhaps multiple times with
10 # different message files, then attached to elements in the vob
11 # as needed. Make the trigger with:
13 # cleartool mktrtype -element -postop checkin \
15 # -exec "<perl> <path_to_trigger>/Notify.pl \
16 # <msg file>" <TRIGGER_NAME>
18 # Assumptions: Clearprompt is in the users PATH
19 # Author: Andrew@DeFaria.com
20 # Created: Tue Mar 12 15:42:55 2002
24 # (c) Copyright 2004, Andrew@DeFaria.com, all rights reserved
26 ################################################################################
32 my $mailhost = "smtphost";
34 # This will be set in the BEGIN block but by putting them here the become
35 # available for the whole script.
45 # Extract relative path and basename from script name.
46 $0 =~ /(.*)[\/\\](.*)/;
48 $abs_path = (!defined $1) ? "." : File::Spec->rel2abs ($1);
49 $me = (!defined $2) ? $0 : $2;
52 $lib_path = "$abs_path/../lib";
53 $triggers_path = "$abs_path/../triggers";
54 $msgfiles_path = "$abs_path/../msgs";
56 # Add the appropriate path to our modules to @INC array.
57 unshift (@INC, "$lib_path");
62 # This routine will replace references to environment variables. If an
63 # environment variable is not defined then the string <Unknown> is
68 while ($line =~ /\$(\w+)/) {
70 if ($ENV{$var} eq "") {
71 $line =~ s/\$$var/\<Unknown\>/;
73 my $value = $ENV{$var};
75 $line =~ s/\$$var/$value/;
90 # First open the message file. If we can't then there's a problem, die!
91 my $msgfile = "$msgfiles_path/$ARGV[0]";
93 or error "Unable to open message file:\n\n$msgfile\n\n($!)";
98 # Connect to mail server
99 my $smtp = Net::SMTP->new ($mailhost);
101 error "Unable to open connection to mail host: $mailhost" if $smtp == undef;
107 my ($line, $from, $to, @addresses);
109 foreach $line (@lines) {
110 next if $line =~ /^\#/;
111 next if $line =~ /--/;
113 $line = ReplaceText $line;
115 if ($line =~ /^From:\s+/) {
124 if ($line =~ /^To:\s+/) {
128 @addresses = split (/,|;| /);
130 foreach (@addresses) {
137 if ($data_sent eq "F") {
139 $smtp->datasend ($from);
140 $smtp->datasend ($to);
144 if ($from_seen eq "T" && $to_seen eq "T" && $data_sent eq "T") {
145 $smtp->datasend ($line);
147 clearlogmsg "Message file ($ARGV[0]) missing From and/or To!";