2 ################################################################################
4 # File: NotifyTrigger.pl,v
6 # Description: This script is a generalized notify trigger. It takes one
7 # parameter, a message file. The format of this file is similar
8 # to an email message. Environment variables will be substituted.
10 # This trigger is typically added, perhaps multiple times with
11 # different message files, then attached to elements in the vob
12 # as needed. Make the trigger with:
14 # cleartool mktrtype -element -postop checkin \
16 # -exec "<perl> <path_to_trigger>/NotifyTrigger.pl \
17 # <msg file>" <TRIGGER_NAME>
19 # Assumptions: Clearprompt is in the users PATH
20 # Author: Andrew@DeFaria.com
21 # Created: Tue Mar 12 15:42:55 2002
22 # Modified: 2007/05/17 07:45:48
25 # (c) Copyright 2004, Andrew@DeFaria.com, all rights reserved
27 ################################################################################
34 # Define mailhost here (or set in the environment)
35 my $mailhost = defined $ENV {MAILHOST} ? $ENV {MAILHOST} : undef;
37 # This will be set in the BEGIN block but by putting them here the become
38 # available for the whole script.
48 # Extract relative path and basename from script name.
49 $0 =~ /(.*)[\/\\](.*)/;
51 $abs_path = (!defined $1) ? "." : File::Spec->rel2abs ($1);
52 $me = (!defined $2) ? $0 : $2;
55 $lib_path = "$abs_path/../lib";
56 $log_path = "$abs_path/../log";
57 $triggers_path = "$abs_path/../triggers";
59 # Add the appropriate path to our modules to @INC array.
60 unshift (@INC, "$lib_path");
65 # This routine will replace references to environment variables. If an
66 # environment variable is not defined then the string <Unknown> is
71 while ($line =~ /\$(\w+)/) {
73 if ($ENV{$var} eq "") {
74 $line =~ s/\$$var/\<Unknown\>/;
76 my $value = $ENV{$var};
78 $line =~ s/\$$var/$value/;
93 # First open the message file. If we can't then there's a problem, die!
94 my $msgfile = "$triggers_path/$ARGV[0]";
96 or error "Unable to open message file:\n\n$msgfile\n\n($!)";
101 # Connect to mail server
102 error "Mailhost is not defined!" if !defined $mailhost;
103 my $smtp = Net::SMTP->new ($mailhost);
105 error "Unable to open connection to mail host: $mailhost" if $smtp == undef;
111 my ($line, $from, $to, @addresses);
113 foreach $line (@lines) {
114 next if $line =~ /^\#/;
115 next if $line =~ /--/;
117 $line = ReplaceText $line;
119 if ($line =~ /^From:\s+/) {
128 if ($line =~ /^To:\s+/) {
132 @addresses = split (/,|;| /);
134 foreach (@addresses) {
141 if ($data_sent eq "F") {
143 $smtp->datasend ($from);
144 $smtp->datasend ($to);
148 if ($from_seen eq "T" && $to_seen eq "T" && $data_sent eq "T") {
149 $smtp->datasend ($line);
151 clearlogmsg "Message file ($ARGV[0]) missing From and/or To!";