diff options
| author | Vosjedev <vosje@vosjedev.net> | 2025-12-06 13:08:12 +0100 |
|---|---|---|
| committer | Vosjedev <vosje@vosjedev.net> | 2025-12-06 13:08:12 +0100 |
| commit | bf58106fdc6022af1cc7ea5c228aa8284db33fc6 (patch) | |
| tree | 4dfd7b51e04c2c254146ecff7fb08e5d27ad162e | |
| parent | 1aeabe75267e3471c153fac159fd3e3f30942b35 (diff) | |
| download | acit-bf58106fdc6022af1cc7ea5c228aa8284db33fc6.tar.gz acit-bf58106fdc6022af1cc7ea5c228aa8284db33fc6.tar.bz2 acit-bf58106fdc6022af1cc7ea5c228aa8284db33fc6.tar.xz | |
More imapmagic:
- don't send emails to nobody, that'll just error out
- use proper column name when updating tokens to UNUSED status
- remove some commenting from the email postprocessor
- fix a bug where I used mariadb incorrectly causing a weird error
- add 'in tracker' to the 'you subscribed' emails, it was missing
formulating weird sentences ("Subscribed to 1 acit" or "Subscribed to
all bugs acit")
- optimise a specific mariadb query to LIMIT 1
- strip patch emails to everything before the first --- for the
description, instead of including all the patch text in the email
| -rw-r--r-- | src/acit/imapplugin.py | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/acit/imapplugin.py b/src/acit/imapplugin.py index 6a85855..a095178 100644 --- a/src/acit/imapplugin.py +++ b/src/acit/imapplugin.py @@ -331,7 +331,7 @@ class ImapPlugin(plugins.SimplePlugin): self.smtp.sendmail( replyto=msg, from_=from_, - body="Subscribed to "+bug+" "+proj+"\nTo unsubscribe, send an email with subjectline `UNSUBSCRIBE` to "+from_ + body="Subscribed to "+bug+" in tracker "+proj+"\nTo unsubscribe, send an email with subjectline `UNSUBSCRIBE` to "+from_ ) mailbox.delete([msg.uid]) @@ -349,7 +349,7 @@ class ImapPlugin(plugins.SimplePlugin): token=proj.removeprefix('$token$=') self.mlog("This email is sent to a secure token, resolving (matching against %s)."%token) with self.dbpool.get_connection() as conn, conn.cursor() as cur: - cur.execute("SELECT email,tracker,bugid,usedin FROM tokens WHERE token=? AND usedin IS NULL",(token,)) + cur.execute("SELECT email,tracker,bugid,usedin FROM tokens WHERE token=? AND usedin IS NULL LIMIT 1",(token,)) data=cur.fetchone() if data and data[0]==msg.from_: # sender matches, or token was used before self.mlog("Resolved to",data) @@ -362,7 +362,7 @@ class ImapPlugin(plugins.SimplePlugin): self.mail_error("Error processing commands:\n "+repr(e)+"\nPlease contact a site admin.") # set token used state - cur.execute("UPDATE tokens SET usedin=? WHERE token=?",(msg.headers["message-id"] if "message-id" else "nomessageid"),token) + cur.execute("UPDATE tokens SET usedin=? WHERE token=?",((msg.headers["message-id"] if "message-id" else "nomessageid"),token)) conn.commit() else: self.mlog("Couldn't resolve.") @@ -429,7 +429,11 @@ class ImapPlugin(plugins.SimplePlugin): bugobj=self.site.newbug(proj,bugtype=bugtype) bugobj.subject=msg.subject[:1024] bugobj.description=\ - 'No description written.\nFirst email in thread:\n\n'+msg.text[:65535] # TODO: don't thruncate silently, send error to user. + 'No description written.\nFirst email in thread:\n\n'+msg.text[:65535] + + if bugtype=="PATCH": + bugobj.description=bugobj.description[:bugobj.description.find("\n---\n")] + self.mlog("Assigned new bugnr %d to '%s'"%(bugobj.bugid,msg.subject)) bug=bugobj.bugid else: @@ -524,14 +528,14 @@ class ImapPlugin(plugins.SimplePlugin): while True: match=re.search(self.addr_regex+"(, )?",cur) if match: - self.mlog("Removing",match.group(),"from",header) + #self.mlog("Removing",match.group(),"from",header) new+=match.string[:match.start()] cur=match.string[match.end():] if not acit_re_added: - self.mlog("Readding",realacitfrom,"instead") + #self.mlog("Readding",realacitfrom,"instead") new+=realacitfrom acit_re_added=True - self.mlog(header,"= ",new,"<<",cur) + #self.mlog(header,"= ",new,"<<",cur) else: break @@ -560,7 +564,7 @@ class ImapPlugin(plugins.SimplePlugin): cur.execute("SELECT email FROM permissiontable WHERE email=? AND (tracker=? OR tracker IS NULL) AND (bugid=? OR bugid IS NULL) LIMIT 1",(email,bug.tracker,bug.bugid)) if cur.fetchone(): token=''.join(( random.choice(string.ascii_letters) for i in range(40))) - cur.execute("UPDATE tokens SET usedin='@@UNUSED@@' WHERE email=? AND tracker=? AND bugid=? AND USEDIN IS NULL",(email,bug.tracker,bug.bugid)) + cur.execute("UPDATE tokens SET usedin='@@UNUSED@@' WHERE email=? AND tracker=? AND bugid=? AND usedin IS NULL",(email,bug.tracker,bug.bugid)) cur.execute("INSERT INTO tokens (email,token,tracker,bugid) VALUES (?,?,?,?)",(msg.from_,token,bug.tracker,bug.bugid)) securereplytos[email]=token @@ -585,16 +589,18 @@ class ImapPlugin(plugins.SimplePlugin): "replyto":replyto, } - self.smtp.sendmail( - from_=from_, - bcc=bcc, - postprocessor=lambda msg: self.email_postprocessor_fix_acit_a_thousand_times(msg, from_), - smtp_to=bcc, - **kwargs - ) + if bcc: + self.smtp.sendmail( + from_=from_, + bcc=bcc, + postprocessor=lambda msg: self.email_postprocessor_fix_acit_a_thousand_times(msg, from_), + smtp_to=bcc, + **kwargs + ) + self.mlog("Sending %d extra emails due to tokens"%len(securereplytos)) for email,token in securereplytos.items(): - self.mlog("Sending extra email to %s bc of token"%email) + #self.mlog("Sending extra email to %s bc of token"%email) from_=self.format_emailaddr(project='$token$='+token) self.smtp.sendmail( to=email, |
