You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在邮件服务器中创建过滤器匹配特定域名的HTTP/HTTPS URL

Alright, let's figure out how to build that email filter you need. You want to catch any emails with URLs starting with http/https that point to any subdomain of domain.org (or the main domain itself), even when those URLs get split across lines with a trailing equals sign. Here's a solid regex solution and how to implement it across common email servers:

Core Regular Expression

This regex handles both full URLs and split URLs with trailing equals signs:

\bhttps?://(?:[^\s=]|=\s)*\.domain\.org(?:[^\s=]|=\s)*

Breakdown of the regex:

  • \b: Word boundary to avoid matching partial strings like xhttps://
  • https?://: Matches both http:// and https:// protocols
  • (?:[^\s=]|=\s)*: Non-capturing group that handles:
    • [^\s=]: Any character that's not a whitespace or equals sign (normal URL characters)
    • =\s: An equals sign followed by any whitespace (including newlines) — this covers the line-split scenario
    • *: Repeats the group zero or more times to handle multiple splits
  • \.domain\.org: Exact match for the target domain (dots are escaped since they're special regex characters)
  • The final (?:[^\s=]|=\s)*: Matches any path/query parameters after the domain, even if they're split across lines
Implementation in Common Email Servers

Here's how to use this regex in popular email systems:

Gmail Filters

  1. Go to Gmail's Filters and Blocked Addresses page
  2. Click Create a new filter
  3. In the Has the words field, paste the regex
  4. Check the box for Also apply filter to matching conversations (if needed)
  5. Click Create filter, then select your desired action (e.g., "Delete it", "Apply label")
  6. Important: Enable regex support by checking the box labeled Search using regular expressions before saving

Postfix (Body/Header Checks)

Add this line to your Postfix body checks file (usually /etc/postfix/body_checks):

/^\bhttps?://(?:[^\s=]|=\s)*\.domain\.org(?:[^\s=]|=\s)*$/ REJECT
  • Replace REJECT with your desired action (e.g., DISCARD, REDIRECT your-archive@example.com)
  • Reload Postfix to apply changes: sudo systemctl reload postfix

Exchange Server

Use PowerShell to create a transport rule (the GUI may not support complex regex fully):

New-TransportRule -Name "Flag domain.org URLs" -SubjectOrBodyMatchesPatterns '\bhttps?://(?:[^\s=]|=\s)*\.domain\.org(?:[^\s=]|=\s)*' -ApplyHtmlLabel "Domain.org URL Detected"
  • Adjust the action (-ApplyHtmlLabel, -DeleteMessage, etc.) to fit your needs
Key Notes for Testing
  • Test with split URL examples to ensure coverage:
    • Split once: https://site1.domain.or=\ng/path?query=123
    • Split multiple times: https://site1.do=\nmai=\nn.org/download
    • Full URL: http://domain.org
  • If your email server's regex engine doesn't recognize \s as newlines, replace \s with [\r\n\t ] to explicitly match line breaks, tabs, and spaces
  • To avoid matching domains like fake.domain.org.evil.com, modify the regex to end with a word boundary: \.domain\.org\b(?:[^\s=]|=\s)*

内容的提问来源于stack exchange,提问作者Luis A.

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 07:41:45