View previous topic :: View next topic |
Author |
Message |
avx Advocate
Joined: 21 Jun 2004 Posts: 2152
|
Posted: Mon Jun 06, 2011 3:31 pm Post subject: [solved] a simple mail viewer? |
|
|
Either I'm missing some functionality in mutt or it just doesn't exist, anyway, I'm looking for a simple way to read a given file out of some maildir in a pleasant format.
Ie, all my mails are stored as single files in maildirs and I can read them via less/most/etc, but they aren't nicely formatted as mutt/claws or any other mailclient would show them.
So, for example, `less somefile` gives (redacted) Code: | Return-Path: <foo@bar.com>
X-Spam-Checker-Version: SpamAssassin x.x.x (yyyy-mm-dd) on
some.server.come
X-Spam-Level:
X-Spam-Status: No, score=-4.0 required=5.0 tests=RCVD_IN_DNSWL_MED
autolearn=ham version=3.2.4
X-Original-To: someone@somewhere.com
Delivered-To: foo@someserver.com
Received: from bar.foo.baz (bar.foo.baz [aaa.bbb.ccc.ddd])
by bla.blub.com (Postfix) with ESMTP id xxxxxxxxxxxx
for <foo@bar.baz>; Sat, d mon yyy hh:mm:ss +0200 (CEST)
Received: from [aaa.bbb.ccc.ddd] (helo=lala.com)
by foo.bar.baz with esmtp (envelope-from <rofl@copter.com>)
id xxxxxx-yyyyy-zz
for bla@blub.com; Sat, dd mon yyyy hh:mm:ss +0200
Date: Sat, 6 mon yyyy hh:mm:ss +0200 (CEST)
From: some person <some@person.com>
To: bla@blub.com
Message-ID: <xxxx@foo.bar.baz>
Subject: dumdidum
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="----=_Part_foo_bla_blub"
X-Transaction: foo_bar_blub
X-Message-ID: weird number
X-Virus-Scanned: Symantec AntiVirus Scan Engine
X-UI-Msg-Verification: nopenotreally
X-Greylist: Delayed for 00:06:25 by milter-greylist-x.y (foobar.blub [0.0.0.0]); Sat, dd mon yyyy hh:mm:ss +0200 (CEST)
X-server3-MailScanner-Information: Please contact the ISP for more information
X-server3-MailScanner: Found to be clean
X-server3-MailScanner-From: doink@clown.com
------=_Part_enough
Content-Type: multipart/related;
boundary="----=_Part_ohcomon"
------=_Part_reallyreally
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
MESSAGE CONTENT HERE
|
But it should just be shown as Code: | date: yyyy-mm-dd
from: someone <bla@blub.com>
to: blub@bla.com
MESSAGE HERE
(flags: replied, ...) |
Reason for something like that is, if `tracker-search` returns mail, I'd like to easily view it directly without searching for it in mutt/something.
So, something already in existance which I missed? _________________ ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Last edited by avx on Wed Jun 08, 2011 9:14 pm; edited 1 time in total |
|
Back to top |
|
|
grimm26 Guru
Joined: 23 May 2004 Posts: 313 Location: Chicagoland, IL
|
Posted: Mon Jun 06, 2011 6:56 pm Post subject: |
|
|
I know with (al)pine you can point it at a local maildir instead of going through IMAP/POP and read it as a mail spool/folder. _________________ "Blessed is he who finds happiness in his own foolishness, for he will always be happy". |
|
Back to top |
|
|
Dr.Willy Guru
Joined: 15 Jul 2007 Posts: 547 Location: NRW, Germany
|
Posted: Mon Jun 06, 2011 9:25 pm Post subject: |
|
|
Hey avx - no, I don't know a good mailviewer, I just found it funny that you always seem to run into the same problems as I do ^^
It should be relatively trivial to write a simple mailviewer though… |
|
Back to top |
|
|
avx Advocate
Joined: 21 Jun 2004 Posts: 2152
|
Posted: Tue Jun 07, 2011 3:23 am Post subject: |
|
|
Dr.Willy wrote: | I just found it funny that you always seem to run into the same problems as I do ^^ | Och mensch, ich werd mich bemühen, in Zukunft weniger triviale Probleme zu haben. Oder soll ich vielleicht in Twitter einsteigen, dann kannst du ja follow'n
Quote: | It should be relatively trivial to write a simple mailviewer though… | My toughts exactly, that's why I find it strange that I couldn't find anything, yet. Given the fact that `less` can even render .html (and even some .pdf) properly, I don't see why something like this isn't available (to my eyes). _________________ ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. |
|
Back to top |
|
|
amk n00b
Joined: 09 Apr 2008 Posts: 12
|
Posted: Tue Jun 07, 2011 2:15 pm Post subject: |
|
|
Create a script to see yourfile like this:
Code: | echo From asdf `date` >/tmp/asdf
cat yourfile >>/tmp/asdf
mutt -f /tmp/asdf
rm /tmp/asdf
|
|
|
Back to top |
|
|
avx Advocate
Joined: 21 Jun 2004 Posts: 2152
|
Posted: Tue Jun 07, 2011 5:06 pm Post subject: |
|
|
amk wrote: | Create a script to see yourfile like this:
Code: | echo From asdf `date` >/tmp/asdf
cat yourfile >>/tmp/asdf
mutt -f /tmp/asdf
rm /tmp/asdf
|
|
Mh, doesn't work for me, all I get is a blank mutt-window?!
Anyway, what I have so far is this (yeah, ugly): Code: | #!/usr/bin/env python
#LIC: BSD-2C
#avx@phorcix.org
from sys import argv, exit
from email.parser import Parser as p
from email.header import decode_header as d_h
from email.Iterators import typed_subpart_iterator as t_s_i
if not len(argv) == 2: exit(1)
mail = p().parse(open(argv[1], 'r'))
def dchdr(txt):
return u"".join(unicode(text, chr or "utf-8") for text, chr in d_h(txt))
def chrst(m, n="utf-8"):
if m.get_content_charset(): return m.get_content_charset()
return n
def bdy(m):
if m.is_multipart():
body = []
for t in [k for k in t_s_i(m, 'text', 'plain')]:
chr = chrst(t, chrst(m))
body.append(unicode(t.get_payload(decode=True), chr, "replace"))
return u"\n".join(body).strip()
else:
return unicode(m.get_payload(decode=True), chrst(m), "replace").strip()
layout = "From: %s\nTo: %s\nDate: %s\n\nSubject: %s\n\nMessage:\n%s"
print layout % (mail['from'],mail['to'], mail['date'],
dchdr(mail['subject']), bdy(mail)) | This mostly works the way I would expect it to work, but it sometimes breaks on some charsets. Maybe I'll find the problem, maybe not, we'll see. _________________ ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. |
|
Back to top |
|
|
amk n00b
Joined: 09 Apr 2008 Posts: 12
|
Posted: Tue Jun 07, 2011 10:54 pm Post subject: |
|
|
Quote: | Mh, doesn't work for me, all I get is a blank mutt-window?! |
The difference between file in maildir and a mbox is basically the first From line.
I do not need to open the files into all details (and extract attachments) that often
and this approach of manually adding the From line works for me. Perhaps your
output of 'date' was not liked by mutt?
Your python could be possibly added to /usr/bin/lesspipe or ~/.lessfilter, file seems
to recognize the message file as smtp mail text so could invoke it in lesspipe_file. |
|
Back to top |
|
|
avx Advocate
Joined: 21 Jun 2004 Posts: 2152
|
Posted: Wed Jun 08, 2011 9:13 pm Post subject: |
|
|
Problem solved, at least for me.
I added notmuch (ebuild available via sunrise) to the system and now using the following, I get the mail's body (working on adding date, from/to, ...)
Code: | notmuch show "WHAT TO SHOW HERE" | awk '/part}/{p=0};p;/text\/plain/{p=1}' |
_________________ ++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|