Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The proper way to delete mails? #236

Open
hills opened this issue Mar 30, 2023 · 6 comments
Open

The proper way to delete mails? #236

hills opened this issue Mar 30, 2023 · 6 comments

Comments

@hills
Copy link
Contributor

hills commented Mar 30, 2023

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.

@leahneukirchen
Copy link
Owner

Yes, xargs rm should work (modulo usual quoting issues). You can also flash as trashed and let the IMAP server expire it.

@hills
Copy link
Contributor Author

hills commented Mar 30, 2023

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

@leahneukirchen
Copy link
Owner

You may like my other project https://github.com/leahneukirchen/xe/ which is xargs with reasonable defaults. ;)

@leahneukirchen
Copy link
Owner

I'll add an mrm script to contrib at some point.

@hills
Copy link
Contributor Author

hills commented Mar 30, 2023

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.

hills added a commit to hills/mblaze that referenced this issue Mar 30, 2023
leahneukirchen pushed a commit that referenced this issue Mar 30, 2023
@Anachron
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants