'Sets the specified message\'s flags to the given set.
This function moves the message to the cur or new subdir,
depending on the \'S\'een flag.
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 savemessageflags(self, uid, flags):

    assert (uid in self.messagelist)
    oldfilename = self.messagelist[uid]['filename']
    (dir_prefix, filename) = os.path.split(oldfilename)
    dir_prefix = ('cur' if ('S' in flags) else 'new')
    if (flags != self.messagelist[uid]['flags']):
        infomatch = self.re_flagmatch.search(filename)
        if infomatch:
            filename = filename[:(- len(infomatch.group()))]
        infostr = ('%s2,%s' % (self.infosep, ''.join(sorted(flags))))
        filename += infostr
    newfilename = os.path.join(dir_prefix, filename)
    if (newfilename != oldfilename):
        try:
            os.rename(os.path.join(self.getfullname(), oldfilename), os.path.join(self.getfullname(), newfilename))
        except OSError as e:
            six.reraise(OfflineImapError, OfflineImapError(("Can't    rename    file    '%s'    to    '%s':    %s" % (oldfilename, newfilename, e[1])), OfflineImapError.ERROR.FOLDER), exc_info()[2])
        self.messagelist[uid]['flags'] = flags
        self.messagelist[uid]['filename'] = newfilename
