unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* BUG: Python's Message.header fails for empty headers
@ 2024-01-07 22:49 Vojtěch Káně
  2024-01-08 23:08 ` David Bremner
  0 siblings, 1 reply; 5+ messages in thread
From: Vojtěch Káně @ 2024-01-07 22:49 UTC (permalink / raw)
  To: notmuch

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-01-09 12:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-07 22:49 BUG: Python's Message.header fails for empty headers Vojtěch Káně
2024-01-08 23:08 ` 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

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).