Re: Statistics about senders with notmuch possible?

Subject: Re: Statistics about senders with notmuch possible?

Date: Fri, 07 Jan 2022 09:32:43 -0800

To: signmeup1337@cock.li, notmuch@notmuchmail.org

Cc:

From: Carl Worth


On Mon, Dec 27 2021, signmeup wrote:
> I would like to create some kind of statistics to see from which sender
> I've got the most emails, having something like a TOP 10 list.
>
[ 4 more citation lines. Click/Enter to show. ]
> In the end of every year I delete all my emails, which are not marked as
> archive and this year I got over 4.000 and most of them are just
> notifications (like ebay, if someone buys something). But I really would
> like to figure out where else the most mails are coming from to avoid
> them in the next year.
>
> Is something like this possible with notmuch?

Yes, it's definitely possible. Being able to script up operations like
this that act on your email store has always been a primary design goal
of notmuch, so this isn't actually hard to do.

Given any sender address you can ask notmuch to count the emails sent
from that address. Such as:

        notmuch count from:cworth@cworth.org

And you can also use notmuch to generate a list of all sender email
addresses across all of your email, with:

        notmuch address --output=sender --output=address '*'

So you can take the output from that second command and then run the
first command with email address in the output.

Doing that all combined, and the sorting the result might look something
like the following (assuming you are using bash as your shell):

        for sender in $(notmuch address --output=sender --output=address
'*'); do count=$(notmuch count from:$sender); echo "$count $sender"; done |
sort -n

If you wanted to run this on a subset of your email, just change the '*'
to a search specification for the messages you want to match, (where '*'
will match all messages).

And of course, this is running a separate notmuch search for every
sender email address you have in all of your emails, (not only the top
10 like you really want), so this could take some time if you have a lot
of messages. I just tested with a small subset of my own email messages
(the 21k+ messages I have matching 'subject:notmuch') and the above
script took about 30 seconds on my laptop.

I hope that helps,

-Carl
signature.asc (application/pgp-signature)
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: