Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] a simple mail viewer?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Mon Jun 06, 2011 3:31 pm    Post subject: [solved] a simple mail viewer? Reply with quote

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
View user's profile Send private message
grimm26
Guru
Guru


Joined: 23 May 2004
Posts: 313
Location: Chicagoland, IL

PostPosted: Mon Jun 06, 2011 6:56 pm    Post subject: Reply with quote

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
View user's profile Send private message
Dr.Willy
Guru
Guru


Joined: 15 Jul 2007
Posts: 547
Location: NRW, Germany

PostPosted: Mon Jun 06, 2011 9:25 pm    Post subject: Reply with quote

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
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Tue Jun 07, 2011 3:23 am    Post subject: Reply with quote

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 :twisted:
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
View user's profile Send private message
amk
n00b
n00b


Joined: 09 Apr 2008
Posts: 12

PostPosted: Tue Jun 07, 2011 2:15 pm    Post subject: Reply with quote

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
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Tue Jun 07, 2011 5:06 pm    Post subject: Reply with quote

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
View user's profile Send private message
amk
n00b
n00b


Joined: 09 Apr 2008
Posts: 12

PostPosted: Tue Jun 07, 2011 10:54 pm    Post subject: Reply with quote

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
View user's profile Send private message
avx
Advocate
Advocate


Joined: 21 Jun 2004
Posts: 2152

PostPosted: Wed Jun 08, 2011 9:13 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
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