'Writes a new message, with the specified uid.
The UIDMaps class will not return a newly assigned uid, as it
internally maps different uids between IMAP servers. So a
successful savemessage() invocation will return the same uid it
has been invoked with. As it maps between 2 IMAP servers which
means the source message must already have an uid, it requires a
positive uid to be passed in. Passing in a message with a
negative uid will do nothing and return the negative uid.
If the uid is > 0, the backend should set the uid to this, if it can.
If it cannot set the uid to that, it will save it anyway.
It will return the uid assigned in any case.
See folder/Base for details. Note that savemessage() does not
check against dryrun settings, so you need to ensure that
savemessage is never called in a dryrun mode.'

def savemessage(self, uid, content, flags, rtime):

    self.ui.savemessage('imap', uid, flags, self)
    if (uid < 0):
        return uid
    if (uid in self.r2l):
        self.savemessageflags(uid, flags)
        return uid
    newluid = self._mb.savemessage((-1), content, flags, rtime)
    if (newluid < 1):
        raise OfflineImapError(("server    of    repository    '%s'    did    not    return    a    valid    UID    (got    '%s')    for    UID    '%s'    from    '%s'" % (self._mb.getname(), newluid, uid, self.getname())), OfflineImapError.ERROR.MESSAGE)
    with self.maplock:
        self.diskl2r[newluid] = uid
        self.diskr2l[uid] = newluid
        self.l2r[newluid] = uid
        self.r2l[uid] = newluid
        self._savemaps()
    return uid
