From 6f6802313340ba7ed152f0953e1e0a1a43fbd394 Mon Sep 17 00:00:00 2001 From: Luke Date: Tue, 13 Feb 2018 12:15:43 -0700 Subject: [PATCH] mailbox wizard added --- detect_mailboxes.sh | 22 ++++++++++++++++++++++ mutt-wizard.sh | 35 ++++++++++++++++++++++++++++------- 2 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 detect_mailboxes.sh diff --git a/detect_mailboxes.sh b/detect_mailboxes.sh new file mode 100644 index 0000000..7a015e1 --- /dev/null +++ b/detect_mailboxes.sh @@ -0,0 +1,22 @@ +#!/bin/sh +muttdir="$HOME/.config/mutt/" + +find ~/.mail/$1 -maxdepth 1 -mindepth 1 -type d | sed -e "s/.*\///g;s/^/=/g" > /tmp/$1_boxes +oneline=$(cat /tmp/$1_boxes | tr "\n" " ") +sed -i "/^mailboxes/d" "$muttdir"accounts/$1.muttrc +echo mailboxes $oneline >> "$muttdir"accounts/$1.muttrc + +formatShortcut() { \ + while read data; do + echo "macro index,pager g$1 \"$data\" \"Go to $2.\"" >> "$muttdir"accounts/$3.muttrc + done ;} + +sed -i "/^macro index,pager g/d" "$muttdir"accounts/$1.muttrc + +grep -vi /tmp/$1_boxes -e "trash\|drafts\|sent\|trash\|spam\|junk\|archive" | sort -n | sed 1q | formatShortcut i inbox $1 +grep -i /tmp/$1_boxes -e sent | formatShortcut s sent $1 +grep -i /tmp/$1_boxes -e trash | formatShortcut t trash $1 +grep -i /tmp/$1_boxes -e spam | formatShortcut S spam $1 +grep -i /tmp/$1_boxes -e draft | formatShortcut d drafts $1 +grep -i /tmp/$1_boxes -e archive | formatShortcut a archive $1 + diff --git a/mutt-wizard.sh b/mutt-wizard.sh index 08f7512..710ce5b 100755 --- a/mutt-wizard.sh +++ b/mutt-wizard.sh @@ -2,6 +2,25 @@ muttdir="$HOME/.config/mutt/" +formatShortcut() { \ + while read data; do + echo "macro index,pager g$1 \"$data\" \"Go to $2.\"" >> "$muttdir"accounts/$3.muttrc + done ;} + + +detectMailboxes() { \ + find ~/.mail/$1 -maxdepth 1 -mindepth 1 -type d | sed -e "s/.*\///g;s/^/=/g" > /tmp/$1_boxes + oneline=$(cat /tmp/$1_boxes | tr "\n" " ") + sed -i "/^mailboxes/d" "$muttdir"accounts/$1.muttrc + echo mailboxes $oneline >> "$muttdir"accounts/$1.muttrc + sed -i "/^macro index,pager g/d" "$muttdir"accounts/$1.muttrc + grep -vi /tmp/$1_boxes -e "trash\|drafts\|sent\|trash\|spam\|junk\|archive" | sort -n | sed 1q | formatShortcut i inbox $1 + grep -i /tmp/$1_boxes -e sent | formatShortcut s sent $1 + grep -i /tmp/$1_boxes -e trash | formatShortcut t trash $1 + grep -i /tmp/$1_boxes -e spam | formatShortcut S spam $1 + grep -i /tmp/$1_boxes -e draft | formatShortcut d drafts $1 + grep -i /tmp/$1_boxes -e archive | formatShortcut a archive $1 ;} + # Sees what accounts have been generated bny the wizard # by checking ~/.offlineimap and yields a menu of them. inventory() { \ @@ -132,12 +151,13 @@ wipe () { rm $HOME/.offlineimaprc while : ; do choice=$(dialog --title "Luke's mutt/offlineIMAP wizard" \ - --menu "What would you like to do?" 14 45 5 \ + --menu "What would you like to do?" 13 45 6 \ 0 "List all email accounts configured." \ 1 "Add an email account." \ - 2 "Remove an email account." \ - 3 "Remove all email accounts." \ - 4 "Exit this wizard." \ + 2 "Auto-detect mailboxes for an account." \ + 3 "Remove an email account." \ + 4 "Remove all email accounts." \ + 5 "Exit this wizard." \ 3>&1 1>&2 2>&3 3>&1 ) @@ -146,8 +166,9 @@ case $choice in $(grep ~/.offlineimaprc -e "^accounts =" | sed 's/accounts =//g') " 6 60;; 1) addChosen;; -2) inventory && for i in $userchoices; do removeAccount $i ; done;; -3) (dialog --defaultno --title "Wipe all custom neomutt/offlineIMAP settings?" --yesno "Would you like to wipe all of the mutt/offlineIMAP settings generated by the system?" 6 60 && wipe) ;; -4) clear && break +2) inventory && for i in $userchoices; do detectMailboxes $1 ; done &&exit;; +3) inventory && for i in $userchoices; do removeAccount $i ; done;; +4) (dialog --defaultno --title "Wipe all custom neomutt/offlineIMAP settings?" --yesno "Would you like to wipe all of the mutt/offlineIMAP settings generated by the system?" 6 60 && wipe) ;; +5) clear && break esac done