From a61cefe80c544632bbdd8bddfb336e331816bf49 Mon Sep 17 00:00:00 2001 From: David Runge Date: Sat, 20 Feb 2021 10:46:02 +0100 Subject: mbsync/mutt: Guard against empty mailbox file bin/mbsync2mutt_mailboxes: Change script to only copy the temporary mailboxes.rc file in place if at least one account entry is found (prevents override of existing data with an empty file, if mbsync returns nothing due to locked secret). --- bin/mbsync2mutt_mailboxes | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'bin') diff --git a/bin/mbsync2mutt_mailboxes b/bin/mbsync2mutt_mailboxes index c98e219..ccf9505 100755 --- a/bin/mbsync2mutt_mailboxes +++ b/bin/mbsync2mutt_mailboxes @@ -27,11 +27,16 @@ get_mailboxes_by_account() { } output_mailboxes_to_file() { + local tmpfile counter tmpfile="$(mktemp)" + counter=0 for account in "${!mailboxes[@]}"; do echo -e "mailboxes ${mailboxes[$account]}\n" >> "$tmpfile" + counter=$(( "$counter" + 1 )) done - mv "$tmpfile" "$output_file" + if (( "$counter" > 0 )); then + mv "$tmpfile" "$output_file" + fi } if [ $# -ne 1 ]; then -- cgit v1.2.3-70-g09d2