Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What threading algorithm(s) does Python's IMAP library support?

The documentation for IMAP4.thread() in the imaplib library says

The thread command is a variant of search 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?

like image 854
Michael A Avatar asked May 24 '16 20:05

Michael A


People also ask

What is IMAP in python?

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.

What is threading in python?

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.

How many threads can python run?

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.

Why is python multithreading slower sometime than multiprocess?

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.


1 Answers

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.

like image 133
Max Avatar answered Sep 26 '22 16:09

Max