By using OpenSSL you can access your inbox and easily parse the result via grep. Assuming you have a linux box available follow these simple steps:
Connect via SSL to GMail (tee output to a file):
openssl s_client -crlf -connect imap.gmail.com:993 | tee /tmp/mail-headers.txt
Once connected you need to login with your username and application specific password:
tag login firstname.lastname@example.org password
tag login email@example.com apppassword
The application password can be generated in your GMail's preferences menu.
With the prefered inbox (folder) type in the following command to see the the number of messages in the folder.
tag STATUS INBOX (MESSAGES)
* STATUS "INBOX" (MESSAGES 3214)
tag OK Success
This tells me I have 3214 messages in the folder INBOX. Now I can write all the messages (including headers) out and store them as I wish. Issue the following commands to print all messages:
tag SELECT INBOX
tag FETCH 1:3214 (BODY[HEADER])
The numbers are to specify I want to print message 1 through 3214.
Proceed with a logout:
Then you can grep through the output as you see fit like so:
grep '220.127.116.11' /tmp/mail-headers.txt
You may prefer to see context around the lines and page through them to find related
Subject: headers too:
grep --color=always -C 10 '18.104.22.168' /tmp/mail-headers.txt | less -R