Question:
Would I be able to do email has attachment search using some flag? Please help
Assuming you are using IMAP, it appears that the answer is no - there is no flag to support server-side searching for messages with attachments. However, a workaround where you download the headers, then search locally for messages that have attachment appears possible. You should be able to modify this example to suit your needs:
Thanks you.