'Pass 4: Label Synchronization (Gmail only)
Compare label mismatches in self with those in statusfolder. If
msg has a valid UID and exists on dstfolder (has not e.g. been
deleted there), sync the labels change to both dstfolder and
statusfolder.
Also skips messages whose mtime remains the same as statusfolder, as the
contents have not changed.
This function checks and protects us from action in ryrun mode.'

def syncmessagesto_labels(self, dstfolder, statusfolder):

    addlabellist = {}
    dellabellist = {}
    uidlist = []
    try:
        for uid in self.getmessageuidlist():
            if offlineimap.accounts.Account.abort_NOW_signal.is_set():
                break
            if ((uid < 0) or (not dstfolder.uidexists(uid))):
                continue
            selfmtime = self.getmessagemtime(uid)
            if statusfolder.uidexists(uid):
                statusmtime = statusfolder.getmessagemtime(uid)
            else:
                statusmtime = 0
            if (selfmtime > statusmtime):
                uidlist.append(uid)
        self.ui.collectingdata(uidlist, self)
        for uid in uidlist:
            if offlineimap.accounts.Account.abort_NOW_signal.is_set():
                break
            selflabels = self.getmessagelabels(uid)
            if statusfolder.uidexists(uid):
                statuslabels = statusfolder.getmessagelabels(uid)
            else:
                statuslabels = set()
            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():
            if offlineimap.accounts.Account.abort_NOW_signal.is_set():
                break
            self.ui.addinglabels(uids, lb, dstfolder)
            if self.repository.account.dryrun:
                continue
            dstfolder.addmessageslabels(uids, set([lb]))
            statusfolder.addmessageslabels(uids, set([lb]))
        for (lb, uids) in dellabellist.items():
            if offlineimap.accounts.Account.abort_NOW_signal.is_set():
                break
            self.ui.deletinglabels(uids, lb, dstfolder)
            if self.repository.account.dryrun:
                continue
            dstfolder.deletemessageslabels(uids, set([lb]))
            statusfolder.deletemessageslabels(uids, set([lb]))
        mtimes = {}
        for uid in uidlist:
            if offlineimap.accounts.Account.abort_NOW_signal.is_set():
                break
            if self.repository.account.dryrun:
                continue
            filename = self.messagelist[uid]['filename']
            filepath = os.path.join(self.getfullname(), filename)
            mtimes[uid] = int(os.stat(filepath).st_mtime)
        statusfolder.savemessagesmtimebulk(mtimes)
    except NotImplementedError:
        self.ui.warn("Can't    sync    labels.    You    need    to    configure    a    remote    repository    of    type    Gmail.")
