Re: [SPAM?] mutt deletes temporary HTML file before I can view it

2016-06-27 Thread Paul Tansom
** Xu Wang  [2016-06-22 10:07]:
> Hello,
> 
> I would like to be able to do
> 'v' and then 'm' to open an HTML email in my browser. I can succeed in
> this regard by having the following entry in ~/.mailcap:
> text/html; chromium-browser %s; description=HTML Text;
> 
> However, mutt will be unresponsive until I exit the browser. This is
> not my work style. So I added & to detach. This is good in the sense
> that mutt now does not wait for the browser. However, by the time my
> browser opens, mutt has already deleted the .html temporary file
> because after adding & the command returned immediately?
> 
> Has any one come across this situation and has a similar desire?
> 
> Is there a setting I can choose to ask mutt to not delete the
> temporary files? They are stored in /tmp and space is cheap so I would
> like to ask mutt to not worry about them.
> 
> Kind regards,
> 
> Xu
** end quote [Xu Wang]

There are several solutions to this of varying levels of complexity, but I use
a simple one liner to fix this. I always ensure that the browser is running
first, but even when it is the deletion of the temporary file isn't uncommon so
I make the following change to /etc/mailcap

# - User Section Begins - #
text/html; /usr/bin/sensible-browser %s; description=HTML Text; 
nametemplate=%s.html; needsterminal
# -  User Section Ends  - #

You don't need to add the comments above and below, but I've included them to
emphasis that this goes in the user section at the top so that it is not
deleted automatically.

All this does is make Mutt wait until a key is pressed to return to normal
operations and thereby delays the file deletion. Since you always have to do
that anyway on returning it is just a double press instead of a single one.

-- 
 Paul Tansom  |  Aptanet Ltd.  |  https://www.aptanet.com/  |  023 9238 0001
 Vice Chair, FSB Portsmouth & SE Hampshire Branch  |  http://www.fsb.org.uk/
=
Registered in England | Company No: 4905028 | Registered Office: Ralls House,
Parklands Business Park, Forrest Road, Denmead, Waterlooville, Hants, PO7 6XP


Re: mutt deletes temporary HTML file before I can view it

2016-06-26 Thread Xu Wang
On Sun, Jun 26, 2016 at 10:54 AM, Marcus C. Gottwald  wrote:
>
> Xu Wang wrote (Wed 2016-Jun-22 21:49:12 -0400):
>
>> ... Many solutions
>> involve preserving the .html file. But is it possible for .html file
>> to include images that were included in the email file? ...
>
> Somewhere within such a solution, you would need a piece of code
> parsing the email and probably store its MIME-parts as files
> (possibly using "munpack"? "mu extract"? Python "email.parser"?
> Perl "MIME::Tools"?). You will need to identify the HTML part(s)
> and possibly glue several of them together. You might need to
> modify references in the HTML code, then start the webbrowser,
> and clean it all up later, I guess.
>
> FWIW, here's my approach: Use a macro to copy the whole email
> into a file and fire up Icedove (= Thunderbird), which does a
> good job at displaying HTML email.
>
>macro index,pager I '\
>set my_confirmcreate=$confirmcreate\
>set confirmcreate=no\
>rm -f ~/email-from-mutt.eml\
>~/email-from-mutt.eml\
>icedove --no-remote ~/email-from-mutt.eml\
>set confirmcreate=$my_confirmcreate\
>' 'invoke Icedove'
>
> You would probably want to modify the macro to start Icedove in
> the background. It might then be necessary to work around the
> race condition regarding the filename recycling. The solution
> might not suit you at all because it doesn't actually invoke
> a web browser of your choice; but maybe it does provide some
> inspiration.
>
>
> Cheers, Marcus
>
> --
>Marcus C. Gottwald  ·    ·  https://cheers.de

Thank you, Marcus. Interesting solution! I will take a look at Icedove
for HTML email.

Kind regards,

Xu


Re: mutt deletes temporary HTML file before I can view it

2016-06-26 Thread Marcus C. Gottwald

Xu Wang wrote (Wed 2016-Jun-22 21:49:12 -0400):

> ... Many solutions
> involve preserving the .html file. But is it possible for .html file
> to include images that were included in the email file? ...

Somewhere within such a solution, you would need a piece of code
parsing the email and probably store its MIME-parts as files
(possibly using "munpack"? "mu extract"? Python "email.parser"?
Perl "MIME::Tools"?). You will need to identify the HTML part(s)
and possibly glue several of them together. You might need to
modify references in the HTML code, then start the webbrowser,
and clean it all up later, I guess.

FWIW, here's my approach: Use a macro to copy the whole email
into a file and fire up Icedove (= Thunderbird), which does a
good job at displaying HTML email.

   macro index,pager I '\
   set my_confirmcreate=$confirmcreate\
   set confirmcreate=no\
   rm -f ~/email-from-mutt.eml\
   ~/email-from-mutt.eml\
   icedove --no-remote ~/email-from-mutt.eml\
   set confirmcreate=$my_confirmcreate\
   ' 'invoke Icedove'

You would probably want to modify the macro to start Icedove in
the background. It might then be necessary to work around the
race condition regarding the filename recycling. The solution
might not suit you at all because it doesn't actually invoke
a web browser of your choice; but maybe it does provide some
inspiration.


Cheers, Marcus

-- 
   Marcus C. Gottwald  ·    ·  https://cheers.de


Re: mutt deletes temporary HTML file before I can view it

2016-06-23 Thread Xu Wang
On Thu, Jun 23, 2016 at 3:14 AM, Ulrich Lauther
 wrote:
> On Wed, Jun 22, 2016 at 09:49:12PM -0400, Xu Wang wrote:
>> On Wed, Jun 22, 2016 at 9:07 AM, Gregor Zattler  wrote:
>> > Hi Xu Wang,
>> > * Xu Wang  [22. Jun. 2016]:
>> >> So I added & to detach. This is good in the sense
>> >> that mutt now does not wait for the browser. However, by the time my
>> >> browser opens, mutt has already deleted the .html temporary file
>> >> because after adding & the command returned immediately?
>> >>
>> >> Has any one come across this situation and has a similar desire?
>
> an easy and fast solution is to start the browser BEFORE you enter mutt
> and/or to keep it open at all times.

Thank you, I have indeed tested this and it works. But I would prefer
a more general solution. I do realize that it is a luxury to dream of
solving small annoying issues such as this one.

Kind regards,

Xu


Re: mutt deletes temporary HTML file before I can view it

2016-06-23 Thread Ulrich Lauther
On Wed, Jun 22, 2016 at 09:49:12PM -0400, Xu Wang wrote:
> On Wed, Jun 22, 2016 at 9:07 AM, Gregor Zattler  wrote:
> > Hi Xu Wang,
> > * Xu Wang  [22. Jun. 2016]:
> >> So I added & to detach. This is good in the sense
> >> that mutt now does not wait for the browser. However, by the time my
> >> browser opens, mutt has already deleted the .html temporary file
> >> because after adding & the command returned immediately?
> >>
> >> Has any one come across this situation and has a similar desire?

an easy and fast solution is to start the browser BEFORE you enter mutt
and/or to keep it open at all times.

Best
ulrich


Re: mutt deletes temporary HTML file before I can view it

2016-06-22 Thread Xu Wang
On Wed, Jun 22, 2016 at 9:07 AM, Gregor Zattler  wrote:
> Hi Xu Wang,
> * Xu Wang  [22. Jun. 2016]:
>> So I added & to detach. This is good in the sense
>> that mutt now does not wait for the browser. However, by the time my
>> browser opens, mutt has already deleted the .html temporary file
>> because after adding & the command returned immediately?
>>
>> Has any one come across this situation and has a similar desire?
>
> Search for  mutt_bgrun
>
> It's purpose is to start programms in background and keeps the
> file till the background process exits.

Dear all, thank you for these great replies! I will do research into
each one. This brings me to one question already. Many solutions
involve preserving the .html file. But is it possible for .html file
to include images that were included in the email file? If so,
although .html file is preserved (using the solutions in this thread),
might the images be deleted, which the .html file depends on?

Kind regards,

Xu


Re: mutt deletes temporary HTML file before I can view it

2016-06-22 Thread Gregor Zattler
Hi Xu Wang,
* Xu Wang  [22. Jun. 2016]:
> So I added & to detach. This is good in the sense
> that mutt now does not wait for the browser. However, by the time my
> browser opens, mutt has already deleted the .html temporary file
> because after adding & the command returned immediately?
> 
> Has any one come across this situation and has a similar desire?

Search for  mutt_bgrun

It's purpose is to start programms in background and keeps the
file till the background process exits.


Ciao, Gregor
-- 
 -... --- .-. . -.. ..--.. ...-.-



Re: [SPAM?] mutt deletes temporary HTML file before I can view it

2016-06-22 Thread Grant Edwards
On 2016-06-22, Xu Wang  wrote:

[using external viewer program defined in mailcap]

> However, mutt will be unresponsive until I exit the browser. This is
> not my work style. So I added & to detach. This is good in the sense
> that mutt now does not wait for the browser. However, by the time my
> browser opens, mutt has already deleted the .html temporary file
> because after adding & the command returned immediately?

I usually just write a wrapper script that copies the file to a
temporary location, starts a background progcess that runs the viewer
and removes the temporary file when the viewer exits.

Here's what I use for viewing .pdf files with atril:

 #!/bin/bash
 TMPDIR=$(mktemp -d)
 mv "$1" $TMPDIR
 NAME=$(basename "$1")
 setsid bash -c "atril '$TMPDIR/$NAME'; rm '$TMPDIR/$NAME'; rmdir '$TMPDIR'" &

-- 
Grant Edwards   grant.b.edwardsYow! JAPAN is a WONDERFUL
  at   planet -- I wonder if we'll
  gmail.comever reach their level of
   COMPARATIVE SHOPPING ...



[SPAM?] Re: [SPAM?] mutt deletes temporary HTML file before I can view it

2016-06-22 Thread cs

On 22Jun2016 02:08, Xu Wang  wrote:

I would like to be able to do
'v' and then 'm' to open an HTML email in my browser. I can succeed in
this regard by having the following entry in ~/.mailcap:
text/html; chromium-browser %s; description=HTML Text;

However, mutt will be unresponsive until I exit the browser. This is
not my work style. So I added & to detach. This is good in the sense
that mutt now does not wait for the browser. However, by the time my
browser opens, mutt has already deleted the .html temporary file
because after adding & the command returned immediately?

Has any one come across this situation and has a similar desire?

Is there a setting I can choose to ask mutt to not delete the
temporary files? They are stored in /tmp and space is cheap so I would
like to ask mutt to not worry about them.


This is something of a standard problem with popping up HTML in an external 
browser, for exactly the reasons you outline. Try something like this 
(untested):


 text/html; cp %s /tmp/$$.html && chromium-browser /tmp/$$.html &; 
description=HTML Text;

That is still one line in case it gets folded in email. Note the html on the 
temp file name, can help the browser decide how to treat it.


If you want something more elaborate (clean up the temp file after a delay) you 
would use withstdin:


 https://bitbucket.org/cameron_simpson/css/src/tip/bin/withstdin

Disclaimer: mine, all mine.

And try this:

 text/html; withstdin --ext=.html --keepfor=10 chromium-browser <%s &; 
description=HTML Text;

Cheers,
Cameron Simpson 


[SPAM?] mutt deletes temporary HTML file before I can view it

2016-06-22 Thread Xu Wang
Hello,

I would like to be able to do
'v' and then 'm' to open an HTML email in my browser. I can succeed in
this regard by having the following entry in ~/.mailcap:
text/html; chromium-browser %s; description=HTML Text;

However, mutt will be unresponsive until I exit the browser. This is
not my work style. So I added & to detach. This is good in the sense
that mutt now does not wait for the browser. However, by the time my
browser opens, mutt has already deleted the .html temporary file
because after adding & the command returned immediately?

Has any one come across this situation and has a similar desire?

Is there a setting I can choose to ask mutt to not delete the
temporary files? They are stored in /tmp and space is cheap so I would
like to ask mutt to not worry about them.

Kind regards,

Xu