From patchwork Mon Feb 10 10:03:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukas Fleischer X-Patchwork-Id: 1500 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id EFEF316F753D1 for ; Mon, 10 Feb 2020 10:03:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.3 (2019-12-06) on apollo.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1, MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001, T_DMARC_POLICY_NONE=0.01 autolearn=ham autolearn_force=no version=3.4.3 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Mon, 10 Feb 2020 10:03:23 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id B3B7418CBE3778; Mon, 10 Feb 2020 10:03:22 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: luna) by orion.archlinux.org (Postfix) with ESMTPSA id 7712818CBE3774; Mon, 10 Feb 2020 10:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1581329002; bh=VE4ryNfv2svPG7v1MNgezrVxfwTEGBLyClYo4UGTBPk=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=e7cAxSDfKnvVE6bY4j47Xl4kdmYbgiLWADmouq31f/3E3NxA2Rv7SeaGkIj0lWAte 0gfZb9+XiceBINovqkK/fDxqOjRG4wSGILrPaKcAHCy32BPcjr+G0cXumXh3IYC+mN 2FmTZHei5zoKoBJi2hKR6rSzaMRFfydd+7lVDjNWt0KTdoJW72eVEV6j2mDZMSgXep vub66FVxZLfo2zie1+KAFeOVKLgsjhm8G47jFJleXHQ1Z3GjwSBFSq/V4QCdKSAn17 PCYYtkF6bapl776Jbxy6yxIFJ5qP4KCtfuqIpkaZkm3AUTTUM8FB61kwoifVH6VBip pPKb1IzoIuO/xKMB9IQ6P3LVthPBK/all2KtStItEyZ/jSHem4au0UeyssZU8lamXa CP2AwonTPo4T9Yxw61SiZ7WiGoa/pQhqBVmNW0vxJF7idpCKzy+cWtrBXNGmWF/JJI gU3nyTbi3wtLGR1644djaThHNO1TuvfQzL0eQFg/I/ujhrMwM3J/m5+3fydALVxhPs NvKMlfYrZ54LQDxoyswhScqwGxws+XJ6vDQLZQg4AWGSfzR7z34reKOjLWOEYZvlM6 wf3xKl65MqHYjS2mDxaBlcQLVdQT0ZMqcJ7b5aF2L4n20zFu8aMMQMu87bCPVLhjED HE2Vmt7S+Zn+vE+OVjgt+NSw= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 86B6B2BFE6; Mon, 10 Feb 2020 10:03:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=luna2; t=1581329000; bh=VE4ryNfv2svPG7v1MNgezrVxfwTEGBLyClYo4UGTBPk=; h=From:To:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe; b=WEGhw7pVR9Zmi2fNKPKI1CmzTDJ9Y9YP/EVGGPuI05gzdaBonVKdqJMbbDkmCEFzG VhFn57y3iO7v7MpN1Ca7nECuxSSXlSrFcgQ5depGfVaLod/q19B9auaqfQO02EFwpI i1OnQ6UcdenR+kGLVhECQ/JMZE0LUS54/R4FoILfLm3Td5BJmp5BJBAsCllSBRcI/9 vvnOkj8+wR8Sih+bmdrBf3R0T7XkK9f+6w4MnvDn0sZ+kKGg7rzHIyJNaK2R8rhFeV V0YGKu6kRrfdheoVq9iI+LHm4FS6PKVWHOjgIa+r3wrF7hPwMS4UB2KLUS75W0Uju4 eIjp7LzTpjSWX07RJ2klSYrX2MOGr5HMY5aG3L+j+iNzvpU05v8r6mVQwR0TEYwb/Z Sq1ZFiHkmGLmMLMblUsBQ7MdhoknZVaJ9Zy6EoOF5/qb/bzS3IvoCiBHj0sLXRRRsO V/5gwdQ+fizmwooIkSwzrW6SPsa0tjT71xua009/kSMZe4ONYpt/V4Zce/7hL4uZ2h sVQGIDffMej7HVpwAs3BonS9DYtkUGLQsHQTJq6pzjDeFU9UW/f/RQhvROXZFCuzfa ahDFnVjRtnaxNA+w9WLznFNCLWAZaaQCcHKLs2OSdG6M3gy5+dg8Hq2janW4yy92ld 1fN3+6pIBnqolNHBo83Z1xN8= Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id CA2ED2BFE6 for ; Mon, 10 Feb 2020 10:03:17 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by luna.archlinux.org (Postfix) with ESMTPS for ; Mon, 10 Feb 2020 10:03:17 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 513F818CBE3766 for ; Mon, 10 Feb 2020 10:03:11 +0000 (UTC) Received: from localhost (unknown [IPv6:2a02:8070:24e4:b800:b66b:fcff:fe3e:6273]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: lfleischer) by orion.archlinux.org (Postfix) with ESMTPSA id AFEAC18CBE3765 for ; Mon, 10 Feb 2020 10:03:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=archlinux.org; s=orion; t=1581328990; bh=VE4ryNfv2svPG7v1MNgezrVxfwTEGBLyClYo4UGTBPk=; h=From:To:Subject:Date; b=l5MklAWEv2LxjQNMLQEsc35zv7DBkryjXP816cvtKUoElrWgr3exork2DxWYGGXFn 0s1onzGU2jvB1Tj/BqRBMRl7MP71FF1QCI8EldOu52sqCBulCzRvLpHSP/x+KL6FER RpUI72LVr5qo90iOFugev6PIPCDuRNE44luRUQIzfhpPR0D1xif8Z2YULv77YjhZUn 1+pg30B6ZJIHZPz7lIbBHePLYBzLSEPhKyb+mgCC90xhublqhqw8fZVnO5QrLQToDJ RGqeL2S+MW6hJdfeYZRcqzLeUqSXT6mPR+D1CP68rAFalVruj/haTPF7GyEXNQdaX9 ZKSW3o5Tj19ZOFpZS8Uk+ZIgxVbcg/2TJsrkGUk6D+jD+9RIGVAY9TXni+rtRUyRY/ fW7sWgj+A3BxyR3zxuX3eY0yVB4atTzJEURocwQ81y4rOF0szqLouaJVRQ0nyoA9vY vOTB0zPfh87Ijs1qkWxYuX9DstEFcS7/wViuxk+U1db7kQUHggfDSyJcF1NrzBOsLS igGtsaxKFstSPPLqEGmlMCOErQ57uNitRbrWz1roXcjgeTYwZDdYJHOVcTRiexkiAn XZSSOJ7LADv27m1jVIFoUpHO5zyL6nqoR897x/LFI3yQzglnOsWdO0eMBlH+mwf2+y Y6UPaMlCfGQzk32VbFBSyMak= From: Lukas Fleischer To: aur-dev@archlinux.org Subject: [PATCH v3 1/2] Support smtplib for sending emails Date: Mon, 10 Feb 2020 11:03:27 +0100 Message-Id: <20200210100328.75985-1-lfleischer@archlinux.org> X-Mailer: git-send-email 2.25.0 MIME-Version: 1.0 X-BeenThere: aur-dev@archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Arch User Repository \(AUR\) Development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: aur-dev-bounces@archlinux.org Sender: "aur-dev" Support mail delivery without a local MTA. Instead, an SMTP server can now be configured using the smtp-server option in the [notifications] section. In order to use this option, the value of the sendmail option must be empty. Signed-off-by: Lukas Fleischer --- Reintroduce the option to use a local sendmail binary (needed for the test suite) and only use smtplib if no such binary is configured. aurweb/scripts/notify.py | 22 ++++++++++++++++++---- conf/config.defaults | 3 ++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/aurweb/scripts/notify.py b/aurweb/scripts/notify.py index b0f218b..941187e 100755 --- a/aurweb/scripts/notify.py +++ b/aurweb/scripts/notify.py @@ -1,6 +1,8 @@ #!/usr/bin/env python3 import email.mime.text +import email.utils +import smtplib import subprocess import sys import textwrap @@ -63,7 +65,6 @@ class Notification: return body.rstrip() def send(self): - sendmail = aurweb.config.get('notifications', 'sendmail') sender = aurweb.config.get('notifications', 'sender') reply_to = aurweb.config.get('notifications', 'reply-to') reason = self.__class__.__name__ @@ -79,13 +80,26 @@ class Notification: msg['Reply-to'] = reply_to msg['To'] = to msg['X-AUR-Reason'] = reason + msg['Date'] = email.utils.formatdate(localtime=True) for key, value in self.get_headers().items(): msg[key] = value - p = subprocess.Popen([sendmail, '-t', '-oi'], - stdin=subprocess.PIPE) - p.communicate(msg.as_bytes()) + sendmail = aurweb.config.get('notifications', 'sendmail') + if sendmail: + # send email using the sendmail binary specified in the + # configuration file + p = subprocess.Popen([sendmail, '-t', '-oi'], + stdin=subprocess.PIPE) + p.communicate(msg.as_bytes()) + else: + # send email using smtplib; no local MTA required + server_addr = aurweb.config.get('notifications', 'smtp-server') + + server = smtplib.SMTP(server_addr) + server.set_debuglevel(1) + server.sendmail(sender, recipient, msg.as_bytes()) + server.quit() class ResetKeyNotification(Notification): diff --git a/conf/config.defaults b/conf/config.defaults index c519eae..23d46b0 100644 --- a/conf/config.defaults +++ b/conf/config.defaults @@ -47,7 +47,8 @@ window_length = 86400 [notifications] notify-cmd = /usr/local/bin/aurweb-notify -sendmail = /usr/bin/sendmail +sendmail = +smtp-server = localhost sender = notify@aur.archlinux.org reply-to = noreply@aur.archlinux.org