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 emailsThis 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 fileHere 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.
#set archive directory
#define archive directory suffix
#define archive directory name
#create archive directory
tar czf $desdir/archive.tar.gz archive
#remove old mailbox
#create a new archive mailbox
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.
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.
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.
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.