diff --git a/bin/mw b/bin/mw index f54934c..b62a07a 100755 --- a/bin/mw +++ b/bin/mw @@ -22,6 +22,7 @@ muttrc="$muttdir/muttrc" msmtprc="${XDG_CONFIG_HOME:-$HOME/.config}/msmtp/config" msmtplog="${XDG_CONFIG_HOME:-$HOME/.config}/msmtp/msmtp.log" marker="# mw-autogenerated" +imap_h_delim='.' 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/" @@ -33,9 +34,27 @@ getaccounts() { accounts="$(find -L "$accdir" -type f | grep -o "[0-9]-.*.muttrc list() { getaccounts && [ -n "$accounts" ] && echo "$accounts" ;} +updihdelim() { + if command -V curl >/dev/null 2>&1 && command -V sed >/dev/null 2>&1 ; then + imap_h_delim="$(printf -- '-u %s:%s\n' "$login" "$(pass "$pass_prefix$fulladdr")" |\ + curl -s -k --url "imaps://$imap" -K- --request 'LIST "" ""' |\ + sed -n 's/\* LIST (\\Noselect) "\(.*\)" ""/\1/p')" + fi + + if [ -z "${imap_h_delim}" ] || [ "${imap_h_delim}" = '\' ] || [ "${imap_h_delim}" = '/' ]; then + printf '%s\n' 'Defaulting IMAP hierarchy delimiter to "."' + imap_h_delim='.' + fi +} + + getprofiles() { \ unset msmtp_header msmtp_profile mutt_profile mbsync_profile [ "$iport" = "1143" ] && imapssl="None" + + # Determine IMAP hierarchy delimiter + updihdelim + msmtp_header="defaults auth on tls on @@ -63,7 +82,7 @@ MaildirStore $fulladdr-local Subfolders Verbatim Path ${XDG_DATA_HOME:-$HOME/.local/share}/mail/$fulladdr/ Inbox ${XDG_DATA_HOME:-$HOME/.local/share}/mail/$fulladdr/INBOX -Flatten . +Flatten ${imap_h_delim} Channel $fulladdr Expunge Both @@ -89,6 +108,8 @@ set header_cache = $cachedir/$fulladdr/headers set message_cachedir = $cachedir/$fulladdr/bodies set mbox_type = Maildir +set sidebar_delim_chars = '/${imap_h_delim}' + bind index,pager gg noop bind index,pager g noop bind index,pager M noop @@ -115,6 +136,8 @@ set mbox_type = Maildir set ssl_starttls = yes set ssl_force_tls = yes +set sidebar_delim_chars = '/${imap_h_delim}' + bind index,pager gg noop bind index,pager g noop bind index,pager M noop @@ -188,6 +211,7 @@ createpass() { echo "$password" > "$PASSWORD_STORE_DIR/$pass_prefix$fulladdr" "$GPG" -qer "$(cat "$PASSWORD_STORE_DIR/.gpg-id")" "$PASSWORD_STORE_DIR/$pass_prefix$fulladdr" rm -f "$PASSWORD_STORE_DIR/$pass_prefix$fulladdr" ;} + writeinfo() { mkdir -p "$muttdir" "$accdir" "$cachedir/$fulladdr/bodies" "${XDG_CONFIG_HOME:-$HOME/.config}/msmtp" "$maildir/$fulladdr" # Get accounts and find the first missing account number (max. 9). @@ -230,7 +254,7 @@ Junk Trash Sent Archive" && return 0 - if mailboxes="$(mbsync -l "$fulladdr" | sed 's/\//./')" >/dev/null 2>&1 && [ -n "$mailboxes" ]; then + if mailboxes="$(mbsync -l "$fulladdr" | sed "s/\//${imap_h_delim}/")" >/dev/null 2>&1 && [ -n "$mailboxes" ]; then [ -n "${online+x}" ] && sed -ibu "/IMAPStore $fulladdr-remote$/,/# End profile/d" "$mbsyncrc" ; rm -f "$mbsyncrc"bu return 0 else