]> git.ipfire.org Git - ipfire.org.git/commitdiff
messages: Do not manually pass recipients any more
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 16 Jan 2020 09:47:13 +0000 (09:47 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 16 Jan 2020 09:47:13 +0000 (09:47 +0000)
They are not put into the email and read back from there.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/accounts.py
src/backend/messages.py

index 8eababbd144b0565b469381d37b4d273b2f0b17c..e3405cdae97fcfed3aa7b9121d8aecb0caa5ece3 100644 (file)
@@ -452,8 +452,7 @@ class Accounts(Object):
 
                # Send an account activation email
                self.backend.messages.send_template("auth/messages/register",
-                       recipients=[email], priority=100, uid=uid,
-                       activation_code=activation_code, email=email,
+                       priority=100, uid=uid, activation_code=activation_code, email=email,
                        first_name=first_name, last_name=last_name)
 
        def activate(self, uid, activation_code):
@@ -751,7 +750,7 @@ class Account(LDAPObject):
 
                # Send a password reset email
                self.backend.messages.send_template("auth/messages/password-reset",
-                       recipients=[self.email], priority=100, account=self, reset_code=reset_code)
+                       priority=100, account=self, reset_code=reset_code)
 
        def reset_password(self, reset_code, new_password):
                # Delete the reset token
index 1a89d2329e111425d85b3d8629891f38c96e7d65..7f06e47bde0acae5cbbf6df2f9956e9225f642a0 100644 (file)
@@ -48,19 +48,13 @@ class Messages(misc.Object):
        def bounce_email_address(self):
                return self.settings.get("bounce_email_address")
 
-       def _send(self, recipients, message, sender=None, priority=0):
-               if not recipients:
-                       raise ValueError("Empty list of recipients")
-
-               # Format recipients
-               recipients = [self.make_recipient(r) for r in recipients]
-
-               res = self.db.get("INSERT INTO messages(message, priority, envelope_recipients) \
-                       VALUES(%s, %s, %s) RETURNING id", message, priority, recipients)
+       def _send(self, message, sender=None, priority=0):
+               res = self.db.get("INSERT INTO messages(message, priority) \
+                       VALUES(%s, %s) RETURNING id", message, priority)
 
                logging.debug("Message queued with ID %s" % res.id)
 
-       def send(self, recipients, message, priority=0, headers={}):
+       def send(self, message, priority=0, headers={}):
                # Convert message from string
                if not isinstance(message, email.message.Message):
                        message = email.message_from_string(message)
@@ -76,10 +70,6 @@ class Messages(misc.Object):
                        except KeyError:
                                message.add_header(k, v)
 
-               # Read recipients from To: header
-               if not recipients:
-                       recipients = message.get("To").split(", ")
-
                # Add date if the message doesn't have one already
                if "Date" not in message:
                        message.add_header("Date", email.utils.formatdate())
@@ -89,9 +79,9 @@ class Messages(misc.Object):
                        message.add_header("Errors-To", "<%s>" % self.bounce_email_address)
 
                # Send the message
-               self._send(recipients, message.as_string(), priority=priority)
+               self._send(message.as_string(), priority=priority)
 
-       def send_template(self, template_name, recipients=[],
+       def send_template(self, template_name,
                        sender=None, priority=0, headers={}, **kwargs):
                """
                        Send a message based on the given template
@@ -151,7 +141,7 @@ class Messages(misc.Object):
                        message.attach(message_part)
 
                # Send the message
-               self.send(recipients, message, priority=priority, headers=headers)
+               self.send(message, priority=priority, headers=headers)
 
                # In debug mode, re-compile the templates with every request
                if self.backend.debug:
@@ -180,7 +170,7 @@ class Messages(misc.Object):
                        "post" : random.choice(posts),
                }
 
-               return self.send_template(template, recipients=[recipient,], **kwargs)
+               return self.send_template(template, **kwargs)
 
 
 class Queue(misc.Object):
@@ -222,7 +212,7 @@ class Queue(misc.Object):
                msg = email.message_from_string(message.message)
 
                logging.debug("Sending a message %s to: %s" % (
-                       msg.get("Subject"), ", ".join(message.envelope_recipients)
+                       msg.get("Subject"), msg.get("To"),
                ))
 
                error_messages = []
@@ -230,8 +220,7 @@ class Queue(misc.Object):
 
                # Try delivering the email
                try:
-                       rejected_recipients = self.relay.send_message(msg,
-                               to_addrs=message.envelope_recipients)
+                       rejected_recipients = self.relay.send_message(msg)
 
                except smtplib.SMTPRecipientsRefused as e:
                        rejected_recipients = e.recipients