From: Ian Jackson Date: Thu, 17 Jan 2019 15:17:22 +0000 (+0000) Subject: line wrapping: Provide cr-fold-long-lines script X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=b2e08cdce30d42625ca4b3c6d3b2d62b8a83dc2d;p=osstest.git line wrapping: Provide cr-fold-long-lines script 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 --- diff --git a/cr-fold-long-lines b/cr-fold-long-lines new file mode 100755 index 0000000..821c46a --- /dev/null +++ b/cr-fold-long-lines @@ -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\ | bar => ooobar ( 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