modoboa / modoboa-imap-migration

An extension to ease the migration between 2 IMAP servers using offlineimap
ISC License
16 stars 12 forks source link

offlineimap is python2 which is troublesome with modoboa on python3 #61

Closed olaf7 closed 1 year ago

olaf7 commented 4 years ago

offlineimap does not fully support python3 and never will. See issues (github) and documentation (website).

Python3 is the only current supported Python: https://www.python.org/doc/sunset-python-2/ So hopefully Modoboa is running in a Python3 environment. If you do, you run into problems due to libraries/dependencies. This can be overcome with a wrapper script:

.offlineimap.py

# offlineimap executes as Python2 which is troublesome
# we need to use python3 in a virtualenv
#import sys
import os

pyint = "/srv/modoboa/env/bin/python3"

cmd = pyint + " " + "~/offlineimap.py"

os.system(cmd)

where the original .offlineimap.py as published in the ReadMe.md section Helper script on https://github.com/modoboa/modoboa-imap-migration is now stored as offlineimap.py. see: https://github.com/modoboa/modoboa-imap-migration#helper-script-for-offlineimap

olaf7 commented 4 years ago

my cron entry looks like:

# offlineimap sync
0   */1 *   *   *   modoboa cd /vmail && $PYTHON $INSTANCE/manage.py generate_offlineimap_config --output /vmail/.offlineimaprc && offlineimap -c /vmail/.offlineimaprc > /dev/null 2>&1
olaf7 commented 4 years ago

Chances are this fix will not do the trick. After battling with a self-signed cert I get:

cd /vmail && /srv/modoboa/env/bin/python3 /srv/modoboa/env/instance/manage.py generate_offlineimap_config --output /vmail/.offlineimaprc && offlineimap -c /vmail/.offlineimaprc -dALL OfflineIMAP 7.2.3 Licensed under the GNU GPL v2 or any later version (with an OpenSSL exception) imaplib2 v2.57 (system), Python v2.7.16, OpenSSL 1.1.1d 10 Sep 2019 Now debugging for imap: IMAP protocol debugging Now debugging for maildir: Maildir repository debugging Now debugging for thread: Threading debugging Now debugging for : Other offlineimap related sync messages Account sync me@example.eu: [thread]: Register new thread 'Account sync me@example.eu' (account 'me@example.eu') [imap]: Using authentication mechanisms ['GSSAPI', 'XOAUTH2', 'CRAM-MD5', 'PLAIN', 'LOGIN'] [imap]: Using authentication mechanisms ['GSSAPI', 'XOAUTH2', 'CRAM-MD5', 'PLAIN', 'LOGIN'] * Processing account me@example.eu Establishing connection to mail.example.com:993 (Remote_me@example.eu) [imap]: Remote_me@example.eu: level 'tls_compat', version 'None' [imap]: Attempting PLAIN authentication ERROR: While attempting to sync account 'me@example.eu' name 'get_user_password' is not defined [' File "/usr/share/offlineimap/offlineimap/accounts.py", line 283, in syncrunner\n self.sync()\n', ' File "/usr/share/offlineimap/offlineimap/accounts.py", line 359, in sync\n remoterepos.getfolders()\n', ' File "/usr/share/offlineimap/offlineimap/repository/IMAP.py", line 452, in getfolders\n imapobj = self.imapserver.acquireconnection()\n', ' File "/usr/share/offlineimap/offlineimap/imapserver.py", line 586, in acquireconnection\n self.authn_helper(imapobj)\n', ' File "/usr/share/offlineimap/offlineimap/imapserver.py", line 450, in __authn_helper\n if func(imapobj):\n', ' File "/usr/share/offlineimap/offlineimap/imapserver.py", line 376, in authn_plain\n imapobj.authenticate(\'PLAIN\', self.plainhandler)\n', ' File "/usr/lib/python2.7/dist-packages/imaplib2.py", line 742, in authenticate\n typ, dat = self._simple_command(\'AUTHENTICATE\', mechanism.upper())\n', ' File "/usr/lib/python2.7/dist-packages/imaplib2.py", line 1748, in _simple_command\n return self._command_complete(self._command(name, *args), kw)\n', ' File "/usr/lib/python2.7/dist-packages/imaplib2.py", line 1474, in _command\n literal = literator(data, rqb)\n', ' File "/usr/lib/python2.7/dist-packages/imaplib2.py", line 2339, in process\n ret = self.mech(self.decode(data))\n', ' File "/usr/share/offlineimap/offlineimap/imapserver.py", line 211, in plainhandler\n passwd = self.getpassword()\n', ' File "/usr/share/offlineimap/offlineimap/imapserver.py", line 181, in getpassword\n self.password = self.repos.getpassword() or \\n', ' File "/usr/share/offlineimap/offlineimap/repository/IMAP.py", line 392, in getpassword\n return self.localeval.eval(passwd).encode(\'UTF-8\')\n', ' File "/usr/share/offlineimap/offlineimap/localeval.py", line 48, in eval\n return eval(text, names)\n', ' File "", line 1, in \n'] * Finished account 'me@example.eu' in 0:00 [thread]: Unregister thread 'Account sync me@example.eu' ERROR: Exceptions occurred during the run! ERROR: While attempting to sync account 'me@example.eu' name 'get_user_password' is not defined

Traceback: File "/usr/share/offlineimap/offlineimap/accounts.py", line 283, in syncrunner self.sync() File "/usr/share/offlineimap/offlineimap/accounts.py", line 359, in sync remoterepos.getfolders() File "/usr/share/offlineimap/offlineimap/repository/IMAP.py", line 452, in getfolders imapobj = self.imapserver.acquireconnection() File "/usr/share/offlineimap/offlineimap/imapserver.py", line 586, in acquireconnection self.authn_helper(imapobj) File "/usr/share/offlineimap/offlineimap/imapserver.py", line 450, in __authn_helper if func(imapobj): File "/usr/share/offlineimap/offlineimap/imapserver.py", line 376, in authn_plain imapobj.authenticate('PLAIN', self.plainhandler) File "/usr/lib/python2.7/dist-packages/imaplib2.py", line 742, in authenticate typ, dat = self._simple_command('AUTHENTICATE', mechanism.upper()) File "/usr/lib/python2.7/dist-packages/imaplib2.py", line 1748, in _simple_command return self._command_complete(self._command(name, *args), kw) File "/usr/lib/python2.7/dist-packages/imaplib2.py", line 1474, in _command literal = literator(data, rqb) File "/usr/lib/python2.7/dist-packages/imaplib2.py", line 2339, in process ret = self.mech(self.decode(data)) File "/usr/share/offlineimap/offlineimap/imapserver.py", line 211, in plainhandler passwd = self.getpassword() File "/usr/share/offlineimap/offlineimap/imapserver.py", line 181, in getpassword self.password = self.repos.getpassword() or \ File "/usr/share/offlineimap/offlineimap/repository/IMAP.py", line 392, in getpassword return self.localeval.eval(passwd).encode('UTF-8') File "/usr/share/offlineimap/offlineimap/localeval.py", line 48, in eval return eval(text, names) File "", line 1, in

The problem is here that the "name 'get_user_password' is not defined" is not entirely true. It is defined in Python3 but not in Python2.