def syncmessagesto_copy(self, dstfolder, statusfolder): """Pass2: Copy locally existing messages This will copy messages with a valid UID but are not on the other side yet. The strategy is: 1) Look for messages present in self but not in statusfolder. 2) invoke copymessageto() on those which: - If dstfolder doesn't have it yet, add them to dstfolder. - Update statusfolder """ threads = [] copylist = filter(lambda uid: uid>=0 and not \ statusfolder.uidexists(uid), self.getmessageuidlist()) for uid in copylist: if self.suggeststhreads(): self.waitforthread() thread = threadutil.InstanceLimitedThread(\ self.getcopyinstancelimit(), target = self.copymessageto, name = "Copy message %d from %s" % (uid, self.getvisiblename()), args = (uid, dstfolder, statusfolder)) thread.setDaemon(1) thread.start() threads.append(thread) else: self.copymessageto(uid, dstfolder, statusfolder, register=0) for thread in threads: thread.join()
def syncmessagesto_neguid(self, dstfolder, statusfolder): """Pass 1 of folder synchronization. Look for messages in self with a negative uid. These are messages in Maildirs that were not added by us. Try to add them to the dstfolder. If that succeeds, get the new UID, add it to the statusfolder, add it to local for real, and delete the old fake (negative) one. :param dstfolder: A BaseFolder-derived instance :param statusfolder: A LocalStatusFolder instance""" uidlist = [uid for uid in self.getmessageuidlist() if uid < 0] threads = [] for uid in uidlist: if dstfolder.suggeststhreads(): dstfolder.waitforthread() thread = threadutil.InstanceLimitedThread(\ dstfolder.getcopyinstancelimit(), target = self.syncmessagesto_neguid_msg, name = "New msg sync from %s" % self.getvisiblename(), args = (uid, dstfolder, statusfolder)) thread.setDaemon(1) thread.start() threads.append(thread) else: self.syncmessagesto_neguid_msg(uid, dstfolder, statusfolder, register=0) #wait for all uploads to finish for thread in threads: thread.join()
def syncmessagesto_copy(self, dstfolder, statusfolder): """Pass1: Copy locally existing messages not on the other side This will copy messages to dstfolder that exist locally but are not in the statusfolder yet. The strategy is: 1) Look for messages present in self but not in statusfolder. 2) invoke copymessageto() on those which: - If dstfolder doesn't have it yet, add them to dstfolder. - Update statusfolder """ threads = [] copylist = filter(lambda uid: not \ statusfolder.uidexists(uid), self.getmessageuidlist()) num_to_copy = len(copylist) for num, uid in enumerate(copylist): self.ui.copyingmessage(uid, num+1, num_to_copy, self, dstfolder) # exceptions are caught in copymessageto() if self.suggeststhreads(): self.waitforthread() thread = threadutil.InstanceLimitedThread(\ self.getcopyinstancelimit(), target = self.copymessageto, name = "Copy message from %s:%s" % (self.repository, self), args = (uid, dstfolder, statusfolder)) thread.setDaemon(1) thread.start() threads.append(thread) else: self.copymessageto(uid, dstfolder, statusfolder, register = 0) for thread in threads: thread.join()
def __syncmessagesto_copy(self, dstfolder, statusfolder): """Pass1: Copy locally existing messages not on the other side. This will copy messages to dstfolder that exist locally but are not in the statusfolder yet. The strategy is: 1) Look for messages present in self but not in statusfolder. 2) invoke copymessageto() on those which: - If dstfolder doesn't have it yet, add them to dstfolder. - Update statusfolder This function checks and protects us from action in dryrun mode.""" # 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), args = (uid, dstfolder, statusfolder)) thread.start() threads.append(thread) else: self.copymessageto(uid, dstfolder, statusfolder, register=0) for thread in threads: thread.join() # Execute new mail hook if we have new mail if self.have_newmail: if self.newmail_hook != None: self.newmail_hook()
def syncitall(list_accounts, config): """The target when in multithreading mode for running accounts threads.""" threads = threadutil.accountThreads( ) # The collection of accounts threads. for accountname in list_accounts: # Start a new thread per account and store it in the collection. account = accounts.SyncableAccount(config, accountname) thread = threadutil.InstanceLimitedThread(ACCOUNT_LIMITED_THREAD_NAME, target=account.syncrunner, name="Account sync %s" % accountname) thread.setDaemon(True) # The add() method expects a started thread. thread.start() threads.add(thread) # Wait for the threads to finish. threads.wait() # Blocks until all accounts are processed.
def syncmessagesto_copy(self, dstfolder, statusfolder): """Pass1: Copy locally existing messages not on the other side This will copy messages to dstfolder that exist locally but are not in the statusfolder yet. The strategy is: 1) Look for messages present in self but not in statusfolder. 2) invoke copymessageto() on those which: - If dstfolder doesn't have it yet, add them to dstfolder. - Update statusfolder This function checks and protects us from action in ryrun mode. """ 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 self.ui.copyingmessage(uid, num+1, num_to_copy, self, dstfolder) # exceptions are caught in copymessageto() if self.suggeststhreads(): self.waitforthread() thread = threadutil.InstanceLimitedThread(\ self.getcopyinstancelimit(), target = self.copymessageto, name = "Copy message from %s:%s" % (self.repository, self), args = (uid, dstfolder, statusfolder)) thread.start() threads.append(thread) else: self.copymessageto(uid, dstfolder, statusfolder, register = 0) for thread in threads: thread.join()
def __syncmessagesto_copy(self, dstfolder, statusfolder): """Pass1: Copy locally existing messages not on the other side. This will copy messages to dstfolder that exist locally but are not in the statusfolder yet. The strategy is: 1) Look for messages present in self but not in statusfolder. 2) invoke copymessageto() on those which: - If dstfolder doesn't have it yet, add them to dstfolder. - Update statusfolder. This function checks and protects us from action in dryrun mode.""" # We have no new mail yet. self.have_newmail = False threads = [] copylist = [uid for uid in self.getmessageuidlist() if not statusfolder.uidexists(uid)] num_to_copy = len(copylist) # Honor 'copy_ignore_eval' configuration option. if self.copy_ignoreUIDs is not None: for uid in self.copy_ignoreUIDs: if uid in copylist: copylist.remove(uid) self.ui.ignorecopyingmessage(uid, self, dstfolder) if num_to_copy > 0 and self.repository.account.dryrun: self.ui.info("[DRYRUN] Copy {} messages from {}[{}] to {}".format( num_to_copy, self, self.repository, dstfolder.repository) ) return with self: 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: self.ui.warn("Assertion that UID != 0 failed; ignoring message.") continue if uid > 0 and dstfolder.uidexists(uid): # dstfolder 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(): self.waitforthread() thread = threadutil.InstanceLimitedThread( self.getinstancelimitnamespace(), target=self.copymessageto, name="Copy message from %s:%s" % (self.repository, self), args=(uid, dstfolder, statusfolder) ) thread.start() threads.append(thread) else: self.copymessageto(uid, dstfolder, statusfolder, register=0) for thread in threads: thread.join() # Block until all "copy" threads are done. # Execute new mail hook if we have new mail. if self.have_newmail: if self.newmail_hook is not None: self.newmail_hook()