def read(imap_account, mail_uid, directory=None, save_directory=None):
    raw_mails = fetch(imap_account, mail_uid)
    if raw_mails is None:
        log.error('Server didn\'t sent this email')
        yield None
    for raw_mail in raw_mails or []:
        if raw_mail is None or raw_mail == ')':
            continue
        mail = email.message_from_string(raw_mail[1])

        mail_headers = {}
        for header_name, header_value in mail.items():
            value, encoding = header.decode_header(header_value)[0]
            if encoding is not None:
                value = value.decode(encoding)
            mail_headers[header_name] = value

        message_parts = []
        for part in mail.walk():
            # multipart/* are just containers
            if part.get_content_maintype() == 'multipart':
                continue

            if part.get_content_type().startswith('text'):
                charset = get_charset(part, get_charset(mail))
                message_parts.append({
                    'content_type': part.get_content_type(),
                    'data': part.as_string(),
                    'as_string': part.get_payload(decode=True).decode(
                        charset, 'replace')})
            elif part.get_filename():
                message_parts.append({
                    'content_type': part.get_content_type(),
                    'filename': part.get_filename(),
                    'data': part.get_payload(decode=True),
                })
                if save_directory is not None and os.path.isdir(
                        save_directory):
                    attachment_full_filename = os.path.join(
                        save_directory, part.get_filename())
                    with open(attachment_full_filename, 'wb') as attachment:
                        attachment.write(part.get_payload(decode=True))
                elif save_directory is not None:
                    log.error(' '.join([
                        'Can\'t save attachment, directory {}',
                        'does not exist']).format(save_directory))

        yield {
            'headers': mail_headers,
            'parts': message_parts,
        }
Update the request with its sha
dataset/ETHPy150Open Gentux/imap-cli/imap_cli/fetch.py/read--crossover with--dataset/ETHPy150Open YelpArchive/pushmanager/pushmanager/tests/test_core_git.py/CoreGitTest.test_process_queue_successful