You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2020/08/19 11:13:12 UTC

[incubator-ponymail-foal] branch master updated: if we converted lone LFs, convert back after unflowing.

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git


The following commit(s) were added to refs/heads/master by this push:
     new 7a065d8  if we converted lone LFs, convert back after unflowing.
7a065d8 is described below

commit 7a065d8bd66189ca563c0a6e3e050797d40a41f0
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Wed Aug 19 13:12:58 2020 +0200

    if we converted lone LFs, convert back after unflowing.
    
    This doesn't make a ton of difference, but makes things consistent.
---
 tools/archiver.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/tools/archiver.py b/tools/archiver.py
index f69815d..8b0d98b 100755
--- a/tools/archiver.py
+++ b/tools/archiver.py
@@ -191,12 +191,13 @@ class Body:
     def encode(self, charset="utf-8", errors="strict"):
         return self.string.encode(charset, errors=errors)
 
-    def unflow(self, convert_lf = False):
+    def unflow(self, convert_lf=False):
         if self.string:
             if self.flowed:
                 # Convert lone LF to CRLF if found
                 if convert_lf:
-                    fixed_string = "\r\n".join([x.strip() for x in self.string.split("\n")])
+                    fixed_string = "\r\n".join([x.rstrip("\r") for x in self.string.split("\n")])
+                    conversion_was_needed = fixed_string != self.string
                 else:
                     fixed_string = self.string
                 flow_fixed = formatflowed.convertToWrapped(
@@ -204,6 +205,9 @@ class Body:
                     wrap_fixed=False,
                     character_set=self.character_set,
                 )
+                # If we "upconverted" from LF to CRLF, convert back after flow decoding
+                if convert_lf and conversion_was_needed:
+                    flow_fixed = "\n".join([x.rstrip("\r") for x in self.string.split("\n")])
                 return flow_fixed
         return self.string