Add licencing, README and file hierarchy
[imap-mark-seen] / imap_set_annotation.py
diff --git a/imap_set_annotation.py b/imap_set_annotation.py
deleted file mode 100644 (file)
index aaf52ae..0000000
+++ /dev/null
@@ -1,92 +0,0 @@
-"""Collection of functions for mass IMAP server manipulation"""
-import imaplib
-import logging
-import re
-
-SERVER = 'intranator.m.i2n'
-USERNAME = 'FIXME'
-PASSWORD = 'FIXME'
-ANNOTATION_SHARED_SEEN = '"/vendor/cmu/cyrus-imapd/sharedseen"'
-
-MAILBOX_RESP = re.compile(r'\((?P<flags>.*?)\) "(?P<delimiter>.*)" (?P<name>.*)')
-
-# imaplib.Debug = 5
-
-class ImapAction:
-    """Class for mass IMAP manipulation"""
-
-    def __init__(self, server, username, password):
-        self.mail_con = None
-        self.mailboxes = None
-
-        # connect to server
-        try:
-            self.mail_con = imaplib.IMAP4(server)
-        except Exception as ex:
-            raise UserWarning("Could not connect to host %s: %s" % (server, ex))
-
-        # log in
-        try:
-            self.mail_con.login(username, password)
-            logging.info("Logged in as %s.", username)
-        except:
-            self.logged_in = False
-            raise UserWarning("Could not log in as user " + username)
-        self.logged_in = True
-
-        # list mailboxes
-        try:
-            _result, self.mailboxes = self.mail_con.list()
-        except (self.mail_con.error):
-            raise UserWarning("Could not retrieve mailboxes for user " + username)
-
-    def mass_set_group_rights(self, identifier, rights):
-        """Mass set ACL rights on mailboxes"""
-        for raw_mailbox in self.mailboxes:
-            mailbox = MAILBOX_RESP.match(raw_mailbox.decode('iso-8859-1')).groups()[2]
-            if not mailbox.startswith('\"INBOX'):
-                print('Skipping mailbox %s' % mailbox)
-                continue
-            print('Modifying ACL for mailbox %s' % mailbox)
-
-            self.mail_con.setacl(mailbox, identifier, rights)
-
-    def mass_set_shared_seen(self):
-        """Enable shared seen state on all mailboxes"""
-        for raw_mailbox in self.mailboxes:
-            mailbox = MAILBOX_RESP.match(raw_mailbox.decode('iso-8859-1')).groups()[2]
-            if not mailbox.startswith('\"INBOX'):
-                print('Skipping mailbox %s' % mailbox)
-                continue
-            print('Setting sharedseen annotation on mailbox %s' % mailbox)
-
-            self.mail_con.setannotation(mailbox, ANNOTATION_SHARED_SEEN, '("value.shared" "true")')
-
-    def list_sharedseen_state(self):
-        """List shared seen state on all mailboxes"""
-        for raw_mailbox in self.mailboxes:
-            mailbox = MAILBOX_RESP.match(raw_mailbox.decode('iso-8859-1')).groups()[2]
-            if not mailbox.startswith('\"INBOX'):
-                print('Skipping mailbox %s' % mailbox)
-                continue
-
-            raw_annotations = self.mail_con.getannotation(mailbox, ANNOTATION_SHARED_SEEN, '"value.shared"')
-
-            # Hack to parse annotation result
-            sharedseen_enabled = False
-            if str(raw_annotations[1]).find('("value.shared" "true")') != -1:
-                sharedseen_enabled = True
-
-            print('sharedseen state on mailbox %s: %s' % (mailbox, sharedseen_enabled))
-
-def main():
-    """Main function"""
-    imap = ImapAction(SERVER, USERNAME, PASSWORD)
-
-    imap.mass_set_group_rights("group:infokonto", "lrswipcd")
-    imap.mass_set_shared_seen()
-
-    imap.list_sharedseen_state()
-
-if(__name__ == "__main__"):
-    main()