]> code.delx.au - offlineimap/blob - offlineimap/syncmaster.py
64f2380b3fc86466300317e0debb9a6ef47cd0bf
[offlineimap] / offlineimap / syncmaster.py
1 # OfflineIMAP synchronization master code
2 # Copyright (C) 2002-2007 John Goerzen
3 # <jgoerzen@complete.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 import imaplib
20 from offlineimap import imapserver, repository, folder, mbnames, threadutil, version
21 from offlineimap.threadutil import InstanceLimitedThread, ExitNotifyThread
22 import offlineimap.accounts
23 from offlineimap.accounts import SyncableAccount
24 from offlineimap.ui import UIBase
25 import re, os, os.path, offlineimap, sys
26 from ConfigParser import ConfigParser
27 from threading import *
28
29 def syncaccount(threads, config, accountname):
30 account = SyncableAccount(config, accountname)
31 thread = InstanceLimitedThread(instancename = 'ACCOUNTLIMIT',
32 target = account.syncrunner,
33 name = "Account sync %s" % accountname)
34 thread.setDaemon(1)
35 thread.start()
36 threads.add(thread)
37
38 def syncitall(accounts, config):
39 currentThread().setExitMessage('SYNC_WITH_TIMER_TERMINATE')
40 ui = UIBase.getglobalui()
41 threads = threadutil.threadlist()
42 mbnames.init(config, accounts)
43 for accountname in accounts:
44 syncaccount(threads, config, accountname)
45 # Wait for the threads to finish.
46 threads.reset()