'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.
This function checks and protects us from action in dryrun mode.'

def syncmessagesto_labels(self, dstfolder, statusfolder):

    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
            selflabels = (self.getmessagelabels(uid) - self.ignorelabels)
            if statusfolder.uidexists(uid):
                statuslabels = (statusfolder.getmessagelabels(uid) - self.ignorelabels)
            else:
                statuslabels = set()
            if (selflabels != statuslabels):
                uidlist.append(uid)
        mtimes = {}
        labels = {}
        for (i, uid) in enumerate(uidlist):
            if offlineimap.accounts.Account.abort_NOW_signal.is_set():
                break
            selflabels = (self.getmessagelabels(uid) - self.ignorelabels)
            if statusfolder.uidexists(uid):
                statuslabels = (statusfolder.getmessagelabels(uid) - self.ignorelabels)
            else:
                statuslabels = set()
            if (selflabels != statuslabels):
                self.ui.settinglabels(uid, (i + 1), len(uidlist), sorted(selflabels), dstfolder)
                if self.repository.account.dryrun:
                    continue
                dstfolder.savemessagelabels(uid, selflabels, ignorelabels=self.ignorelabels)
                mtime = dstfolder.getmessagemtime(uid)
                mtimes[uid] = mtime
                labels[uid] = selflabels
        statusfolder.savemessageslabelsbulk(labels)
        statusfolder.savemessagesmtimebulk(mtimes)
    except NotImplementedError:
        self.ui.warn("Can't    sync    labels.    You    need    to    configure    a    local    repository    of    type    GmailMaildir")
