def data (cargo):
    stream = cargo[0]
    email_data = cargo[1]

    with_stream_write (stream, '354 End data with \\r\\n.\\r\\n'+cr_lf)

    contents = []
    client_error = False
    subject = None

    while 1:
        client_msg = with_stream_read (stream)
        if client_is_idle(email_data['start']):
            client_error = True
            break
        elif end_pattern.search(client_msg.rstrip()):
            break
        else:
            contents.append(client_msg)
            if subject is None:
                if subject_pattern.search(client_msg):
                    try:
                        subject = filter(lambda x: x!='', re.split(subject_pattern, client_msg))[0].lstrip()
                        email_data['subject'] = get_base_subject(subject)
                        if not valid_subject(subject):
                            client_error = True
                            break
                    except __HOLE__:
                        pass

    if client_error or len(contents) == 0:
        with_stream_write (stream, bad_request+cr_lf)
        return ('done', cargo)
    else:
        with_stream_write (stream, '250 Ok: queued'+cr_lf)
        email_data['contents'] = ''.join(contents)
        return ('process', (stream, email_data))
dataset/ETHPy150Open dpapathanasiou/intelligent-smtp-responder/server/smtp_server.py/data