diff --git a/bin/.bin/checkworkmail.py b/bin/.bin/checkworkmail.py index 5991bc3..dd13cdd 100755 --- a/bin/.bin/checkworkmail.py +++ b/bin/.bin/checkworkmail.py @@ -78,6 +78,22 @@ def clean_slack_body(body): ) return cleaned.strip() +def clean_and_relocate_slack_footer(body): + # Match the "View in the archives" block + archive_pattern = re.compile( + r"(@\w+)?\s*View in the archives: (https://.*?\.slack\.com/\S+)", re.IGNORECASE + ) + + match = archive_pattern.search(body) + if match: + slack_url = match.group(2).strip() + cleaned_body = archive_pattern.sub("", body).strip() + # Format the link cleanly at the bottom + footer = f"🔗 View in Slack: {slack_url}" + return f"{cleaned_body}\n\n---\n{footer}" + else: + return body.strip() + def extract_github_link(subject, body): pr_match = re.search(r'\(PR\s+#(\d+)\)', subject) @@ -157,7 +173,7 @@ def check_notifications(): elif is_slack_email(from_email, subject): source = "Slack" link = "" - body = clean_slack_body(body) + body = clean_and_relocate_slack_footer(clean_slack_body(body)) else: print(f"Skipping non-matching email: {subject}") continue