Hello Antoine,
Antoine Beaupré dijo [Tue, Nov 08, 2022 at 09:13:01AM -0500]:
> > dmarc-cat insists AFAICT to work on existing files. I tried to get it
> > to process the reports I found attached to received mails; for this, I
> > would love to be able to ask my MTA to pipe the attachment to
> > dmarc-cat. However, I could not get it to work, either with the
> > convention of using '-' or even with capturing via <( ... )
> >
> > So, please, could you add an option for dmarc-cat to work on reports
> > from STDIN?
>
> It *looks* like this is fixed upstream, according to:
>
> https://github.com/keltia/dmarc-cat/issues/14
>
> I'm going to upload 0.15 soon-ish, maybe you can confirm it's fixed
> there? In any case, I'll marked this as fixed there because it looks
> like upstream assumes it's fixed, so it must have happened after 0.14...
Thanks for following up on this. I see it does now _say to_ accept
files via STDIN, but...
$ dmarc-cat -h
Usage of dmarc-cat:
-D Debug mode
-N Do not resolve IPs
-S string
Sort results (default "\"Count\" \"dsc\"")
-j int
Parallel jobs (default 8)
-t string
File type for stdin mode
-v Verbose mode
-version
Display version
$ dmarc-cat
2022/11/09 12:27:08 Error: realmain: You must specify at least one file.
$ dmarc-cat -
2022/11/09 12:27:10 Error: SelectInput: Wrong file type, use -t
It really lacks documentation! :-( I don't know where to get the
filetype from.
Took a quick dive in dmarc-cat's source, and found only two probable
strings as file types: ".zip" and ".xml". It was not a very scientific
test, but:
$ grep -ri ftype .
./file.go: debug("%d %s", typ, fType)
./main.go: fType string
./main.go: flag.StringVar(&fType, "t", "", "File type for stdin mode")
./main.go: if fType == "" {
./main.go: var fType = filepath.Ext(file)
./main.go: if strings.ToLower(fType) == ".zip" {
./main.go: typ := archive.Ext2Type(fType)
./main_test.go: fType = ".xml"
./main_test.go: fType = ""
$
But handling it as .zip does not seem to work:
$ cat report.zip | dmarc-cat -t .zip -
2022/11/09 12:34:38 Error: file -:: unmarshall: XML syntax error on line 2:
illegal character code U+0003
However, it does work when I give it the uncompressed XML:
$ unzip -p file.zip | dmarc-cat -t .zip -
dmarc-cat 0.15.0,parallel/j8 by Ollivier Robert
Reporting by: google.com — [email protected]
From 2022-03-28 18:00:00 -0600 CST to 2022-03-29 17:59:59 -0600 CST
Domain: gwolf.org
Policy: p=none; dkim=r; spf=r
Reports(1):
IP Count From RFrom RDKIM RSPF
mail.iiec.unam.mx. 2 gwolf.org gwolf.org pass pass
Given that file.go has the needed bits to handle a .zip file, I'd
still consider a bug to be present (albeit a different one).
I was able to find two spots in the code where this was not correctly
handled. First, in main.go, fType is clobbered even if specificed; it
should only be replaced if not specified:
diff --git a/main.go b/main.go
index 736a8e7..e6d4e98 100644
--- a/main.go
+++ b/main.go
@@ -115,7 +115,9 @@ func realmain(args []string) error {
verbose("Analyzing %s", file)
- var fType = filepath.Ext(file)
+ if fType == "" {
+ fType = filepath.Ext(file)
+ }
if strings.ToLower(fType) == ".zip" {
txt, err = HandleZipFile(ctx, file)
The other point is in file.go. It seems trivial to fix, but I've never
worked with Go before; function HandleZipFile is failing to open a
file named "-"; it should just read it if so speficied. I tried to
copy the differing logic from HandleSingleFile, but failed and decided
to throw the ball back at you ;-)
Anyway, besides getting dmarc-cat to work with piped zip files, it
should at least be minimally documented!
Thanks,
- Gunnar.