Skip to content

Commit

Permalink
Merge pull request #44 from kelockhart/single-bounce
Browse files Browse the repository at this point in the history
Added flag to disable emails for user-input email addresses
  • Loading branch information
kelockhart committed May 22, 2024
2 parents 8b3ebb7 + d75d41c commit ea891bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python_actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: |
py.test
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v4
with:
name: coverage-myads
path: .coverage
Expand Down
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 ea891bf

Please sign in to comment.