'Saves the entire messagelist to disk.'

def saveall(self):

    with self.savelock:
        cachefd = open((self.filename + '.tmp'), 'wt')
        cachefd.write(((self.magicline % self.cur_version) + '\n'))
        for msg in self.messagelist.values():
            flags = ''.join(sorted(msg['flags']))
            labels = ',    '.join(sorted(msg['labels']))
            cachefd.write(('%s|%s|%d|%s\n' % (msg['uid'], flags, msg['mtime'], labels)))
        cachefd.flush()
        if self.doautosave:
            os.fsync(cachefd.fileno())
        cachefd.close()
        os.rename((self.filename + '.tmp'), self.filename)
        if self.doautosave:
            fd = os.open(os.path.dirname(self.filename), os.O_RDONLY)
            os.fsync(fd)
            os.close(fd)
