From 4537d35666b9c23f82e9c5f2c0e838c09959906a Mon Sep 17 00:00:00 2001
From: Abin Simon <abinsimon10@gmail.com>
Date: Tue, 13 Mar 2018 10:25:21 +0530
Subject: MacOS fixes

fix adding new account in macos

Fix mailsync ping command

Fix mutt-wizard

Fix muttrc for mac

Add files for offlineimap_profile and offlineimap_header

Update README with MacOS install instructions
---
 README.md                          |  2 ++
 autoconf/offlineimap_header.macos  |  6 ++++++
 autoconf/offlineimap_profile.macos | 19 +++++++++++++++++++
 etc/mailsync.sh                    |  9 +++++++--
 mutt-wizard.sh                     | 13 ++++++++++---
 muttrc                             |  1 +
 6 files changed, 45 insertions(+), 5 deletions(-)
 create mode 100644 autoconf/offlineimap_header.macos
 create mode 100644 autoconf/offlineimap_profile.macos

diff --git a/README.md b/README.md
index 352437b..e27d766 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,8 @@ Note also that Gmail and some providers require you to enable sign-ins from thir
 
 ## Installation and Dependencies
 
+> **MacOS prerequisites** - Install `iproute2mac` and `mpv` ( brew install iproute2mac mpv )
+
 `dialog`, `neomutt` and `offlineimap` should be installed. You also need to have a GPG public/private key pair for the wizard to automatically store your passwords. The whole repo should be cloned to `~/.config/mutt/`. (If you have a previous mutt folder, you'll want to back it up or delete it first.)
 
 ```
diff --git a/autoconf/offlineimap_header.macos b/autoconf/offlineimap_header.macos
new file mode 100644
index 0000000..86d5678
--- /dev/null
+++ b/autoconf/offlineimap_header.macos
@@ -0,0 +1,6 @@
+[general]
+accounts =
+starttls = yes
+ssl = true
+pythonfile = ~/.config/mutt/credentials/imappwd.py
+
diff --git a/autoconf/offlineimap_profile.macos b/autoconf/offlineimap_profile.macos
new file mode 100644
index 0000000..e985538
--- /dev/null
+++ b/autoconf/offlineimap_profile.macos
@@ -0,0 +1,19 @@
+[Account $title]
+
+localrepository = $title-local
+remoterepository = $title-remote
+
+[Repository $title-remote]
+auth_mechanisms = LOGIN
+type = $type
+remoteuser = $login
+sslcacertfile = /usr/local/etc/openssl/cert.pem
+remotepasseval = mailpasswd("$title")
+remotehost = $imap
+remoteport = $iport
+folderfilter = lambda foldername: foldername not in ['[Gmail]/All Mail']
+sslcacertfile = /usr/local/etc/openssl/cert.pem
+
+[Repository $title-local]
+type = Maildir
+localfolders = ~/.mail/$title
diff --git a/etc/mailsync.sh b/etc/mailsync.sh
index 61eeade..4810ce7 100755
--- a/etc/mailsync.sh
+++ b/etc/mailsync.sh
@@ -7,8 +7,13 @@
 #
 # I have this run as a cronjob every 5 minutes.
 
-# Check for internet connection. Exit script if none.
-ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` >/dev/null || exit
+# Check for internet connection. Exit script if none. (timeout in mac is `-t`)
+if [ "$(uname)" == "Darwin" ]
+then
+	ping -q -t 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` >/dev/null || exit
+else
+	ping -q -w 1 -c 1 `ip r | grep default | cut -d ' ' -f 3` >/dev/null || exit
+fi
 
 # Get current number of new mail, then begin sync.
 ori=$(find ~/.mail -wholename '*/new/*' | grep -vi "spam\|trash\|junk" | wc -l)
diff --git a/mutt-wizard.sh b/mutt-wizard.sh
index 18ee806..7256f16 100755
--- a/mutt-wizard.sh
+++ b/mutt-wizard.sh
@@ -1,5 +1,12 @@
 #!/bin/bash
 
+if [[ "$(uname)" == "Darwin" ]]
+then
+	os=".macos"
+else
+	os=""
+fi
+
 muttdir="$HOME/.config/mutt/"
 
 chooseSync() { (crontab -l && testSync) || dialog --msgbox "No cronjob manager detected. Please install one and return to enable automatic mailsyncing" 10 60 ;}
@@ -173,8 +180,8 @@ addAccount() {
 	mkdir -p "$muttdir"accounts/$title/cache/bodies
 
 	# Creating the offlineimaprc if it doesn't exist already.
-	if [ ! -f ~/.offlineimaprc ]; then cp "$muttdir"autoconf/offlineimap_header ~/.offlineimaprc; fi
-	cat "$muttdir"autoconf/offlineimap_profile | sed -e "$replacement" >> ~/.offlineimaprc
+	if [ ! -f ~/.offlineimaprc ]; then cp "$muttdir"autoconf/offlineimap_header"$os" ~/.offlineimaprc; fi
+	cat "$muttdir"autoconf/offlineimap_profile"$os" | sed -e "$replacement" >> ~/.offlineimaprc
 	mkdir -p ~/.mail/$title
 
 	# Add the mutt profile.
@@ -183,7 +190,7 @@ addAccount() {
 	echo "macro index,pager i$idnum '<sync-mailbox><enter-command>source "$muttdir"accounts/$title.muttrc<enter><change-folder>!<enter>'" >> "$muttdir"personal.muttrc
 
 	# Add to offlineimaprc sync list.
-	sed -i "s/^accounts =.*[a-zA-Z]$/&, $title/g;s/^accounts =\s*$/accounts = $title/g" ~/.offlineimaprc
+	sed -i.bu "s/^accounts =.*[a-zA-Z]$/&, $title/g;s/^accounts =\s*$/accounts = $title/g" ~/.offlineimaprc && rm ~/.offlineimaprc.bu
 
 	# Makes account default if there is no default account.
 	grep "$muttdir"personal.muttrc -e "^source .*accounts.*" >/dev/null && echo there || \
diff --git a/muttrc b/muttrc
index 041198f..88ee9fa 100644
--- a/muttrc
+++ b/muttrc
@@ -19,6 +19,7 @@ set forward_format = "Fwd: %s"
 set markers = no
 set mark_old = no
 set mime_forward = yes
+set smtp_authenticators = 'gssapi:login'
 auto_view text/html
 auto_view application/pdf
 alternative_order text/plain text/enriched text/html
-- 
cgit v1.2.3


From b739589fa5bb6c7a6f86658d3d6dbd6c184e4c47 Mon Sep 17 00:00:00 2001
From: Abin Simon <abinsimon10@gmail.com>
Date: Tue, 13 Mar 2018 19:48:34 +0530
Subject: Use `$EDITOR` instead of hardcoding vim

---
 muttrc | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/muttrc b/muttrc
index 041198f..ca54b84 100644
--- a/muttrc
+++ b/muttrc
@@ -7,7 +7,7 @@ source etc/muttcol
 source etc/aliases
 set sleep_time = 0
 set sort = 'reverse-date'
-set editor = vim
+set editor = $EDITOR
 #set copy = no
 set timeout = "5"
 set mail_check = "10"
-- 
cgit v1.2.3


From fe85cb6835278ce804657a486629d0b2be7f34b5 Mon Sep 17 00:00:00 2001
From: ZethJack <jerabek.michal@gmail.com>
Date: Fri, 16 Mar 2018 07:26:58 +0000
Subject: Update offlineimap_profile

Removed "sslcacerfile = /etc/ssl/cets/ca-certificates.crt" on line 10 - it was pointing to non-existant directory "cets" instead of "certs" - this setting is overwritten later with correct path therefore no errors would register.
---
 autoconf/offlineimap_profile | 1 -
 1 file changed, 1 deletion(-)

diff --git a/autoconf/offlineimap_profile b/autoconf/offlineimap_profile
index 0711979..2277d6b 100644
--- a/autoconf/offlineimap_profile
+++ b/autoconf/offlineimap_profile
@@ -7,7 +7,6 @@ remoterepository = $title-remote
 auth_mechanisms = LOGIN
 type = $type
 remoteuser = $login
-sslcacerfile = /etc/ssl/cets/ca-certificates.crt
 remotepasseval = mailpasswd("$title")
 remotehost = $imap
 remoteport = $iport
-- 
cgit v1.2.3