more consistent style
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
# Base folder support
|
||||
# Copyright (C) 2002-2011 John Goerzen & contributors
|
||||
# Copyright (C) 2002-2015 John Goerzen & contributors
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -23,7 +23,6 @@ import offlineimap.accounts
|
||||
import os.path
|
||||
import re
|
||||
from sys import exc_info
|
||||
import traceback
|
||||
|
||||
|
||||
class BaseFolder(object):
|
||||
@ -113,6 +112,7 @@ class BaseFolder(object):
|
||||
def quickchanged(self, statusfolder):
|
||||
""" Runs quick check for folder changes and returns changed
|
||||
status: True -- changed, False -- not changed.
|
||||
|
||||
:param statusfolder: keeps track of the last known folder state.
|
||||
"""
|
||||
return True
|
||||
@ -129,11 +129,13 @@ class BaseFolder(object):
|
||||
return 1
|
||||
|
||||
def getvisiblename(self):
|
||||
"""The nametrans-transposed name of the folder's name"""
|
||||
"""The nametrans-transposed name of the folder's name."""
|
||||
|
||||
return self.visiblename
|
||||
|
||||
def getexplainedname(self):
|
||||
""" Name that shows both real and nametrans-mangled values"""
|
||||
"""Name that shows both real and nametrans-mangled values."""
|
||||
|
||||
if self.name == self.visiblename:
|
||||
return self.name
|
||||
else:
|
||||
@ -603,6 +605,7 @@ class BaseFolder(object):
|
||||
:param new_uid: (optional) If given, the old UID will be changed
|
||||
to a new UID. This allows backends efficient renaming of
|
||||
messages if the UID has changed."""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
def deletemessage(self, uid):
|
||||
@ -610,6 +613,7 @@ class BaseFolder(object):
|
||||
Note that this function does not check against dryrun settings,
|
||||
so you need to ensure that it is never called in a
|
||||
dryrun mode."""
|
||||
|
||||
raise NotImplementedError
|
||||
|
||||
def deletemessages(self, uidlist):
|
||||
@ -617,6 +621,7 @@ class BaseFolder(object):
|
||||
Note that this function does not check against dryrun settings,
|
||||
so you need to ensure that it is never called in a
|
||||
dryrun mode."""
|
||||
|
||||
for uid in uidlist:
|
||||
self.deletemessage(uid)
|
||||
|
||||
@ -632,6 +637,7 @@ class BaseFolder(object):
|
||||
:param statusfolder: A LocalStatusFolder instance
|
||||
:param register: whether we should register a new thread."
|
||||
:returns: Nothing on success, or raises an Exception."""
|
||||
|
||||
# Sometimes, it could be the case that if a sync takes awhile,
|
||||
# a message might be deleted from the maildir before it can be
|
||||
# synced to the status cache. This is only a problem with
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Local status cache virtual folder
|
||||
# Copyright (C) 2002 - 2011 John Goerzen & contributors
|
||||
# Copyright (C) 2002-2015 John Goerzen & contributors
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -15,10 +15,10 @@
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
from .Base import BaseFolder
|
||||
import os
|
||||
import threading
|
||||
|
||||
from .Base import BaseFolder
|
||||
|
||||
class LocalStatusFolder(BaseFolder):
|
||||
"""LocalStatus backend implemented as a plain text file"""
|
||||
@ -33,9 +33,9 @@ class LocalStatusFolder(BaseFolder):
|
||||
self.filename = os.path.join(self.getroot(), self.getfolderbasename())
|
||||
self.messagelist = {}
|
||||
self.savelock = threading.Lock()
|
||||
self.doautosave = self.config.getdefaultboolean("general", "fsync",
|
||||
False)
|
||||
"""Should we perform fsyncs as often as possible?"""
|
||||
# Should we perform fsyncs as often as possible?
|
||||
self.doautosave = self.config.getdefaultboolean(
|
||||
"general", "fsync", False)
|
||||
|
||||
# Interface from BaseFolder
|
||||
def storesmessages(self):
|
||||
@ -63,13 +63,12 @@ class LocalStatusFolder(BaseFolder):
|
||||
|
||||
|
||||
def readstatus_v1(self, fp):
|
||||
"""
|
||||
Read status folder in format version 1.
|
||||
"""Read status folder in format version 1.
|
||||
|
||||
Arguments:
|
||||
- fp: I/O object that points to the opened database file.
|
||||
|
||||
"""
|
||||
|
||||
for line in fp.xreadlines():
|
||||
line = line.strip()
|
||||
try:
|
||||
@ -86,13 +85,12 @@ class LocalStatusFolder(BaseFolder):
|
||||
|
||||
|
||||
def readstatus(self, fp):
|
||||
"""
|
||||
Read status file in the current format.
|
||||
"""Read status file in the current format.
|
||||
|
||||
Arguments:
|
||||
- fp: I/O object that points to the opened database file.
|
||||
|
||||
"""
|
||||
|
||||
for line in fp.xreadlines():
|
||||
line = line.strip()
|
||||
try:
|
||||
@ -164,11 +162,13 @@ class LocalStatusFolder(BaseFolder):
|
||||
|
||||
|
||||
def save(self):
|
||||
"""Save changed data to disk. For this backend it is the same as saveall"""
|
||||
"""Save changed data to disk. For this backend it is the same as saveall."""
|
||||
|
||||
self.saveall()
|
||||
|
||||
def saveall(self):
|
||||
"""Saves the entire messagelist to disk"""
|
||||
"""Saves the entire messagelist to disk."""
|
||||
|
||||
with self.savelock:
|
||||
file = open(self.filename + ".tmp", "wt")
|
||||
file.write((self.magicline % self.cur_version) + "\n")
|
||||
@ -198,6 +198,7 @@ class LocalStatusFolder(BaseFolder):
|
||||
See folder/Base for detail. Note that savemessage() does not
|
||||
check against dryrun settings, so you need to ensure that
|
||||
savemessage is never called in a dryrun mode."""
|
||||
|
||||
if uid < 0:
|
||||
# We cannot assign a uid.
|
||||
return uid
|
||||
@ -235,6 +236,7 @@ class LocalStatusFolder(BaseFolder):
|
||||
|
||||
def savemessageslabelsbulk(self, labels):
|
||||
"""Saves labels from a dictionary in a single database operation."""
|
||||
|
||||
for uid, lb in labels.items():
|
||||
self.messagelist[uid]['labels'] = lb
|
||||
self.save()
|
||||
@ -254,6 +256,7 @@ class LocalStatusFolder(BaseFolder):
|
||||
|
||||
def savemessagesmtimebulk(self, mtimes):
|
||||
"""Saves mtimes from the mtimes dictionary in a single database operation."""
|
||||
|
||||
for uid, mt in mtimes.items():
|
||||
self.messagelist[uid]['mtime'] = mt
|
||||
self.save()
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Maildir folder support
|
||||
# Copyright (C) 2002 - 2011 John Goerzen & contributors
|
||||
# Copyright (C) 2002-2015 John Goerzen & contributors
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -19,15 +19,12 @@ import socket
|
||||
import time
|
||||
import re
|
||||
import os
|
||||
import tempfile
|
||||
from .Base import BaseFolder
|
||||
from threading import Lock
|
||||
|
||||
try:
|
||||
from hashlib import md5
|
||||
except ImportError:
|
||||
from md5 import md5
|
||||
|
||||
try: # python 2.6 has set() built in
|
||||
set
|
||||
except NameError:
|
||||
@ -131,6 +128,7 @@ class MaildirFolder(BaseFolder):
|
||||
|
||||
:returns: (prefix, UID, FMD5, flags). UID is a numeric "long"
|
||||
type. flags is a set() of Maildir flags"""
|
||||
|
||||
prefix, uid, fmd5, flags = None, None, None, set()
|
||||
prefixmatch = self.re_prefixmatch.match(filename)
|
||||
if prefixmatch:
|
||||
@ -227,7 +225,8 @@ class MaildirFolder(BaseFolder):
|
||||
|
||||
# Interface from BaseFolder
|
||||
def getmessage(self, uid):
|
||||
"""Return the content of the message"""
|
||||
"""Return the content of the message."""
|
||||
|
||||
filename = self.messagelist[uid]['filename']
|
||||
filepath = os.path.join(self.getfullname(), filename)
|
||||
file = open(filepath, 'rt')
|
||||
@ -249,6 +248,7 @@ class MaildirFolder(BaseFolder):
|
||||
:param uid: The UID`None`, or a set of maildir flags
|
||||
:param flags: A set of maildir flags
|
||||
:returns: String containing unique message filename"""
|
||||
|
||||
timeval, timeseq = _gettimeseq()
|
||||
return '%d_%d.%d.%s,U=%d,FMD5=%s%s2,%s' % \
|
||||
(timeval, timeseq, os.getpid(), socket.gethostname(),
|
||||
@ -256,8 +256,7 @@ class MaildirFolder(BaseFolder):
|
||||
|
||||
|
||||
def save_to_tmp_file(self, filename, content):
|
||||
"""
|
||||
Saves given content to the named temporary file in the
|
||||
"""Saves given content to the named temporary file in the
|
||||
'tmp' subdirectory of $CWD.
|
||||
|
||||
Arguments:
|
||||
@ -265,9 +264,7 @@ class MaildirFolder(BaseFolder):
|
||||
- content: data to be saved.
|
||||
|
||||
Returns: relative path to the temporary file
|
||||
that was created.
|
||||
|
||||
"""
|
||||
that was created."""
|
||||
|
||||
tmpname = os.path.join('tmp', filename)
|
||||
# open file and write it out
|
||||
@ -364,7 +361,7 @@ class MaildirFolder(BaseFolder):
|
||||
infomatch = self.re_flagmatch.search(filename)
|
||||
if infomatch:
|
||||
filename = filename[:-len(infomatch.group())] #strip off
|
||||
infostr = '%s2,%s' % (self.infosep, ''.join(sorted(flags)))
|
||||
infostr = '%s2,%s'% (self.infosep, ''.join(sorted(flags)))
|
||||
filename += infostr
|
||||
|
||||
newfilename = os.path.join(dir_prefix, filename)
|
||||
@ -386,8 +383,10 @@ class MaildirFolder(BaseFolder):
|
||||
|
||||
This will not update the statusfolder UID, you need to do that yourself.
|
||||
:param new_uid: (optional) If given, the old UID will be changed
|
||||
to a new UID. The Maildir backend can implement this as an efficient
|
||||
rename."""
|
||||
to a new UID. The Maildir backend can implement this as
|
||||
an efficient rename.
|
||||
"""
|
||||
|
||||
if not uid in self.messagelist:
|
||||
raise OfflineImapError("Cannot change unknown Maildir UID %s" % uid)
|
||||
if uid == new_uid: return
|
||||
|
@ -1,5 +1,5 @@
|
||||
# Base folder support
|
||||
# Copyright (C) 2002-2012 John Goerzen & contributors
|
||||
# Copyright (C) 2002-2015 John Goerzen & contributors
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -59,8 +59,8 @@ class MappedIMAPFolder(IMAPFolder):
|
||||
try:
|
||||
line = line.strip()
|
||||
except ValueError:
|
||||
raise Exception("Corrupt line '%s' in UID mapping file '%s'" \
|
||||
%(line, mapfilename))
|
||||
raise Exception("Corrupt line '%s' in UID mapping file '%s'"%
|
||||
(line, mapfilename))
|
||||
(str1, str2) = line.split(':')
|
||||
loc = long(str1)
|
||||
rem = long(str2)
|
||||
@ -89,7 +89,7 @@ class MappedIMAPFolder(IMAPFolder):
|
||||
raise OfflineImapError("Could not find UID for msg '{0}' (f:'{1}'."
|
||||
" This is usually a bad thing and should be reported on the ma"
|
||||
"iling list.".format(e.args[0], self),
|
||||
OfflineImapError.ERROR.MESSAGE)
|
||||
OfflineImapError.ERROR.MESSAGE)
|
||||
|
||||
# Interface from BaseFolder
|
||||
def cachemessagelist(self):
|
||||
|
Reference in New Issue
Block a user