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.
 
 
 
 

100 lines
3.4 KiB

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