I use the following cron job on my server using doveadm running on the imap server:
lrosenman:~ lrosenman$ ssh tbh.lerctr.org cat bin/archive-mail
#!/bin/sh
PATH=$PATH:/usr/local/bin
#Expects to be run after midnight on the first of the month
# to archive all the previous months mail
#Date Run:
TODAY=`date "+%Y-%m-%d"`
#last month in YYYY/MM
YEAR_LAST_MONTH=`date -v-1d "+%Y/%m"`
#1st of last month as 01-Mon-YYYY
FIRST_LAST_MONTH=`date -v-1d "+01-%b-%Y"`
echo 'TODAY=' ${TODAY}
echo 'YEAR_LAST_MONTH=' ${YEAR_LAST_MONTH}
echo 'FIRST_LAST_MONTH=' ${FIRST_LAST_MONTH}
# get a list of all the mailboxes with at least one real message
doveadm -f tab mailbox status vsize \* 2>/dev/null |
sed -e 1d | sort -k 1,1 |
awk 'BEGIN {FS="\t"} {if ($2 > 0) print $1}' |
while read i
do
echo `date` start ${i}
doveadm mailbox create "ARCHIVE/${YEAR_LAST_MONTH}/${i}"
doveadm -f tab mailbox status messages "${i}"
doveadm move "ARCHIVE/${YEAR_LAST_MONTH}/${i}" mailbox \
"${i}" BEFORE ${TODAY} SINCE ${FIRST_LAST_MONTH}
doveadm -f tab mailbox status messages "${i}"
echo `date` done ${i}
done
lrosenman:~ lrosenman$
Whether you can run on YOUR server, I do not know, but I've been running this script for ~1 year.
--
Larry Rosenman http://www.lerctr.org/~ler
Phone: +1 214-642-9640 E-Mail: ***@lerctr.org
US Mail: 5708 Sabbia Drive, Round Rock, TX 78665-2106
Post by Dan RitterPost by tech-listsI'm running mutt 1.9.1 (2017-09-22) on freebsd-11-stable.
What I'd like to have is, when mutt loads, it scans its subscribed
folders and moves the mail based on date received into preconfigured
mail folders. Either that, or maybe run another standalone program in a
screen or cron that does the same. I don't want to "download" the mail
at this stage - it needs to be moved around on the remote server.
Can mutt do this, or is there another program that does this with imap4?
If your IMAP server supports SIEVE, that is the easiest way to
get this done. Sorting will happen at delivery time.
Hi, sorry for the late reply
The reason I can't use SIEVE is because SIEVE rules act at delivery time
only. By delivery time, I mean the time they arrive on the imap server.
What I want to happen is, for emails already in folders on the imap
server, if they're over say 30 days old, for an automatic process to
move them into an archive folder on the same server.
thanks,
--
J.