You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

86 lines
3.5 KiB

  1. #!/bin/bash
  2. muttdir="$HOME/.config/mutt/"
  3. mkdir -p "$muttdir"credentials/ "$muttdir"accounts/
  4. 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>&- )
  5. mainloop() { fulladdr=$( dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Insert the full email address for the account you want to configure." 10 60 3>&1 1>&2 2>&3 3>&- )
  6. # Check to see if domain is in domain list
  7. serverinfo=$(cat "$muttdir"autoconf/domains.csv | grep -w ^${fulladdr##*@})
  8. if [ -z "$serverinfo" ];
  9. then
  10. echo No suitable match. && exit
  11. else
  12. # Read in server data as variables
  13. IFS=, read service imap iport smtp sport spoolfile postponed record <<EOF
  14. $serverinfo
  15. EOF
  16. fi
  17. realname=$( dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Enter the full name you'd like to be identified by on this email account." 10 60 3>&1 1>&2 2>&3 3>&- )
  18. title=$( dialog --title "Luke's mutt/offlineIMAP autoconfig" --inputbox "Give a short, one-word name for this email account that will differentiate it from other email accounts." 10 60 3>&1 1>&2 2>&3 3>&- )
  19. # Sets the repo type and other variables for the sed regex.
  20. if [[ "$service" == "gmail.com" ]];
  21. then
  22. type="Gmail"
  23. delet="remotehost"
  24. else
  25. type="IMAP"
  26. delet="Gmail]\/"
  27. fi
  28. # The replacements
  29. replacement="
  30. s/\$realname/$realname/g;
  31. s/\$title/$title/g;
  32. s/\$fulladdr/$fulladdr/g;
  33. s/\$imap/$imap/g;
  34. s/\$iport/$iport/g;
  35. s/\$smtp/$smtp/g;
  36. s/\$sport/$sport/g;
  37. s/\$spoolfile/$spoolfile/g;
  38. s/\$postponed/$postponed/g;
  39. s/\$record/$record/g;
  40. s/\$type/$type/g;
  41. /$delet/d"
  42. # Gets the first unused shortcut number in the muttrc and puts it in $idnum.
  43. cat "$muttdir"personal.muttrc | grep i[0-9] | awk '{print $3}' | sed -e 's/i//g' > /tmp/mutt_used
  44. echo -e "1\n2\n3\n4\n5\n6\n7\n8\n9" > /tmp/mutt_all_possible
  45. idnum=$(diff /tmp/mutt_all_possible /tmp/mutt_used | sed -n 2p | awk '{print $2}')
  46. addAccount \
  47. ;}
  48. addAccount() {
  49. # First, adding the encrypted password.
  50. dialog --title "Luke's mutt/offlineIMAP password wizard" --passwordbox "Enter the password for the \"$title\" account." 10 60 2> /tmp/$title
  51. gpg -r $gpgemail --encrypt /tmp/$title
  52. shred -u /tmp/$title && echo "Password encrypted and memory shredded."
  53. mv /tmp/$title.gpg ~/.config/mutt/credentials/
  54. # Creating the offlineimaprc if it doesn't exist already.
  55. if [ ! -f ~/.offlineimaprc ]; then cp "$muttdir"autoconf/offlineimap_header ~/.offlineimaprc; fi
  56. cat "$muttdir"autoconf/offlineimap_profile | sed -e "$replacement" >> ~/.offlineimaprc
  57. # Add the mutt profile.
  58. cat "$muttdir"autoconf/mutt_profile | sed -e "$replacement" > "$muttdir"accounts/$title.muttrc
  59. # Add a numbered shortcut in the muttrc
  60. echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source "$muttdir"accounts/$title.muttrc<enter><change-folder>!<enter>'" >> "$muttdir"personal.muttrc
  61. # Adding directory structure for cache.
  62. mkdir -p "$muttdir"accounts/$title/cache/bodies
  63. # Add to offlineimaprc sync list.
  64. sed -i "s/^accounts =.*[a-zA-Z]$/&, $title/g;s/^accounts =$/accounts = $title/g" ~/.offlineimaprc
  65. # Makes account default if there is no default account.
  66. grep "$muttdir"personal.muttrc -e "^source .*accounts.*" >/dev/null && echo there || \
  67. echo "source ${muttdir}accounts/$title.muttrc" >> "$muttdir"personal.muttrc ;}
  68. mainloop
  69. while : ;
  70. do
  71. dialog --title "Luke's mutt/offlineIMAP password wizard" --yesno "Would you like to add another email account?" 10 60 || break
  72. mainloop
  73. done
  74. clear