summaryrefslogtreecommitdiff
path: root/postgresqleu/mailqueue/util.py
diff options
context:
space:
mode:
authorMagnus Hagander2018-12-14 11:43:50 +0000
committerMagnus Hagander2018-12-14 11:43:50 +0000
commit5e8a4a7ab78a9939b21d11094234231bda59567a (patch)
tree9d32974ce783aeecbae020d6391baef4fa376a95 /postgresqleu/mailqueue/util.py
parent5e500d7d55ef048adc1dcf009db42d10c7ad53fc (diff)
Replace tabs with spaces
In an effort to close up with PEP8, we should use spaces for indent rather than tabs... Time to update your editor config!
Diffstat (limited to 'postgresqleu/mailqueue/util.py')
-rw-r--r--postgresqleu/mailqueue/util.py78
1 files changed, 39 insertions, 39 deletions
diff --git a/postgresqleu/mailqueue/util.py b/postgresqleu/mailqueue/util.py
index 93a19d38..3b0ddb57 100644
--- a/postgresqleu/mailqueue/util.py
+++ b/postgresqleu/mailqueue/util.py
@@ -12,50 +12,50 @@ from django.template.loader import get_template
from models import QueuedMail
def template_to_string(templatename, attrs = {}):
- context = {}
- context.update(attrs)
- context.update(settings_context())
- return get_template(templatename).render(context)
+ context = {}
+ context.update(attrs)
+ context.update(settings_context())
+ return get_template(templatename).render(context)
def send_template_mail(sender, receiver, subject, templatename, templateattr={}, attachments=None, bcc=None, sendername=None, receivername=None):
- send_simple_mail(sender, receiver, subject,
- template_to_string(templatename, templateattr),
- attachments, bcc, sendername, receivername)
+ send_simple_mail(sender, receiver, subject,
+ template_to_string(templatename, templateattr),
+ attachments, bcc, sendername, receivername)
def _encoded_email_header(name, email):
- if name:
- return formataddr((str(Header(name, 'utf-8')), email))
- return email
+ if name:
+ return formataddr((str(Header(name, 'utf-8')), email))
+ return email
def send_simple_mail(sender, receiver, subject, msgtxt, attachments=None, bcc=None, sendername=None, receivername=None):
- # attachment format, each is a tuple of (name, mimetype,contents)
- # content should be *binary* and not base64 encoded, since we need to
- # use the base64 routines from the email library to get a properly
- # formatted output message
- msg = MIMEMultipart()
- msg['Subject'] = subject
- msg['To'] = _encoded_email_header(receivername, receiver)
- msg['From'] = _encoded_email_header(sendername, sender)
- msg['Date'] = formatdate(localtime=True)
-
- msg.attach(MIMEText(msgtxt, _charset='utf-8'))
-
- if attachments:
- for filename, contenttype, content in attachments:
- main,sub = contenttype.split('/')
- part = MIMENonMultipart(main,sub)
- part.set_payload(content)
- part.add_header('Content-Disposition', 'attachment; filename="%s"' % filename)
- encoders.encode_base64(part)
- msg.attach(part)
-
-
- # Just write it to the queue, so it will be transactionally rolled back
- QueuedMail(sender=sender, receiver=receiver, fullmsg=msg.as_string()).save()
- # Any bcc is just entered as a separate email
- if bcc:
- QueuedMail(sender=sender, receiver=bcc, fullmsg=msg.as_string()).save()
+ # attachment format, each is a tuple of (name, mimetype,contents)
+ # content should be *binary* and not base64 encoded, since we need to
+ # use the base64 routines from the email library to get a properly
+ # formatted output message
+ msg = MIMEMultipart()
+ msg['Subject'] = subject
+ msg['To'] = _encoded_email_header(receivername, receiver)
+ msg['From'] = _encoded_email_header(sendername, sender)
+ msg['Date'] = formatdate(localtime=True)
+
+ msg.attach(MIMEText(msgtxt, _charset='utf-8'))
+
+ if attachments:
+ for filename, contenttype, content in attachments:
+ main,sub = contenttype.split('/')
+ part = MIMENonMultipart(main,sub)
+ part.set_payload(content)
+ part.add_header('Content-Disposition', 'attachment; filename="%s"' % filename)
+ encoders.encode_base64(part)
+ msg.attach(part)
+
+
+ # Just write it to the queue, so it will be transactionally rolled back
+ QueuedMail(sender=sender, receiver=receiver, fullmsg=msg.as_string()).save()
+ # Any bcc is just entered as a separate email
+ if bcc:
+ QueuedMail(sender=sender, receiver=bcc, fullmsg=msg.as_string()).save()
def send_mail(sender, receiver, fullmsg):
- # Send an email, prepared as the full MIME encoded mail already
- QueuedMail(sender=sender, receiver=receiver, fullmsg=fullmsg).save()
+ # Send an email, prepared as the full MIME encoded mail already
+ QueuedMail(sender=sender, receiver=receiver, fullmsg=fullmsg).save()