On Wed, Sep 19, 2001 at 09:20:57AM -0400, Jean-Sebastien Morisset decreed: > Hi all. > > I often receive plain/text e-mails with URLs in them. Normally, I would > call up urlview, select the url, and then lynx would start-up to display > that page. My problem is that some of the URLs point to images. :-) If I > use the standard urlview->lynx technique, lynx will download the image, > start xv (my prefered image viewer), and then exit. When lynx exits, it > removes the temporary file it downloaded, which causes xv to display an > error about not finding the specified file. :-) Apologies for hitting send too soon without adding the attachment! --- original response --- I tried urlview and decided that I prefered to see the entire email when dealing with the links. So I wrote my own script. The attached Python script loads the entire email into a GUI browser as HTML, with URLs made into real hyperlinks. I have the following lines in my .muttrc to invoke it from Ctrl-b and invoke the Opera browser. It should be easy to adapt to other browsers. macro index \cb "|email2html.py > /tmp/email.html; opera /tmp/email.html \n" macro pager \cb "|email2html.py > /tmp/email.html; opera /tmp/email.html \n" Let me know if this is useful enough to post somewhere. Obviously enjoy it, but use it entirely at your own risk. HTH and cheers, Steve -- \_O< \_O< \_O< ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Steve Cooper Redmond, WA
#!/usr/bin/env python2 import sys import re #=== Globals # Regular expression for isolating URLs reURL = re.compile('(((http|https|ftp|gopher)|mailto)[.:][^ >"\t]*|www\.[-a-z0-9.]+)') # Colors bgColor = "#ffffff" labelColor = "#5050e0" textColor = "#000000" #=== Fix line function def FixLine(line): line = line.strip() line = line.replace('<','<') line = line.replace('>','>') return line #=== Header list class class HeaderList: def __init__(self): self.headers = {} # Specification for desired visible headers # TODO: Un-hardcode this! self.reHeaders = re.compile('^[ \t]*(From|To|Date|Subject):[ \t]*(.*)$', re.IGNORECASE) def ScanLine(self, line): matchHeader = self.reHeaders.search(line) if matchHeader is not None: self.headers[matchHeader.group(1).lower()] = matchHeader.group(2) def OutputLine(self, name, label, size = "+0"): if self.headers.has_key(name): print '<b><font color="%s" size="%s">%s: </font></b>' % (labelColor, size, label) print '<font color="%s" size="%s">%s</font><br>' % (textColor, size, self.headers[name]) def Output(self): # TODO: Un-hardcode this! self.OutputLine('from', 'From') self.OutputLine('to', 'To', '-1') self.OutputLine('date', 'Date', '-1') self.OutputLine('subject', 'Subject', '+1') print '<hr><br>' print '<html>' print '<head>' print '<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">' print '<title>Mutt Email</title>' print '</head>' print '<body bgcolor="%s">' % bgColor #=== Scan headers headers = HeaderList() line = sys.stdin.readline() while line: line = FixLine(line) # Assume first empty line is the end of the headers if not line: break headers.ScanLine(line) line = sys.stdin.readline() #=== Format header lines headers.Output() #=== Scan and display body print '<PRE>' nLine = 0 line = sys.stdin.readline() while line: line = FixLine(line) nLine = nLine + 1 match = reURL.search(line) while match is not None: sub = '<a href="%s">%s</a>' % (match.group(1), match.group(1)) line = line[:match.start(1)] + sub + line[match.end():] skip = match.start() + len(sub) match = reURL.search(line, skip) print '%s' % line line = sys.stdin.readline() print '</PRE>' print '</body>' print '</html>'