From: "Vojtěch Káně" <vojta001@vkane.cz>
To: notmuch@notmuchmail.org
Subject: BUG: Python's Message.header fails for empty headers
Date: Sun, 7 Jan 2024 23:49:17 +0100 [thread overview]
Message-ID: <ZZsqbUF4AGwYjSHt@ucw.cz> (raw)
Dear notmuch developers,
I'll start with a short description of how I encountered the bug, so my
report is more understandable and also so that you can potentially
direct me to other places where the bug actually resides (I am a bit
skeptic I would find a bug in such a popular open source project as
notmuch is).
I use Lieer https://github.com/gauteh/lieer to sync my maildir and nm
database with Gmail. When I send a reply, Lieer checks whether the
subject matches the original one and prints a warning otherwise (Google
presumably knows better what a thread is and breaks it if the subject is
different). The relevant snippet is:
>if 'In-Reply-To' in eml:
> repl = eml['In-Reply-To'].strip().strip('<>')
> self.vprint("looking for original message: %s" % repl)
> with notmuch2.Database(mode = notmuch2.Database.MODE.READ_ONLY) as db:
> try:
> nmsg = db.find(repl)
> except LookupError:
> nmsg = None
> if nmsg is not None:
> (_, gids) = self.local.messages_to_gids([nmsg])
> if nmsg.header('Subject') != eml['Subject']:
> self.vprint ("warning: subject does not match, might not be able to associate with existing thread.")
But there is a catch: when the original message's subject is empty, the
check fails with a LookupError. Stack trace follows. I use NixOS, so
while the file paths are weird, they also guarantee reproducible
package set.
>Traceback (most recent call last):
> File "/nix/store/9l521wrzalkhqk46qn57z0wc5lnmdzwk-lieer-1.4/bin/.gmi-wrapped", line 25, in <module>
> g.main ()
> File "/nix/store/9l521wrzalkhqk46qn57z0wc5lnmdzwk-lieer-1.4/lib/python3.10/site-packages/lieer/gmailieer.py", line 230, in main
> args.func (args)
> File "/nix/store/9l521wrzalkhqk46qn57z0wc5lnmdzwk-lieer-1.4/lib/python3.10/site-packages/lieer/gmailieer.py", line 837, in send
> if nmsg.header('Subject') != eml['Subject']:
> File "/nix/store/y12m0r41lcwz1ksqs6gncra0djln92cj-python3.10-notmuch2-0.37/lib/python3.10/site-packages/notmuch2/_message.py", line 266, in header
> raise LookupError
At first, this sounds reasonable: the subject is empty, so it is
effectively missing. That would indicate a bug in Lieer itself and would
be fixed by a try-catch block. Notmuch's source for Message.header,
however, states:
>:returns: The header value, an empty string if the header is not present.
>:rtype: str
This makes an impression that no error should be raised and a harmless
value (at least for the above-mentioned code) should be returned. Yet
the docs continue with
>:raises LookupError: if the header is not present.
completely contradicting itself.
And so here the questions:
Is my confusion justified? What is the expected nm's behavior? Can we
fix the docs and possible the implementation?
Thank you all for reading this long report and for your dedication to
open source,
Vojta Káně
p.s. I am not subscribed to the mailing list, so please keep me in the
replies.\r
next reply other threads:[~2024-01-08 15:15 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-07 22:49 Vojtěch Káně [this message]
2024-01-08 23:08 ` BUG: Python's Message.header fails for empty headers David Bremner
2024-01-09 10:22 ` Michael J Gruber
2024-01-09 12:38 ` David Bremner
2024-01-09 12:54 ` Michael J Gruber
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZZsqbUF4AGwYjSHt@ucw.cz \
--to=vojta001@vkane.cz \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).