25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

154 satır
5.8 KiB

  1. #!/bin/bash
  2. muttdir="$HOME/.config/mutt/"
  3. # Sees what accounts have been generated bny the wizard
  4. # by checking ~/.offlineimap and yields a menu of them.
  5. inventory() { \
  6. cat ~/.offlineimaprc | grep "^accounts =" | sed -e 's/accounts =\( \)//g;s/\(,\) /\n/g;' | nl --number-format=ln > /tmp/numbered
  7. accounts=()
  8. while read n s ; do
  9. accounts+=($n "$s" off)
  10. done < /tmp/numbered
  11. choices=$(dialog --separate-output --checklist "Choose an email account." 22 76 16 "${accounts[@]}" 2>&1 >/dev/tty)
  12. if [ -z "$choices" ];
  13. then
  14. clear
  15. else
  16. userchoices=$(IFS="|"; keys="${choices[*]}"; keys="${keys//|/\\|}"; grep -w "${keys}" /tmp/numbered | awk '{print $2}')
  17. fi ;}
  18. removeAccount() { sed -ie "
  19. /Account $1]/,/Account/{//!d}
  20. /Account $1]/d
  21. s/ $1\(,\|$\)//g
  22. s/=$1\(,\|$\)/=/g
  23. s/,$//g
  24. " ~/.offlineimaprc
  25. rm "$muttdir"accounts/$1.muttrc
  26. rm "$muttdir"credentials/$1.gpg
  27. rm -rf "$muttdir"accounts/$1
  28. echo $1 deleted. ;}
  29. manual() { \
  30. imap=$( dialog --inputbox "Insert the IMAP server for your email provider (excluding the port number)" 10 60 3>&1 1>&2 2>&3 3>&- )
  31. iport=$(dialog --inputbox "What is your server's IMAP port number? (Usually 993)" 10 60 3>&1 1>&2 2>&3 3>&-)
  32. smtpserver=$( dialog --inputbox "Insert the SMTP server for your email provider (excluding the port number)" 10 60 3>&1 1>&2 2>&3 3>&- )
  33. sport=$( dialog --inputbox "What is your server's SMTP port number? (Usually 587 or 465)" 10 60 3>&1 1>&2 2>&3 3>&- ) ;}
  34. addloop() { 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>&- )
  35. # Check to see if domain is in domain list
  36. serverinfo=$(cat "$muttdir"autoconf/domains.csv | grep -w ^${fulladdr##*@})
  37. if [ -z "$serverinfo" ];
  38. then
  39. manual
  40. else
  41. # Read in server data as variables
  42. IFS=, read service imap iport smtp sport spoolfile postponed record <<EOF
  43. $serverinfo
  44. EOF
  45. fi
  46. 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>&- )
  47. 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>&- )
  48. # Sets the repo type and other variables for the sed regex.
  49. if [[ "$service" == "gmail.com" ]];
  50. then
  51. type="Gmail"
  52. delet="remotehost"
  53. else
  54. type="IMAP"
  55. delet="Gmail]\/"
  56. fi
  57. # The replacements
  58. replacement="
  59. s/\$realname/$realname/g;
  60. s/\$title/$title/g;
  61. s/\$fulladdr/$fulladdr/g;
  62. s/\$imap/$imap/g;
  63. s/\$iport/$iport/g;
  64. s/\$smtp/$smtp/g;
  65. s/\$sport/$sport/g;
  66. s/\$spoolfile/$spoolfile/g;
  67. s/\$postponed/$postponed/g;
  68. s/\$record/$record/g;
  69. s/\$type/$type/g;
  70. /$delet/d"
  71. # Gets the first unused shortcut number in the muttrc and puts it in $idnum.
  72. cat "$muttdir"personal.muttrc | grep i[0-9] | awk '{print $3}' | sed -e 's/i//g' > /tmp/mutt_used
  73. echo -e "1\n2\n3\n4\n5\n6\n7\n8\n9" > /tmp/mutt_all_possible
  74. idnum=$(diff /tmp/mutt_all_possible /tmp/mutt_used | sed -n 2p | awk '{print $2}')
  75. addAccount \
  76. ;}
  77. addAccount() {
  78. # First, adding the encrypted password.
  79. dialog --title "Luke's mutt/offlineIMAP password wizard" --passwordbox "Enter the password for the \"$title\" account." 10 60 2> /tmp/$title
  80. gpg -r $gpgemail --encrypt /tmp/$title
  81. shred -u /tmp/$title
  82. mv /tmp/$title.gpg ~/.config/mutt/credentials/
  83. # Creating the offlineimaprc if it doesn't exist already.
  84. if [ ! -f ~/.offlineimaprc ]; then cp "$muttdir"autoconf/offlineimap_header ~/.offlineimaprc; fi
  85. cat "$muttdir"autoconf/offlineimap_profile | sed -e "$replacement" >> ~/.offlineimaprc
  86. # Add the mutt profile.
  87. cat "$muttdir"autoconf/mutt_profile | sed -e "$replacement" > "$muttdir"accounts/$title.muttrc
  88. # Add a numbered shortcut in the muttrc
  89. echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source "$muttdir"accounts/$title.muttrc<enter><change-folder>!<enter>'" >> "$muttdir"personal.muttrc
  90. # Adding directory structure for cache.
  91. mkdir -p "$muttdir"accounts/$title/cache/bodies
  92. # Add to offlineimaprc sync list.
  93. sed -i "s/^accounts =.*[a-zA-Z]$/&, $title/g;s/^accounts =$/accounts = $title/g" ~/.offlineimaprc
  94. # Makes account default if there is no default account.
  95. grep "$muttdir"personal.muttrc -e "^source .*accounts.*" >/dev/null && echo there || \
  96. echo "source ${muttdir}accounts/$title.muttrc" >> "$muttdir"personal.muttrc ;}
  97. # This is run when a user chooses to add an account.
  98. addChosen() { \
  99. mkdir -p "$muttdir"credentials/ "$muttdir"accounts/
  100. 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>&- )
  101. addloop
  102. while : ;
  103. do
  104. dialog --title "Luke's mutt/offlineIMAP password wizard" --yesno "Would you like to add another email account?" 10 60 || break
  105. addloop
  106. done ;}
  107. wipe () { rm $HOME/.offlineimaprc
  108. rm -rf "$muttdir"/accounts
  109. rm -f "$muttdir"credentials/*gpg
  110. rm "$muttdir"personal.muttrc ;}
  111. while : ;
  112. do
  113. choice=$(dialog --title "Luke's mutt/offlineIMAP wizard" \
  114. --menu "What would you like to do?" 14 45 5 \
  115. 0 "List all email accounts configured." \
  116. 1 "Add an email account." \
  117. 2 "Remove an email account." \
  118. 3 "Remove all email accounts." \
  119. 4 "Exit this wizard." \
  120. 3>&1 1>&2 2>&3 3>&1 )
  121. case $choice in
  122. 0) dialog --title "Accounts detected" --msgbox "The following accounts have been detected:
  123. $(grep ~/.offlineimaprc -e "^accounts =" | sed 's/accounts =//g')
  124. " 6 60;;
  125. 1) addChosen;;
  126. 2) inventory && for i in $userchoices; do removeAccount $i ; done;;
  127. 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) ;;
  128. 4) clear && break
  129. esac
  130. done