Script question: Integrating SpamAssassin and GroupWise

This is something that I had running, but had to revise because of upgrades. Basically I want to send off incoming mail in GroupWise 2018 to SpamAssassin for analysis.

In GW this is relatively easy, you define a third-party dir and then what you need to do is to have a process that does this:

A) Move files from the \send directory to the \third\send directory.
2) Move files from the \third\recieve directory to the \receive directory.
And
C) Move files from the \third\results directory to the \results directory.

An added twist is that the received files have a preamble that needs to be removed and put back after processing by sa.

I intitially did this as a script that was kicked off by cron every 2 minutes, but would using the watch command be a bette choice, ie watch -n 30 myscript.sh

I have added the script below. Feel free to suggest improvements or to shoot it down in flames. Bash is not my programming language of choice :slight_smile:

[CODE]#!/bin/bash
INFILES=/media/nss/GWVOL/gw/gw6dom/wpgate/gwia/third/receive/*
TMPFILES=/tmp/sa/
OUTFILES=/media/nss/GWVOL/gw/gw6dom/wpgate/gwia/receive/
SENDIN=/media/nss/GWVOL/gw/gw6dom/wpgate/gwia/send/*
SENDOUT=/media/nss/GWVOL/gw/gw6dom/wpgate/gwia/third/send/
RESULTSIN=/media/nss/GWVOL/gw/gw6dom/wpgate/gwia/third/results/*
RESULTSOUT=/media/nss/GWVOL/gw/gw6dom/wpgate/gwia/results/

This makes an empty dir return nothing, instead of ‘*’

shopt -s nullglob
date +%Y-%m-%d_%H:%M:%S

for f in $INFILES
do
echo “Processing $f file…”

take action on each file. $f store current file name

get basename for temp files

fbname=$(basename “$f” | cut -d. -f1) (without ext)

fbname=$(basename “$f”)

Make a copy

cp $f $TMPFILES$fbname

Make a copy for GW XML header

sed -n -e ‘//,/<\/IaHead>/p’ $f > $TMPFILES$fbname.IaHead

Make a copy of SMTP stuff. Needs to be a case-insesitive match.

sed -n -e ‘/^MAIL FROM:/Ip’ $f > $TMPFILES$fbname.gwstuff
sed -n -e ‘/^RCPT TO:/Ip’ $f >> $TMPFILES$fbname.gwstuff

Make temp file with SMTP stuff removed

sed -e ‘/^RCPT TO:/I d’ $f > $TMPFILES$fbname.tmp
sed -e ‘/^MAIL FROM:/I d’ $TMPFILES$fbname.tmp > $TMPFILES$fbname.tmp2

Make a temp file with GW XML removed

sed -e ‘//,/<\/IaHead>/ d’ $TMPFILES$fbname.tmp2 > $TMPFILES$fbname.tmp3
spamassassin --cf “rewrite_header Subject SPAM(SCORE)” < $TMPFILES$fbname.tmp3 > $TMPFILES$fbname.tmp4
cat $TMPFILES$fbname.IaHead $TMPFILES$fbname.gwstuff $TMPFILES$fbname.tmp4 > $TMPFILES$fbname.tmp5

Push file to GW

echo “copying file”

echo “cp $TMPFILES$fbname.tmp5 $OUTFILES$fbname”

cp $TMPFILES$fbname.tmp5 $OUTFILES$fbname
echo “Removing $f file…”
rm $f
echo “Removing temporary files…”
rm $TMPFILES$fbname.tmp5
rm $TMPFILES$fbname.tmp4
rm $TMPFILES$fbname.tmp3
rm $TMPFILES$fbname.tmp2
rm $TMPFILES$fbname.tmp
rm $TMPFILES$fbname.gwstuff
rm $TMPFILES$fbname.IaHead
done

Take care of outgoing

for f in $SENDIN
do
echo “Moving send file $f …”
fbname=$(basename “$f”)
mv $f $SENDOUT$fbname
done

Take care of results

for f in $RESULTSIN
do
echo “Moving send file $f …”
fbname=$(basename “$f”)
mv $f $RESULTSOUT$fbname
done[/CODE]

Wow, this is an oldie - I haven’t touched GroupWise in nearly 15 years :confused:

I see what you’re trying to do; two comments come to mind. First, a BASH style item - I suggest you get in the habit of enclosing your variable names in curly braces. For example:
mv ${f} ${RESULTSOUT}${fbname}
The second has more to do with architecture. Back nearly 15 years ago, I wanted to do something similar with GroupWise v6,5. I put a SLES 9 (or maybe it was SLES 10) host in front of GroupWise and ran MIMEdefang mimedefang.org, which among many other Anti-SPAM capabilities also gave me a way to submit inbound E-mail to SpamAssassin. With MIMEdefang I made sure that inbound E-mail complied with RFCs, to help blunt attacks that relied on malformed E-mails.

I don’t know if that idea helps, but it could end up being easier than trying to integrate SA with GWIA. I always thought they should have made GWIA a Sendmail Mailer. It would have opened up a lot of possible 3rd party integrations.