Bounce processing

Need some custom code changes to the phpBB core simple enough that you feel doesn't require an extension? Then post your request here so that community members can provide some assistance.

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTE: NO OFFICIAL SUPPORT IS PROVIDED IN THIS SUB-FORUM
Post Reply
lrgrthnlf
Registered User
Posts: 58
Joined: Fri Jun 14, 2002 7:29 am
Location: Melbourne, Australia

Bounce processing

Post by lrgrthnlf » Sun Oct 20, 2019 8:52 am

Not a support thing, just what I do on my site.. figured it might help others..

Code: Select all

#!/bin/bash

pushd /var/log 2>&1 >/dev/null
zgrep -ha ': sender non-delivery notification: ' mail.log* |\
	sed -nre '/^.*\]: [A-Z0-9]*: sender non-delivery notification.*$/ s/^.*\]: (.*): sender non-delivery notification.*$/\1: from=<messageboarduser@example.com>/g p' |\
	sort -u |\
	zegrep -haf - mail.log* |\
	sed -nre '/^.*\](: [A-Z0-9]*: )from=<.*$/ s/^.*\](: [A-Z0-9]*: )from=<.*$/\1to=<.*, dsn=5/g p' |\
	sort -u |\
	zegrep -haf - mail.log* |\
	sed -re 's/^.*: to=<([^>]*)>,.*$/\1/g' -e 's/^.*to=<//g' -e 's/>.*$//g' |\
	sort -u |\
	egrep -va '\s|[/'\''"`,;:]' |\
	xargs echo |\
	sed -re "s/^/('/g" -e "s/ /','/g" -e "s/$/')/g"

popd 2>&1 >/dev/null
... spits out a comma delimited set of email addresses which have had bounces recorded by MTA trying to send from the messageboard's configured address.

Then this generates SQL:

Code: Select all

#!/bin/bash

BOUNCELIST="$(bouncelist)"

buildsql() {
cat<<EOF
USE mbdb;

SELECT pu.user_id as ID, pu.username_clean as Username, pu.user_email as Email, pu.user_rank as Rank, pu.user_allow_pm as PMs, pu.user_notify_pm as PMNotify, pu.user_allow_viewemail as Emails, pu.user_allow_massemail as MassEmail, pu.user_notify_type as NotifyType
	FROM
		users pu
	WHERE
		pu.user_email IN ${BOUNCELIST}
	ORDER BY
		pu.username_clean;

DELETE ptw
	FROM topics_watch ptw
	INNER JOIN
		users pu ON ptw.user_id=pu.user_id
	WHERE
		pu.user_rank=5 AND
		pu.user_allow_viewemail=0 AND
		pu.user_allow_pm=1 AND
		pu.user_email IN ${BOUNCELIST};

DELETE pfw
	FROM forums_watch pfw
	INNER JOIN
		users pu ON pfw.user_id=pu.user_id
	WHERE
		pu.user_rank=5 AND
		pu.user_allow_viewemail=0 AND
		pu.user_allow_pm=1 AND
		pu.user_email IN ${BOUNCELIST};

UPDATE users pu
	SET
		pu.user_allow_pm=1,
		pu.user_allow_viewemail=0
	WHERE
		pu.user_rank=5 AND
		pu.user_email IN ${BOUNCELIST};

UPDATE users pu
	SET
		pu.user_rank=5,
		pu.user_notify_pm=0,
		pu.user_allow_massemail=0
	WHERE
		pu.user_email IN ${BOUNCELIST};
EOF
}

buildsql
... it's a bit grotty.. but basically it progressively removes email generating options from profiles when it sees bounces in MTA logs. Has helped to cut back the amount of "mailbox unavailable", "you have been blocked" messages, and along with DKIM and SPF reduced the amount of times I get detected as spam sending standard notifications.

I'm open to feedback on it.

Post Reply

Return to “phpBB Custom Coding”