Piero V.

Another rant on emails

A pair of weeks ago, some people asked me for help because their Outlook was not working anymore. It complained that its data file had reached the maximum size.

Being a Linux user, I have never had Outlook on my machines.

I used it only at my previous job, with an exchange server. I must admit it used to work fine. It even has some appreciable features, such as the company directory, shared calendars that work immediately, etc.

So, when people ask me if I can help them with their Outlook problems, I try to answer as a courtesy. Usually, they are easy problems, and I solve them by searching for their error messages in English and translating the solution into Italian.

One of the suggested solutions for the problem was to empty the bin. But it contained almost one million emails 😨️. So, I went to the webmail and found that the webmail also has the same amount of emails to delete.

The web client also says that emails are automatically deleted after 90 days, but it contained emails from more than two years ago.

It also has a button to empty the folder… but I think it communicates to the backend through IMAP itself, and of course, it went on timeout 😄️.

So, I wrote this Python script to the rescue…

from datetime import datetime
import imaplib
import sys

# Too many emails, Python needs higher limits!
imaplib._MAXLINE *= 1000

HOST = "imap.yourdomain.tld"
USER = "username"
PASS = "password"

M = imaplib.IMAP4(HOST)
M.starttls()
print(M.login(USER, PASS))
M.select("INBOX.Trash")
for i in range(100):
    print("Starting again")
    # In case some messages were not deleted, yet
    M.expunge()
    t, data = M.search(None, "ALL")
    messages = data[0].split(b" ")
    i = 0
    for mail in sorted(messages):
        try:
            M.store(mail, "+FLAGS", "\\Deleted")
        except imaplib.IMAP4.error as e:
            # Not sure why, but the loop stops at a certain point
            print("Error", e)
            break
        i += 1
        # Show that the script is actually working
        if (i % 1000) == 0:
            M.expunge()
            print("Purging", i, datetime.now())

# Final purge
M.expunge()
M.close()
M.logout()

It was extremely slow: it could delete only ten emails per second 😢️. So, I left it working on an always-on server, hoping it would solve the problem.

I arrived to see an empty bin a pair of weeks ago, but today it has 300,000 emails, and still emails from May 2020. Many of them are even repeated.

I still have not understood where the problem lies. But IMAP 4 is almost 20, and Outlook is even older. I can find only a word for a similar issue: unacceptable.

I do not know if we will ever find the cause and a solution to this problem. I do not have any tools to debug it: for me it is just a blackbox of proprietary software and cloud services.

Now, I am all-in for open standards, but if the person who contacted me wants to keep using Outlook, it is their choice, and they should switch to Office 365. It would also solve other problems they have.

My other solution is that they should finally ditch Outlook in favor of anything else.