stuff
This commit is contained in:
		
							
								
								
									
										77
									
								
								bin/mw
									
									
									
									
									
								
							
							
						
						
									
										77
									
								
								bin/mw
									
									
									
									
									
								
							@@ -1,10 +1,11 @@
 | 
				
			|||||||
#!/bin/sh
 | 
					#!/bin/sh
 | 
				
			||||||
muttdir="$HOME/.config/mutt"		# Main mutt config location
 | 
					 | 
				
			||||||
[ ! -f "$HOME/.password-store/.gpg-id" ] && printf "\`pass\` must be installed and initialized to encrypt passwords.\\nBe sure it is installed and run \`pass init <yourgpgemail>\`.\\nIf you don't have a GPG public private key pair, run \`gpg --full-gen-key\` first.\\n" && exit
 | 
					[ ! -f "$HOME/.password-store/.gpg-id" ] && printf "\`pass\` must be installed and initialized to encrypt passwords.\\nBe sure it is installed and run \`pass init <yourgpgemail>\`.\\nIf you don't have a GPG public private key pair, run \`gpg --full-gen-key\` first.\\n" && exit
 | 
				
			||||||
 | 
					muttdir="$HOME/.config/mutt"		# Main mutt config location
 | 
				
			||||||
accdir="$muttdir/accounts"		# Directory for account settings
 | 
					accdir="$muttdir/accounts"		# Directory for account settings
 | 
				
			||||||
maildir="$HOME/.local/share/mail"	# Location of mail storage
 | 
					maildir="$HOME/.local/share/mail"	# Location of mail storage
 | 
				
			||||||
namere="^[a-z_][a-z0-9_-]*$"		# Regex to ensure viable username
 | 
					namere="^[a-z_][a-z0-9_-]*$"		# Regex to ensure viable username
 | 
				
			||||||
emailre=".\+@.\+\\..\+" 		# Regex to confirm valid email address
 | 
					emailre=".\+@.\+\\..\+" 		# Regex to confirm valid email address
 | 
				
			||||||
 | 
					muttshare="/usr/share/mutt-wizard"
 | 
				
			||||||
mbsyncrc="$HOME/.mbsyncrc"
 | 
					mbsyncrc="$HOME/.mbsyncrc"
 | 
				
			||||||
sslcert="/etc/ssl/certs/ca-certificates.crt"
 | 
					sslcert="/etc/ssl/certs/ca-certificates.crt"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -66,7 +67,7 @@ bind index,pager g noop
 | 
				
			|||||||
bind index,pager M noop
 | 
					bind index,pager M noop
 | 
				
			||||||
bind index,pager C noop
 | 
					bind index,pager C noop
 | 
				
			||||||
bind index gg first-entry
 | 
					bind index gg first-entry
 | 
				
			||||||
macro index o \"<shell-escape>$HOME/.config/mutt/bin/mailsync -V $title<enter>\" \"run mbsync to sync $title\"
 | 
					macro index o \"<shell-escape>mailsync -V $title<enter>\" \"run mbsync to sync $title\"
 | 
				
			||||||
unmailboxes *
 | 
					unmailboxes *
 | 
				
			||||||
"
 | 
					"
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
@@ -98,7 +99,7 @@ fi
 | 
				
			|||||||
	printf "DONE.\\n"
 | 
						printf "DONE.\\n"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
addaccount() { \
 | 
					askinfo() { \
 | 
				
			||||||
	printf "Insert the \033[31memail address\033[0m that you want to autoconfigure for mutt/mbsync\\n\tEmail: \033[36m"
 | 
						printf "Insert the \033[31memail address\033[0m that you want to autoconfigure for mutt/mbsync\\n\tEmail: \033[36m"
 | 
				
			||||||
	read -r fulladdr
 | 
						read -r fulladdr
 | 
				
			||||||
	printf "\033[0m"
 | 
						printf "\033[0m"
 | 
				
			||||||
@@ -109,7 +110,7 @@ addaccount() { \
 | 
				
			|||||||
	done
 | 
						done
 | 
				
			||||||
	domain="$(echo "$fulladdr" | sed "s/.*@//")"
 | 
						domain="$(echo "$fulladdr" | sed "s/.*@//")"
 | 
				
			||||||
	printf "\\nSearching for \033[32m%s\033[0m in \033[34m\`domains.csv\`\033[0m..." "$domain"
 | 
						printf "\\nSearching for \033[32m%s\033[0m in \033[34m\`domains.csv\`\033[0m..." "$domain"
 | 
				
			||||||
	serverinfo="$(grep "$domain" "$muttdir/domains.csv" 2>/dev/null)"
 | 
						serverinfo="$(grep "$domain" "$muttshare/domains.csv" 2>/dev/null)"
 | 
				
			||||||
	if [ -z "$serverinfo" ]; then
 | 
						if [ -z "$serverinfo" ]; then
 | 
				
			||||||
		printf "Your email domain is not in mutt-wizard's database yet.\\nmutt-wizard will still autoconfigure everything, but you will have to manually type in your service's IMAP and SMTP server information.\\nYou can usually quickly find this by internet searching for it.\\n"
 | 
							printf "Your email domain is not in mutt-wizard's database yet.\\nmutt-wizard will still autoconfigure everything, but you will have to manually type in your service's IMAP and SMTP server information.\\nYou can usually quickly find this by internet searching for it.\\n"
 | 
				
			||||||
		printf "Insert the IMAP server for your email provider (excluding the port number)\\n\033[36m\t"
 | 
							printf "Insert the IMAP server for your email provider (excluding the port number)\\n\033[36m\t"
 | 
				
			||||||
@@ -155,9 +156,8 @@ EOF
 | 
				
			|||||||
	echo "$msmtp_profile" >> "$HOME/.config/msmtp/config"
 | 
						echo "$msmtp_profile" >> "$HOME/.config/msmtp/config"
 | 
				
			||||||
	echo "$mutt_profile" > "$accdir/$title.muttrc"
 | 
						echo "$mutt_profile" > "$accdir/$title.muttrc"
 | 
				
			||||||
	echo "$mbsync_profile" >> "$mbsyncrc"
 | 
						echo "$mbsync_profile" >> "$mbsyncrc"
 | 
				
			||||||
	echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source $accdir/$title.muttrc<enter><change-folder>!<enter>;<check-stats>' \"switch to $fulladdr\"" >> "$muttdir/personal.muttrc"
 | 
					 | 
				
			||||||
	! grep "^source.*.muttrc" "$muttdir/personal.muttrc" >/dev/null && echo "source $accdir/$title.muttrc" >> "$muttdir/personal.muttrc"
 | 
						! grep "^source.*.muttrc" "$muttdir/personal.muttrc" >/dev/null && echo "source $accdir/$title.muttrc" >> "$muttdir/personal.muttrc"
 | 
				
			||||||
	trysync && finalize
 | 
						echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source $accdir/$title.muttrc<enter><change-folder>!<enter>;<check-stats>' \"switch to $fulladdr\"" >> "$muttdir/personal.muttrc"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
getpass() { while : ; do pass rm -f "mutt-wizard-$title" >/dev/null 2>&1
 | 
					getpass() { while : ; do pass rm -f "mutt-wizard-$title" >/dev/null 2>&1
 | 
				
			||||||
@@ -169,7 +169,7 @@ formatShortcut() { \
 | 
				
			|||||||
	echo "macro index,pager C$1 \"<copy-message>$data<enter>\" \"copy mail to $2\" # autogenerated"; } >> "$accdir/$3.muttrc"
 | 
						echo "macro index,pager C$1 \"<copy-message>$data<enter>\" \"copy mail to $2\" # autogenerated"; } >> "$accdir/$3.muttrc"
 | 
				
			||||||
	done ;}
 | 
						done ;}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
trysync() { ! ping -q -c 1 1.1.1.1 > /dev/null && printf "No internet connection detected.\\nTry rerunning \`mbsync %s\` manually when connection is established, then select the option to detect mailboxes and finalize installation.\\n" "$title" && return 1
 | 
					tryconnect() { ! ping -q -c 1 1.1.1.1 > /dev/null && printf "No internet connection detected.\\nTry rerunning \`mbsync %s\` manually when connection is established, then select the option to detect mailboxes and finalize installation.\\n" "$title" && return 1
 | 
				
			||||||
	mkdir -p "$maildir/$title"
 | 
						mkdir -p "$maildir/$title"
 | 
				
			||||||
	if mailboxes="$(mbsync -l "$title" | sed 's/\//./')" >/dev/null 2>&1; then
 | 
						if mailboxes="$(mbsync -l "$title" | sed 's/\//./')" >/dev/null 2>&1; then
 | 
				
			||||||
		[ "$accounttype" = "online" ] && sed -i "/IMAPStore $title-remote$/,/# End profile/d" "$mbsyncrc"
 | 
							[ "$accounttype" = "online" ] && sed -i "/IMAPStore $title-remote$/,/# End profile/d" "$mbsyncrc"
 | 
				
			||||||
@@ -178,8 +178,7 @@ trysync() { ! ping -q -c 1 1.1.1.1 > /dev/null && printf "No internet connection
 | 
				
			|||||||
	else
 | 
						else
 | 
				
			||||||
		printf "\033[31m\033[31mLog-on not successful.\033[0m\\nIt seems that either you inputted the wrong password or sever settings, or there are other requirements for your account out of the control of mutt-wizard.\\n"
 | 
							printf "\033[31m\033[31mLog-on not successful.\033[0m\\nIt seems that either you inputted the wrong password or sever settings, or there are other requirements for your account out of the control of mutt-wizard.\\n"
 | 
				
			||||||
		delete "$title"; return 1
 | 
							delete "$title"; return 1
 | 
				
			||||||
	fi
 | 
						fi ;}
 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
finalize() { \
 | 
					finalize() { \
 | 
				
			||||||
	boxes="$(du -a "$maildir/$title/"* -d 0 | sed "s/^.*\//=/")"
 | 
						boxes="$(du -a "$maildir/$title/"* -d 0 | sed "s/^.*\//=/")"
 | 
				
			||||||
@@ -210,7 +209,7 @@ finalize() { \
 | 
				
			|||||||
	[ "$accounttype" = "offline" ] && printf "All done.\\n\033[33mYou should now be able to run \`\033[32mmbsync %s\033[33m\` to begin to download your mail.\033[0m\\n" "$title"
 | 
						[ "$accounttype" = "offline" ] && printf "All done.\\n\033[33mYou should now be able to run \`\033[32mmbsync %s\033[33m\` to begin to download your mail.\033[0m\\n" "$title"
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
confirm() { printf "Do you want to to %s?\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "^y$\|^yes$" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
 | 
					confirm() { printf "Do you want to to %s? [y/N]\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "^y$\|^yes$" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
 | 
				
			||||||
	printf "Are you really, really sure you want to %s?\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "^y$\|^yes$" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
 | 
						printf "Are you really, really sure you want to %s?\\n\t" "$@" && read -r input && ! echo "$input" | grep -i "^y$\|^yes$" >/dev/null && printf "That doesn't seem like a yes to me.\\n\\n" && return 1
 | 
				
			||||||
	return 0 ;}
 | 
						return 0 ;}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -249,58 +248,34 @@ choosecron() { ! pgrep crond >/dev/null && echo "No cron manager running. Instal
 | 
				
			|||||||
			read -r minnum
 | 
								read -r minnum
 | 
				
			||||||
			printf "\033[0m"
 | 
								printf "\033[0m"
 | 
				
			||||||
		done
 | 
							done
 | 
				
			||||||
		(crontab -l; echo "*/$minnum * * * * export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus; export DISPLAY=:0; . \$HOME/.profile; $muttdir/bin/mailsync") | crontab - &&
 | 
							(crontab -l; echo "*/$minnum * * * * export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus; export DISPLAY=:0; . \$HOME/.profile; $(type mailsync | cut -d' ' -f3)") | crontab - &&
 | 
				
			||||||
			echo "Cronjob added. Mail will sync every $minnum minutes. Be sure you have your cron manager running."
 | 
								echo "Cronjob added. Mail will sync every $minnum minutes. Be sure you have your cron manager running."
 | 
				
			||||||
	fi ;}
 | 
						fi ;}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
addtype() { ! command -v mbsync >/dev/null && printf "You must have the \`mbsync\` command to add an account.\\nIt syncs mail and detects remote mailboxes.\\nYou can typically get it by installing \`isync\`.\\n" && return 1
 | 
					asktype() { while : ; do
 | 
				
			||||||
	while : ; do
 | 
					 | 
				
			||||||
		printf "Do you want to keep your mail for this account offline with mbsync? [yes/no]\\n\t"
 | 
							printf "Do you want to keep your mail for this account offline with mbsync? [yes/no]\\n\t"
 | 
				
			||||||
		read -r offnot
 | 
							read -r offnot
 | 
				
			||||||
		case "$offnot" in
 | 
							case "$offnot" in
 | 
				
			||||||
			[Yy][Ee][Ss]) accounttype="offline" && break ;;
 | 
								[Yy][Ee][Ss]) accounttype="offline" && break ;;
 | 
				
			||||||
			[Nn][Oo]) accounttype="online" && break ;;
 | 
								[Nn][Oo]) accounttype="online" && break ;;
 | 
				
			||||||
			*) echo "Write out either yes or no completely. Try again or press ctrl-c to quit." ;;
 | 
								*) echo "Write out either yes or no completely. Try again or press ctrl-c to quit." ;;
 | 
				
			||||||
		esac
 | 
							esac; done ;}
 | 
				
			||||||
	done
 | 
					 | 
				
			||||||
	addaccount ;}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
main() { while : ; do
 | 
					init() { \
 | 
				
			||||||
	printf "Welcome to:\\n\033[34m"
 | 
						echo "Initializing a mutt-wizard configuration..."
 | 
				
			||||||
cat << "EOF"
 | 
						[ -f "$muttdir/muttrc" ] && echo "There is already a preexisting config." && return 1
 | 
				
			||||||
 _ __ ___  _   _| |_| |_    __      _(_)______ _ _ __ __| |
 | 
						cp -v "$muttshare/mailcap" "$muttdir"
 | 
				
			||||||
| '_ ` _ \| | | | __| __|___\ \ /\ / / |_  / _` | '__/ _` |
 | 
						cp -v "$muttshare/muttrc" "$muttdir"
 | 
				
			||||||
| | | | | | |_| | |_| ||_____\ V  V /| |/ / (_| | | | (_| |
 | 
					}
 | 
				
			||||||
|_| |_| |_|\__,_|\__|\__|     \_/\_/ |_/___\__,_|_|  \__,_|
 | 
					 | 
				
			||||||
EOF
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	printf "\033[0mMade and maintained by Luke Smith <https://lukesmith.xyz>
 | 
					case "$1" in
 | 
				
			||||||
 | 
						init) init ;;
 | 
				
			||||||
What would you like \033[32mmutt-wizard\033[0m to do?
 | 
						new) asktype && askinfo && tryconnect && finalize ;;
 | 
				
			||||||
	1 Add an email account
 | 
						passedit) pick "change the password of" && confirm "change \`$title\`'s password" && getpass ;;
 | 
				
			||||||
	2 Change an account's password
 | 
						delete) pick delete && confirm "delete the \`$title\` profile" && delete ;;
 | 
				
			||||||
	3 Remove an account
 | 
						purge) confirm "delete all account data" && rm -rf "$mbsyncrc" "$accdir" "$muttdir/personal.muttrc" && echo "All configs and account settings have been purged." ;;
 | 
				
			||||||
	4 Purge all account data
 | 
						cron) choosecron ;;
 | 
				
			||||||
	5 Enable/disable autosync
 | 
					 | 
				
			||||||
	0 Exit
 | 
					 | 
				
			||||||
Input a number to continue or press ctrl-c.\\n"
 | 
					 | 
				
			||||||
	printf "\033[36m\t"
 | 
					 | 
				
			||||||
	read -r choice
 | 
					 | 
				
			||||||
	printf "\033[0m"
 | 
					 | 
				
			||||||
	case "$choice" in
 | 
					 | 
				
			||||||
		1) addtype ;;
 | 
					 | 
				
			||||||
		2) pick "change the password of" && confirm "change \`$title\`'s password" && getpass ;;
 | 
					 | 
				
			||||||
		3) pick delete && confirm "delete the \`$title\` profile" && delete ;;
 | 
					 | 
				
			||||||
		4) confirm "delete all account data" && rm -rf "$mbsyncrc" "$accdir" "$muttdir/personal.muttrc" && echo "All configs and account settings have been purged." ;;
 | 
					 | 
				
			||||||
		5) choosecron ;;
 | 
					 | 
				
			||||||
		0) break ;;
 | 
					 | 
				
			||||||
	*) printf "Invalid input.\\n"
 | 
						*) printf "Invalid input.\\n"
 | 
				
			||||||
	esac
 | 
					esac
 | 
				
			||||||
	printf "Press Enter to continue.\\n"
 | 
					 | 
				
			||||||
	stty -echo
 | 
					 | 
				
			||||||
	read -r null
 | 
					 | 
				
			||||||
	stty echo
 | 
					 | 
				
			||||||
done ;}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
main
 | 
					 | 
				
			||||||
rm -rf "$tmpdir"
 | 
					rm -rf "$tmpdir"
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										2
									
								
								muttrc
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								muttrc
									
									
									
									
									
								
							@@ -56,7 +56,7 @@ bind editor <Tab> complete-query
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
macro index,pager a "|abook --add-email\n" 'add sender to abook'
 | 
					macro index,pager a "|abook --add-email\n" 'add sender to abook'
 | 
				
			||||||
macro index \Cr "T~U<enter><tag-prefix><clear-flag>N<untag-pattern>.<enter>" "mark all messages as read"
 | 
					macro index \Cr "T~U<enter><tag-prefix><clear-flag>N<untag-pattern>.<enter>" "mark all messages as read"
 | 
				
			||||||
macro index O "<shell-escape>$HOME/.config/mutt/bin/mailsync -Va<enter>" "run offlineimap to sync all mail"
 | 
					macro index O "<shell-escape>mailsync -Va<enter>" "run offlineimap to sync all mail"
 | 
				
			||||||
macro index \Cf "<enter-command>unset wait_key<enter><shell-escape>read -p 'Enter a search term to find with notmuch: ' x; echo \$x >~/.cache/mutt_terms<enter><limit>~i \"\`notmuch search --output=messages \$(cat ~/.cache/mutt_terms) | head -n 600 | perl -le '@a=<>;chomp@a;s/\^id:// for@a;$,=\"|\";print@a'\`\"<enter>" "show only messages matching a notmuch pattern"
 | 
					macro index \Cf "<enter-command>unset wait_key<enter><shell-escape>read -p 'Enter a search term to find with notmuch: ' x; echo \$x >~/.cache/mutt_terms<enter><limit>~i \"\`notmuch search --output=messages \$(cat ~/.cache/mutt_terms) | head -n 600 | perl -le '@a=<>;chomp@a;s/\^id:// for@a;$,=\"|\";print@a'\`\"<enter>" "show only messages matching a notmuch pattern"
 | 
				
			||||||
macro index A "<limit>all\n" "show all messages (undo limit)"
 | 
					macro index A "<limit>all\n" "show all messages (undo limit)"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user