Home > OS >  IMAPlib how to select only emails since a given date
IMAPlib how to select only emails since a given date

Time:10-13

With IMAPlib I am using:

self.m.select("Inbox") 
typ, mail = self.m.search(None, "(ALL)", f'(SENTSINCE {datesince})')

where:

datesince = (datetime.date.today() - datetime.timedelta(days=self.timerange)).strftime("%d-%b-%Y")

print("Datesince:", datesince)

Gives:

Datesince: 08-Oct-2021

But in my log file I can see that all the following emails were dealt with, some are from previous dates way in the past, why is the since filter not precise?

This is how I loop through the emails:

typ, mail = self.m.search(None, "(ALL)", f'(SENTSINCE {datesince})')
    ids = mail[0]
    id_list = ids.split()
    latest_email_id = int(id_list[-1])
    oldest_email_id = int(id_list[0])
    countmail = latest_email_id - oldest_email_id   1
    print("countmail:", countmail)

    for self.i in tqdm(range(latest_email_id, oldest_email_id - 1, -1)):
        print("Incrementation:",self.i)
        typ, x = self.m.fetch(str(self.i), '(RFC822)')

I expunge deleted emails only after the loop.

Iterating over all mails to extract NAVs countmail: 16 Incrementation: 265 subject: Amundi CDA Abs RTN MLT-STRGY Fund (ARMS) - 10082021 price delay Date: Fri, 8 Oct 2021 22:10:34 0000 Mail not deleted Incrementation: 264 subject: TR: Cashoutflow 01110066S03, DeAM-Fonds ENPT CORP Date: Thu, 7 Oct 2021 11:29:46 0200 Mail not deleted Incrementation: 263 subject: R: ALIFOND: OUTFLOW Date: Fri, 8 Oct 2021 16:21:30 0200 Mail not deleted Incrementation: 262 subject: RE: ONBOARDING - PF92671 – BOK GLOBAL DEVELOPED MARKETS FIXED INCOM - LAUNCH DATE 08/10/2021 Date: Fri, 8 Oct 2021 16:19:51 0200 Mail not deleted Incrementation: 261 subject: RE: ONBOARDING - PF92671 – BOK GLOBAL DEVELOPED MARKETS FIXED INCOM - LAUNCH DATE 08/10/2021 Date: Fri, 8 Oct 2021 14:58:31 0200 Mail not deleted Incrementation: 260 subject: RE: STANLIB IM ADVICE - CreLiq_Amundi-MM Global Bond - 06/10/2021 Date: Fri, 8 Oct 2021 12:50:06 0200 Mail not deleted Incrementation: 259 subject: RE: September 30,2021 NAV AM-MY EURO CREDIT FUND Not received Date: Fri, 8 Oct 2021 12:01:27 0200 Mail not deleted Incrementation: 258 subject: RE: Problème perf daido Date: Thu, 7 Oct 2021 17:34:51 0200 Mail not deleted Incrementation: 257 subject: NAV officielle PF82299 Mirae - intégration PAMS Date: Tue, 12 Jan 2021 11:19:41 0100 Mail not deleted Incrementation: 256 subject: NAV officielle PF82299 Mirae - intégration PAMS Date: Tue, 12 Jan 2021 11:19:41 0100 Mail not deleted Incrementation: 255 subject: RE: ONBOARDING - PF90548 – CAVOM OBLIGATIONS INTERNATIONALES - LAUNCH DATE 06/10/2021 Date: Wed, 6 Oct 2021 13:22:53 0200 Mail not deleted Incrementation: 254 subject: RE: Aged claim !!- LU3503 DVD query ISIN: SE0000115446 ex date 30/06/2021 Account: 373662 -- Claim #186735 --- 1053736620W [AS3PAM-MAS-13894] Date: Thu, 7 Oct 2021 03:04:26 0000 Mail not deleted Incrementation: 253 subject: FW: Trade FX Settlement Query -LU3510 Monnet -373669 Date: Tue, 28 Sep 2021 13:51:08 0200 Mail not deleted Incrementation: 252 subject: RE: Devises - Desjardins Desjardins Pooled Fund State Farm & TPIC Pension Plan September 2021 Date: Wed, 29 Sep 2021 14:23:09 0200 Mail not deleted Incrementation: 251 subject: ONBOARDING - PF90548 – CAVOM OBLIGATIONS INTERNATIONALES - LAUNCH DATE 06/10/2021 Date: Thu, 30 Sep 2021 13:48:26 0200 /home/ludo915/automate_PDP_IMAP/attachments/Onboarding Form CAVOM Obligations Internationales.xlsx /home/ludo915/automate_PDP_IMAP/attachments/CAVOM_Obligations_Internationales_2021-09-30_1630583721207.pdf

CodePudding user response:

It is precise. IMAP allows you to search for email both by arrival date at the recipient's server and by the sender's stated date. As you can see from the spec the relevant keys are since and sentsince.

CodePudding user response:

Although I am getting a few emails way in the past, outside the SINCE boundaries, I believe this is due to maternity leaves and people on holidays turning off their computers, and being part of a given mailing list, coming back to work & switching back on their outlook.

  • Related