Skip to content

Instantly share code, notes, and snippets.

@martinrusev
Last active March 22, 2024 06:50
Show Gist options
  • Star 94 You must be signed in to star a gist
  • Fork 30 You must be signed in to fork a gist
  • Save martinrusev/6121028 to your computer and use it in GitHub Desktop.
Save martinrusev/6121028 to your computer and use it in GitHub Desktop.
IMAP Search criteria
@HamidSayeed
Copy link

can you give an example with HEADER / UID where we can search with MESSAGE id of the mail?
Any help would be much appreciated. Thanks

@PEKTOP
Copy link

PEKTOP commented Nov 9, 2018

@HamidSayeed

UID SEARCH HEADER Message-ID <53513DD7.8090606@imap.local>

@tiev
Copy link

tiev commented Feb 21, 2019

@tscheer100
Copy link

is there a link with examples to these?

@tobiasm-1
Copy link

Do you know of a search key where the first/last email is found?

@harshmalvi97
Copy link

@tobiasm-1 This will gives you latest uid of email.
client.selectMailbox("INBOX").then((inbox) => {
let numberEmails = inbox.exists;
console.log("# messages: " + numberEmails);
return numberEmails;
})

@gregsvieira
Copy link

i'm using the download-email-attachments library and after modified date criterion through the function processMails(node_modules\download-email-attachments\lib\find-emails.js.) from "SINCE" to "UNSEEN" doesnt work.
Someone know why?

@paulonteri
Copy link

Here's one example:

https://stackoverflow.com/a/66906573/10904662


You can use SENTSINCE to get most recent messages

date = (datetime.date.today() - datetime.timedelta(days=2)).strftime("%d-%b-%Y")
typ, messages = m.search(None, '(ALL)', f'(SENTSINCE {date})')

To get only today messages you can use

date = datetime.date.today().strftime("%d-%b-%Y")

Une can as well replace '(ALL)' by '(UNSEEN)' to get only unseen messages

@karado58
Copy link

karado58 commented Aug 23, 2022

Can you please give me an example for the HEADER <field-name> <string>
field-name is: Authentication-Results
string is: header.i=@

This below is generating errors:
resp_code, mails = imap_ssl.search(None, '(HEADER "Authentication-Results" "header.i=@")')

@ravitalaviya
Copy link

I want to extract only automatic reply mail body and signature. so, anyone help me please

@n9
Copy link

n9 commented Aug 30, 2023

@iamansingh0
Copy link

Can anyone help? I only want to extract emails sent since 8 hour ago.

@ayushsingh021
Copy link

hey why search function not searching correctly if there are spaces in the subject can anyone tell??

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment