stevejenkins/postwhite

Postwhite silently crashes on some custom hosts

qskousen opened this issue · 8 comments

When I add these specific custom hosts, Postwhite silently fails after querying the last host. Without this, it works fine.

custom_hosts="sparkpost.com sparkpostmail.com"

Not sure if this matters since after attempting to add them I noticed you had already added Sparkpost, but I thought the behavior was strange. This was on a fresh and unmodified Postwhite install.

Oh yes it works without the custom_hosts. Same issue. Thanks.

Thanks for reporting.

Looks like the issue is with the despf.sh results for sparkpostmail.com (sparkpost.com works fine). Postwhite is choking on them. I verified this by moving sparkpostmail.com into the bulk_mailers section of the main script. Same result - exit without error.

The despf.sh output (which postwhite parses) is:

# /usr/local/bin/spf-tools/despf.sh sparkpostmail.com
Getting _spf.sparkpostmail.com
exists:%{i}._spf.sparkpostmail.com
ptr:flyingenvelope.com
ptr:sparkpostmail.com
ptr:spmta.com

I'm wondering if it doesn't like the exists. I'll tinker today.

After further tinkering, it seems that if a mailer has no valid desph.sh output (i.e. output starting with ip) -- which is the case with sparkpostmail.com -- when postwhite attempts to write the blank output to the temp file via this line:

"${spftoolspath}"/despf.sh "$1" | grep ^ip >> "${tmp1}"

Bash calls it an error. And because set -e is on line 45, said error causes the postwhite script to exit.

The easiest fix (for now) is to simply comment out line 45, which I've done. When I have more time, I might go back in and check for blank output before attempting to write it to the temp file.

Unless @jcbf has a quick solution? :)

Fixed, but would prefer something more elegant that still allows the script to exit on error.

jcbf commented

@stevejenkins , you should alway try filter out content that you be able to process correctly.
Fixes in current spf-tools may start to output records that can't ( or should try to) expand. Records with macros or records starting with modifiers like, -ip4:1.2.3.4 are good examples.

Hi, @jcbf. I agree... but it's the current filter that is causing the issue. This is the current line that writes to the temp file:

"${spftoolspath}"/despf.sh "$1" | grep -Ei ^ip >> "${tmp1}"

The grep is a quick and dirty way of grabbing lines that start with ip -- but for some reason, if the output is nothing (nothing matches the grep), Bash considers it an error, and with set -e in the script, the script exits. So I'll have to check whether the output of grep -Ei ^ip is blank before attempting to write to the temp file. If I get time to tinker with that soon, I will. If someone else beats me to it, that's awesome. :)

jcbf commented

I think this will do the trick ...

"${spftoolspath}"/despf.sh "$1" | (grep -Ei ^ip || true ) >> "${tmp1}"

Yep! That seems to do the trick! Thanks, @jcbf