Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #75787 > unrolled thread

Re: How to delete letters automatically with imaplib?

Started byBen Finney <ben+python@benfinney.id.au>
First post2014-08-06 19:14 +1000
Last post2014-08-06 19:14 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: How to delete letters automatically with imaplib? Ben Finney <ben+python@benfinney.id.au> - 2014-08-06 19:14 +1000

#75787 — Re: How to delete letters automatically with imaplib?

FromBen Finney <ben+python@benfinney.id.au>
Date2014-08-06 19:14 +1000
SubjectRe: How to delete letters automatically with imaplib?
Message-ID<mailman.12694.1407316492.18130.python-list@python.org>
elearn <elearn2014@gmail.com> writes:

> status,  data=  con.search(None,  "ALL")
> print(len(data[0].split()))
> 48
> typ,  data=  con.search(None,  'Body',  '"xxx@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', '"xxx@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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web