Strip carriage returns (^M) when filtering emails

Presumably some email servers will transform newlines into carriage
return new lines to better support windows users. I can't prove this but
that's the best explanation I have for my hosted email provider
(fastmail).

Without this patch, I was seeing annoying `^M`s at the end of every
filtered line.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
This commit is contained in:
Daniel Xu 2019-08-19 19:06:52 -07:00 committed by Drew DeVault
parent 6fcc047c31
commit ea4fe71360
2 changed files with 9 additions and 0 deletions

View File

@ -10,6 +10,9 @@ BEGIN {
}
{
if (hit_diff == 0) {
# Strip carriage returns from line
gsub(/\r/, "", $0)
if ($0 ~ /^diff /) {
hit_diff = 1;
print bright $0 reset
@ -23,6 +26,9 @@ BEGIN {
print $0
}
} else {
# Strip carriage returns from line
gsub(/\r/, "", $0)
if ($0 ~ /^-/) {
print red $0 reset
} else if ($0 ~ /^\+/) {

View File

@ -5,6 +5,9 @@ BEGIN {
reset = "\x1B[0m"
}
{
# Strip carriage returns from line
gsub(/\r/, "", $0)
if ($0 ~ /^On .*, .* wrote:/ || $0 ~ /^>+/) {
print dim cyan $0 reset
} else {