astroidmail / astroid

A graphical threads-with-tags style, lightweight and fast, e-mail client for Notmuch
http://astroidmail.github.io
Other
613 stars 65 forks source link

astroid immediately deletes opened attachment files #339

Closed tigoesnumb3rs closed 7 years ago

tigoesnumb3rs commented 7 years ago

Hey,

I've astroid 0.9.1 set up using:

    "attachment": {
        "external_open_cmd": "xdg-open"
    },

However I can't seem to open attachments properly. The correct applications are opened, and astroid copies the attachment into ~/.cache/astroid/, however the files are deleted immediately after they are created.

This is the log output:

[17:20:54.370230] [0x00007f253e50eb00] [info] chunk: bla.pdf, opening..
[17:20:54.370470] [0x00007f253e50eb00] [debug] chunk: saving to tmp path: ~/.cache/astroid/6wx1s4zqqe-bla.pdf
[17:20:54.370583] [0x00007f253e50eb00] [info] chunk: saving to: "~/.cache/astroid/6wx1s4zqqe-bla.pdf"
[17:20:54.371152] [0x00007f253e50eb00] [info] chunk: contents: loaded 34913 bytes in 0.417 ms.
[17:20:54.371538] [0x00007f253e50eb00] [debug] tv: element action emitted: 2, action: enter
[17:20:54.371834] [0x00007f24b22c7700] [debug] chunk: spawning: xdg-open, ~/.cache/astroid/6wx1s4zqqe-bla.pdf
[17:20:54.491095] [0x00007f24b22c7700] [info] chunk: deleting tmp file: ~/.cache/astroid/6wx1s4zqqe-bla.pdf

I don't think this is the intended behavoir, and would be happy if this could be fixed or if anyone could tell me how to properly configure astroid. I don't think the

cheers

gauteh commented 7 years ago

Hi, you can use the approach described here to prevent the files from being deleted before they are closed:

https://github.com/astroidmail/astroid/wiki/Opening-attachments-and-virus-detection

Regards, Gaute

tigoesnumb3rs commented 7 years ago

Thanks, the link put me in the right direction. I can now open attachments using the following script:

#!/bin/bash

cachedir=~/.cache/astroid-attachments
attachment=$(echo $1 | sed "s#.*astroid/##")

touch $cachedir/token.$attachment

mv $1 ~/.cache/astroid-attachments/

inotifywait -e close "$1" &
ip=$!

# open file (you can replace this with xdg-open)
xdg-open "$cachedir/$attachment"

while inotifywait -r -e close $cachedir/$attachment; do rm $cachedir/token.$attachment || rm $cachedir/$attachment; done

The script moves the file to ~/.cache/astroid-attachementsbefore astroid can delete it and creates a second empty file inside the same directory. Then the file is opened using xdg-open and the inotifywait loop is started to wait for the file to be closed. At this point, since the inotifywait loop raises an close event immediately after starting, the token-file is removed. When the file is closed in the application the token-file is removed a second time, which fails and triggers the removal of the actual attachment file.

Probably not the best solution, but it works.

gauteh commented 7 years ago

Great, I think it might be worth putting in a sleep somewhere as well. Then it should work with out the move.