eMail Archiver as extension for MIAB

Hi!

as i found out in another thread meanwhile, there is no way to automatically archive his mails with roundcube or sieve. After I thought about this for a while it makes more and more sense to leave this task to the server.

What do you think?

Is there any software that does an automatic archiving, for example directly through IMAP? That would be a simple solution that would be a nice addition to Mail in a box, wouldn’t it?

From the (lack of) traction that other post got, I doubt that there is any interest.

However, I will say that MiaB takes a ‘keep it simple’ approach, so the likelihood of anything like this being added is slim to none.

Google is your friend. :slight_smile: (or maybe DuckDuckGo)

One, not simple and two not really in the scope of the project.

This would be very easy to set up with a script running on the MiaB server.
I currently have a script that deletes old messages from my trash folder once they are 30 days old. It does this by looking at the “Last Modified” date of the file itself. That date is updated whenever a file is moved, so the messages are deleted 30 days after they are placed in the trash. This nicely accounts for very old messages that I put in the trash; they won’t be deleted for 30 more days even though they were received much more than that ago.

My script is:

# cat /opt/filters/purge.sh 
#!/bin/bash

HOST=host.tld
USER=your_user
MAIL_BASE="/home/user-data/mail/mailboxes/${HOST}/${USER}"
find "${MAIL_BASE}"/.Trash/cur/ -type f -ctime +30 -print0 | xargs -r0 rm -v

And it’s run by cron every 5 minutes:

# crontab -l
*/5 * * * * root /opt/filters/purge.sh >/dev/null

This could be adapted to archive the messages by moving them from whatever folder you specify in to the archive folder.

find "${MAIL_BASE}"/cur/ -type f -ctime +30 -print0 | xargs -r0I% mv -n % "${MAIL_BASE}"/.Archive/new/

That will search the Inbox for messages last modified more than 30 days ago and move them to the Archive folder. It uses a non-overwriting ‘mv’ command as a safety measure. Worst case, it will repeatedly fail to move a message.

And my standard disclaimer that you shouldn’t try this unless you understand what the commands are doing and you have backups ready to fix any mistakes. I haven’t tested this example personally, but the trash purging has been working for me.

3 Likes

Thank you! Will try that :grinning:

This topic was automatically closed after 61 days. New replies are no longer allowed.