Sep-03-2023, 04:06 PM
I have a python script that scrubs emails and works well.
I need to add the ability to remove everything including and after the string "Still have questions" after the second def of "removte_http_links" in the following part of the script.
Thanks in advance.
Mark
I need to add the ability to remove everything including and after the string "Still have questions" after the second def of "removte_http_links" in the following part of the script.
def extract_http_links(payload): # pattern = r'https?://[^\s<>"]+|www\.[^\s<>"]+' pattern = r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+=]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' http_links = re.findall(pattern, payload) return http_links def remove_http_links(payload): #pattern = r'https?://[^\s<>"]+|www\.[^\s<>"]+' pattern = r'<http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+=<>]|[\r\n]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' payload_without_links = re.sub(pattern, '', payload) pattern = r'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+=<>]|[\r\n]|[!*\\(\\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' payload_without_links = re.sub(pattern, '', payload_without_links) return payload_without_linksNEW EXPRESSION TO BE PUT IN HERE IN THE PROCESS
def send_all_email(message_all , subject): print(subject) print(message_all.encode('utf-8')) msg = MIMEMultipart() msg['From'] = username msg['To'] = forward_address # msg['Subject'] = subject msg.attach(MIMEText(message_all)) mail = smtplib.SMTP(smtp_server, smtp_port) mail.ehlo() mail.starttls() mail.ehlo() mail.login(username, password) mail.sendmail(username, forward_address, msg.as_string()) mail.quit()I would appreciate any input to accomplish this task in the sequence above.
Thanks in advance.
Mark