Skip to content

Instantly share code, notes, and snippets.

@martinrusev
Last active December 19, 2025 22:58
Show Gist options
  • Select an option

  • Save martinrusev/6121028 to your computer and use it in GitHub Desktop.

Select an option

Save martinrusev/6121028 to your computer and use it in GitHub Desktop.
IMAP Search criteria
@nickdenisenko

Copy link
Copy Markdown

@HamidSayeed

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

@tiev

tiev commented Feb 21, 2019

Copy link
Copy Markdown

@tscheer100

Copy link
Copy Markdown

is there a link with examples to these?

@tobiasm-1

Copy link
Copy Markdown

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

@harshmalvi97

Copy link
Copy Markdown

@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
Copy Markdown

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
Copy Markdown

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

karado58 commented Aug 23, 2022

Copy link
Copy Markdown

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
Copy Markdown

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

@n9

n9 commented Aug 30, 2023

Copy link
Copy Markdown

@iamansingh0

Copy link
Copy Markdown

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

@ayushsingh021

Copy link
Copy Markdown

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