Patch #798297: Add IMAP THREAD command.
diff --git a/Lib/imaplib.py b/Lib/imaplib.py
index d9166e0..8004982 100644
--- a/Lib/imaplib.py
+++ b/Lib/imaplib.py
@@ -69,6 +69,7 @@
         'STATUS':       ('AUTH', 'SELECTED'),
         'STORE':        ('SELECTED',),
         'SUBSCRIBE':    ('AUTH', 'SELECTED'),
+        'THREAD':       ('SELECTED',),
         'UID':          ('SELECTED',),
         'UNSUBSCRIBE':  ('AUTH', 'SELECTED'),
         }
@@ -679,6 +680,16 @@
         return self._simple_command('SUBSCRIBE', mailbox)
 
 
+    def thread(self, threading_algorithm, charset, *search_criteria):
+        """IMAPrev1 extension THREAD command.
+
+        (type, [data]) = <instance>.thread(threading_alogrithm, charset, search_criteria, ...)
+        """
+        name = 'THREAD'
+        typ, dat = self._simple_command(name, threading_algorithm, charset, *search_criteria)
+        return self._untagged_response(typ, dat, name)
+
+
     def uid(self, command, *args):
         """Execute "command arg ..." with messages identified by UID,
                 rather than message number.