Exemplo n.º 1
0
        else:
            print("No match found for " + file_fullname)

# parse each file! And extract some interesting data before any emails can be sent out
master_histogram = dict()
uid_template_map = dict()

for UID in file_list.keys():
    my_email = EmailTemplate(UID)
    try:
        with open(file_list[UID], encoding="utf-8-sig") as input_file:
            raw_data = input_file.readlines()
            for line in raw_data:
                line = line.strip()
                if "From" in line:
                    my_email.set_from(line)
                elif "Subject:" in line:
                    my_email.set_subject(line)
                elif line:
                    my_email.append_body(line)
    except:
        print("Caught an exception on UID " + UID + ", file " + file_list[UID])

    if not (my_email.from_address.lower(),
            my_email.subject_line.lower()) in master_histogram:
        master_histogram[(my_email.from_address.lower(),
                          my_email.subject_line.lower())] = my_email

    uid_template_map[UID] = master_histogram[(
        my_email.from_address.lower(), my_email.subject_line.lower())].filename