mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 03:43:19 +00:00
Set custom path to mailcap file
This commit is contained in:
parent
5bf3f62797
commit
78a5a30f65
3 changed files with 12 additions and 2 deletions
|
@ -186,11 +186,13 @@ KEEP_MEDIA = 7
|
|||
|
||||
FILE_PICKER_CMD = "ranger --choosefile={file_path}"
|
||||
# FILE_PICKER_CMD = "nnn -p {file_path}"
|
||||
|
||||
MAILCAP_FILE = os.path.expanduser("~/.config/mailcap")
|
||||
```
|
||||
|
||||
### Mailcap file
|
||||
|
||||
Mailcap file is used for deciding how to open telegram files (docs, pics, voice notes, etc.).
|
||||
Mailcap file is used for deciding how to open telegram files (docs, pics, voice notes, etc.). Path to the file can be overriden with `MAILCAP_FILE` in config file.
|
||||
|
||||
Example: `~/.mailcap`
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ _linux = "Linux"
|
|||
CONFIG_DIR = os.path.expanduser("~/.config/tg/")
|
||||
CONFIG_FILE = os.path.join(CONFIG_DIR, "conf.py")
|
||||
FILES_DIR = os.path.expanduser("~/.cache/tg/")
|
||||
MAILCAP_FILE = None
|
||||
|
||||
LOG_LEVEL = "INFO"
|
||||
LOG_PATH = os.path.expanduser("~/.local/share/tg/")
|
||||
|
|
|
@ -72,12 +72,19 @@ def get_mime(file_path: str) -> str:
|
|||
return mtype.split("/")[0]
|
||||
|
||||
|
||||
def get_mailcap():
|
||||
if config.MAILCAP_FILE:
|
||||
with open(config.MAILCAP_FILE) as f:
|
||||
return mailcap.readmailcapfile(f)
|
||||
return mailcap.getcaps()
|
||||
|
||||
|
||||
def get_file_handler(file_path: str) -> str:
|
||||
mtype, _ = mimetypes.guess_type(file_path)
|
||||
if not mtype:
|
||||
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))
|
||||
|
||||
caps = mailcap.getcaps()
|
||||
caps = get_mailcap()
|
||||
handler, view = mailcap.findmatch(caps, mtype, filename=file_path)
|
||||
if not handler:
|
||||
return config.DEFAULT_OPEN.format(file_path=shlex.quote(file_path))
|
||||
|
|
Loading…
Reference in a new issue