Compare commits

..

No commits in common. "ad306ad0e95a2265161e7c4f4062c70fb2b259a5" and "c2d48d48b1f09239dd3a2b603c5c1f44ef589d89" have entirely different histories.

2 changed files with 7 additions and 8 deletions

View File

@ -1,19 +1,18 @@
#!/usr/bin/python3
#!python3
import struct
import socket
import os
import sys
import mimetypes
import subprocess
s = socket.socket(socket.AF_UNIX)
s.connect(os.path.join(os.environ["HOME"], ".mailcap.sock"))
filename = sys.argv[1]
mime = subprocess.run(["file", "-i", "-b", filename], check=True, stdout=subprocess.PIPE).stdout.decode('utf-8')
data = open(filename, "rb").read()
file = sys.argv[1]
mime = mimetypes.guess_type(file)[0]
data = open(file, "rb").read()
def strtr(x, c="B"):
return struct.pack(c, len(x)) + x
s.sendall(strtr(filename.encode('utf-8')) + strtr(mime.encode('utf-8')) + strtr(data, "!I"))
s.sendall(strtr(file.encode('utf-8')) + strtr(mime.encode('utf-8')) + strtr(data, "!I"))

View File

@ -112,8 +112,8 @@ if __name__ == "__main__":
if rv:
f, mime = rv
print(f, mime)
match = mailcap.findmatch(caps, mime.split(';')[0], filename=f)
if match and match[0]:
match = mailcap.findmatch(caps, mime, filename=f)
if match:
os.system(match[0])
if 'nodelete' not in match[1]:
os.remove(f)