def unsubscribe(): email = request.args.get("email") if not email or not re.match( r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", email): return gettext('Please enter a valid email address') try: mailing_list.unsubscribe(email) mailing_list.unsubscribe_sendgrid_contact(email) feedback = gettext('You have been unsubscribed') except Exception as err: log('Failure: %s' % err) feedback = gettext('Ooops, something went wrong') flash(feedback) return redirect('/en/', code=302)
def process_batch(emails, update_sg, update_db, do_it): if not len(emails): return True print('%s mode. Unsubscribing %s Update SG=%s Update DB=%s' % ('Prod' if do_it else 'Dry-run', emails, update_sg, update_db)) if not do_it: return True try: if update_sg: # Call SendGrid to remove the emails from all mailing lists. mailing_list.mass_unsubscribe_sendgrid_contact(emails) if update_db: # Set the 'unsubscribed' flag on the email_list table. for email in emails: mailing_list.unsubscribe(email) except Exception as e: print('ERROR process_batch:', type(e), e) traceback.print_exc() return False return True
def unsubscribe(): email = request.args.get("email") feedback = mailing_list.unsubscribe(email) flash(feedback) return redirect('/', code=302)