The documentation for IMAP4.thread()
in the imaplib
library says
The
thread
command is a variant ofsearch
with threading semantics for the results. Returned data contains a space separated list of thread members.Thread members consist of zero or more messages numbers, delimited by spaces, indicating successive parent and child.
Thread has two arguments before the search_criterion argument(s); a threading_algorithm, and the searching charset.
It's not clear to me what to use for the threading_algorithm argument. The documentation doesn't indicate a default value, and the source code for the IMAP4.thread()
function
def thread(self, threading_algorithm, charset, *search_criteria):
"""IMAPrev1 extension THREAD command.
(type, [data]) = <instance>.thread(threading_algorithm, charset, search_criteria, ...)
"""
name = 'THREAD'
typ, dat = self._simple_command(name, threading_algorithm, charset, *search_criteria)
return self._untagged_response(typ, dat, name)
doesn't give me any ideas either, even after digging into the _simple_command
helper function.
What should I use for this argument? Is there documentation elsewhere for this?
Python's client side library called imaplib is used for accessing emails over imap protocol. IMAP stands for Internet Mail Access Protocol. It was first proposed in 1986. Key Points: IMAP allows the client program to manipulate the e-mail message on the server without downloading them on the local computer.
Threading in python is used to run multiple threads (tasks, function calls) at the same time. Note that this does not mean that they are executed on different CPUs. Python threads will NOT make your program faster if it already uses 100 % CPU time.
Generally, Python only uses one thread to execute the set of written statements. This means that in python only one thread will be executed at a time.
This is due to the Python GIL being the bottleneck preventing threads from running completely concurrently. The best possible CPU utilisation can be achieved by making use of the ProcessPoolExecutor or Process modules which circumvents the GIL and make code run more concurrently.
This depends on the server; the CAPABILITIES response should tell you what threading algorithms the server supports, under the THREAD= keys.
For example:
* OK [CAPABILITY IMAP4rev1 UIDPLUS CHILDREN NAMESPACE THREAD=ORDEREDSUBJECT THREAD=REFERENCES SORT QUOTA IDLE AUTH=PLAIN ACL ACL2=UNION ID] Courier-IMAP ready. Copyright 1998-2011 Double Precision, Inc. See COPYING for distribution information.
This server supports the ORDEREDSUBJECT and REFERENCES algorithms.
The description of the baseline algorithms is indicated in the IMAP SORT and THREAD RFC.
imaplib is a very low level library, you will need to parse the responses yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With