Closed hills closed 3 weeks ago
Yes, xargs rm
should work (modulo usual quoting issues). You can also flash as trashed and let the IMAP server expire it.
Thanks for such a quick reply.
I don't think my IMAP server automatically does this (though there's a command at my client, alpine, to "purge")
(modulo usual quoting issues)
I suppose that's another good reason for a dedicated command (could be equivalent of rm or even xargs for mails): ensure one message per-line and have a safety check that the filename (and possibly first block of content) looks like a mail message.
In the spirit of community, shall I see if I can patch the docs so people don't need to ask again.
The existing example:
mdirs ~/Maildir | xargs minc | mthread | mless
there's no consideration for pathnames with spaces. So should I just follow in the spirit of it being an example, with a simple xargs again:
mlist ~/Maildir | mpick -t 'mtime < "-365d"' | xargs rm
Because the full example gets cluttered and is probably only moving the goalposts:
`mlist ~/Maildir | mpick -t 'mtime < "-365d"' | xargs -d '\n' -r rm
You may like my other project https://github.com/leahneukirchen/xe/ which is xargs with reasonable defaults. ;)
I'll add an mrm
script to contrib at some point.
You may like my other project https://github.com/leahneukirchen/xe/ which is xargs with reasonable defaults. ;)
Brilliant! I was thinking exactly that as I wrote the previous message.
To give you another idea on how to do it, I wrote a script to automatically move old mails to an "ARCHIVE" mailbox which isn't synced back to the server.
This way I don't clutter my inbox while still being able to read them later if needed to.
#!/bin/sh
MAILACC="${1}"
MAILINBOX="${HOME}/usr/mls/${MAILACC}/INBOX"
MAILARCHIVE="${HOME}/usr/mls/${MAILACC}/ARCHIVE"
MAILYEAR=$(echo "$(date +%Y) -2" | bc -s)
test -d "${MAILINBOX}" || exit 1
! test -d "${MAILARCHIVE}" && mmkdir "${MAILARCHIVE}"
printf 'Searching for messages older than %s-01-01\n' "${MAILYEAR}"
ml=$(mlist "${MAILINBOX}" | mpick -t 'date <= "'"${MAILYEAR}"'-01-01"' | msort -d)
test -n "${ml}" || { printf 'Nothing found!\n'; exit; }
printf 'Archiving %s messages\n' $(printf '%s\n' "${ml}" | wc -l)
printf '%s\n' "${ml}" | mrefile "${MAILARCHIVE}"
printf 'Creating inbox sequence\n'
mlist "${MAILINBOX}" | msort -r -d > "${HOME}/usr/mls/${MAILACC}/inbox.seq"
printf 'Creating archive sequence\n'
mlist "${MAILARCHIVE}" | msort -r -d > "${HOME}/usr/mls/${MAILACC}/archive.seq"
I'm very pleased to have discovered mblaze, thank you.
I'd like to automate deletion of some old mails, but no such example is given in the docs.
If this is as simple as "xargs rm", or should it be "mflag -T"?
If I use the latter, is there an mblaze command to actually delete "trashed" mails?
Just a single example of the best practice in the docs would help.
I'm not saying a specific blaze command is needed, but one could have some safety checks. Waving "xargs rm" around makes me nervous...
In my cases, mails are served from Dovecot which keeps its own index, and therefore I'm assuming it's its own responsibility to deal with changes to the underlying Maildir.