aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <hello@eugenetriguba.com>2025-07-20 18:50:30 -0400
committerEugene Triguba <hello@eugenetriguba.com>2025-07-20 18:50:30 -0400
commit004db1b9fe33c501907764fe6ecf718afe1bcd92 (patch)
treee98ff0ffb032e7c6b684379b11746b18b756257a
parentReplace barbar with harpoon / adjust config (diff)
downloaddotfiles-004db1b9fe33c501907764fe6ecf718afe1bcd92.zip
Add msmtp/isync setup for local email processing via aerc
-rw-r--r--.gitignore2
-rw-r--r--aerc/.config/aerc/accounts.conf30
-rwxr-xr-xexecutables/bin/get-password44
-rwxr-xr-xexecutables/bin/msmtp-queue294
-rwxr-xr-xexecutables/bin/msmtp-send147
-rw-r--r--homebrew/Brewfile15
-rwxr-xr-xinstall.sh8
-rw-r--r--isync/.config/isync/mbsync.conf56
-rw-r--r--msmtp/.config/msmtp/config23
9 files changed, 581 insertions, 38 deletions
diff --git a/.gitignore b/.gitignore
index 235823d..f44725e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,5 @@
.DS_Store
/tags
/tmux/.config/tmux/plugins
+/msmtp/.config/msmtp/*.log
+
diff --git a/aerc/.config/aerc/accounts.conf b/aerc/.config/aerc/accounts.conf
index eb8d118..2b9c0ed 100644
--- a/aerc/.config/aerc/accounts.conf
+++ b/aerc/.config/aerc/accounts.conf
@@ -1,19 +1,17 @@
[Personal Gmail]
-source = imaps://eugenetriguba%40gmail.com@imap.gmail.com:993
-outgoing = smtps://eugenetriguba%40gmail.com@smtp.gmail.com:587
-default = INBOX
-from = Eugene Triguba <eugenetriguba@gmail.com>
-copy-to = ~/Documents/Email/Gmail
-cache-headers = true
-source-cred-cmd = get-password --credential "Personal Gmail - Sourcehut"
-outgoing-cred-cmd = get-password --credential "Personal Gmail - Sourcehut"
+source = maildir://~/Mail/Gmail
+outgoing = /usr/local/bin/msmtp-send --account gmail
+default = INBOX
+from = Eugene Triguba <eugenetriguba@gmail.com>
+copy-to = Sent
+check-mail-cmd = 'mbsync -c ~/.config/isync/mbsync.conf gmail-inbox'
+check-mail = 1m
[Personal iCloud]
-source = imaps://eugenetriguba%40gmail.com@imap.mail.me.com:993
-outgoing = smtps://eugenetriguba%40gmail.com@smtp.mail.me.com:587
-default = INBOX
-from = Eugene Triguba <hello@eugenetriguba.com>
-copy-to = ~/Documents/Email/iCloud
-cache-headers = true
-source-cred-cmd = get-password --credential "Personal iCloud - Sourcehut"
-outgoing-cred-cmd = get-password --credential "Personal iCloud - Sourcehut"
+source = maildir://~/Mail/iCloud
+outgoing = /usr/local/bin/msmtp-send --account icloud
+default = INBOX
+from = Eugene Triguba <hello@eugenetriguba.com>
+copy-to = Sent
+check-mail-cmd = 'mbsync -c ~/.config/isync/mbsync.conf icloud-inbox'
+check-mail = 1m
diff --git a/executables/bin/get-password b/executables/bin/get-password
index ca13d93..3b83bb7 100755
--- a/executables/bin/get-password
+++ b/executables/bin/get-password
@@ -5,32 +5,32 @@ VAULT="Private"
CREDENTIAL=""
main() {
- parse_args "$@"
- op read "op://$VAULT/$CREDENTIAL/password"
+ parse_args "$@"
+ op read "op://$VAULT/$CREDENTIAL/password"
}
parse_args() {
- while [ $# -gt 0 ]; do
- case "$1" in
- --vault)
- VAULT="$2"
- shift 2
- ;;
- --credential)
- CREDENTIAL="$2"
- shift 2
- ;;
- *)
- echo "Usage: $0 [--vault <name>] --credential <name>"
- exit 1
- ;;
- esac
- done
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --vault)
+ VAULT="$2"
+ shift 2
+ ;;
+ --credential)
+ CREDENTIAL="$2"
+ shift 2
+ ;;
+ *)
+ echo "Usage: $0 [--vault <name>] --credential <name>"
+ exit 1
+ ;;
+ esac
+ done
- if [ -z "$CREDENTIAL" ]; then
- echo "Invalid or empty CREDENTIAL" >&2
- exit 1
- fi
+ if [ -z "$CREDENTIAL" ]; then
+ echo "Invalid or empty CREDENTIAL" >&2
+ exit 1
+ fi
}
main "$@"
diff --git a/executables/bin/msmtp-queue b/executables/bin/msmtp-queue
new file mode 100755
index 0000000..fb1e487
--- /dev/null
+++ b/executables/bin/msmtp-queue
@@ -0,0 +1,294 @@
+#!/usr/bin/env bash
+# msmtp queue management utility
+#
+# Provides commands to process, check status, and clear the
+# msmtp email queue that is populated by msmtp-send.
+set -euo pipefail
+
+DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
+QUEUE_DIR="${DATA_DIR}/msmtp-queue"
+LOG_FILE="${DATA_DIR}/msmtp-queue-processor.log"
+MSMTP_PATH="$(command -v msmtp)"
+
+main() {
+ if [[ $# -eq 0 ]]; then
+ print_usage
+ exit 1
+ fi
+
+ local subcommand="$1"
+ shift
+
+ case "$subcommand" in
+ process)
+ process_queue "$@"
+ ;;
+ status)
+ show_status "$@"
+ ;;
+ clear)
+ clear_queue "$@"
+ ;;
+ -h | --help)
+ print_usage
+ exit 0
+ ;;
+ *)
+ log_message "ERROR" "Unknown subcommand: $subcommand"
+ print_usage
+ exit 1
+ ;;
+ esac
+}
+
+print_usage() {
+ cat <<USAGE
+Usage: $(basename "$0") <subcommand> [OPTIONS]
+
+A utility to manage the msmtp email queue.
+
+SUBCOMMANDS:
+ process Process all queued emails (attempt to send)
+ status Show queue status and recent activity
+ clear [ACCOUNT] Clear queued emails (all accounts or specific account)
+
+OPTIONS:
+ -h, --help Show this help message
+
+EXAMPLES:
+ $(basename "$0") process
+ $(basename "$0") status
+ $(basename "$0") clear
+ $(basename "$0") clear gmail
+
+NOTES:
+ - Queue directory: $QUEUE_DIR
+ - Log file: $LOG_FILE
+ - Queued files are named: timestamp-pid-random-ACCOUNT
+USAGE
+}
+
+log_message() {
+ local level="$1"
+ shift
+ local message
+ message="$(date '+%Y-%m-%d %H:%M:%S') [$level] $*"
+
+ if [[ -d "$QUEUE_DIR" ]]; then
+ echo "$message" >>"$LOG_FILE"
+ fi
+ echo "$message" >&2
+}
+
+process_queue() {
+ if [[ $# -gt 0 ]]; then
+ log_message "ERROR" "process subcommand takes no arguments"
+ print_usage
+ exit 1
+ fi
+
+ if ! command -v "$MSMTP_PATH" >/dev/null 2>&1; then
+ log_message "ERROR" "msmtp not found at $MSMTP_PATH"
+ exit 1
+ fi
+
+ setup_queue_directory
+
+ local total_count
+ total_count="$(count_queued_files)"
+ if [[ "$total_count" -eq 0 ]]; then
+ log_message "INFO" "No emails in queue"
+ return 0
+ fi
+
+ log_message "DEBUG" "Files from get_queued_files:"
+ get_queued_files | while IFS= read -r debug_file; do
+ log_message "DEBUG" " - $debug_file"
+ done
+
+ log_message "INFO" "Processing $total_count queued emails"
+ local sent_count=0
+ local failed_count=0
+ # NOTE: Temporarily disable exit on error for msmtp call
+ # so that it can continue processing other files even if
+ # one fails.
+ set +e
+ while IFS= read -r file; do
+ if [[ -n "$file" ]]; then
+ local account
+ account="$(extract_account_from_filename "$file")"
+
+ log_message "INFO" "Attempting to send $(basename "$file") via $account"
+
+ local msmtp_output
+ if msmtp_output=$("$MSMTP_PATH" --account="$account" -t <"$file" 2>&1); then
+ rm "$file"
+ log_message "INFO" "SUCCESS: Sent $(basename "$file") via $account"
+ ((sent_count++))
+ else
+ log_message "ERROR" "FAILED: Could not send $(basename "$file") via $account - $msmtp_output"
+ ((failed_count++))
+ fi
+ fi
+ done < <(get_queued_files)
+ set -e
+
+ log_message "INFO" "Processing complete: $sent_count sent, $failed_count failed"
+}
+
+setup_queue_directory() {
+ if ! mkdir -p "$QUEUE_DIR"; then
+ log_message "ERROR" "Failed to create queue directory: $QUEUE_DIR"
+ exit 1
+ fi
+}
+
+extract_account_from_filename() {
+ local filename="$1"
+ local basename_file
+ basename_file="$(basename "$filename")"
+
+ # NOTE: Expected format of timestamp-pid-random-ACCOUNT
+ if [[ "$basename_file" =~ ^[0-9]+-[0-9]+-[a-fA-F0-9]+-(.+)$ ]]; then
+ echo "${BASH_REMATCH[1]}"
+ else
+ log_message "WARN" "Could not extract account from filename: $basename_file"
+ echo "unknown"
+ fi
+}
+
+get_queued_files() {
+ local account_filter="${1:-}"
+
+ if [[ ! -d "$QUEUE_DIR" ]]; then
+ return 0
+ fi
+
+ for file in "$QUEUE_DIR"/*; do
+ if [[ -f "$file" ]]; then
+ if [[ -z "$account_filter" ]]; then
+ echo "$file"
+ else
+ local file_account
+ file_account="$(extract_account_from_filename "$file")"
+ if [[ "$file_account" == "$account_filter" ]]; then
+ echo "$file"
+ fi
+ fi
+ fi
+ done
+}
+
+count_queued_files() {
+ local account_filter="${1:-}"
+ local count=0
+
+ while IFS= read -r -d '' file; do
+ ((count++))
+ done < <(get_queued_files "$account_filter" | tr '\n' '\0')
+
+ echo "$count"
+}
+
+show_status() {
+ if [[ $# -gt 0 ]]; then
+ log_message "ERROR" "status subcommand takes no arguments"
+ print_usage
+ exit 1
+ fi
+
+ setup_queue_directory
+
+ echo "=== Queue Status ==="
+
+ local total_count
+ total_count="$(count_queued_files)"
+ echo "Total queued: $total_count"
+
+ if [[ "$total_count" -gt 0 ]]; then
+ echo ""
+ echo "By account:"
+ while IFS= read -r account; do
+ if [[ -n "$account" ]]; then
+ local account_count
+ account_count="$(count_queued_files "$account")"
+ echo " $account: $account_count"
+ fi
+ done < <(get_all_accounts)
+ fi
+
+ if [[ -f "$LOG_FILE" ]]; then
+ echo ""
+ echo "=== Recent Activity (last 10 lines) ==="
+ tail -10 "$LOG_FILE" 2>/dev/null || echo "No log entries yet"
+ fi
+}
+
+get_all_accounts() {
+ local accounts=()
+
+ while IFS= read -r file; do
+ if [[ -n "$file" ]]; then
+ local account
+ account="$(extract_account_from_filename "$file")"
+ if [[ "$account" != "unknown" ]]; then
+ accounts+=("$account")
+ fi
+ fi
+ done < <(get_queued_files)
+
+ # Remove duplicates and sort
+ printf '%s\n' "${accounts[@]}" | sort -u
+}
+
+clear_queue() {
+ local account_filter="${1:-}"
+
+ if [[ $# -gt 1 ]]; then
+ log_message "ERROR" "clear subcommand takes at most one argument (account name)"
+ print_usage
+ exit 1
+ fi
+
+ setup_queue_directory
+
+ if [[ -n "$account_filter" ]]; then
+ local account_count
+ account_count="$(count_queued_files "$account_filter")"
+
+ if [[ "$account_count" -eq 0 ]]; then
+ echo "No queued emails for account: $account_filter"
+ return 0
+ fi
+
+ while IFS= read -r file; do
+ if [[ -n "$file" ]]; then
+ rm "$file"
+ fi
+ done < <(get_queued_files "$account_filter")
+
+ log_message "INFO" "Cleared $account_count queued emails for account: $account_filter"
+ echo "Cleared $account_count queued emails for account: $account_filter"
+ else
+ local total_count
+ total_count="$(count_queued_files)"
+
+ if [[ "$total_count" -eq 0 ]]; then
+ echo "No queued emails to clear"
+ return 0
+ fi
+
+ while IFS= read -r file; do
+ if [[ -n "$file" ]]; then
+ rm "$file"
+ fi
+ done < <(get_queued_files)
+
+ log_message "INFO" "Cleared $total_count queued emails (all accounts)"
+ echo "Cleared $total_count queued emails (all accounts)"
+ fi
+}
+
+if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
+ main "$@"
+fi
diff --git a/executables/bin/msmtp-send b/executables/bin/msmtp-send
new file mode 100755
index 0000000..fad2f9e
--- /dev/null
+++ b/executables/bin/msmtp-send
@@ -0,0 +1,147 @@
+#!/bin/bash
+# Smart sendmail replacement with account selection and offline queuing
+#
+# When the mail server is offline, emails are queued in a local directory.
+# When the server is back online, queued emails are sent automatically.
+set -euo pipefail
+
+MSMTP_ACCOUNT=""
+DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}"
+QUEUE_DIR="${DATA_DIR}/msmtp-queue"
+TEMP_DIR="${DATA_DIR}/msmtp-temp"
+MSMTP_PATH="$(command -v msmtp)"
+
+main() {
+ parse_args "$@"
+
+ if ! command -v "$MSMTP_PATH" >/dev/null 2>&1; then
+ log_message "ERROR" "msmtp not found at $MSMTP_PATH"
+ exit 1
+ fi
+
+ setup_directories
+
+ local temp_file
+ temp_file=$(create_temp_file)
+ if ! cat >"$temp_file"; then
+ log_message "ERROR" "Failed to read email content"
+ cleanup_temp_file "$temp_file"
+ exit 1
+ fi
+
+ send_email "$temp_file" "$MSMTP_ACCOUNT"
+}
+
+parse_args() {
+ while [[ $# -gt 0 ]]; do
+ case $1 in
+ --account)
+ if [[ -z "${2:-}" ]]; then
+ log_message "ERROR" "--account requires an argument"
+ print_usage
+ exit 1
+ fi
+ MSMTP_ACCOUNT="$2"
+ shift 2
+ ;;
+ -h | --help)
+ print_usage
+ exit 0
+ ;;
+ esac
+ done
+
+ if [[ -z "$MSMTP_ACCOUNT" ]]; then
+ log_message "ERROR" "No account specified. Use --account <account> to specify an account."
+ print_usage
+ exit 1
+ fi
+}
+
+log_message() {
+ local level="$1"
+ shift
+ echo "$(date '+%Y-%m-%d %H:%M:%S') [$level] $*" >&2
+}
+
+print_usage() {
+ cat <<USAGE
+Usage: $(basename "$0") --account <account> [OPTIONS] [RECIPIENT...]
+
+A sendmail replacement that routes emails through msmtp with offline queuing.
+
+ARGUMENTS:
+ --account <account> Specify the account to use. It should match the name in your
+ msmtp configuration.
+ RECIPIENT... Email recipients (optional, can be specified in email body)
+
+OPTIONS:
+ -h, --help Show this help message
+
+EXAMPLES:
+ echo "test email" | $(basename "$0") --account gmail user@example.com
+
+NOTES:
+ - Emails are queued offline and sent when connection is available
+ - Queue directory: $QUEUE_DIR
+USAGE
+}
+
+create_temp_file() {
+ local timestamp
+ timestamp="$(date +%s)"
+ local pid="$$"
+ local random
+ random="$(od -An -N4 -tx4 </dev/urandom | tr -d ' ')"
+ echo "$TEMP_DIR/${timestamp}-${pid}-${random}"
+}
+
+setup_directories() {
+ if ! mkdir -p "$QUEUE_DIR" "$TEMP_DIR"; then
+ log_message "ERROR" "Failed to create directories"
+ exit 1
+ fi
+}
+
+cleanup_temp_file() {
+ local temp_file="$1"
+ rm -f "$temp_file"
+}
+
+send_email() {
+ local temp_file="$1"
+ local account="$2"
+
+ if "$MSMTP_PATH" --account="$account" -t <"$temp_file" 2>/dev/null; then
+ log_message "INFO" "Email sent successfully via $account"
+ cleanup_temp_file "$temp_file"
+ return 0
+ else
+ log_message "INFO" "Failed to send email, queuing for later"
+ queue_email "$temp_file" "$account"
+ return 1
+ fi
+}
+
+queue_email() {
+ local temp_file="$1"
+ local account="$2"
+ local timestamp
+ timestamp="$(date +%s)"
+ local pid="$$"
+ local random
+ random="$(od -An -N4 -tx4 </dev/urandom | tr -d ' ')"
+ local queued_file="$QUEUE_DIR/${timestamp}-${pid}-${random}-${account}"
+
+ if mv "$temp_file" "$queued_file"; then
+ log_message "INFO" "Email queued for later delivery: $(basename "$queued_file")"
+ else
+ log_message "ERROR" "Failed to queue email"
+ cleanup_temp_file "$temp_file"
+ exit 1
+ fi
+}
+
+if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
+ main "$@"
+fi
diff --git a/homebrew/Brewfile b/homebrew/Brewfile
index 3e448b7..fde03fc 100644
--- a/homebrew/Brewfile
+++ b/homebrew/Brewfile
@@ -1,7 +1,9 @@
tap "neovim/neovim"
tap "eugenetriguba/bolt"
brew "act"
+brew "aerc"
brew "ansible"
+brew "atuin"
brew "bandit"
brew "bash"
brew "bat"
@@ -29,6 +31,7 @@ brew "gcc"
brew "gh"
brew "git"
brew "glab"
+brew "glow"
brew "gnu-sed"
brew "gnupg"
brew "go"
@@ -39,10 +42,12 @@ brew "hugo"
brew "icu4c@76"
brew "icu4c@77"
brew "isort"
+brew "isync"
brew "jc"
brew "jq"
brew "jsonlint"
brew "julia"
+brew "kubernetes-cli"
brew "libffi"
brew "lima"
brew "llvm"
@@ -52,6 +57,8 @@ brew "luarocks"
brew "make"
brew "mas"
brew "meson"
+brew "minikube"
+brew "msmtp"
brew "mvt"
brew "nasm"
brew "ncdu"
@@ -83,6 +90,7 @@ brew "ripgrep"
brew "rsync"
brew "ruff"
brew "rustup"
+brew "scdoc"
brew "shellcheck"
brew "shfmt"
brew "speedtest-cli"
@@ -97,6 +105,7 @@ brew "tmux"
brew "tree"
brew "vale"
brew "vim"
+brew "w3m"
brew "wget"
brew "xz"
brew "yt-dlp"
@@ -108,6 +117,7 @@ cask "anki"
cask "calibre"
cask "discord"
cask "docker-desktop"
+cask "docker"
cask "elgato-control-center"
cask "font-hack-nerd-font"
cask "font-inter"
@@ -115,8 +125,13 @@ cask "font-menlo-for-powerline"
cask "font-monaspace-nerd-font"
cask "font-noto-sans-symbols-2"
cask "ghostty"
+cask "google-chrome"
+cask "hashicorp-vagrant"
cask "iterm2"
+cask "logi-options-plus"
+cask "logi-options+"
cask "mullvad-vpn"
+cask "mullvadvpn"
cask "neovide-app"
cask "neovide"
cask "obsidian"
diff --git a/install.sh b/install.sh
index e0ef219..b2ec3c9 100755
--- a/install.sh
+++ b/install.sh
@@ -26,8 +26,16 @@ main() {
stow tmux
stow ghostty
stow aerc
+ stow isync
+ stow msmtp
echo "Successfully linked all dotfiles."
+ mkdir -p ~/Mail/Gmail/INBOX ~/Mail/iCloud/INBOX ~/bin/ ~/src/
+ sudo ln -s "$HOME/bin/get-password" /usr/local/bin/get-password
+ sudo ln -s "$(which op)" /usr/local/bin/op
+ sudo ln -s "$HOME/bin/msmtp-send" /usr/local/bin/msmtp-send
+ sudo ln -s "$HOME/bin/msmtp-queue" /usr/local/bin/msmtp-queue
+
echo "Initializing TPM (Tmux Plugin Manager)..."
setup_tpm
diff --git a/isync/.config/isync/mbsync.conf b/isync/.config/isync/mbsync.conf
new file mode 100644
index 0000000..b562318
--- /dev/null
+++ b/isync/.config/isync/mbsync.conf
@@ -0,0 +1,56 @@
+CopyArrivalDate yes
+Create Near
+Expunge Both
+
+##################
+# Gmail
+##################
+
+IMAPAccount gmail
+Host imap.gmail.com
+User eugenetriguba@gmail.com
+PassCmd "get-password --credential 'Personal Gmail Password'"
+TLSType IMAPS
+AuthMechs PLAIN
+
+MaildirStore gmail-local
+Path ~/Mail/Gmail/
+Inbox ~/Mail/Gmail/INBOX
+SubFolders Verbatim
+
+IMAPStore gmail-remote
+Account gmail
+
+Channel gmail-inbox
+Far :gmail-remote:
+Near :gmail-local:
+Patterns *
+
+##################
+# iCloud
+##################
+
+IMAPAccount icloud
+Host imap.mail.me.com
+User eugenetriguba@gmail.com
+PassCmd "get-password --credential 'Personal iCloud Password'"
+TLSType IMAPS
+AuthMechs PLAIN
+
+MaildirStore icloud-local
+Path ~/Mail/iCloud/
+Inbox ~/Mail/iCloud/INBOX
+SubFolders Verbatim
+
+IMAPStore icloud-remote
+Account icloud
+
+Channel icloud-inbox
+Far :icloud-remote:
+Near :icloud-local:
+Patterns *
+
+# Group for syncing both accounts
+Group primary
+Channel gmail-inbox
+Channel icloud-inbox
diff --git a/msmtp/.config/msmtp/config b/msmtp/.config/msmtp/config
new file mode 100644
index 0000000..507a013
--- /dev/null
+++ b/msmtp/.config/msmtp/config
@@ -0,0 +1,23 @@
+defaults
+auth on
+tls on
+tls_trust_file /etc/ssl/cert.pem
+logfile ~/.config/msmtp/msmtp.log
+
+account gmail
+host smtp.gmail.com
+port 587
+from eugenetriguba@gmail.com
+user eugenetriguba@gmail.com
+passwordeval get-password --credential 'Personal Gmail Password'
+
+account icloud
+host smtp.mail.me.com
+port 587
+from hello@eugenetriguba.com
+#user eugenetriguba@gmail.com
+user eugenetriguba@icloud.com
+passwordeval get-password --credential 'Personal iCloud Password'
+set_from_header on
+
+account default : icloud