• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

New Mutt user!!

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

mirko_3

Member
Joined
Oct 27, 2002
Location
Italy
Ok, I just spent a couple hours configuring mutt, so that I can check my mail through ssh and stuff, and so that it doesn't interfere with Sylpheed (setting up the MH format with procmail was what took the longest);
anyway, I'm dead tired now, and would like some help with finishing touches:

1- When I delete mail, I'd like it to go to trash/ instead of it being deleted; I was thinking of remapping the D key so that it moves mail... correct?
macro index D "and what next??"

2- Periodically delete mail in trash that is older than x days; no clue on this one...

Anyway, I like mutt, and think I'll get to like it more... wow, I'm getting GUI independent!!
 
right, no one uses mutt here? I don't believe it...

totally unrelated, but I'm including this here just so to bump this thread up, regex: in metalog I want to log everything that doesn't match a single word ("shorewall"); if I try to insert this:
regex = "!shorewall", nothing gets logged. why??
 
I use mutt, just never really had a desire to save deleted message. You should be able to mimic that behaviour with:
Code:
set noconfirmappend  # don't prompt me if I *really* want to save a message
set folder=~/Mail # directory with personal folders

# save to trash folder
macro index d "<save-message>+trash\n"
macro pager d "<save-message>+trash\n"

# Need a *real* delete key now. 
bind index D delete-message  
bind pager D  delete-message
Permanently deleting message older than a given offset will probably need to be done via a script in cron. Something like the following using Perl:
Code:
#!/usr/local/bin/perl -w
use Mail::Box::Manager;
use Date::Calc qw(Parse_Date Today Delta_Days);

my $mgr    = Mail::Box::Manager->new;
my @today = Today();

my %queue = (   # FOLDER         # Offset in days from today
                 'Mail/trash'     => 7,  # keep a week's worth of trash
                #'Mail/somelist'  => 0   # delete all but today's mail from some mailing list
            );

while(my ($folder, $offset) = each %queue){
        my $folder = $mgr->open($folder);               
        for my $message ($folder->messages) {
                my $date = $message->get('Date');
                $date =~ s/^.+?,\s+(\d+\s+)(\w+\s+)(\d+).+$/$2$1$3/;
                next unless my @date = Parse_Date($date);
                $message->delete if Delta_Days(@date, @today) > $offset;
        }
        $folder->close(force => 1) ;
}
BTW, you could of course alias this to clean your trash file on start instead of cron'ing it:

alias mutt='~/bin/mailbox.pl && mutt'
 
Last edited:
ok, this was exactly what I wanted; thank you!!
Now, if only I could figure out those regex...

EDIT:
oh, the 'real delete' doesn't work, it appends to trash; I've checked the mutt manual, but it seems like it should work to me... (I replaced 'D' with <delete>) It's not a big problem though...

EDIT2:
Finally I got all dependencies for the perl script... to find it doesn't work :(
I think it be because you wrote it to use the mbox format, and I'm using MH (similar to Maildir). Correct?
 
Last edited:
So you couldn't use an upper-case D as the bind for delete-message? Strange.

Anyhow, with the script, yes, mbox is the default type unless you specifiy otherwise. Try the following. After the mananger object ($mgr) is created add:
Code:
$mgr->registerType(MH => 'Mail::Box::MH');
Then you'll need to specify this bound type when opening the folders. Change the open line to:
Code:
my $folder = $mgr->open($folder, type => 'MH');
MH folders have some oddities that can be further optimized, e.g. creating an .index file in each folder so each message doesn't need to be opened repeatedly for searching headers.

FYI, I don't have a MH folder to test this with so it would probably be wise to copy one of your MH folders to test on if you already haven't ;)
 
It's not that I couldn't use a capital D, it doesn't matter what key I bind it to; but I'll figure this out eventually...
It's too bad I don't know perl, because I have to keep bothering you :D
anyway, I did that and now I get this error:
Use of uninitialized value in string eq at /usr/lib/perl5/vendor_perl/5.8.0/File/Spec/Unix.pm line 77

I checked:

sub catdir {
my $self = shift;
my @args = @_;
foreach (@args) {
# append a slash to each argument unless it has one there
$_ .= "/" if $_ eq '' || substr($_,-1) ne "/"; <--LINE 77
}
return $self->canonpath(join('', @args));
}
 
You mean perl include directories?
@INC contains: /etc/perl /usr/lib/perl5/site_perl/5.8.0/i686-linux /usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.8.0/i686-linux /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl /usr/lib/perl5/5.8.0/i686-linux /usr/lib/perl5/5.8.0 /usr/local/lib/site_perl .
 
oh...
'/home/mirko_3/Mail/trash' => 7

since
~/Mail/trash didn't work...

thought I noticed that simply leaving 'Mail/trash' as you had written is the same as '/home/mirko_3/Mail/trash'...
 
Well, without an MH dir to work with I'm sort of shooting in the dark but have you tried appending a trailing slash? "trash" is a directory, right, not just a file?
 
yeah, it's the first thing I've tried, because It was what postfix needed to work with MH... so, you're saying that that error means that it has a probelm finding the directory Mail/trash?

btw, thank you for all this help!
 
No, I don't believe the code is yet at the stage of trying to verify whether a file exists. File::Spec is just manipulating the path and has been passed an undefined value from somewhere.

What happens if you create trash as a regular mbox file? Is mutt able to save/delete from your MH folders to an mbox style trash folder?
 
Ok, converted trash to mbox format (yeah, I have backups of course) and I can delete to an mbox style trash; I undid the changes to your script, and noticed that it doesn't work :(
No errors, simply the old messages are still there
 
If it ran without errors, are you sure it didn't just find nothing to delete, i.e. your offset is too large? Are permissions for the trash file rw? Converting to mbox for trash shouldn't be a problem. Unless you need a really slow and bloated trash folder ;)
 
I need a slow, unefficient folder for Sylpheed-Claws :)
anyway, I need to test it some more since I had the impression that it deleted some messages, like last week's, but not older ones... I have to test some more, don't have time now...
 
Yeah, test a little more closely and I think you'll find it likely deleted everything previous to the offset you specified, i.e. one week. The only thing I can think of is that some of your older messages had funky "From" lines. The script expects the following format in order to extract the date for comparison:
Code:
    From [email][email protected][/email]  Wed Jul 16 11:16:59 2003
If it doesn't find this in a particular message it just moves on to the next. If indeed you discover it doesn't find all message before the cutoff I would check this first.
 
ok, there must be something wrong with your script:

First run of the script I get this error:
Unexpected end of header (C parser):
------------E4Z5ixLbwzgypNlDPXW5lm

I refresh the trash folder, and all my messages from 4th december to 8th december (yesterday) are deleted. 3rd december and earlier months aren't. (I set 1 day in the script)
second run: no error, no changes to trash folder.
 
Looks to me like a problem with the C version of the Mail::Box::parser module not being knowing what to do with non-standard header. That message has nothing to do with the script really but is internal to one of the modules. Converting from MH to mbox or a variety of other things may be part of the problem. Sorry, works like a charm for normal mbox files. Only thing I could suggest is that you fill a trash file with spam and send it to me so I could have a look at it.
 
ok, sure, pm me your e-mail address, and I'll send it to you... it's 140k bzipped, shouldn't be a problem... I removed all important e-mails, left the others so that your test would be the same...
 
Back