python - Speeding up email attachment checking -
my script checks email attachments , downloads them if contain strings ever slow right now.. there way speed up? right it's downloading entire email believe...
my script:
def connect(server, user, password): m = imaplib.imap4_ssl(server, 993) print("connect imap") m.login(user, password) print("logged in") m.select() return m def downloaattachmentsinemail(m, emailid, outputdir): resp, data = m.fetch(emailid, "(body.peek[])") email_body = data[0][1] mail = email.message_from_string(email_body.decode('utf8','ignore')) if mail.get_content_maintype() != 'multipart': return part in mail.walk(): if part.get_content_maintype() != 'multipart' , part.get('content-disposition') not none: if (str(part.get_filename()) == "something") or ("something2" in str(part.get_filename())) or ("something3" in str(part.get_filename())): open(outputdir + '/' + str(part.get_filename()), 'wb').write(part.get_payload(decode=true))
Comments
Post a Comment