Here's what we need to do:
- Don't delete emails, archive them into a specific mailbox, say, "archive" when hitting
in Mutt. (By default, it is "d") - Archive this mailbox into .tar file, and organize them in your mail directory so you can read them when you need to
- Delete the old "archive" mailbox file, and create a new and empty "archive" mailbox file.
- Do 1~3 every ten days.
1 Save emails
This is simply redefine the "d" key, by default the delete key, in Mutt. Write the following in your .muttrc
macro index,pager d 's=archive'
Now when you hit "d", the email is not deleted, but saved to the archive mailbox.
2 Archive emails and delete old mailbox file
Here I assume you are using mbox mailboxes. Since we need to do this every ten days, a good choice is to write a script and let the system run this script every ten days. Here's the script I wrote.
#!/bin/sh
#set archive directory
basedir=/home/usrname/mail/archive/
#define archive directory suffix
suffix=$(date +%Y%m%d)
#define archive directory name
desdir=$basedir$suffix
cd /home/usrname/mail/
#create archive directory
mkdir $desdir
tar czf $desdir/archive.tar.gz archive
#remove old mailbox
rm archive
#create a new archive mailbox
touch archive
echo Email archive-$suffix successfully created #echo a success message
Save the script in your home directory, and change the mode of the script by running
chmod 700 email-archive
Then try the script in your home directory.
./email-archive
3 Configure crontab
Cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix, solaris. To set the script to run every ten days, run the following command to edit cron jobs.
crontab -e
By default, it will get you into a vim editor. If you don't know how to use vim, follow the instruction at the end of this post.
In the editor, add the following line.
30 21 1,10,20 * * $HOME/email-archive
Run the following command to see if the cron job is correctly set.
crontab -l
Done!
Vim basics
When vim is started, you are not in the edit mode. Move cursor by hitting "j, k, h, l", and hit "i" at where you want to edit. You can see the INSERT not at the bottom. After done editing, hit ESC to quit edit mode. Then hit shift-z twice to save and quit.
1 comment:
Does Evolution have a similar facility?
Many thanks for your useful post (I am a newbie to Linux).
8-)
Post a Comment