2002-10-07 23:17:13 +02:00
|
|
|
# OfflineIMAP synchronization master code
|
2007-07-04 19:53:48 +02:00
|
|
|
# Copyright (C) 2002-2007 John Goerzen
|
2002-10-07 23:17:13 +02:00
|
|
|
# <jgoerzen@complete.org>
|
|
|
|
#
|
|
|
|
# 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
|
2003-04-16 21:23:45 +02:00
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
2002-10-07 23:17:13 +02:00
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
2006-08-12 06:15:55 +02:00
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-10-07 23:17:13 +02:00
|
|
|
|
2007-07-04 19:53:48 +02:00
|
|
|
import imaplib
|
|
|
|
from offlineimap import imapserver, repository, folder, mbnames, threadutil, version
|
2002-10-07 23:17:13 +02:00
|
|
|
from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
|
2003-01-04 05:57:46 +01:00
|
|
|
import offlineimap.accounts
|
|
|
|
from offlineimap.accounts import SyncableAccount
|
2002-10-07 23:17:13 +02:00
|
|
|
from offlineimap.ui import UIBase
|
|
|
|
import re, os, os.path, offlineimap, sys
|
|
|
|
from ConfigParser import ConfigParser
|
|
|
|
from threading import *
|
|
|
|
|
2008-05-20 08:38:15 +02:00
|
|
|
def syncaccount(threads, config, accountname, folderhash, folderhashlock):
|
|
|
|
account = SyncableAccount(config, accountname, folderhash, folderhashlock)
|
2003-01-04 05:57:46 +01:00
|
|
|
thread = InstanceLimitedThread(instancename = 'ACCOUNTLIMIT',
|
|
|
|
target = account.syncrunner,
|
|
|
|
name = "Account sync %s" % accountname)
|
|
|
|
thread.setDaemon(1)
|
|
|
|
thread.start()
|
2003-04-29 02:04:22 +02:00
|
|
|
threads.add(thread)
|
2002-10-07 23:17:13 +02:00
|
|
|
|
2003-01-04 05:57:46 +01:00
|
|
|
def syncitall(accounts, config):
|
2008-05-20 08:38:15 +02:00
|
|
|
folderhash = {'___sem': Semaphore(0)}
|
|
|
|
folderhashlock = Lock()
|
2003-04-29 02:04:22 +02:00
|
|
|
currentThread().setExitMessage('SYNC_WITH_TIMER_TERMINATE')
|
2002-10-07 23:17:13 +02:00
|
|
|
ui = UIBase.getglobalui()
|
2003-04-29 02:04:22 +02:00
|
|
|
threads = threadutil.threadlist()
|
2003-01-06 21:40:23 +01:00
|
|
|
mbnames.init(config, accounts)
|
2008-05-20 08:38:15 +02:00
|
|
|
|
|
|
|
accountcout = 0
|
|
|
|
for accountname in accounts:
|
|
|
|
syncaccount(threads, config, accountname, folderhash, folderhashlock)
|
|
|
|
accountcount += 1
|
|
|
|
|
|
|
|
# Gather up folder info
|
|
|
|
for i in range(0, accountcount):
|
|
|
|
folderhash['___sem'].acquire()
|
|
|
|
|
|
|
|
# Now we can tally.
|
|
|
|
srcnames =
|
2002-10-07 23:17:13 +02:00
|
|
|
for accountname in accounts:
|
2008-05-20 08:38:15 +02:00
|
|
|
|
|
|
|
|
2003-04-29 02:04:22 +02:00
|
|
|
# Wait for the threads to finish.
|
|
|
|
threads.reset()
|