'Change a message\'s labels to `labels`.
Note that this function does not check against dryrun settings,
so you need to ensure that it is never called in a dryrun mode.'

def savemessagelabels(self, uid, labels):

    if ((uid in self.messagelist) and ('labels' in self.messagelist[uid])):
        oldlabels = self.messagelist[uid]['labels']
    else:
        oldlabels = set()
    labels = (labels - self.ignorelabels)
    newlabels = (labels | (oldlabels & self.ignorelabels))
    if (oldlabels != newlabels):
        result = self._messagelabels_aux('X-GM-LABELS', [uid], newlabels)
        if result:
            self.messagelist[uid]['labels'] = newlabels
        else:
            self.messagelist[uid]['labels'] = oldlabels
