From bae2bceb00eddb8234362dfc1f306ad69ce5f1e5 Mon Sep 17 00:00:00 2001 From: mxmehl Date: Wed, 23 Aug 2017 11:35:53 +0200 Subject: [PATCH] fix attachments with spaces and don't delete them after opening them --- astroid/scripts/attachment-saver.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/astroid/scripts/attachment-saver.sh b/astroid/scripts/attachment-saver.sh index be0ea87..8852ecc 100755 --- a/astroid/scripts/attachment-saver.sh +++ b/astroid/scripts/attachment-saver.sh @@ -1,17 +1,20 @@ #!/bin/bash # +# prevents astroid to delete an attachment file immediately +# but instead copies it to a separate directory and preserves it +# # based on https://github.com/astroidmail/astroid/issues/339#issuecomment-300491869 cachedir=~/.cache/astroid-attachments -attachment=$(echo $1 | sed "s#.*astroid/##") +attachment=$(echo "$1" | sed -E "s#.*astroid/.+?-##") -touch $cachedir/token.$attachment +touch $cachedir/token."$attachment" if [ ! -e ${cachedir} ]; then mkdir -p ${cachedir} fi -mv $1 ~/.cache/astroid-attachments/ +mv "$1" ~/.cache/astroid-attachments/"$attachment" inotifywait -e close "$1" & ip=$! @@ -19,4 +22,6 @@ 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 +while inotifywait -r -e close $cachedir/"$attachment"; do + rm $cachedir/token."$attachment" # || rm $cachedir/"$attachment" +done