Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Other Things Gentoo
  • Search

[solved] a simple mail viewer?

Still need help with Gentoo, and your question doesn't fit in the above forums? Here is your last bastion of hope.
Post Reply
Advanced search
8 posts • Page 1 of 1
Author
Message
avx
Advocate
Advocate
User avatar
Posts: 2152
Joined: Mon Jun 21, 2004 4:06 am

[solved] a simple mail viewer?

  • Quote

Post by avx » Mon Jun 06, 2011 3:31 pm

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: Select all

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: Select all

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.
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Top
grimm26
Guru
Guru
User avatar
Posts: 313
Joined: Sun May 23, 2004 5:40 am
Location: Chicagoland, IL

  • Quote

Post by grimm26 » Mon Jun 06, 2011 6:56 pm

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".
Top
Dr.Willy
Guru
Guru
Posts: 547
Joined: Sun Jul 15, 2007 5:13 pm
Location: NRW, Germany

  • Quote

Post by Dr.Willy » Mon Jun 06, 2011 9:25 pm

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…
Top
avx
Advocate
Advocate
User avatar
Posts: 2152
Joined: Mon Jun 21, 2004 4:06 am

  • Quote

Post by avx » Tue Jun 07, 2011 3:23 am

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:
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).
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Top
amk
n00b
n00b
Posts: 12
Joined: Wed Apr 09, 2008 7:04 am

  • Quote

Post by amk » Tue Jun 07, 2011 2:15 pm

Create a script to see yourfile like this:

Code: Select all

echo From asdf `date` >/tmp/asdf
cat yourfile >>/tmp/asdf
mutt -f /tmp/asdf
rm /tmp/asdf
Top
avx
Advocate
Advocate
User avatar
Posts: 2152
Joined: Mon Jun 21, 2004 4:06 am

  • Quote

Post by avx » Tue Jun 07, 2011 5:06 pm

amk wrote:Create a script to see yourfile like this:

Code: Select all

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: Select all

#!/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.
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Top
amk
n00b
n00b
Posts: 12
Joined: Wed Apr 09, 2008 7:04 am

  • Quote

Post by amk » Tue Jun 07, 2011 10:54 pm

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.
Top
avx
Advocate
Advocate
User avatar
Posts: 2152
Joined: Mon Jun 21, 2004 4:06 am

  • Quote

Post by avx » Wed Jun 08, 2011 9:13 pm

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: Select all

notmuch show "WHAT TO SHOW HERE" |  awk '/part}/{p=0};p;/text\/plain/{p=1}'
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
Top
Post Reply

8 posts • Page 1 of 1

Return to “Other Things Gentoo”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic