PATH=/bin:$PATH
TMP=/tmp1/conv.$$
SENDER="root@ids-mannheim.de"

cat > $TMP

if grep "Subject: aliases$" $TMP > /dev/null
        then	TMP1=/etc/mail/relay-aliases
        	TMP2=/etc/mail/aliases.txt
                sed '
                        1,/^$/d
                        /^ *$/d
                        /^#/d
                        /@admin\./d
                        s|:.*||
                        /^majordomo/d
			/ids-aktuell-liste/d
                        /-alle$/d
                        /-hiwi$/d
                        /-approval/d
                        /-mitarbeiter/d
                        /-archiv$/d
                        /-owner$/d
			/-stock-/d
                        /^alle$/d
                        /^hiwi$/d
			/^fi$/d
			/^fi-forsch/d
                        /^mitarbeiter-/d
                        /-mitarbeiter/d
                        /^mitarbeiter$/d
			/^printer-/d
                        /^idstest$/d
                        /^maus$/d
                        /^maus-announce/d
                        /^stock-/d
                        /^tech$/d
                        /^zdv-tech$/d
                     ' $TMP | sort > $TMP1

		/usr/bin/php -f /usr/local/bin/mail.php |

                sed '
			$r /etc/mail/aliases.rest
                        /^ *$/d
                        /@admin\./d
                        s|:.*||
                        /^majordomo/d
			/ids-aktuell-liste/d
                        /-alle$/d
                        /-hiwi$/d
                        /-approval/d
                        /-mitarbeiter/d
                        /-archiv$/d
                        /-owner$/d
			/-stock-/d
			/^fi$/d
			/^fi-forsch/d
                        /^alle$/d
                        /^hiwi$/d
                        /^mitarbeiter-/d
                        /-mitarbeiter/d
                        /^mitarbeiter$/d
			/^printer-/d
                        /^idstest$/d
                        /^maus$/d
                        /^maus-announce/d
                        /^stock-/d
                        /^tech$/d
                        /^zdv-tech$/d
                     ' | sort > $TMP2

elif grep "Subject: assign$" $TMP > /dev/null

	then	> /tmp1/relay-accounts

		for i in `ldapsearch -h ldap.ids-mannheim.de -xD "cn=casanova,dc=ids-mannheim,dc=de" -b ou=internal,dc=ids-mannheim,dc=de -w giorefi09 "(&(uid=*)(objectClass=idsStaff))" -LLL mail | grep "mail:"`
		do
			if `echo $i | grep "\.ids-mannheim\.de" > /dev/null`
				then	echo $i | cut -d: -f2 | cut -d'@' -f1 >> /tmp1/relay-accounts
			fi
		done

		for i in hosts dueck fuerbacher kunz schmadel westpfahl
		do
			echo $i >> /tmp1/relay-accounts
		done

		grep -v "^ *$" /tmp1/relay-accounts | sort -u -o /etc/mail/relay-accounts

fi

rm $TMP
