# perl script to send am e-mail when delivery complets

use strict;
use warnings;
use SendMail 2.09;
use lib qw(/home/ccvob01/irf/lib);
my $CT="/usr/atria/bin/cleartool";
my $CT1="cleartool";
my $os=$^O;
my @files;
if ($os eq "solaris")
{
print "$ENV{CLEARCASE_ACTIVITY}\n";
chomp($ENV{CLEARCASE_ACTIVITY});
@files = `$CT desc -fmt "%[versions]p\n" activity:$ENV{"CLEARCASE_ACTIVITY"}`;
chomp(@files);
print "@files\n";
for (@files) {
    print $_,"\n";
}

sendmail();
}
else
{
print "$os\n";
print "$ENV{CLEARCASE_ACTIVITY}\n";
chomp($ENV{CLEARCASE_ACTIVITY});
@files = `$CT1 desc -fmt "%[versions]p\n" activity:$ENV{"CLEARCASE_ACTIVITY"}`;
chomp(@files);
print "@files\n";
for (@files) {
    print $_,"\n";
}
sendmail();
}

sub sendmail
{
my $sm = new SendMail("si0003avexu1.global.avaya.com");
# We set the debug mode "ON".
#
 $sm->setDebug($sm->ON);
 my $CT = "/usr/atria/bin/cleartool";

$sm->From("CC VOB Admin -Pune <ccvob01\@puvob01.apac.avaya.com>");

# We set the subject.
#
$sm->Subject("Delivery has been completed successfully");

#
# We set the recipient.
#
#$sm->To("$usr");
$sm->To("isayed\@avaya.com");
#$sm->To("Smita <sgadkari\@in.ibm.com>");

#
# We set the content of the mail.
#
$sm->setMailBody ("This is an auto generated mail.PLease reply to pune-rdps-scm\@list.avaya.com\n\nHi,\n\n Following is the entire description for the delivery.\n\n UCM Project: $ENV{CLEARCASE_PROJECT}\n UCM source stream: $ENV{CLEARCASE_SRC_STREAM}\nUCM destination stream:$ENV{CLEARCASE_STREAM}\nUCM integration activity: $ENV{CLEARCASE_ACTIVITY}\nUCM activities delivered: $ENV{CLEARCASE_DLVR_ACTS}\nUCM view: $ENV{CLEARCASE_VIEW_TAG}\n\n Following files got delivered in this operation \n\n @files\n\n Thank You \n Pune RDPS SCM Team"); 
#
# Attach a testing image.
#
#$sm->Attach("/tmp/lsco_log");
#$sm->Attach("/tmp/lsco_log1");
#
# Check if the mail sent successfully or not.
#
if ($sm->sendMail() != 0) {
  print $sm->{'error'}."\n";
  exit -1;
}

#
# Mail sent successfully.
#
print "Done\n\n";
#exit 0;
}

