I have connected and logged in to gmail's imap server using openssl. I intend to search for all mails that have an attachment with them. How can I do that?
IMAP itself does not have a search term for that, but Gmail's extended search support should allow you to search for messages with attachments. You'll have to select the folder you're interested in:
a SELECT INBOX
Then use the GMail specific search command:
b UID SEARCH X-GM-RAW "has:attachment"
That should give you a list of UIDs of messages that have attachments.