Skip to content

Commit

Permalink
Added flag to disable emails for user-input email addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
kelockhart committed May 22, 2024
1 parent 8b3ebb7 commit e2192aa
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ def notifications_status_update(user_emails=None, active=False):
dest='user_emails',
action='store',
default=None,
help='Comma delimited list of user emails to run myADS notifications for')
help='Comma delimited list of user emails to process')

parser.add_argument('-d',
'--daily',
Expand Down Expand Up @@ -558,16 +558,19 @@ def notifications_status_update(user_emails=None, active=False):
sys.exit(1)

if args.bounceback_disable:
bounceback_email_file = os.path.join(config.get('BOUNCEBACK_EMAIL_DIR'), 'myADS.bounces.emails')
bounceback_emails = []
try:
with open(bounceback_email_file, 'rt') as flist:
for l in flist.readlines():
bounceback_emails.append(l.strip())
except IOError:
logger.warning('Bounceback email file not found. Exiting.')
# exit with error
sys.exit(1)
if args.user_emails:
bounceback_emails = args.user_emails
else:
bounceback_email_file = os.path.join(config.get('BOUNCEBACK_EMAIL_DIR'), 'myADS.bounces.emails')
bounceback_emails = []
try:
with open(bounceback_email_file, 'rt') as flist:
for l in flist.readlines():
bounceback_emails.append(l.strip())
except IOError:
logger.warning('Bounceback email file not found. Exiting.')
# exit with error
sys.exit(1)

if bounceback_emails:
disabled_dict = notifications_status_update(user_emails=bounceback_emails, active=False)
Expand All @@ -577,9 +580,10 @@ def notifications_status_update(user_emails=None, active=False):
# note: we're ignoring failed disabling from here on - there's a possibility that this email address is
# dead, so we can ignore. If it's not dead, then it'll just show back up in the bounceback file next time
# and we can try it again then
old_file = os.path.join(config.get('BOUNCEBACK_EMAIL_DIR'),
'myADS.bounces.emails' + '.' + get_date().strftime('%Y%m%d'))
os.rename(bounceback_email_file, old_file)
if not args.user_emails:
old_file = os.path.join(config.get('BOUNCEBACK_EMAIL_DIR'),
'myADS.bounces.emails' + '.' + get_date().strftime('%Y%m%d'))
os.rename(bounceback_email_file, old_file)
else:
logger.info('No bounceback emails to process; exiting.')
# exit without error
Expand Down

0 comments on commit e2192aa

Please sign in to comment.