From ccf11e57291c3ccba920d833d059aa11c971a720 Mon Sep 17 00:00:00 2001 From: Frederik Schwan Date: Tue, 13 Oct 2020 23:33:47 +0200 Subject: [PATCH] fix requests not being sent to the cc recipients From a SMTP pov, the To and Cc header are not read. The real recipient is stated at the begining of a send mail transaction. It's up to the client to collect this recipient list. Sendmail does this by reading the To and Cc header. smtplib doesn't do this when being invoked with an explicit To array. This commit adds the Cc people to the recipient array. The issue has been introduced by the switch from sendmail to smtplib. --- aurweb/scripts/notify.py | 49 +++++++++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/aurweb/scripts/notify.py b/aurweb/scripts/notify.py index 9d4f3bde..33be997c 100755 --- a/aurweb/scripts/notify.py +++ b/aurweb/scripts/notify.py @@ -78,7 +78,7 @@ class Notification: msg['Subject'] = self.get_subject(lang) msg['From'] = sender msg['Reply-to'] = reply_to - msg['To'] = to + msg['To'] = self.get_to() if self.get_cc(): msg['Cc'] = str.join(', ', self.get_cc()) msg['X-AUR-Reason'] = reason @@ -89,6 +89,10 @@ class Notification: sendmail = aurweb.config.get('notifications', 'sendmail') if sendmail: + # Since we iterate over self.get_recipients(), we overwrite + # the To header for sendmail to avoid sending the mail + # multiple times to the same recipient + msg['To'] = to # send email using the sendmail binary specified in the # configuration file p = subprocess.Popen([sendmail, '-t', '-oi'], @@ -117,7 +121,6 @@ class Notification: server.login(user, passwd) server.set_debuglevel(0) - deliver_to = [to] + self.get_cc() server.sendmail(sender, to, msg.as_bytes()) server.quit() @@ -136,6 +139,9 @@ class ResetKeyNotification(Notification): else: return [(self._to, self._lang)] + def get_to(self): + return self._to + def get_subject(self, lang): return self._l10n.translate('AUR Password Reset', lang) @@ -184,6 +190,9 @@ class CommentNotification(Notification): def get_recipients(self): return self._recipients + def get_to(self): + return self._recipients + def get_subject(self, lang): return self._l10n.translate('AUR Comment for {pkgbase}', lang).format(pkgbase=self._pkgbase) @@ -228,6 +237,9 @@ class UpdateNotification(Notification): def get_recipients(self): return self._recipients + def get_to(self): + return self._recipients + def get_subject(self, lang): return self._l10n.translate('AUR Package Update: {pkgbase}', lang).format(pkgbase=self._pkgbase) @@ -276,6 +288,9 @@ class FlagNotification(Notification): def get_recipients(self): return self._recipients + def get_to(self): + return self._recipients + def get_subject(self, lang): return self._l10n.translate('AUR Out-of-date Notification for ' '{pkgbase}', @@ -315,6 +330,9 @@ class OwnershipEventNotification(Notification): def get_recipients(self): return self._recipients + def get_to(self): + return self._recipients + def get_subject(self, lang): return self._l10n.translate('AUR Ownership Notification for {pkgbase}', lang).format(pkgbase=self._pkgbase) @@ -350,6 +368,9 @@ class ComaintainershipEventNotification(Notification): def get_recipients(self): return [(self._to, self._lang)] + def get_to(self): + return self._to + def get_subject(self, lang): return self._l10n.translate('AUR Co-Maintainer Notification for ' '{pkgbase}', @@ -394,6 +415,9 @@ class DeleteNotification(Notification): def get_recipients(self): return self._recipients + def get_to(self): + return self._to + def get_subject(self, lang): return self._l10n.translate('AUR Package deleted: {pkgbase}', lang).format(pkgbase=self._old_pkgbase) @@ -435,7 +459,7 @@ class RequestOpenNotification(Notification): 'OR Users.ID = PackageBases.MaintainerUID ' + 'WHERE PackageRequests.ID = ?', [reqid]) self._to = aurweb.config.get('options', 'aur_request_ml') - self._cc = [row[0] for row in cur.fetchall()] + self._cc = [(row[0], 'en') for row in self._cc] cur = conn.execute('SELECT Comments FROM PackageRequests WHERE ID = ?', [reqid]) self._text = cur.fetchone()[0] @@ -444,10 +468,13 @@ class RequestOpenNotification(Notification): self._merge_into = merge_into def get_recipients(self): - return [(self._to, 'en')] + return [(self._to, 'en'), self._cc] + + def get_to(self): + return self._to def get_cc(self): - return self._cc + return [row[0] for row in self._cc] def get_subject(self, lang): return '[PRQ#%d] %s Request for %s' % \ @@ -491,7 +518,7 @@ class RequestCloseNotification(Notification): 'OR Users.ID = PackageBases.MaintainerUID ' + 'WHERE PackageRequests.ID = ?', [reqid]) self._to = aurweb.config.get('options', 'aur_request_ml') - self._cc = [row[0] for row in cur.fetchall()] + self._cc = [(row[0], 'en') for row in self._cc] cur = conn.execute('SELECT PackageRequests.ClosureComment, ' + 'RequestTypes.Name, ' + 'PackageRequests.PackageBaseName ' + @@ -504,10 +531,13 @@ class RequestCloseNotification(Notification): self._reason = reason def get_recipients(self): - return [(self._to, 'en')] + return [(self._to, 'en'), self._cc] + + def get_to(self): + return self._to def get_cc(self): - return self._cc + return [row[0] for row in self._cc] def get_subject(self, lang): return '[PRQ#%d] %s Request for %s %s' % (self._reqid, @@ -554,6 +584,9 @@ class TUVoteReminderNotification(Notification): def get_recipients(self): return self._recipients + def get_to(self): + return self._recipients + def get_subject(self, lang): return self._l10n.translate('TU Vote Reminder: Proposal {id}', lang).format(id=self._vote_id) -- GitLab