]> xenbits.xensource.com Git - osstest.git/commitdiff
line wrapping: Provide cr-fold-long-lines script
authorIan Jackson <ian.jackson@eu.citrix.com>
Thu, 17 Jan 2019 15:17:22 +0000 (15:17 +0000)
committerIan Jackson <ian.jackson@eu.citrix.com>
Thu, 17 Jan 2019 15:25:50 +0000 (15:25 +0000)
This is a reversible transformation which usually just introduces a \
where it splits lines.

We are going to use this to wrap the lines in our emails.  SMTP has a
999-byte length limit (including a CR-LF pair).  This can cause our
emails to go astray.  We don't really want our messages to be q-p or
base64-encoded if we can avoid it, and MTAs don't do that anyway (so
we would have to organise it).  So instead, we will simply wrap any
long lines that occur.

This transformation is not suitable for headers, but we don't intend
or want to generate long lines which would need further wrapping.  (A
reversible transformation suitable for headers would be quite ugly and
would only be right for a subset of headers anyway...)

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
cr-fold-long-lines [new file with mode: 0755]

diff --git a/cr-fold-long-lines b/cr-fold-long-lines
new file mode 100755 (executable)
index 0000000..821c46a
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/perl -wp
+#
+# long lines are broken by inserting \ plus spaces/tabs, somewhere
+# lines already ending with \ and maybe some $s have a $ postpended
+#   so they do not look broken
+#
+# unparsing:
+#      ooo\ | <SPC>bar     =>      ooobar   (<SPC> is >=0 tab/space)
+# then:
+#     ooo\$ | any          =>      ooo\ | any
+#    ooo\$$ | any          =>     ooo\$ | any
+#   ooo\$$$ | any          =>    ooo\$$ | any     etc.
+# others unchanged, specifically:
+#      ooo$ | any          =>      ooo$ | any
+#     ooo$$ | any          =>     ooo$$ | any
+#    ooo$$$ | any          =>    ooo$$$ | any     etc.
+# (where in these diagrams ` | ' means a newline)
+
+use strict;
+
+s{\\(\$*)\n}{\\$1\$\n}; # $-stuffing, now does not end in backslash
+s{.{500}}{$&\\\n }g; # insert \ \n SPC as needed