Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview compressed XMLs with highlighting #11

Open
flatcap opened this issue Sep 14, 2020 · 0 comments
Open

Preview compressed XMLs with highlighting #11

flatcap opened this issue Sep 14, 2020 · 0 comments
Labels
DYK:tips Submit your DYK tips

Comments

@flatcap
Copy link
Member

flatcap commented Sep 14, 2020

This is useful especially to see DMARC reports, which usually come as zip/gzip'd xml files:

Content-Type: application/zip;↓
→   name="google.com!gahr.ch!1576022400!1576108799.zip"
Content-Disposition: attachment;↓
→   filename="google.com!gahr.ch!1576022400!1576108799.zip"
Content-Transfer-Encoding: base64

mailcap

application/zip; /home/gahr/bin/dump-compressed-xml.tcl %s | less -r;           
application/gzip; /home/gahr/bin/dump-compressed-xml.tcl %s | less -r;          
application/xml; /home/gahr/bin/dump-compressed-xml.tcl %s | less -r;

dump-compressed-xml.tcl

#!/usr/bin/env tclsh

# Enter alternate screen
puts "\x1b7\x1b\[?47h"

set g(hi) {highlight -S xml -O xterm256 -s lucretia}
set g(ex) {
    .gz    {gunzip -c}
    .zip   {unzip -p}
    .xml   {cat}
}

if {$argc != 1} {
    puts "Usage: $argv0 filename"
    exit 1
}

set filename [lindex $argv 0]
set extension [file extension $filename]

if {![dict exists $g(ex) $extension]} {
    puts "Unhandled extension: $extension"
    exit 1
}

set fd [open "|[dict get $g(ex) $extension] $filename | $g(hi)"]
puts [read $fd]

By: @gahr

@flatcap flatcap added the DYK:tips Submit your DYK tips label Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DYK:tips Submit your DYK tips
Projects
None yet
Development

No branches or pull requests

1 participant