Changeset View
Changeset View
Standalone View
Standalone View
cyruslib.py
Show All 12 Lines | |||||
# This program is distributed in the hope that it will be useful, | # This program is distributed in the hope that it will be useful, | ||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | # GNU General Public License for more details. | ||||
# You should have received a copy of the GNU General Public License | # You should have received a copy of the GNU General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
# | # | ||||
# Requires python >= 2.3 | # Requires python >= 2.6 | ||||
# | # | ||||
from __future__ import print_function | |||||
__version__ = '0.8.5' | __version__ = '0.8.5' | ||||
__all__ = [ 'CYRUS' ] | __all__ = [ 'CYRUS' ] | ||||
__doc__ = """Cyrus admin wrapper | __doc__ = """Cyrus admin wrapper | ||||
Adds cyrus-specific commands to imaplib IMAP4 Class | Adds cyrus-specific commands to imaplib IMAP4 Class | ||||
and defines new CYRUS class for cyrus imapd commands | and defines new CYRUS class for cyrus imapd commands | ||||
""" | """ | ||||
from sys import exit, stdout | from sys import exit, stdout | ||||
try: | try: | ||||
import imaplib | import imaplib | ||||
import re | import re | ||||
from binascii import b2a_base64 | from binascii import b2a_base64 | ||||
except ImportError, e: | except ImportError, e: | ||||
print e | print(e) | ||||
exit(1) | exit(1) | ||||
Commands = { | Commands = { | ||||
'RECONSTRUCT' : ('AUTH',), | 'RECONSTRUCT' : ('AUTH',), | ||||
'DUMP' : ('AUTH',), # To check admin status | 'DUMP' : ('AUTH',), # To check admin status | ||||
'ID' : ('AUTH',), # Only one ID allowed in non auth mode | 'ID' : ('AUTH',), # Only one ID allowed in non auth mode | ||||
'GETANNOTATION': ('AUTH',), | 'GETANNOTATION': ('AUTH',), | ||||
'SETANNOTATION': ('AUTH',), | 'SETANNOTATION': ('AUTH',), | ||||
▲ Show 20 Lines • Show All 289 Lines • ▼ Show 20 Lines | def __init__(self, url = 'imap://localhost:143'): | ||||
self.__doraise("CONNECT") | self.__doraise("CONNECT") | ||||
def __del__(self): | def __del__(self): | ||||
if self.AUTH: | if self.AUTH: | ||||
self.logout() | self.logout() | ||||
def __verbose(self, msg): | def __verbose(self, msg): | ||||
if self.VERBOSE: | if self.VERBOSE: | ||||
print >> self.LOGFD, msg | print(msg, file=self.LOGFD) | ||||
def __doexception(self, function, msg=None, *args): | def __doexception(self, function, msg=None, *args): | ||||
if msg is None: | if msg is None: | ||||
try: | try: | ||||
msg = self.ERROR.get(function.upper())[1] | msg = self.ERROR.get(function.upper())[1] | ||||
except: | except: | ||||
msg = self.ERROR.get("IMAPLIB")[1] | msg = self.ERROR.get("IMAPLIB")[1] | ||||
value = "" | value = "" | ||||
▲ Show 20 Lines • Show All 478 Lines • Show Last 20 Lines |