Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# We have no new mail yet
self.have_newmail = False
threads = []
copylist = filter(lambda uid: not statusfolder.uidexists(uid),
self.getmessageuidlist())
num_to_copy = len(copylist)
if num_to_copy and self.repository.account.dryrun:
self.ui.info("[DRYRUN] Copy {0} messages from {1}[{2}] to {3}".format(
num_to_copy, self, self.repository, dstfolder.repository))
return
for num, uid in enumerate(copylist):
# bail out on CTRL-C or SIGTERM
if offlineimap.accounts.Account.abort_NOW_signal.is_set():
break
if uid > 0 and dstfolder.uidexists(uid):
# dst has message with that UID already, only update status
flags = self.getmessageflags(uid)
rtime = self.getmessagetime(uid)
statusfolder.savemessage(uid, None, flags, rtime)
continue
self.ui.copyingmessage(uid, num+1, num_to_copy, self, dstfolder)
# exceptions are caught in copymessageto()
if self.suggeststhreads() and not globals.options.singlethreading:
self.waitforthread()
thread = threadutil.InstanceLimitedThread(\
self.getcopyinstancelimit(),
target = self.copymessageto,
name = "Copy message from %s:%s" % (self.repository, self),
if options.has_key('-l'):
ui.setlogfd(open(options['-l'], 'wt'))
ui.init_banner()
if options.has_key('-d'):
for debugtype in options['-d'].split(','):
ui.add_debug(debugtype.strip())
if debugtype == 'imap':
imaplib.Debug = 5
if debugtype == 'thread':
threading._VERBOSE = 1
if options.has_key('-o'):
# FIXME: maybe need a better
for section in accounts.getaccountlist(config):
config.remove_option('Account ' + section, "autorefresh")
lock(config, ui)
try:
if options.has_key('-l'):
sys.stderr = ui.logfile
activeaccounts = config.get("general", "accounts")
if options.has_key('-a'):
activeaccounts = options['-a']
activeaccounts = activeaccounts.replace(" ", "")
activeaccounts = activeaccounts.split(",")
allaccounts = accounts.AccountHashGenerator(config)
syncaccounts = {}
if '-o' in options:
# FIXME: maybe need a better
for section in accounts.getaccountlist(config):
config.remove_option('Account ' + section, "autorefresh")
lock(config, ui)
if '-l' in options:
sys.stderr = ui.logfile
activeaccounts = config.get("general", "accounts")
if '-a' in options:
activeaccounts = options['-a']
activeaccounts = activeaccounts.replace(" ", "")
activeaccounts = activeaccounts.split(",")
allaccounts = accounts.AccountHashGenerator(config)
syncaccounts = {}
for account in activeaccounts:
syncaccounts[account] = allaccounts[account]
server = None
remoterepos = None
localrepos = None
if '-1' in options:
threadutil.initInstanceLimit("ACCOUNTLIMIT", 1)
else:
threadutil.initInstanceLimit("ACCOUNTLIMIT",
config.getdefaultint("general", "maxsyncaccounts", 1))
for reposname in config.getsectionlist('Repository'):
if config.has_option('DEFAULT', 'autorefresh'):
config.remove_option('DEFAULT', 'autorefresh')
# FIXME: spaghetti code alert!
for section in accounts.getaccountlist(config):
config.remove_option('Account ' + section, "autorefresh")
if options.quick:
for section in accounts.getaccountlist(config):
config.set('Account ' + section, "quick", '-1')
# Custom folder list specified?
if options.folders:
foldernames = options.folders.split(",")
folderfilter = "lambda f: f in %s"% foldernames
folderincludes = "[]"
for accountname in accounts.getaccountlist(config):
account_section = 'Account ' + accountname
remote_repo_section = 'Repository ' + \
config.get(account_section, 'remoterepository')
config.set(remote_repo_section, "folderfilter", folderfilter)
config.set(remote_repo_section, "folderincludes",
folderincludes)
if options.logfile:
sys.stderr = self.ui.logfile
socktimeout = config.getdefaultint("general", "socktimeout", 0)
if socktimeout > 0:
socket.setdefaulttimeout(socktimeout)
threadutil.initInstanceLimit(
ACCOUNT_LIMITED_THREAD_NAME,
def __migratefmd5(self, options):
for accountname in self._get_activeaccounts(options):
account = accounts.Account(self.config, accountname)
localrepo = Repository(account, 'local')
if localrepo.getfoldertype() != folder.Maildir.MaildirFolder:
continue
folders = localrepo.getfolders()
for f in folders:
f.migratefmd5(options.dryrun)
def syncnow(self):
"""Request that we stop sleeping asap and continue to sync."""
# if this belongs to an Account (and not *Control), set the
# skipsleep pref
if isinstance(self.account, offlineimap.accounts.Account):
self.ui.info("Requested synchronization for acc: %s"% self.account)
self.account.config.set('Account %s'% self.account.name,
'skipsleep', '1')
addlabels = selflabels - statuslabels
dellabels = statuslabels - selflabels
for lb in addlabels:
if not lb in addlabellist:
addlabellist[lb] = []
addlabellist[lb].append(uid)
for lb in dellabels:
if not lb in dellabellist:
dellabellist[lb] = []
dellabellist[lb].append(uid)
for lb, uids in addlabellist.items():
# bail out on CTRL-C or SIGTERM
if offlineimap.accounts.Account.abort_NOW_signal.is_set():
break
self.ui.addinglabels(uids, lb, dstfolder)
if self.repository.account.dryrun:
continue #don't actually add in a dryrun
dstfolder.addmessageslabels(uids, set([lb]))
statusfolder.addmessageslabels(uids, set([lb]))
for lb, uids in dellabellist.items():
# bail out on CTRL-C or SIGTERM
if offlineimap.accounts.Account.abort_NOW_signal.is_set():
break
self.ui.deletinglabels(uids, lb, dstfolder)
if self.repository.account.dryrun:
continue #don't actually remove in a dryrun
def __sync_singlethreaded(self, list_accounts, profiledir):
"""Executed in singlethreaded mode only.
:param accs: A list of accounts that should be synced
"""
for accountname in list_accounts:
account = accounts.SyncableAccount(self.config, accountname)
threading.currentThread().name = \
"Account sync %s"% account.getname()
if not profiledir:
account.syncrunner()
# Profile mode.
else:
try:
import cProfile as profile
except ImportError:
import profile
prof = profile.Profile()
try:
prof = prof.runctx("account.syncrunner()", globals(), locals())
except SystemExit:
pass
from datetime import datetime