def message_from_imap(self, imap_mail):
        parsed = message_from_string(imap_mail)
        from_user = parsed["From"] 
        # if the from format was something like:
        # "Bob User" <bob@users.com>
        # just pull out the relevant address part from within the carats.
        # Note that we don't currently do anything smart parsing email
        # addresses to make sure they are valid, we either just take
        # what we get, or take what we get between <>.    
        match = re.match(r"^.*<\s*(\S+)\s*>", from_user)
        if match:
            new_addr = match.groups()[0]
            self.debug("converting %s to %s" % (from_user, new_addr))
            from_user = new_addr
            
        subject = parsed["Subject"]
        date_string = parsed["Date"]
        # TODO: until we figure out how to generically parse dates, just use
        # the current time.  This appears to be the standard date format, but
        # currently timezone information is optional.
        # date = datetime.strptime(truncated_date, "%a, %d %b %Y %H:%M:%S")
        date = datetime.now()
        
        message_body = get_message_body(parsed)
        if not message_body:
            self.error("Got a poorly formed email.  Couldn't find any part with content-type text")
            # TODO: not sure how to handle this.  For now still route it with empty body
            message = self.message(from_user, "", date)
            message.subject = subject
            return message
            
        message = self.message(from_user, message_body.get_payload(), date)
        message.subject = subject
        message.mime_type = message_body.get_content_type()
        return message
From an IMAP message object, get a rapidsms message object
dataset/ETHPy150Open rapidsms/rapidsms-core-dev/lib/rapidsms/backends/email.py/Backend.message_from_imap