From 23cbaac193afe222962fe12b8a5710973678b363 Mon Sep 17 00:00:00 2001 From: Jon Turney Date: Wed, 22 Nov 2023 14:07:40 +0000 Subject: Store first msgid for announce of a srcpackage Store the first msgid allocated for a srcpackage announce, so we can set in-reply-to and thus allow threading of subsequent announces for that package. --- calm/calm.py | 12 ++++++++---- calm/db.py | 23 +++++++++++++++++++++++ calm/utils.py | 2 ++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/calm/calm.py b/calm/calm.py index 66337ab..e092468 100755 --- a/calm/calm.py +++ b/calm/calm.py @@ -284,9 +284,6 @@ def _announce_upload(args, scan_result, maintainer, r): # TODO: maybe other mechanisms for getting package ChangeLog? # NEWS inside upstream source tarball? - # TODO: store initial msgid for a package, so we can do in-reply-to and thus - # allow threading of announces for that package - # build the email hdr = {} hdr['From'] = maintainer.name + ' ' @@ -299,6 +296,10 @@ def _announce_upload(args, scan_result, maintainer, r): hdr['Subject'] = srcpkg.orig_name + ' ' + version + (' (TEST)' if test else '') hdr['X-Calm-Announce'] = '1' + irtid = db.announce_msgid_get(args, srcpkg.orig_name) + if irtid: + hdr['In-Reply-To'] = irtid + msg = ''' The following packages have been uploaded to the Cygwin distribution: @@ -311,7 +312,10 @@ The following packages have been uploaded to the Cygwin distribution: # TODO: add an attachment: sha512 hashes of packages, gpg signed? - utils.sendmail(hdr, msg) + msgid = utils.sendmail(hdr, msg) + + if not irtid: + db.announce_msgid_set(args, srcpkg.orig_name, msgid) def _process_maintainer_uploads(scan_result, args, state, all_packages, m, basedir, desc): diff --git a/calm/db.py b/calm/db.py index 0aef83a..3c2f761 100644 --- a/calm/db.py +++ b/calm/db.py @@ -55,6 +55,11 @@ def connect(args): replaces TEXT NOT NULL, PRIMARY KEY (name, arch) )''') + conn.execute('''CREATE TABLE IF NOT EXISTS announce_msgid + (srcpackage TEXT NOT NULL PRIMARY KEY, + msgid TEXT NOT NULL + )''') + conn.commit() return conn @@ -138,3 +143,21 @@ def update_missing_obsolete(args, packages, arch): conn.execute('UPDATE missing_obsolete SET replaces = ? WHERE name = ? AND arch = ?', (' '.join(r), n, arch)) return missing_obsolete + + +def announce_msgid_get(args, srcpackage): + msgid = None + with connect(args) as conn: + conn.row_factory = sqlite3.Row + + cur = conn.execute("SELECT msgid FROM announce_msgid WHERE srcpackage = ?", (srcpackage,)) + row = cur.fetchone() + if row: + msgid = row['msgid'] + + return msgid + + +def announce_msgid_set(args, srcpackage, msgid): + with connect(args) as conn: + conn.execute('INSERT INTO announce_msgid (srcpackage, msgid) VALUES (?, ?)', (srcpackage, msgid)) diff --git a/calm/utils.py b/calm/utils.py index 47085fd..26e3655 100644 --- a/calm/utils.py +++ b/calm/utils.py @@ -196,3 +196,5 @@ def sendmail(hdr, msg): with subprocess.Popen(['/usr/sbin/sendmail', '-t', '-oi', '-f', hdr['From']], stdin=subprocess.PIPE) as p: p.communicate(m.as_bytes()) logging.debug('sendmail: msgid %s, exit status %d' % (m['Message-Id'], p.returncode)) + + return m['Message-Id'] -- cgit v1.2.3