Re: How to prevent file disappearing before browser sees it?

2015-01-22 Thread David Champion
* On 23 Jan 2015, Gary Johnson wrote: 
> > #!/bin/sh
> > COPY="$1.firefox.html"
> > ln "$1" "$COPY"
> > /usr/bin/firefox "$COPY" &
> 
> I'm surprised that linking works because it used to be that mutt
> overwrote the temporary file with 0s before deleting it.  I thought
> it still did, but I don't know for sure.

You're right, it does overwrite (at least for most cases).  I don't
think this was always true, but it's been a very long time since I used
mailcap this way, so I'm pretty distant.

So a hard link won't work.

-- 
David Champion • d...@bikeshed.us


Re: How to prevent file disappearing before browser sees it?

2015-01-22 Thread Gary Johnson
On 2015-01-22, David Champion wrote:

> To solve this you need a wrapper script around Firefox.  The wrapper
> will take the file content from $1 and save it somehow for Firefox, so
> that mutt may delete the original.
> 
> There are various techniques for this.  I personally like the approach
> of hard-linking the temp file so that it doesn't use more storage.
> Something like this:
> 
>   #!/bin/sh
>   COPY="$1.firefox.html"
> ln "$1" "$COPY"
> /usr/bin/firefox "$COPY" &

I'm surprised that linking works because it used to be that mutt
overwrote the temporary file with 0s before deleting it.  I thought
it still did, but I don't know for sure.

Another place that you might look for solutions, Chris, is here:

http://www.spocom.com/users/gjohnson/mutt/#background

Regards,
Gary



Re: How to prevent file disappearing before browser sees it?

2015-01-22 Thread David Champion
* On 22 Jan 2015, Chris Green wrote: 
> The trouble is I'm frequently seeing the temporary HTML file saved by
> mutt disappearing before firefox gets to see it, why does this happen
> sometimes (almost all the time now)?  It used to work OK.  I have just
> moved to a faster computer, would this affect it?

Yes, it's a race condition.  Mutt removes the file when it regains
control of your terminal. /usr/bin/firefox is just a launcher - it will
detach and background the real firefox executable and come back to
mutt.  If Firefox starts up slower than mutt finishes, the file will be
missing.

>   text/html; /usr/bin/firefox %s
>   text/html; lynx -dump %s; copiousoutput; nametemplate=%s.html

To solve this you need a wrapper script around Firefox.  The wrapper
will take the file content from $1 and save it somehow for Firefox, so
that mutt may delete the original.

There are various techniques for this.  I personally like the approach
of hard-linking the temp file so that it doesn't use more storage.
Something like this:

#!/bin/sh
COPY="$1.firefox.html"
ln "$1" "$COPY"
/usr/bin/firefox "$COPY" &

But no matter what option you choose, your wrapper will then be
responsible for removing the saved copy!  The only difference to not
having a wrapper at all is that now it doesn't matter how long you wait
to remove the extra copy, whereas with no wrapper the time that you wait
is the time that it takes to get mutt back.  So something like this
should generally work.  You can append it to the above.

# background a subshell to clean up later
(
sleep 120
rm "$COPY"
) &


> While I'm about it how do the two text/html entries in .mailcap work
> so that lynx is used by default but 'v' takes me to firefox?

I would think you've got it already.  Mutt will only use a copiousoutput
entry for auto_view, and the first appropriate match otherwise.  There
are a number of ways to control what "appropriate" means though; see
http://dev.mutt.org/doc/manual.html#advanced-mailcap

Are you seeing something different?

-- 
David Champion • d...@bikeshed.us


How to prevent file disappearing before browser sees it?

2015-01-22 Thread Chris Green
I usually automatically turn HTML mails into text using lynx and view
them in the mutt pager but occasionally I view them in Firefox by
hitting 'v' and then enter against the HTML part of the message.

Thus my .muttrc file has:-

auto_view text/html

... and my mailcap has:-

text/html; /usr/bin/firefox %s
text/html; lynx -dump %s; copiousoutput; nametemplate=%s.html

The trouble is I'm frequently seeing the temporary HTML file saved by
mutt disappearing before firefox gets to see it, why does this happen
sometimes (almost all the time now)?  It used to work OK.  I have just
moved to a faster computer, would this affect it?


While I'm about it how do the two text/html entries in .mailcap work
so that lynx is used by default but 'v' takes me to firefox?

-- 
Chris Green