diff options
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/mailsync | 8 | ||||
| -rwxr-xr-x | bin/mw | 30 | 
2 files changed, 25 insertions, 13 deletions
| diff --git a/bin/mailsync b/bin/mailsync index af7aa6c..f00baf1 100755 --- a/bin/mailsync +++ b/bin/mailsync @@ -14,7 +14,7 @@  # Run only if user logged in (prevent cron errors)  pgrep -u "${USER:=$LOGNAME}" >/dev/null || { echo "$USER not logged in; sync will not run."; exit ;}  # Run only if not already running in other instance -pidof -s mbsync >/dev/null && { echo "mbsync is already running." ; exit ;} +pidof mbsync >/dev/null && { echo "mbsync is already running."; exit ;}  # First, we have to get the right variables for the mbsync file, the pass  # archive, notmuch and the GPG home.  This is done by searching common profile @@ -25,9 +25,6 @@ eval "$(grep -h -- \  	"$HOME/.profile" "$HOME/.bash_profile" "$HOME/.zprofile"  "$HOME/.config/zsh/.zprofile" "$HOME/.zshenv" \  	"$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.config/zsh/.zshrc" "$HOME/.pam_environment" 2>/dev/null)" -case "$(readlink -f /sbin/init)" in -	*systemd*) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus ;; -esac  export GPG_TTY=$TTY  [ -n "$MBSYNCRC" ] && alias mbsync="mbsync -c $MBSYNCRC" || MBSYNCRC="$HOME/.mbsyncrc" @@ -39,6 +36,9 @@ case "$(uname)" in  		messageinfo() { osascript -e "display notification with title \"📧 $from\" subtitle \"$subject\"" ;}  		;;  	*) +		case "$(readlink -f /sbin/init)" in +			*systemd*) export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$(id -u)/bus ;; +		esac  		# remember if a display server is running since `ps` doesn't always contain a display  		pgrepoutput="$(pgrep -a X\(org\|wayland\))"  		displays="$(echo "$pgrepoutput" | grep -wo "[0-9]*:[0-9]\+" | sort -u)" @@ -12,7 +12,18 @@ mbsyncrc="${MBSYNCRC:-$HOME/.mbsyncrc}"  mpoprc="${XDG_CONFIG_HOME:-$HOME/.config}/mpop/config"  alias mbsync='mbsync -c "$mbsyncrc"' -for x in "/etc/ssl/certs/ca-certificates.crt" "/etc/pki/tls/certs/ca-bundle.crt" "/etc/ssl/ca-bundle.pem" "/etc/pki/tls/cacert.pem" "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" "/etc/ssl/cert.pem" "/usr/local/share/ca-certificates/"; do +# On Ubuntu/Debian, a link is needed since they use an older version. +if command -V apt-get >/dev/null 2>&1; then +	ln -s "$msmtprc" "$HOME/.msmtprc" 2>/dev/null +	master="Master" +	slave="Slave" +fi + +for x in "/etc/ssl/certs/ca-certificates.crt" \ +	"/etc/pki/tls/certs/ca-bundle.crt" "/etc/ssl/cert.pem" \ +	"/etc/ssl/ca-bundle.pem" "/etc/pki/tls/cacert.pem" \ +	"/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem" \ +	"/usr/local/share/ca-certificates/"; do  	[ -f "$x" ] && sslcert="$x" && break  done || { echo "CA Certificate not found. Please install one or link it to /etc/ssl/certs/ca-certificates.crt" && exit 1 ;} @@ -38,8 +49,6 @@ ${tlsline:-tls on}  tls_trust_file	$sslcert  logfile $msmtplog  " >> "$msmtprc" -	# On Ubuntu/Debian, a link is needed since they use an older version. -	command -V apt-get >/dev/null 2>&1 && ln -s "$msmtprc" "$HOME/.msmtprc" 2>/dev/null  }  prepmbsync() { mkdir -p "${mbsyncrc%/*}" @@ -60,8 +69,8 @@ Inbox ${XDG_DATA_HOME:-$HOME/.local/share}/mail/$fulladdr/${inbox:-INBOX}  Channel $fulladdr  Expunge Both -Master :$fulladdr-remote: -Slave :$fulladdr-local: +${master:-Far} :$fulladdr-remote: +${slave:-Near} :$fulladdr-local:  Patterns * !\"[Gmail]/All Mail\"  Create Both  SyncState * @@ -90,6 +99,7 @@ set folder = \"$folder\"  set header_cache = $cachedir/$fulladdr/headers  set message_cachedir = $cachedir/$fulladdr/bodies  set mbox_type = Maildir +set hostname = \"$hostname\"  $extra  bind index,pager gg noop @@ -171,10 +181,8 @@ delete() { if [ -z "${fulladdr+x}" ]; then  	pass rm -f "$fulladdr" >/dev/null 2>&1  	[ -n "${purge+x}" ] && rm -rf "${maildir:?}/${fulladdr:?}" -	# Get rid of those multiple newlines because I don't know awk well enough to do it by default lol.  	for file in "$msmtprc" "$mbsyncrc" "$mpoprc"; do - 		tr '\n' '|' 2>/dev/null  < "$file" | sed "s/||\+/||/g" | tr '|' '\n' >> "$file"bu -		mv -f "$file"bu "$file" +		sed -ibu 'N;/^\n$/D;P;D;' "$file" 2>/dev/null; rm -f "$file"bu  	done  } @@ -182,7 +190,7 @@ askinfo() { \  	[ -z "$fulladdr" ] && echo "Give the full email address to add:" &&  		read -r fulladdr  	while ! echo "$fulladdr" | grep -qE "^.+@.+\.[A-Za-z]+$"; do -		echo "\`$fulladdr\` is not a valid email address. Please retype the address:" +		echo "$fulladdr is not a valid email address. Please retype the address:"  		read -r fulladdr  	done  	getaccounts; echo "$accounts" | grep -q "\s$fulladdr$" 2>/dev/null && @@ -194,6 +202,7 @@ askinfo() { \  		read -r smtp  	[ "$sport" = 465 ] && tlsline="tls_starttls off"  	[ -z "$realname" ] && realname="${fulladdr%%@*}" +	hostname="$(echo "$fulladdr" | cut -d @ -f 2)"  	login="${login:-$fulladdr}"  	if [ -n "${password+x}" ]; then  		createpass @@ -227,6 +236,8 @@ getboxes() { if [ -n "${force+x}" ] ; then  	[ "$type" = "pop" ] && mailboxes="INBOX"  	getaccounts; for x in $(seq 1 9); do echo "$accounts" | grep -q "^$x:" || { export idnum="$x"; break ;}; done  	toappend="mailboxes $(echo "$mailboxes" | sed "s/^/\"=/;s/$/\"/" | paste -sd ' ' - )" +	IFS=' +'  	for x in $mailboxes; do  		case "$x" in  			*[Ss][Ee][Nn][Tt]*) setBox record "$x"; formatShortcut s sent "$x" ;; @@ -238,6 +249,7 @@ getboxes() { if [ -n "${force+x}" ] ; then  			*[Ii][Nn][Bb][Oo][Xx]) formatShortcut i inbox "$x"; setBox spoolfile "$x" inbox="$x" ;;  		esac  	done +	unset IFS  }  finalize() { echo "$toappend" >> "$accdir/$idnum-$fulladdr.muttrc" | 
