Skip to content

Commit

Permalink
Fix plain redirect subjects (#3209)
Browse files Browse the repository at this point in the history
* remove references to ESP, use name from settings

* check if email code exists (for plainredirects or aliases)(cherry picked from commit e606e25)
  • Loading branch information
milescalabresi committed Feb 18, 2021
1 parent 60c3c1e commit 8f93fa5
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions esp/mailgates/mailgate.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python

# Main mailgate for ESP.
# Main mailgate
# Handles incoming messages etc.

import sys, os, email, re, smtplib, socket, sha, random
Expand All @@ -10,13 +10,13 @@
os.environ['DJANGO_SETTINGS_MODULE'] = 'esp.settings'

import logging
# Make sure we end up in our logger even though this file is outside esp
# Make sure we end up in our logger even though this file is outside esp/esp/
logger = logging.getLogger('esp.mailgate')

import os.path
project = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

# Path for ESP code
# Path for site code
sys.path.insert(0, project)

# Check if a virtualenv has been installed and activated from elsewhere.
Expand All @@ -39,12 +39,11 @@
server = smtplib.SMTP('localhost')
ARCHIVE = settings.DEFAULT_EMAIL_ADDRESSES['archive']
SUPPORT = settings.DEFAULT_EMAIL_ADDRESSES['support']
ORGANIZATION_NAME = settings.INSTITUTION_NAME + '_' + settings.ORGANIZATION_SHORT_NAME

DEBUG=True
#DEBUG=True
DEBUG=False

#os.environ['LOCAL_PART'] = 'axiak'

user = "UNKNOWN USER"

def send_mail(message):
Expand Down Expand Up @@ -89,7 +88,7 @@ def send_mail(message):

subject = message['subject']
del(message['subject'])
if instance.emailcode:
if hasattr(instance, 'emailcode') and instance.emailcode:
subject = '[%s] %s' % (instance.emailcode, subject)
if handler.subject_prefix:
subject = '[%s] %s' % (handler.subject_prefix, subject)
Expand Down Expand Up @@ -129,15 +128,12 @@ def send_mail(message):
else:
logger.warning("Couldn't find user '%s'", user)
print """
ESP MAIL SERVER
%s MAIL SERVER
===============
Could not find user "%s"
If you are experiencing difficulty, please email %s.
-Educational Studies Program
""" % (user, SUPPORT)
""" % (ORGANIZATION_NAME, user, SUPPORT)
sys.exit(1)

0 comments on commit 8f93fa5

Please sign in to comment.