Merge pull request #75 from thekix/master

Windows patches
This commit is contained in:
Rodolfo García Peñas (kix) 2021-07-25 15:58:28 +02:00 committed by GitHub
commit 87f9507cc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 13 deletions

View File

@ -302,7 +302,15 @@ class BaseFolder:
with open(uidfilename + ".tmp", "wt") as uidfile:
uidfile.write("%d\n" % newval)
os.rename(uidfilename + ".tmp", uidfilename)
# This is weird, os.rename on Windows raises an exception,
# But not in Linux. In linux the file is overwritten.
try:
os.rename(uidfilename + ".tmp", uidfilename)
except WindowsError:
os.remove(uidfilename)
os.rename(uidfilename + ".tmp", uidfilename)
self._base_saved_uidvalidity = newval
def get_uidvalidity(self):

View File

@ -183,7 +183,7 @@ class GmailMaildirFolder(MaildirFolder):
os.rename(tmppath, filepath)
except OSError as e:
raise OfflineImapError("Can't rename file '%s' to '%s': %s" %
(tmppath, filepath, e[1]),
(tmppath, filepath, e.errno),
OfflineImapError.ERROR.FOLDER,
exc_info()[2])

View File

@ -470,7 +470,7 @@ class MaildirFolder(BaseFolder):
except OSError as e:
raise OfflineImapError(
"Can't rename file '%s' to '%s': %s" %
(oldfilename, newfilename, e[1]),
(oldfilename, newfilename, e.errno),
OfflineImapError.ERROR.FOLDER,
exc_info()[2])
@ -556,7 +556,7 @@ class MaildirFolder(BaseFolder):
except OSError as e:
raise OfflineImapError(
"Can't rename file '%s' to '%s': %s" %
(filename, newfilename, e[1]),
(filename, newfilename, e.errno),
OfflineImapError.ERROR.FOLDER,
exc_info()[2])

View File

@ -15,7 +15,6 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import datetime
import os
import fcntl
import time
import subprocess
import threading
@ -29,6 +28,14 @@ from offlineimap import OfflineImapError
from offlineimap.ui import getglobalui
from imaplib2 import IMAP4, IMAP4_SSL, InternalDate
try:
import portalocker
except:
try:
import fcntl
except:
pass # Ok if this fails, we can do without.
class UsefulIMAPMixIn:
def __getselectedfolder(self):

View File

@ -26,6 +26,7 @@ import collections
from optparse import OptionParser
import offlineimap
from offlineimap.utils.distro_utils import get_os_name
import imaplib2 as imaplib
# Ensure that `ui` gets loaded before `threadutil` in order to
@ -72,7 +73,18 @@ class OfflineImap:
"""
def get_env_info(self):
info = "imaplib2 v%s, Python v%s" % (imaplib.__version__, PYTHON_VERSION)
# Transitional code between imaplib2 versions
try:
# imaplib2, previous versions, based on Python 2.x
l_imaplib_version = imaplib.__version__
except AttributeError:
# New imaplib2, version >= 3.06
l_imaplib_version = imaplib.version()
except:
# This should not happen
l_imaplib_version = " Unknown"
info = "imaplib2 v%s, Python v%s" % (l_imaplib_version, PYTHON_VERSION)
try:
import ssl
info = "%s, %s" % (info, ssl.OPENSSL_VERSION)
@ -446,13 +458,16 @@ class OfflineImap:
try:
self.num_sigterm = 0
signal.signal(signal.SIGHUP, sig_handler)
signal.signal(signal.SIGUSR1, sig_handler)
signal.signal(signal.SIGUSR2, sig_handler)
signal.signal(signal.SIGABRT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGQUIT, sig_handler)
# We cannot use signals in Windows
if get_os_name() != 'windows':
signal.signal(signal.SIGHUP, sig_handler)
signal.signal(signal.SIGUSR1, sig_handler)
signal.signal(signal.SIGUSR2, sig_handler)
signal.signal(signal.SIGABRT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGQUIT, sig_handler)
# Various initializations that need to be performed:
activeaccounts = self._get_activeaccounts(options)