From: Erik Mackdanz Date: Sat, 14 Feb 2026 16:56:45 +0000 (-0600) Subject: initial commit X-Git-Url: https://git.humopery.space/?a=commitdiff_plain;h=7f1e8e2caeeba44830489f2b5f8b994a4e2359b0;p=dsnview.git initial commit --- 7f1e8e2caeeba44830489f2b5f8b994a4e2359b0 diff --git a/README.md b/README.md new file mode 100644 index 0000000..6f79a26 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +This is a hastily vibe-coded script (thanks DeepSeek) that takes an +email delivery status notification (DSN) on stdin, formats the report +within to HTML and displays it with lynx. It's good to quickly view +these report in mutt. + +Put it in your path with `chmod +x` and then add to your muttrc: + +``` +macro attach 'R' "dsnview" +``` + diff --git a/dsnview b/dsnview new file mode 100755 index 0000000..4b4bb51 --- /dev/null +++ b/dsnview @@ -0,0 +1,284 @@ +#!/bin/sh +# Create temporary directory +tmpdir=$(mktemp -d) + +# Set trap to clean up on exit +cleanup() { + rm -rf "$tmpdir" +} +trap cleanup EXIT + +# Read stdin and save as attachment +cat > "$tmpdir/attachment" + +# Determine file type and extract accordingly +filetype=$(file -b "$tmpdir/attachment") + +case "$filetype" in + *"Zip archive"*) + echo "Detected ZIP archive" + unzip -q "$tmpdir/attachment" -d "$tmpdir" + ;; + *"gzip compressed"*) + echo "Detected gzip compressed file" + gunzip -c "$tmpdir/attachment" > "$tmpdir/extracted.xml" 2>/dev/null + ;; + *"XML"*) + echo "Detected XML file" + cp "$tmpdir/attachment" "$tmpdir/extracted.xml" + ;; + *) + echo "Unknown file type: $filetype" + exit 1 + ;; +esac + +# List contents +echo "Extracted contents:" +ls -la "$tmpdir" + +# Find and display the XML file +xml_file=$(find "$tmpdir" -name "*.xml" -type f | head -1) +if [ -n "$xml_file" ] && [ -f "$xml_file" ]; then + echo -e "\n=== Generating HTML DMARC Report for $(basename "$xml_file") ===" + + # Create colorful HTML XSL stylesheet + cat > "$tmpdir/dmarc-html.xsl" << 'EOF' + + + + + + + DMARC Aggregate Report + + + +

📊 DMARC Aggregate Report

+ +
+

📋 Report Metadata

+ + + + + + +
FieldValue
Organization
Report ID
Date Range
Contact Email
+
+ +
+

⚙️ Published DMARC Policy

+ + + + + + + + +
FieldValue
Domain
DKIM Alignment
SPF Alignment
Policy
Subdomain Policy
Percentage%
+
+ +
+

📨 Email Records

+ +
+

📧 Record

+ + + + +
Source IP:
Message Count:
Header From:
+ +

Policy Evaluation:

+ + + + + + + + + + + +
DispositionDKIMSPF
+ +

Authentication Results:

+ + + + + + + + + + + + + + + + + + + +
TypeDomainResultSelector
DKIM
SPF—
+
+
+
+ + +
+
+EOF + + # Generate HTML using xsltproc (more reliable for HTML output) + if command -v xsltproc >/dev/null 2>&1; then + html_file="$tmpdir/dmarc-report.html" + if xsltproc -o "$html_file" "$tmpdir/dmarc-html.xsl" "$xml_file"; then + echo "HTML report generated: $html_file" + + # Display with lynx if available + if command -v lynx >/dev/null 2>&1; then + echo -e "\n=== Displaying with lynx (press 'q' to quit) ===" + lynx "$html_file" + else + echo "lynx not found. HTML file saved to: $html_file" + echo "You can view it with: cat $html_file" + fi + else + echo "xsltproc failed, showing raw XML instead:" && cat "$xml_file" + fi + else + echo "xsltproc not found, showing raw XML:" + cat "$xml_file" + fi +else + echo "No XML file found in extracted contents." +fi + +# Sample XML: + +# +# +# 1.0 +# +# google.com +# noreply-dmarc-support@google.com +# https://support.google.com/a/answer/2466580 +# 9340001457015044932 +# +# 1770768000 +# 1770854399 +# +# +# +# atxsra.org +# r +# r +#

none

+# none +# 100 +# none +#
+# +# +# 173.255.193.22 +# 16 +# +# none +# pass +# pass +# +# +# +# atxsra.org +# +# +# +# atxsra.org +# pass +# lin +# +# +# atxsra.org +# pass +# +# +# +# +# +# 2600:3c00::f03c:95ff:fee2:e488 +# 23 +# +# none +# pass +# pass +# +# +# +# atxsra.org +# +# +# +# atxsra.org +# pass +# lin +# +# +# atxsra.org +# pass +# +# +# +# +# +# 209.85.220.41 +# 3 +# +# none +# pass +# fail +# +# +# +# atxsra.org +# +# +# +# atxsra.org +# pass +# lin +# +# +# gmail.com +# pass +# +# +# +#