Merge pull request #86 from dopefishh/communicate-syncmode-to-synchooks
Communicate syncmode to synchooks
This commit is contained in:
		| @@ -320,6 +320,9 @@ remoterepository = RemoteExample | ||||
| # | ||||
| # The pre sync script has to complete before a sync to the account will start. | ||||
| # | ||||
| # The environment variable OFFLINEIMAPSYNCMODE will be set to either full, | ||||
| # quick or idle to communicate the syncmode to the external command. | ||||
| # | ||||
| #presynchook = imapfilter -c someotherconfig.lua | ||||
| #postsynchook = notifysync.sh | ||||
|  | ||||
|   | ||||
| @@ -338,18 +338,6 @@ class SyncableAccount(Account): | ||||
|  | ||||
|         folderthreads = [] | ||||
|  | ||||
|         hook = self.getconf('presynchook', '') | ||||
|         self.callhook(hook) | ||||
|  | ||||
|         if self.utf_8_support and self.remoterepos.getdecodefoldernames(): | ||||
|             raise OfflineImapError("Configuration mismatch in account " + | ||||
|                                    "'%s'. " % self.getname() + | ||||
|                                    "\nAccount setting 'utf8foldernames' and repository " + | ||||
|                                    "setting 'decodefoldernames'\nmay not be used at the " + | ||||
|                                    "same time. This account has not been synchronized.\n" + | ||||
|                                    "Please check the configuration and documentation.", | ||||
|                                    OfflineImapError.ERROR.REPO) | ||||
|  | ||||
|         quickconfig = self.getconfint('quick', 0) | ||||
|         if quickconfig < 0: | ||||
|             quick = True | ||||
| @@ -363,6 +351,19 @@ class SyncableAccount(Account): | ||||
|         else: | ||||
|             quick = False | ||||
|  | ||||
|  | ||||
|         hook = self.getconf('presynchook', '') | ||||
|         self.callhook(hook, "quick" if quick else "full") | ||||
|  | ||||
|         if self.utf_8_support and self.remoterepos.getdecodefoldernames(): | ||||
|             raise OfflineImapError("Configuration mismatch in account " + | ||||
|                                    "'%s'. " % self.getname() + | ||||
|                                    "\nAccount setting 'utf8foldernames' and repository " + | ||||
|                                    "setting 'decodefoldernames'\nmay not be used at the " + | ||||
|                                    "same time. This account has not been synchronized.\n" + | ||||
|                                    "Please check the configuration and documentation.", | ||||
|                                    OfflineImapError.ERROR.REPO) | ||||
|  | ||||
|         try: | ||||
|             startedThread = False | ||||
|             remoterepos = self.remoterepos | ||||
| @@ -444,9 +445,9 @@ class SyncableAccount(Account): | ||||
|             remoterepos.holdordropconnections() | ||||
|  | ||||
|         hook = self.getconf('postsynchook', '') | ||||
|         self.callhook(hook) | ||||
|         self.callhook(hook, "quick" if quick else "full") | ||||
|  | ||||
|     def callhook(self, cmd): | ||||
|     def callhook(self, cmd, syncmode): | ||||
|         # Check for CTRL-C or SIGTERM and run postsynchook. | ||||
|         if Account.abort_NOW_signal.is_set(): | ||||
|             return | ||||
| @@ -456,9 +457,11 @@ class SyncableAccount(Account): | ||||
|             self.ui.callhook("Calling hook: " + cmd) | ||||
|             if self.dryrun: | ||||
|                 return | ||||
|             environ = os.environ.copy() | ||||
|             environ['OFFLINEIMAPSYNCMODE'] = syncmode | ||||
|             p = Popen(cmd, shell=True, | ||||
|                       stdin=PIPE, stdout=PIPE, stderr=PIPE, | ||||
|                       close_fds=True) | ||||
|                       close_fds=True, env=environ) | ||||
|             stdout, stderr = p.communicate() | ||||
|             self.ui.callhook("Hook stdout: %s\nHook stderr:%s\n" | ||||
|                     % (stdout.decode('utf-8'), stderr.decode('utf-8'))) | ||||
|   | ||||
| @@ -838,10 +838,10 @@ class IdleThread: | ||||
|         remotefolder = remoterepos.getfolder(self.folder, decode=False) | ||||
|  | ||||
|         hook = account.getconf('presynchook', '') | ||||
|         account.callhook(hook) | ||||
|         account.callhook(hook, "idle") | ||||
|         offlineimap.accounts.syncfolder(account, remotefolder, quick=False) | ||||
|         hook = account.getconf('postsynchook', '') | ||||
|         account.callhook(hook) | ||||
|         account.callhook(hook, "idle") | ||||
|  | ||||
|         ui = getglobalui() | ||||
|         ui.unregisterthread(currentThread())  # syncfolder registered the thread | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Rodolfo García Peñas (kix)
					Rodolfo García Peñas (kix)