{"id":211,"date":"2026-02-24T07:39:17","date_gmt":"2026-02-24T15:39:17","guid":{"rendered":"https:\/\/chris.tsehome.com\/?p=211"},"modified":"2026-02-22T22:40:26","modified_gmt":"2026-02-23T06:40:26","slug":"the-ai-sentry-hardening-postfix-with-openclaw","status":"publish","type":"post","link":"https:\/\/chris.tsehome.com\/?p=211","title":{"rendered":"The AI Sentry: Hardening Postfix with OpenClaw"},"content":{"rendered":"\r\n<p>In the world of self-hosted email, security isn\u2019t just a feature; it\u2019s a daily battle. While traditional spam filters like SpamAssassin do a heavy lifting, they often struggle with the &#8220;human-like&#8221; nuances of modern phishing. This week, we leveled up my Postfix mail server by integrating OpenClaw and a local AI sentry to identify and block sophisticated phishing attempts that traditional regex patterns miss.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">The Problem: When Keywords Aren&#8217;t Enough<\/h2>\r\n\r\n\r\n\r\n<p>Traditional filtering relies on known signatures or simple keyword matching. But what happens when a scammer sends a &#8220;Password Expiration Notice&#8221; from a legitimate-looking domain, or uses obfuscated text that bypasses standard string checks?<\/p>\r\n\r\n\r\n\r\n<p>We recently encountered a phishing email claiming a password would expire on <strong>February 30th<\/strong>. To a simple string matcher, &#8220;February 30th&#8221; is just text. To an AI with a baseline understanding of reality, it&#8217;s an immediate red flag.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">The Hybrid Sentry Architecture<\/h2>\r\n\r\n\r\n\r\n<p>For my technical readers, here is the architecture of how we automated this defense. We didn&#8217;t want to pipe every single email to an LLM (too slow and expensive). Instead, we built a <strong>Hybrid Sentry<\/strong> workflow:<\/p>\r\n\r\n\r\n\r\n<ol class=\"wp-block-list\">\r\n<li><strong>Fetch (Himalaya CLI):<\/strong> A bash script uses the <a href=\"https:\/\/github.com\/soywod\/himalaya\">Himalaya CLI<\/a> to fetch unflagged email envelopes from the Trash folders of multiple accounts.<\/li>\r\n<li><strong>Fast Filter (Local Regex):<\/strong> The script runs a fast keyword check. If it matches obvious junk, it\u2019s blocked immediately.<\/li>\r\n<li><strong>Smart Analysis (AI Inference):<\/strong> If the email is ambiguous, the script extracts the headers (From, Subject, Reply-To) and a 500-character body snippet, then sends it to a local AI model for a &#8220;common sense&#8221; check.<\/li>\r\n<li><strong>Block (Postfix Integration):<\/strong> Verified threats are written to Postfix <code>header_checks<\/code> and <code>sender_access<\/code> files in real-time.<\/li>\r\n<\/ol>\r\n\r\n\r\n\r\n<h3 class=\"wp-block-heading\">Technical Implementation: The Bash Script<\/h3>\r\n\r\n\r\n\r\n<p>Here is the core logic used in our <code>scan_mail_trash.sh<\/code>. It leverages the structured JSON output of Himalaya to make parsing reliable:<\/p>\r\n\r\n\r\n\r\n<pre class=\"wp-block-code\"><code># Fetch unflagged envelopes\r\nENVELOPES=$(himalaya envelope list --account \"$ACCOUNT\" --folder \"$TRASH_FOLDER\" --output json | jq -c '.[] | select(.flags | contains([\"flagged\"]) | not)')\r\n\r\necho \"$ENVELOPES\" | while read -r MSG; do\r\n    SENDER=$(echo \"$MSG\" | jq -r '.from.addr')\r\n    SUBJECT=$(echo \"$MSG\" | jq -r '.subject')\r\n    \r\n    # Simple regex pre-filter\r\n    if [[ \"$SUBJECT\" =~ (Win|Prize|Urgent|Verify|Invoice) ]]; then\r\n        # ... logic to update Postfix blocklists ...\r\n    fi\r\ndone<\/code><\/pre>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Closing the Loop with Postfix<\/h2>\r\n\r\n\r\n\r\n<p>Once the script identifies a threat, it appends the data to the Postfix configuration files. In our workspace, we maintain:<\/p>\r\n\r\n\r\n\r\n<ul class=\"wp-block-list\">\r\n<li><code>phish_sender_access.txt<\/code>: Mapping senders to <code>REJECT<\/code>.<\/li>\r\n<li><code>phish_header_checks.txt<\/code>: Mapping subject regex to <code>REJECT<\/code>.<\/li>\r\n<\/ul>\r\n\r\n\r\n\r\n<p>These files are then synced to the Postfix server, where a simple <code>postfix reload<\/code> makes the new defenses live. This turns my AI&#8217;s &#8220;learning&#8221; into a hard firewall for the entire mail system.<\/p>\r\n\r\n\r\n\r\n<h2 class=\"wp-block-heading\">Why This Matters<\/h2>\r\n\r\n\r\n\r\n<p>In the &#8220;Filing System&#8221; analogy of home automation, traditional filters are like a simple label-maker. They can label what you tell them to. Our new AI Sentry is like having a librarian who actually reads the labels and the first few pages, catching the nonsense that a machine would ignore.<\/p>\r\n\r\n\r\n\r\n<p>By automating this screening with OpenClaw, we\u2019ve moved from reactive blocking to proactive defense. Every day, the system gets slightly smarter, and my inbox gets slightly safer.<\/p>\r\n\r\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>In the world of self-hosted email, security isn\u2019t just a feature; it\u2019s a daily battle. While traditional spam filters like SpamAssassin do a heavy lifting, they often struggle with the &#8220;human-like&#8221; nuances of modern phishing. This week, we leveled up &hellip; <a href=\"https:\/\/chris.tsehome.com\/?p=211\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[18,23,22],"tags":[25,38,37,39,14,31,36],"class_list":["post-211","post","type-post","status-publish","format-standard","hentry","category-ai","category-productivity","category-technology","tag-automation","tag-february","tag-himalaya","tag-himalaya-cli","tag-postfix","tag-self-hosted","tag-sentry-hardening-postfix"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/chris.tsehome.com\/index.php?rest_route=\/wp\/v2\/posts\/211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/chris.tsehome.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/chris.tsehome.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/chris.tsehome.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/chris.tsehome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=211"}],"version-history":[{"count":1,"href":"https:\/\/chris.tsehome.com\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions"}],"predecessor-version":[{"id":212,"href":"https:\/\/chris.tsehome.com\/index.php?rest_route=\/wp\/v2\/posts\/211\/revisions\/212"}],"wp:attachment":[{"href":"https:\/\/chris.tsehome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/chris.tsehome.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/chris.tsehome.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}