* Fix an off-by-one error when splitting an email in headers and body.
[matthijs/projects/xerxes.git] / tools / notify.py
index 4530255510787754beaaaa670aad191e4aa2fab8..8dca1ba081ae551f70da5ddee9633fefecc436be 100644 (file)
@@ -23,7 +23,7 @@ def notify(recipients, template, context = {}):
     context['addresses'] = addresses 
 
     rendered = loader.render_to_string(template, context)
-    (headers, body) = rendered.split('\n\n', 2)
+    (headers, body) = rendered.split('\n\n', 1)
 
     # Turn the headers into a dict so EmailMessage can turn them into a
     # string again. Bit pointless, but it works. 
@@ -36,14 +36,20 @@ def notify(recipients, template, context = {}):
     from_email = None
     for header in headers.split('\n'):
         (field, value) = header.split(':')
-        headers_dict[field] = value
         if (field == 'From'):
             from_email = value
+        elif (field == 'Subject'):
+            subject = value
+        else:
+            # Don't put From and Subject in the dict, else they'll be
+            # present twice.
+            headers_dict[field] = value
 
     msg = EmailMessage(
         # Only setting the From address through headers won't set the
         # envelope address right.
         from_email = from_email,
+        subject    = subject,
         body       = body, 
         to         = addresses, 
         headers    = headers_dict