Blah
This commit is contained in:
parent
64400a1ade
commit
349ee8a646
8
mailcap-server.py
Normal file → Executable file
8
mailcap-server.py
Normal file → Executable file
|
@ -50,7 +50,7 @@ class Server(object):
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
self._dir = dir
|
self._dir = dir
|
||||||
else:
|
else:
|
||||||
self._dir = tempfile.TemporaryDirectory()
|
self._dir = tempfile.TemporaryDirectory(prefix="mailcapd")
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self._socket.close()
|
self._socket.close()
|
||||||
|
@ -100,12 +100,15 @@ class Server(object):
|
||||||
full_name = os.path.join(self._dir.name, fn)
|
full_name = os.path.join(self._dir.name, fn)
|
||||||
append = 0
|
append = 0
|
||||||
# While the filename already exists, check if we have a hash match
|
# While the filename already exists, check if we have a hash match
|
||||||
|
print("Trying path %s" % (full_name,))
|
||||||
while os.path.exists(full_name):
|
while os.path.exists(full_name):
|
||||||
hash = hashlib.sha256()
|
hash = hashlib.sha256()
|
||||||
hash.update(open(full_name, "rb").read())
|
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.
|
# Found a matching file. Do not receive the file.
|
||||||
if data == hash.digest():
|
if data == hash.digest():
|
||||||
|
print("Hash matches received hash. Closing connection.")
|
||||||
conn.send(b'\x00')
|
conn.send(b'\x00')
|
||||||
conn.close()
|
conn.close()
|
||||||
return full_name, mime
|
return full_name, mime
|
||||||
|
@ -116,7 +119,8 @@ class Server(object):
|
||||||
if len(name_parts) > 1:
|
if len(name_parts) > 1:
|
||||||
full_name = os.path.join(self._dir.name, "%s-%d.%s" % ('.'.join(name_parts[:-1]), append, name_parts[-1]))
|
full_name = os.path.join(self._dir.name, "%s-%d.%s" % ('.'.join(name_parts[:-1]), append, name_parts[-1]))
|
||||||
else:
|
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')
|
conn.send(b'\x01')
|
||||||
|
|
||||||
# Receive the file length
|
# Receive the file length
|
||||||
|
|
Loading…
Reference in New Issue
Block a user