From 349ee8a646db6e97326b1e1b25f23c4566d1e2c6 Mon Sep 17 00:00:00 2001 From: Valentin Ochs Date: Thu, 2 Apr 2020 19:28:10 +0200 Subject: [PATCH] Blah --- mailcap-server.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) mode change 100644 => 100755 mailcap-server.py diff --git a/mailcap-server.py b/mailcap-server.py old mode 100644 new mode 100755 index 365d333..5fdf001 --- a/mailcap-server.py +++ b/mailcap-server.py @@ -50,7 +50,7 @@ class Server(object): os.makedirs(dir) self._dir = dir else: - self._dir = tempfile.TemporaryDirectory() + self._dir = tempfile.TemporaryDirectory(prefix="mailcapd") def close(self): self._socket.close() @@ -100,12 +100,15 @@ class Server(object): full_name = os.path.join(self._dir.name, fn) append = 0 # While the filename already exists, check if we have a hash match + print("Trying path %s" % (full_name,)) while os.path.exists(full_name): hash = hashlib.sha256() hash.update(open(full_name, "rb").read()) + print("File exists, hash is %s" % (" ".join(["%02x" % (x,) for x in hash.digest()]))) # Found a matching file. Do not receive the file. if data == hash.digest(): + print("Hash matches received hash. Closing connection.") conn.send(b'\x00') conn.close() return full_name, mime @@ -116,7 +119,8 @@ class Server(object): if len(name_parts) > 1: full_name = os.path.join(self._dir.name, "%s-%d.%s" % ('.'.join(name_parts[:-1]), append, name_parts[-1])) else: - full_name = os.path.join(self._dir.name, "%s-%d" % (fn, append, name_parts[-1])) + full_name = os.path.join(self._dir.name, "%s-%d" % (fn, append)) + print("Accepted filename %s" % (full_name,)) conn.send(b'\x01') # Receive the file length