diff options
Diffstat (limited to 'mutt-wizard.sh')
-rwxr-xr-x | mutt-wizard.sh | 62 |
1 files changed, 42 insertions, 20 deletions
diff --git a/mutt-wizard.sh b/mutt-wizard.sh index 1625267..7fb5413 100755 --- a/mutt-wizard.sh +++ b/mutt-wizard.sh @@ -2,6 +2,15 @@ muttdir="$HOME/.config/mutt/" +chooseSync() { (crontab -l && testSync) || dialog --msgbox "No cronjob manager detected. Please install one and return to enable automatic mailsyncing" 10 60 ;} +testSync() { (crontab -l | grep .config/mutt/etc/mailsync && removeSync) || addSync ;} + +addSync() { min=$(dialog --inputbox "How many minutes should be between mail syncs?" 8 60 3>&1 1>&2 2>&3 3>&-) + (crontab -l; echo "*/$min * * * * /home/$(whoami)/.config/mutt/etc/mailsync.sh") | crontab - && + dialog --msgbox "Cronjob successfully added. Remember you may need to restart or tell systemd/etc. to start your cron manager for this to take effect." 7 60 ;} + +removeSync() { ((crontab -l | sed -e '/.config\/mutt\/etc\/mailsync/d') | crontab - >/dev/null) && dialog --msgbox "Cronjob successfully removed. To reactivate, select this option again." 6 60 ;} + changePassword() { \ gpgemail=$( dialog --title "Luke's mutt/offlineIMAP password wizard" --inputbox "Insert the email address with which you originally created your GPG key pair. This is NOT necessarily the email you want to configure." 10 60 3>&1 1>&2 2>&3 3>&- ) dialog --title "Luke's mutt/offlineIMAP password wizard" --passwordbox "Enter the new password for the \"$1\" account." 10 60 2> /tmp/$1 @@ -36,21 +45,32 @@ formatShortcut() { \ echo "macro index,pager g$1 \"<change-folder>$data<enter>\" \"Go to $2.\"" >> "$muttdir"accounts/$3.muttrc done ;} +gen_delim() { \ + delim="=" + for i in `seq $(( $1 - 1 ))` + do + delim="$delim-" + done + echo $delim ;} + 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" " ") + sidebar_width=$(sed -n -e '/^set sidebar_width/p' "$muttdir"/muttrc | awk -F'=' '{print $2}') + delim=$(gen_delim $sidebar_width) + oneline=$(cat /tmp/$1_boxes | sed -e "s/^\|$/\"/g" | tr "\n" " ") + oneline="=$1 $delim $oneline" sed -i "/^mailboxes\|^set spoolfile\|^set record\|^set postponed/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\|chat\|old\|new\|gmail\|sms\|call" | 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 draft | formatShortcut d drafts $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 archive | formatShortcut a archive $1 + grep -i /tmp/$1_boxes -e sent | sed 1q | formatShortcut s sent $1 + grep -i /tmp/$1_boxes -e draft | sed 1q | formatShortcut d drafts $1 + grep -i /tmp/$1_boxes -e trash | sed 1q | formatShortcut t trash $1 + grep -i /tmp/$1_boxes -e spam | sed 1q | formatShortcut S spam $1 + grep -i /tmp/$1_boxes -e archive | sed 1q | formatShortcut a archive $1 spoolfile=$(grep -vi /tmp/$1_boxes -e "trash\|drafts\|sent\|trash\|spam\|junk\|archive\|chat\|old\|new\|gmail\|sms\|call" | sort -n | sed 1q | sed -e 's/=/+/g') - record=$(grep -i /tmp/$1_boxes -e sent | sed -e 's/=/+/g') - postponed=$(grep -i /tmp/$1_boxes -e draft | sed -e 's/=/+/g') + record=$(grep -i /tmp/$1_boxes -e sent | sed -e 's/=/+/g' | sed 1q) + postponed=$(grep -i /tmp/$1_boxes -e draft | sed -e 's/=/+/g' | sed 1q) echo "set spoolfile = \"$spoolfile\"" >> "$muttdir"accounts/$1.muttrc echo "set record = \"$record\"" >> "$muttdir"accounts/$1.muttrc echo "set postponed = \"$postponed\"" >> "$muttdir"accounts/$1.muttrc ;} @@ -149,6 +169,9 @@ addAccount() { shred -u /tmp/$title mv /tmp/$title.gpg ~/.config/mutt/credentials/ + # Adding directory structure for cache. + mkdir -p "$muttdir"accounts/$title/cache/bodies + # Creating the offlineimaprc if it doesn't exist already. if [ ! -f ~/.offlineimaprc ]; then cp "$muttdir"autoconf/offlineimap_header ~/.offlineimaprc; fi cat "$muttdir"autoconf/offlineimap_profile | sed -e "$replacement" >> ~/.offlineimaprc @@ -159,9 +182,6 @@ addAccount() { # Add a numbered shortcut in the muttrc echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source "$muttdir"accounts/$title.muttrc<enter><change-folder>!<enter>'" >> "$muttdir"personal.muttrc - # Adding directory structure for cache. - mkdir -p "$muttdir"accounts/$title/cache/bodies - # Add to offlineimaprc sync list. sed -i "s/^accounts =.*[a-zA-Z]$/&, $title/g;s/^accounts =$/accounts = $title/g" ~/.offlineimaprc @@ -195,14 +215,15 @@ wipe () { rm $HOME/.offlineimaprc while : ; do choice=$(dialog --title "Luke's mutt/offlineIMAP wizard" --nocancel \ - --menu "What would you like to do?" 14 45 7 \ + --menu "What would you like to do?" 16 45 8 \ 0 "List all email accounts configured." \ 1 "Add an email account." \ 2 "Auto-detect mailboxes for an account." \ - 3 "Change an account's password." \ - 4 "Remove an email account." \ - 5 "Remove all email accounts." \ - 6 "Exit this wizard." \ + 3 "Enable/disable autosync." \ + 4 "Change an account's password." \ + 5 "Remove an email account." \ + 6 "Remove all email accounts." \ + 7 "Exit this wizard." \ 3>&1 1>&2 2>&3 3>&1 ) case $choice in @@ -211,9 +232,10 @@ $(grep ~/.offlineimaprc -e "^accounts =" | sed 's/accounts =//g') " 6 60;; 1) chooseAdd;; 2) detectWarning && chooseDetect ;; -3) inventory && for i in $userchoices; do changePassword $i ; done;; -4) inventory && for i in $userchoices; do removeAccount $i ; done;; -5) (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) ;; -6) clear && break ;; +3) chooseSync;; +4) inventory && for i in $userchoices; do changePassword $i ; done;; +5) inventory && for i in $userchoices; do removeAccount $i ; done;; +6) (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) ;; +7) clear && break ;; esac done |