Skip to content

Instantly share code, notes, and snippets.

@mikeziri
Created April 26, 2019 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeziri/845f948c6d40d5b2dfd62b79a0eb0cae to your computer and use it in GitHub Desktop.
Save mikeziri/845f948c6d40d5b2dfd62b79a0eb0cae to your computer and use it in GitHub Desktop.
conditions for macos on mutt-wizard
From 85beb39c6b77158a5ff7ead7d5f373302beaafa6 Mon Sep 17 00:00:00 2001
From: Miguel Wahnon Monteiro <mi@mwmdev.com>
Date: Fri, 26 Apr 2019 15:14:44 +0100
Subject: [PATCH] first attempt with bsd binaries
---
Makefile | 7 +++++
bin/mw | 78 +++++++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 70 insertions(+), 15 deletions(-)
diff --git a/Makefile b/Makefile
index 6a4ee2e..7b15284 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,13 @@
PREFIX = /usr
MANPREFIX = $(PREFIX)/share/man
+ifeq ($(shell uname), Darwin)
+ PREFIX=/usr/local
+ $(info Running for Macos)
+else
+ $(info Running for Linux)
+endif
+
install:
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -f bin/mw $(DESTDIR)$(PREFIX)/bin
diff --git a/bin/mw b/bin/mw
index 1c1ed58..8f79ccb 100755
--- a/bin/mw
+++ b/bin/mw
@@ -1,6 +1,8 @@
#!/bin/sh
[ ! -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
! command -v mbsync >/dev/null && printf "\`mbsync\` must be installed to run mutt-wizard.\\n" && exit
+os=$(uname)
+
muttdir="$HOME/.config/mutt" # Main mutt config location
accdir="$muttdir/accounts" # Directory for account settings
maildir="$HOME/.local/share/mail" # Location of mail storage
@@ -12,10 +14,22 @@ mwconfig="$muttshare/mutt-wizard.muttrc"
cachedir="$HOME/.cache/mutt-wizard"
muttrc="$muttdir/muttrc"
+if [[ $os == "Darwin" ]];then
+ muttshare="/usr/local/share/mutt-wizard"
+ alias sed='gsed'
+ alis du='gdu'
+fi
+
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"
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 ;}
+done || {
+ echo "CA Certificate not found. Please install one or link it to /etc/ssl/certs/ca-certificates.crt"
+ if [[ $os == "Darwin" ]]; then
+ echo "There is probably a certificate on Macos @ /etc/ssl/cert.pem to link"
+ fi
+ exit 1;
+}
getaccounts() { accounts="$(find "$accdir" -type f | grep -o "[0-9]-.*.muttrc" | sed "s/-/: /;s/\..*//" | sort -n)" ;}
list() { getaccounts && [ -n "$accounts" ] && echo "$accounts" ;}
@@ -43,6 +57,7 @@ User $login
PassCmd \"pass mutt-wizard-$title\"
SSLType IMAPS
CertificateFile $sslcert
+AuthMechs LOGIN
MaildirStore $title-local
Subfolders Verbatim
@@ -185,35 +200,68 @@ tryconnect() { mkdir -p "$maildir/$title"
echo "$mailboxes" | xargs -I {} mkdir -p "$maildir/$title/{}"
return 0
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 server settings, or there are other requirements for your account out of the control of mutt-wizard.\\n"
return 1
fi ;}
finalize() { \
- boxes="$(du -a "$maildir/$title/"* -d 0 | sed "s/^.*\//=/")"
+ if [[ $os == "Darwin" ]]; then
+ boxes="$(du -d 1 "$maildir/$title/"* | sed "s/^.*\//=/")"
+ else
+ boxes="$(du -a "$maildir/$title/"* -d 0 | sed "s/^.*\//=/")"
+ fi
[ -z "$boxes" ] && printf "\033[31mNo local mailboxes have been detected for %s.\033[0m\\nThis means that mbsync has not been successfully run.\\nRun mbsync, and if it has an error, be sure to check your password and server settings manually if needbe.\\n" "$title" && return
printf "Setting default mailboxes for your Inbox, Sent, Drafts and Trash in mutt...\\n"
- spoolfile=$(echo "$boxes" | grep -i -m 1 inbox | sed 's/=/+/g')
- record=$(echo "$boxes" | grep -i -m 1 sent | sed 's/=/+/g')
- postponed=$(echo "$boxes" | grep -i -m 1 draft | sed 's/=/+/g')
- trash=$(echo "$boxes" | grep -i -m 1 trash | sed 's/=/+/g')
+ if [[ $os == "Darwin" ]];then
+ spoolfile=$(echo "$boxes" | grep -i inbox | head -n 1 | sed 's/=/+/g')
+ else
+ spoolfile=$(echo "$boxes" | grep -i -m 1 inbox | sed 's/=/+/g')
+ fi
+ if [[ $os == "Darwin" ]];then
+ record=$(echo "$boxes" | grep -i sent | head -n 1 | sed 's/=/+/g')
+ else
+ record=$(echo "$boxes" | grep -i -m 1 sent | sed 's/=/+/g')
+ fi
+ if [[ $os == "Darwin" ]];then
+ postponed=$(echo "$boxes" | grep -i draft | head -n 1 | sed 's/=/+/g')
+ else
+ postponed=$(echo "$boxes" | grep -i -m 1 draft | sed 's/=/+/g')
+ fi
+ if [[ $os == "Darwin" ]];then
+ trash=$(echo "$boxes" | grep -i trash | head -n 1 | sed 's/=/+/g')
+ else
+ trash=$(echo "$boxes" | grep -i -m 1 trash | sed 's/=/+/g')
+ fi
+
sed -i "/^mailboxes\|^set record\|^set postponed\|^set trash\|^set spoolfile/d" "$accdir/$idnum-$title.muttrc"
{ echo "set spoolfile = \"$spoolfile\""; echo "set record = \"$record\""; echo "set postponed = \"$postponed\""; echo "set trash = \"$trash\""; } >> "$accdir/$idnum-$title.muttrc"
echo "mailboxes =$title ===================== $(echo "$boxes" | sed -e "s/^\|$/\"/g" | tr "\n" " ")" >> "$accdir/$idnum-$title.muttrc"
printf "Setting up your keyboard shortcuts for jumping between mailboxes...\\n"
sed -i "/# mw-autogenerated/d" "$accdir/$idnum-$title.muttrc"
- echo "$boxes" | grep -i -m 1 inbox | formatShortcut i inbox
- echo "$boxes" | grep -i -m 1 sent | formatShortcut s sent
- echo "$boxes" | grep -i -m 1 draft | formatShortcut d drafts
- echo "$boxes" | grep -i -m 1 trash | formatShortcut t trash
- echo "$boxes" | grep -i -m 1 spam | formatShortcut S spam
- echo "$boxes" | grep -i -m 1 junk | formatShortcut j junk
- echo "$boxes" | grep -i -m 1 archive | formatShortcut a archive
+
+ if [[ $os == "Darwin" ]]; then
+ echo "$boxes" | grep -i inbox | head -n 1 | formatShortcut i inbox
+ echo "$boxes" | grep -i sent | head -n 1 | formatShortcut s sent
+ echo "$boxes" | grep -i draft | head -n 1 | formatShortcut d drafts
+ echo "$boxes" | grep -i trash | head -n 1 | formatShortcut t trash
+ echo "$boxes" | grep -i spam | head -n 1 | formatShortcut S spam
+ echo "$boxes" | grep -i junk | head -n 1 | formatShortcut j junk
+ echo "$boxes" | grep -i archive | head -n 1 | formatShortcut a archive
+ else
+ echo "$boxes" | grep -i -m 1 inbox | formatShortcut i inbox
+ echo "$boxes" | grep -i -m 1 sent | formatShortcut s sent
+ echo "$boxes" | grep -i -m 1 draft | formatShortcut d drafts
+ echo "$boxes" | grep -i -m 1 trash | formatShortcut t trash
+ echo "$boxes" | grep -i -m 1 spam | formatShortcut S spam
+ echo "$boxes" | grep -i -m 1 junk | formatShortcut j junk
+ echo "$boxes" | grep -i -m 1 archive | formatShortcut a archive
+ fi
+
[ "$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"
return 0
}
-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
+confirm() { printf "Do you want 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
return 0 ;}
--
2.20.1
Copy link

ghost commented Apr 29, 2019

Hi, there's a typo in Line 49 (alis instead of alias)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment