From f202d11124347783dbd679ae521f1bcb09e73cbb Mon Sep 17 00:00:00 2001
From: Dennis Camera <dennis.camera@ssrq-sds-fds.ch>
Date: Thu, 1 Oct 2020 13:45:20 +0200
Subject: [PATCH] [type/__mail_alias] Fix continuation line processing

---
 type/__mail_alias/explorer/aliases         | 12 ++++--------
 type/__mail_alias/files/update_aliases.awk |  8 +++-----
 2 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/type/__mail_alias/explorer/aliases b/type/__mail_alias/explorer/aliases
index 5b5d68d..ac13d7c 100755
--- a/type/__mail_alias/explorer/aliases
+++ b/type/__mail_alias/explorer/aliases
@@ -31,7 +31,7 @@ function print_aliases(aliases,    matches) {
 	split(aliases, matches, /,[ \t]*/)
 	for (i in matches) {
 		gsub(/^[ \t]*|[ \t]*$/, "", matches[i])
-		print matches[i]
+		if (matches[i]) print matches[i]
 	}
 }
 
@@ -47,14 +47,10 @@ function print_aliases(aliases,    matches) {
 	is_cont = /^[ \t]/ || cont
 
 	# detect if the line is a line to be continued (ends with a backslash)
-	cont = ($0 ~ /\\$/)
+	cont = /\\$/
 
-	# if it is, we drop the backslash from the line and skip to next line
-	# (the contents have been printed above if they should)
-	if (cont) {
-		sub(/[ \t]*\\$/, "", $0)
-		next
-	}
+	# if it is, we drop the backslash from the line
+	if (cont) sub(/[ \t]*\\$/, "", $0)
 }
 
 is_cont {
diff --git a/type/__mail_alias/files/update_aliases.awk b/type/__mail_alias/files/update_aliases.awk
index 87ea202..336009f 100644
--- a/type/__mail_alias/files/update_aliases.awk
+++ b/type/__mail_alias/files/update_aliases.awk
@@ -67,14 +67,12 @@ BEGIN {
 	is_cont = /^[ \t]/ || cont
 
 	# detect if the line is a line to be continued (ends with a backslash)
-	cont = ($0 ~ /\\$/)
-	# if it is, we drop the backslash from the line.
-	if (cont) sub(/[ \t]*\\$/, "", $0)
+	cont = /\\$/
 }
 
 is_cont {
-	# we ignore the line as it has been rewritten previously or is not
-	# interesting
+	# we only print the line if it has not been rewritten (select)
+	if (!select) print
 	next
 }