Skip to content

Instantly share code, notes, and snippets.

@barik
Last active August 5, 2017 17:57
Show Gist options
  • Save barik/a966731cfae1450b39244aadf1c7c9e1 to your computer and use it in GitHub Desktop.
Save barik/a966731cfae1450b39244aadf1c7c9e1 to your computer and use it in GitHub Desktop.
import imaplib
HOST = "imap.gmail.com"
USER = "tbarik@ncsu.edu"
PASSWORD = "---"
BATCH_FOLDER = "Batch"
INBOX_FOLDER = "\\Inbox"
def batch_mail():
server = imaplib.IMAP4_SSL(HOST)
server.login(USER, PASSWORD)
server.select(BATCH_FOLDER)
typ, [msg_uids] = server.uid("SEARCH", "ALL")
msg_uids = msg_uids.replace(' ', ',')
if msg_uids:
server.uid("STORE", msg_uids, "+X-GM-LABELS", INBOX_FOLDER)
server.uid("STORE", msg_uids, "+FLAGS.SILENT", r"(\Deleted)")
server.uid("EXPUNGE", msg_uids)
print msg_uids
return msg_uids
# noinspection PyUnusedLocal
def lambda_handler(event, context):
return batch_mail()
if __name__ == '__main__':
batch_mail()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment