]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Simplify Gmail label methods
authorMenno Smits <menno@freshfoo.com>
Mon, 5 Sep 2016 12:11:03 +0000 (00:11 +1200)
committerMenno Smits <menno@freshfoo.com>
Mon, 5 Sep 2016 12:17:56 +0000 (00:17 +1200)
Introduced a intermediate method to cover the commonalities between the
various Gmail label handling methods. Note: Gmail labels can be quoted,
whereas standard IMAP flags can't.

imapclient/imapclient.py

index 0b7c714f951b74d9da829206a55ae46813a435df..b6d470cd4558abe8e173a118fd3ddb228031fe21 100644 (file)
@@ -887,9 +887,8 @@ class IMAPClient(object):
         This only works with IMAP servers that support the X-GM-LABELS
         attribute (eg. Gmail).
         """
-        return self._store(b'+X-GM-LABELS', messages,
-                           self._normalise_labels(labels), b'X-GM-LABELS',
-                           silent=silent)
+        return self._gm_label_store(b'+X-GM-LABELS', messages, labels,
+                                    silent=silent)
 
     def remove_gmail_labels(self, messages, labels, silent=False):
         """Remove one or more *labels* from *messages* in the
@@ -903,9 +902,8 @@ class IMAPClient(object):
         This only works with IMAP servers that support the X-GM-LABELS
         attribute (eg. Gmail).
         """
-        return self._store(b'-X-GM-LABELS', messages,
-                           self._normalise_labels(labels), b'X-GM-LABELS',
-                           silent=silent)
+        return self._gm_label_store(b'-X-GM-LABELS', messages, labels,
+                                    silent=silent)
 
     def set_gmail_labels(self, messages, labels, silent=False):
         """Set the *labels* for *messages* in the currently selected
@@ -919,9 +917,8 @@ class IMAPClient(object):
         This only works with IMAP servers that support the X-GM-LABELS
         attribute (eg. Gmail).
         """
-        return self._store(b'X-GM-LABELS', messages,
-                           self._normalise_labels(labels), b'X-GM-LABELS',
-                           silent=silent)
+        return self._gm_label_store(b'X-GM-LABELS', messages, labels,
+                                    silent=silent)
 
     def delete_messages(self, messages, silent=False):
         """Delete one or more *messages* from the currently selected
@@ -1201,6 +1198,10 @@ class IMAPClient(object):
     def _checkok(self, command, typ, data):
         self._check_resp('OK', command, typ, data)
 
+    def _gm_label_store(self, cmd, messages, labels, silent):
+        return self._store(cmd, messages, self._normalise_labels(labels),
+                           b'X-GM-LABELS', silent=silent)
+
     def _store(self, cmd, messages, flags, fetch_key, silent):
         """Worker function for the various flag manipulation methods.