Re: How to delete letters automatically with imaplib?
elearn elearn2...@gmail.com writes: status, data= con.search(None, ALL) print(len(data[0].split())) 48 typ, data= con.search(None, 'Body', 'x...@gmail.com') data [b'1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 32 33 34 35 36 37 44'] len(data[0].split()) 36 How can i delete 48-36=12 letters? Set operations are designed for this:: # Construct a set of all message numbers. status, data = con.search(None, ALL) ids_of_all_messages = set(data[0].split()) # Construct a set of messages mentioning the address. status, data = con.search(None, 'Body', 'x...@gmail.com') ids_of_messages_containing_address = set(data[0].split()) # Get the messages to delete. ids_of_messages_to_delete = ( ids_of_all_messages - ids_of_messages_containing_address) -- \ “Too many pieces of music finish too long after the end.” —Igor | `\ Stravinskey | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: How to delete letters automatically with imaplib?
and how to write the delete command with imaplib? On 8/6/2014 5:14 PM, Ben Finney wrote: elearn elearn2...@gmail.com writes: status, data= con.search(None, ALL) print(len(data[0].split())) 48 typ, data= con.search(None, 'Body', 'x...@gmail.com') data [b'1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 32 33 34 35 36 37 44'] len(data[0].split()) 36 How can i delete 48-36=12 letters? Set operations are designed for this:: # Construct a set of all message numbers. status, data = con.search(None, ALL) ids_of_all_messages = set(data[0].split()) # Construct a set of messages mentioning the address. status, data = con.search(None, 'Body', 'x...@gmail.com') ids_of_messages_containing_address = set(data[0].split()) # Get the messages to delete. ids_of_messages_to_delete = ( ids_of_all_messages - ids_of_messages_containing_address) -- https://mail.python.org/mailman/listinfo/python-list
Re: How to delete letters automatically with imaplib?
elearn elearn2...@gmail.com writes: and how to write the delete command with imaplib? (Please don't top-post. Instead, compose your responses interleaved URL:https://en.wikipedia.org/wiki/Posting_style#Interleaved_style so the conversation is easier to follow in the message.) I'm not familiar with the API of the ‘imaplib’ module. Start with URL:https://docs.python.org/3/library/imaplib.html and remember that it is a library designed to work intimately with the IMAP command-response protocol. If, instead, you wish to manipulate mailboxes without needing to know much about the detailed features of the storage format, use the URL:https://docs.python.org/3/library/mailbox.html ‘mailbox’ module for that purpose. -- \“No matter how cynical you become, it's never enough to keep | `\up.” —Jane Wagner, via Lily Tomlin | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list