1

I know this is theoretically possible, but I'm trying to avoid reinventing the wheel.

I'm using Ubuntu Linux, with Maildir mailbox format. I want to put something in my .login that will parse the ~/Maildir contents and display a summary of my unread email messages.

I'm running Ubuntu 13.04 (Raring Ringtail), and I use mutt for my email client, and I'm using Postfix and dovecot for SMTP and MDA/IMAP.

Is there something already written that will do this? Or will I need to write something myself using Perl and Mail::Box::Maildir? It seems like this would be a common thing, but for the life of me I can't find a package or utility that will do what I'm looking for.

6
  • 1
    Can you be more specific about what this summary would like? An example would help.
    – jasonwryan
    Jul 18, 2013 at 18:16
  • I wound up writing a Perl script to do what I want. It uses Mail::Box::Maildir to scan for unread messages and then print a summary of each message, including date, who it's from, and the subject. I leave it running in a window, and I can glance at it from time to time to see if I have new mail. I have been using mutt and vim for years, and don't want to switch to a GUI mail client.
    – m0j0
    Jul 18, 2013 at 19:32
  • So, in theory, I've solved my own problem, but it seems like this would be something that would be in more demand. Maybe I need to clean up my code and submit it as an opensource package. :)
    – m0j0
    Jul 18, 2013 at 19:38
  • You should submit it as an answer.
    – jasonwryan
    Jul 18, 2013 at 19:51
  • You can use the output of your custom script in conjunction with MOTD to display the details on login.
    – Tim
    Jul 18, 2013 at 20:22

2 Answers 2

1

I found a shorter and simpler way to implement with Python.

Sample code below.

#!/usr/bin/python

import mailbox
import email.utils
import os

mbox = mailbox.Maildir(os.environ['HOME'] + "/Maildir" )
mbox.lock()
spam = mbox.get_folder('INBOX.junk')
print "INBOX:"
for message in mbox:
    print "- [%s] %s:  \"%s\"" % ( message['date'], message['from'], message['subject'] )
print
print "SPAM messages:"
for message in spam:
    print "- [%s] %s:  \"%s\"" % ( message['date'], message['from'], message['subject'] )

mbox.close()
0

Here's what I came up with...a home-grown Perl script using the Mail::Box::Maildir CPAN module.

#!/usr/bin/perl
use strict;
use Mail::Box::Maildir;

my $folder = new Mail::Box::Maildir folder=>"$ENV{HOME}/Maildir";

my $message;
my $messsages;
my $to;
my $from;
my $date;
my $subject;

print "********************************************************************************\n";
foreach $message( $folder->messages('ALL') ) {
    #print $message->{'MM_head'}, "\n";
    parse_header( $message->{'MM_head'} );
    print "   Date:  $date\n";
    print "   From:  $from\n";
    print "     To:  $to\n";
    print "Subject:  $subject\n";
    print "********************************************************************************\n";
}

exit 0;

sub parse_header {
    my @lines = split( /\n/, shift(@_) );
    undef $to;
    undef $from;
    undef $date;
    undef $subject;

    foreach ( @lines ) {
        if ( /^To:\s+?(.*)$/ ) {
            $to = $1;
        }
        elsif ( /^From:\s+?(.*)$/ ) {
            $from = $1;
        }
        elsif ( /^Date:\s+?(.*)$/ ) {
            $date = $1;
        }
        elsif ( /^Subject:\s+?(.*)$/ ) {
            $subject = $1;
        }
    }
}
1
  • I still think that there should be some sort of Ubuntu or Debian package that I could install that would do the same thing. If I don't get any better answers, I may try packaging my solution for others.
    – m0j0
    Jul 19, 2013 at 1:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.