From a659e3a188fe593a6eddfb0bb3a8e9a7085e4fc6 Mon Sep 17 00:00:00 2001 From: unman Date: Mon, 18 Jul 2022 13:52:20 +0000 Subject: [PATCH] Mutt - include helper script --- mutt/install.sls | 11 ++++- mutt/muttrc | 28 +++++++------ mutt/setup_mutt.sh | 102 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 13 deletions(-) create mode 100755 mutt/setup_mutt.sh diff --git a/mutt/install.sls b/mutt/install.sls index 41847a9..6cbe0e6 100644 --- a/mutt/install.sls +++ b/mutt/install.sls @@ -30,10 +30,11 @@ installed: - mutt - notmuch - notmuch-mutt - - offline-imap + - offlineimap3 - openssh-client - rsync - w3m + - zenity - skip_suggestions: True - install_recommends: False @@ -51,4 +52,12 @@ default_muttrc: - user: user - group: user +helper_script: + file.managed: + - name: /etc/skel/setup_mutt.sh + - source: salt://mutt/setup_mutt.sh + - user: user + - group: user + - mode: 744 + {% endif %} diff --git a/mutt/muttrc b/mutt/muttrc index 41dee39..82cc443 100644 --- a/mutt/muttrc +++ b/mutt/muttrc @@ -5,36 +5,40 @@ ## PGP # Specify what key to use for signing here: #set pgp_sign_as=0x +## END PGP ## IMAP -#set folder=imaps://YOUR_SERVER/ -#set imap_user=YOUR_USERNAME_HERE -#set imap_pass=YOUR_PASSWORD_HERE +#set folder=imaps://IMAP_SERVER/ +#set imap_user=IMAP_USERNAME +#set imap_pass=IMAP_PASSWORD #set spoolfile=+INBOX #set imap_check_subscribed +## END IMAP ## POP3 -#set pop_host=pops://YOUR_SERVER -#set pop_user=YOUR_USERNAME_HERE -#set pop_pass=YOUR_PASSWORD_HERE +#set pop_host=pops://POP3_SERVER +#set pop_user=POP3_USERNAME +#set pop_pass=POP3_PASSWORD #set pop_checkinterval=120 #set pop_delete=ask-no #set pop_last=yes +## END POP3 -##SMTP -#set my_user=YOUR_USERNAME_HERE -#set smtp_url=smtps://$my_user@YOUR_SMTP_SERVER +## SMTP +#set my_user=SMTP_USERNAME +#set smtp_url=smtps://$my_user@SMTP_SERVER #set ssl_force_tls=yes #set record= +Sent -#set smtp_pass=YOUR_PASSWORD_HERE -#set realname=YOUR_REAL_NAME -#set from=YOUR_EMAIL_ADDRESS +#set smtp_pass=SMTP_PASSWORD +#set realname=SMTP_REAL_NAME +#set from=EMAIL_ADDRESS #set use_from=yes #set ssl_starttls=yes #set ssl_force_tls=yes +## END SMTP ### END USER CONFIGURATION ### ############################## diff --git a/mutt/setup_mutt.sh b/mutt/setup_mutt.sh new file mode 100755 index 0000000..5311d16 --- /dev/null +++ b/mutt/setup_mutt.sh @@ -0,0 +1,102 @@ +#!/bin/bash +target_file=/home/user/.muttrc + +if grep -q "##CONFIGURED" "$target_file" ; then + zenity --question --text="Mutt is already configured\nDo you want to change configuration?" --no-wrap + if [ $? = 1 ];then + exit + else + configured=1 + fi +fi + +zenity --question --text="Do you have the details of your mail server ready?" +if [ $? = 0 ] ;then + + type="$(zenity --list --title="Connection type" --text="Select the connection type" --radiolist --column=Selection --column="Connection Type" \ + FALSE "POP3" FALSE "IMAP" )" + if [ $? = 1 ]; then + exit + fi + if [ "x$type" == "x" ]; then + zenity --warning --text="No connection type selected" --no-wrap + exit + fi + + zenity --info --text="Now you need to enter the details of your mail server.\nIf you leave the password blank you will be prompted for it each time you connect." --no-wrap + details="$(zenity --forms --title='Log in details' \ + --text='Enter information about your email server' \ + --add-entry='Server address' \ + --add-entry='Server port' \ + --add-entry='Username' \ + --add-password='Password' )" + if [ $? = 1 ]; then + exit + fi + if [[ $details =~ "||" ]]; then + zenity --warning --text="Missing information" + exit + fi + + zenity --info --text="Now you need to enter the details of your SMTP server.\nIf you leave the password blank you will be prompted for it each time you send mail." --no-wrap + smtp_details="$(zenity --forms --title='Log in details' \ + --text='Enter information about your SMTP server' \ + --add-entry='Name on outgoing emails' \ + --add-entry='Email address' \ + --add-entry='Server address' \ + --add-entry='Server port' \ + --add-entry='Username' \ + --add-password='Password' )" + if [ $? = 1 ]; then + exit + fi + if [[ $smtp_details =~ "||" ]]; then + zenity --warning --text="Missing information" + exit + fi + oldifs=$IFS + IFS='|' read -r server_address server_port name pw <<<$details + IFS='|' read -r smtp_outname email smtp_address smtp_port smtp_name smtp_pw <<<$smtp_details + IFS=$oldifs + if [ $type == "POP3" ]; then + type=POP + fi + if [ "x$pw" != "x" ]; then + sed -i -E "/$type/,/END $type/ s^(set ${type,,}_pass).*^\1=$pw^ " $target_file + else + sed -i -E "/$type/,/END $type/ s^(set ${type,,}_pass).*^#\1=^ " $target_file + fi + sed -i -E -e "/USER CONFIGURATION/,/END USER CONFIGURATION/ s/^([^#])/#\1/ " \ + -e "/$type/,/END $type/ { //! s/^#// }" \ + -e "/$type/,/END $type/ s^(set folder.*\/\/).*^\1$server_address:$server_port/^ " \ + -e "/$type/,/END $type/ s^(set pop_host.*\/\/).*^\1$server_address:$server_port^ " \ + -e "/$type/,/END $type/ s^(set ${type,,}_user).*^\1=$name^ " $target_file + + sed -i -E -e "/SMTP/,/END SMTP/ { //! s/^#// }" \ + -e "/SMTP/,/END SMTP/ s^(set my_user=).*^\1$smtp_name^ " \ + -e "/SMTP/,/END SMTP/ s^(set smtp_url.*\/\/).*^\1\$my_user@$smtp_address:$smtp_port^ " \ + -e "/SMTP/,/END SMTP/ s^(set realname=).*^\1$smtp_outname^ " \ + -e "/SMTP/,/END SMTP/ s^(set from=).*^\1$email^ " $target_file + if [ "x$smtp_pw" != "x" ]; then + sed -i -E "/SMTP/,/END SMTP/ s^(set smtp_pass=).*^\1$smtp_pw^ " $target_file + else + sed -i -E "/SMTP/,/END SMTP/ s^(set smtp_pass=).*^#\1^ " $target_file + fi + + zenity --question --text="Do you use PGP?" + if [ $? = 0 ] ;then + key=$(zenity --entry --title "PGP key ID" --text "Enter your PGP Key ID 0x....." ) + else + sed -i -E "/PGP/,/END PGP/ s/^(set pgp_sign_as=).*/#\1/ " $target_file + fi + if [ "x$key" != "x" ]; then + sed -i -E "/PGP/,/END PGP/ s^.*(set pgp_sign_as=).*^\1$key^ " $target_file + fi + if [ $configured != 1 ];then + sed -i '1 i ##CONFIGURED ' $target_file + fi + exit +else + zenity --error --text="You need those details to set up mutt." + exit +fi