apparmour and viewing mutt attachments -- Re: how to background mutt external viewer applications

Zenaan Harkness zen at
Fri Jul 3 22:55:38 PDT 2020

On Sat, May 18, 2019 at 02:28:14PM +1000, Zenaan Harkness wrote:
> A hint is here:
> To make it work, do e.g. the following in $HOME/.mailcap as follows
> (the following is to be on one line):
> application/pdf; (mv %s %s-\; evince %s-\; rm -f %s-)& sleep 0.2s; test=test -n "$DISPLAY"
> Couple keys:
>  - mv mutt's temp file to a new name, so mutt cannot delete the file
>    from under the viewer's feet
>  - do the mv, view and rm in a subshell, so that this mini process
>    can be backgrounded
>  - escape the semi colons in that are part of the viewer mailcap
>    entry (ampersand does not need escaping)
>  - rm the temp file (using its new name) after viewing is finished
>  - sleep for a short bit after backgrounding the viewer, in the hope
>    that your kernel will schedule the viewer to do its thing within
>    that time - this time is a racy heuristic, so can fail of course
> The ideal solution would be another mailcap part of the line, or
> option, which specifies that the viewer should be backgrounded, so
> that this little dance does not have to be copied for every entry of
> interest - although a handful of such entries will likely capture the
> bulk of daily requirements...

So AppArmour is making it's presence felt - disallowing Evince to open the user's files named "__.pdf-" but still thankfully opening user files named "__.pdf".

The solution is simple, change the above mailcap entry to read e.g. as follows:

application/pdf; (mv %s %s.pdf\; evince %s.pdf\; rm -f %s.pdf)& sleep 0.2s; test=test -n "$DISPLAY"

More information about the cypherpunks mailing list