Browse Source

[bin] Clean boilerplate from slack body

Colin Powell 2 months ago
parent
commit
bafdbd5486
1 changed files with 22 additions and 0 deletions
  1. 22 0
      bin/.bin/checkworkmail.py

+ 22 - 0
bin/.bin/checkworkmail.py

@@ -58,6 +58,27 @@ def extract_body(msg):
         return payload
     return "(No readable body content found)"
 
+def clean_slack_body(body):
+    # Remove intro like: "Hi Colin,\n\nYou have a new direct message from ..."
+    cleaned = re.sub(
+        r"Hi .*?,\s+You have a new direct message from.*?\(.*?\.slack\.com.*?\)\.\s+---",
+        "",
+        body,
+        flags=re.DOTALL,
+    )
+    return cleaned.strip()
+
+def clean_slack_body(body):
+    # Remove intro like: "Hi Colin,\n\nYou have a new direct message from ..."
+    cleaned = re.sub(
+        r"Hi .*?,\s+You have a new direct message from.*?\(.*?\.slack\.com.*?\)\.\s+---",
+        "",
+        body,
+        flags=re.DOTALL,
+    )
+    return cleaned.strip()
+
+
 def extract_github_link(subject, body):
     pr_match = re.search(r'\(PR\s+#(\d+)\)', subject)
     repo_match = re.search(r'\[([^\]]+)\]', subject)  # [owner/repo]
@@ -136,6 +157,7 @@ def check_notifications():
         elif is_slack_email(from_email, subject):
             source = "Slack"
             link = ""
+            body = clean_slack_body(body)
         else:
             print(f"Skipping non-matching email: {subject}")
             continue