Compare commits

..

No commits in common. "349ee8a646db6e97326b1e1b25f23c4566d1e2c6" and "f23097084e81ee13043c2d9f08e3dbeead9e72bb" have entirely different histories.

8
mailcap-server.py Executable file → Normal file
View File

@ -50,7 +50,7 @@ class Server(object):
os.makedirs(dir)
self._dir = dir
else:
self._dir = tempfile.TemporaryDirectory(prefix="mailcapd")
self._dir = tempfile.TemporaryDirectory()
def close(self):
self._socket.close()
@ -100,15 +100,12 @@ 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
@ -119,8 +116,7 @@ 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))
print("Accepted filename %s" % (full_name,))
full_name = os.path.join(self._dir.name, "%s-%d" % (fn, append, name_parts[-1]))
conn.send(b'\x01')
# Receive the file length