Neomutt: %s variable isn't set correctly when viewing attachment

Created on 3 May 2021  路  4Comments  路  Source: neomutt/neomutt

Expected Behaviour


I'm trying to view a .png file from the compose menu but I can't open it because the %s isn't set correctly.

Actual Behaviour


So this is inside the composer:

- I     1 /tmp/neomutt-TORNAX-ARCH-1000-340160-431                                                                                                          [text/plain, 7bit, us-ascii, 0K]
  A     2 ~/Screenshot.png                                                                                                                                          [image/png, base64, 33K]

Now if I go down to Screenshot.png and press v for view-attachment, than I'm getting the following from my notification:

image

I chose the file from ~/Screenshot.png and I'm also getting the following error message:

cp: cannot stat '/tmp/Screenshot.png': No such file or directory

Interestingly I can view .jpg files.

This is in my ~/.mailcap

image/png; mkdir -p /tmp/neomutt/ && notify-send 'Test' %s && cp %s /tmp/neomutt && vimiv /tmp/neomutt/$(basename %s) & disown
image/jpg; mkdir -p /tmp/neomutt/ && cp %s /tmp/neomutt && vimiv /tmp/neomutt/$(basename %s) & disown

If NeoMutt crashed, did your OS create a 'coredump' file?
Neomutt didn't crashed.

Steps to Reproduce

  1. Put this into your ~/.mailcap:
image/png; mkdir -p /tmp/neomutt/ && notify-send 'Test' %s && cp %s /tmp/neomutt && vimiv /tmp/neomutt/$(basename %s) & disown
image/jpg; mkdir -p /tmp/neomutt/ && cp %s /tmp/neomutt && vimiv /tmp/neomutt/$(basename %s) & disown

This is my ~/.config/neomutt/neomuttrc:

# vim: filetype=neomuttrc
# == Global options ==
source ./colorscheme/custom.muttrc

#unset record
ignore *
unignore from: date: subject: to: cc: reply-to:

#set use_from=yes
set autoedit
set edit_headers
set header_cache=~/.cache/mutt/headers/
set include
set index_format="%4C %Z %{%Y-%b-%d} %-23.23F|%4c| %s"
set mail_check=60
set message_cachedir=~/.cache/mutt/messages/
set query_command = "abook --mutt-query '%s'"
set sort=threads
set sort_aux=last-date-received
set timeout=15
set pager_stop=true
set postponed="/rest/mails/postponed"
#set pager=nvim
source ./sidebar.muttrc
source ./mappings.muttrc

# == ACCOUNTS ==
# Account 1: XX
source ./accounts/XX.muttrc
folder-hook "/rest/mails/XX/" 'source ~/.config/neomutt/accounts/XX.muttrc'

# Account 2: gmail
source ./accounts/gmail.muttrc
folder-hook "/rest/mails/tornax07/" 'source ~/.config/neomutt/accounts/gmail.muttrc'

# Account 3: XX
folder-hook "/rest/mails/XX/" 'source ~/.config/neomutt/accounts/XX.muttrc'

# Switching between tem
macro index <f2> '<sync-mailbox><enter-command>source ~/.config/neomutt/accounts/XX.muttrc<enter><change-folder>!<enter>'
macro index <f3> '<sync-mailbox><enter-command>source ~/.config/neomutt/accounts/gmail.muttrc<enter><change-folder>!<enter>'
macro index <f4> '<sync-mailbox><enter-command>source ~/.config/neomutt/accounts/XX.muttrc<enter><change-folder>!<enter>'

  1. Create a new mail and insert a .png file as an attachment.
  2. Press v to view the attachment.
  3. Only /tmp/<filename>.png should pop up and an error message that cp couldn't copy the png file to the temporary directory.

How often does this happen?

  • Always
    I've only tried .png files currently.

  • Sometimes

  • On a particular email
    If the email isn't private, please attach it to this issue.

When did it start to happen?

  • When I upgraded

It used to work so I think since the latest update.

Which version did you use to use?

Output of neomutt -v:

NeoMutt 20210205
Copyright (C) 1996-2020 Michael R. Elkins and others.
NeoMutt comes with ABSOLUTELY NO WARRANTY; for details type 'neomutt -vv'.
NeoMutt is free software, and you are welcome to redistribute it
under certain conditions; type 'neomutt -vv' for details.

System: Linux 5.11.16-arch1-1 (x86_64)
ncurses: ncurses 6.2.20200212 (compiled with 6.2.20200212)
libidn2: 2.3.0 (compiled with 2.3.0)
GPGME: 1.15.1
GnuTLS: 3.7.0
libnotmuch: 5.3.0
storage: kyotocabinet, gdbm, bdb, lmdb
compression: lz4, zlib, zstd

Configure options: --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib --gpgme --sqlite --autocrypt --lua --notmuch --gss --gnutls --sasl --with-ui=ncurses --with-idn2=/usr --disable-idn --idn2 --bdb --lmdb --kyotocabinet --gdbm --lz4 --zlib --zstd

Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -std=c99 -fno-delete-null-pointer-checks -D_ALL_SOURCE=1 -D_GNU_SOURCE=1 -D__EXTENSIONS__ -I/usr/include -I/usr/include/lua5.3 -DNCURSES_WIDECHAR -I/include -I/usr/include/

Default options:
  +attach_headers_color +compose_to_sender +compress +cond_date +debug
  +encrypt_to_self +forgotten_attachments +forwref +ifdef +imap +index_color
  +initials +limit_current_thread +multiple_fcc +nested_if +new_mail +nntp +pop
  +progress +quasi_delete +regcomp +reply_with_xorig +sensible_browser +sidebar
  +skip_quoted +smtp +status_color +timeout +tls_sni +trash

Compile options:
  +autocrypt +bkgdset +color +curs_set +fcntl -flock -fmemopen +futimens
  +getaddrinfo +gnutls +gpgme +gss +hcache -homespool +idn +inotify
  -locales_hack +lua +meta -mixmaster +nls +notmuch -openssl +pgp +regex +sasl
  +smime +sqlite +start_color +sun_attachment +typeahead
MAILPATH="/var/mail"
PKGDATADIR="/usr/share/neomutt"
SENDMAIL="/usr/sbin/sendmail"
SYSCONFDIR="/etc"

To learn more about NeoMutt, visit: https://neomutt.org
If you find a bug in NeoMutt, please raise an issue at:
    https://github.com/neomutt/neomutt/issues
or send an email to: <[email protected]>

  • When I changed my config
    Can you narrow down what you changed?

NeoMutt Version

NeoMutt 20210205
Copyright (C) 1996-2020 Michael R. Elkins and others.
NeoMutt comes with ABSOLUTELY NO WARRANTY; for details type 'neomutt -vv'.
NeoMutt is free software, and you are welcome to redistribute it
under certain conditions; type 'neomutt -vv' for details.

System: Linux 5.11.16-arch1-1 (x86_64)
ncurses: ncurses 6.2.20200212 (compiled with 6.2.20200212)
libidn2: 2.3.0 (compiled with 2.3.0)
GPGME: 1.15.1
GnuTLS: 3.7.0
libnotmuch: 5.3.0
storage: kyotocabinet, gdbm, bdb, lmdb
compression: lz4, zlib, zstd

Configure options: --prefix=/usr --sysconfdir=/etc --libexecdir=/usr/lib --gpgme --sqlite --autocrypt --lua --notmuch --gss --gnutls --sasl --with-ui=ncurses --with-idn2=/usr --disable-idn --idn2 --bdb --lmdb --kyotocabinet --gdbm --lz4 --zlib --zstd

Compilation CFLAGS: -march=x86-64 -mtune=generic -O2 -pipe -fno-plt -std=c99 -fno-delete-null-pointer-checks -D_ALL_SOURCE=1 -D_GNU_SOURCE=1 -D__EXTENSIONS__ -I/usr/include -I/usr/include/lua5.3 -DNCURSES_WIDECHAR -I/include -I/usr/include/

Default options:
  +attach_headers_color +compose_to_sender +compress +cond_date +debug
  +encrypt_to_self +forgotten_attachments +forwref +ifdef +imap +index_color
  +initials +limit_current_thread +multiple_fcc +nested_if +new_mail +nntp +pop
  +progress +quasi_delete +regcomp +reply_with_xorig +sensible_browser +sidebar
  +skip_quoted +smtp +status_color +timeout +tls_sni +trash

Compile options:
  +autocrypt +bkgdset +color +curs_set +fcntl -flock -fmemopen +futimens
  +getaddrinfo +gnutls +gpgme +gss +hcache -homespool +idn +inotify
  -locales_hack +lua +meta -mixmaster +nls +notmuch -openssl +pgp +regex +sasl
  +smime +sqlite +start_color +sun_attachment +typeahead
MAILPATH="/var/mail"
PKGDATADIR="/usr/share/neomutt"
SENDMAIL="/usr/sbin/sendmail"
SYSCONFDIR="/etc"

To learn more about NeoMutt, visit: https://neomutt.org
If you find a bug in NeoMutt, please raise an issue at:
    https://github.com/neomutt/neomutt/issues
or send an email to: <[email protected]>

Extra Info

  • Operating System and its version
    Arch Linux, 5.11.16-arch1-1
  • Were you using multiple copies of NeoMutt at once?
    I don't really understand, what you mean with "multiple copies". I just ran one instance.
  • Were you using 'screen' or 'tmux'?
    No.
  • Is your email local (maildir) or remote (IMAP)?
    I download them with mbsync.
confirmed bug

Most helpful comment

Thanks for the detailed bug report 鉂わ笍

How on earth has nobody noticed _that_ before?
I feel like you deserve a prize :-)

I checked back through the last year of NeoMutt releases (always present),
and I checked the current Mutt release (also present).

We're a bit low on developers, atm, but I'll try to have a look soon.

All 4 comments

Thanks for the detailed bug report 鉂わ笍

How on earth has nobody noticed _that_ before?
I feel like you deserve a prize :-)

I checked back through the last year of NeoMutt releases (always present),
and I checked the current Mutt release (also present).

We're a bit low on developers, atm, but I'll try to have a look soon.

Could there be a race condition here? I say this because if I go step by step, the file opens normally.
If I use neomutt normally, it shows the message cp: cannot stat '/tmp/Screenshot.png': No such file or directory.

When commenting the unlink in mutt_attach.c:691, it works normally.

Also, if not using the disown command, it works normally too. But it obviously blocks Neomutt window.

Could there be a race condition here?

Oh. That's interesting.
When viewing attachments elsewhere, we (optionally?) put the filename in a queue to be deleted later.

Yes, because this does not happen when, for example, viewing an e-mail that I received that has a PNG. Opening that PNG with @TornaxO7 mailcap works perfectly.

Consider this:

if (fp && !mutt_buffer_is_empty(tmpfile))
{
      /* add temporary file to TempAttachmentsList to be deleted on timeout hook */
      mutt_add_temp_attachment(mutt_buffer_string(tmpfile));
}
    else if (unlink_tempfile)
{
      unlink(mutt_buffer_string(tmpfile));
}

When viewing an attachment in the e-mail you're sending, it goes directly to unlink, when viewing the attachment in an e-mail you've received, it goes to the first branch.

Is this change viable?:

  if (!entry || !entry->xneomuttkeep)
  {
    if ((fp && !mutt_buffer_is_empty(tmpfile)) || unlink_tempfile)
    {
      /* add temporary file to TempAttachmentsList to be deleted on timeout hook */
      mutt_add_temp_attachment(mutt_buffer_string(tmpfile));
    }
  }
Was this page helpful?
0 / 5 - 0 ratings