Add mutt and offlineimap config to edit mails on the terminal easily

This commit is contained in:
2025-10-10 13:18:18 +02:00
parent c1430386c0
commit 4c0c743a33
9 changed files with 209 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
set realname = "Felix Nehrke"
set from = "nemoinho@gmail.com"
set smtp_url = "smtp://nemoinho@gmail.com@smtp.gmail.com:587/"
set smtp_pass = `gmail-app-credentials pass nemoinho@gmail.com`
set folder = ~/.local/state/offlineimap/nemoinho_gmail
set header_cache = "$XDG_CACHE_HOME/mutt/com.gmail_nemoinho/cache/headers"
set message_cachedir = "$XDG_CACHE_HOME/mutt/com.gmail_nemoinho/cache/bodies"
set certificate_file = "$XDG_CACHE_HOME/mutt/com.gmail_nemoinho/certificates"
source "$XDG_CONFIG_HOME/mutt/gmail.muttrc"

View File

@@ -0,0 +1,13 @@
set realname = "Felix Nehrke"
set from = "felix@nehrke.info"
set smtp_url = "smtp://felix@nehrke.info@smtp.gmail.com:587/"
set smtp_pass = `gmail-app-credentials pass felix@nehrke.info`
set folder = ~/.local/state/offlineimap/felix_nehrke_info_gmail
set header_cache = "$XDG_CACHE_HOME/mutt/info.nehrke_felix/cache/headers"
set message_cachedir = "$XDG_CACHE_HOME/mutt/info.nehrke_felix/cache/bodies"
set certificate_file = "$XDG_CACHE_HOME/mutt/info.nehrke_felix/certificates"
source "$XDG_CONFIG_HOME/mutt/gmail.muttrc"

34
.config/mutt/gmail.muttrc Normal file
View File

@@ -0,0 +1,34 @@
# Location of inbox
set spoolfile = "=INBOX"
set postponed = "=[Gmail]/Drafts"
set record = "=[Gmail]/Sent Mail"
# In Gmail the trash works different...
unset trash
mailboxes =INBOX \
-label Drafts "=[Gmail]/Drafts" \
-label Sent "=[Gmail]/Sent Mail" \
-label Trash "=[Gmail]/Trash" \
-label Spam "=[Gmail]/Spam" \
-label Archive "=[Gmail]/All Mail" \
# Headers to show
ignore *
unignore date from to cc subject x-mailer resent-from reply-to
bind pager,index d noop
bind pager,index e noop
macro index,pager d "<tag-prefix><save-message>=[Gmail]/Trash<enter>" "Move message to chosen folder"
macro pager d "<save-message>=[Gmail]/Trash<enter>" "Move message to chosen folder"
macro index,pager e "<tag-prefix><purge-message>" "Move message to chosen folder"
macro index,pager ga "<change-folder>=[Gmail]/All^V Mail<enter>" "Switch to Archive"
macro index,pager gd "<change-folder>=[Gmail]/Drafts<enter>" "Switch to Drafts"
macro index,pager gi "<change-folder>=INBOX<enter>" "Switch to Inbox"
macro index,pager gs "<change-folder>=[Gmail]/Sent^V Mail<enter>" "Switch to Sent Mail"
macro index,pager gS "<change-folder>=[Gmail]/Spam<enter>" "Switch to Spam"
macro index,pager gt "<change-folder>=[Gmail]/Trash<enter>" "Switch to Trash"
macro index,pager ml "<tag-prefix><copy-message>?" "Move message to chosen folder"
macro index,pager mi "<tag-prefix><copy-message>=INBOX<enter>" "Add to Inbox"
macro index,pager mr "<tag-prefix><clear-flag>O" "Mark as read"
macro index,pager mu "<tag-prefix><set-flag>O" "Mark as read"

7
.config/mutt/mailcap Normal file
View File

@@ -0,0 +1,7 @@
text/html; lynx -force_html -dump %s; copiousoutput
application/pdf; evince %s
application/vnd.openxmlformats-officedocument.wordprocessingml.document; pandoc --from docx --to markdown %s; copiousoutput
application/vnd.oasis.opendocument.text; pandoc --from odt --to markdown %s; copiousoutput
image/png; feh --scale-down %s
image/jpeg; feh --scale-down %s
image/gif; feh --scale-down %s

56
.config/mutt/muttrc Normal file
View File

@@ -0,0 +1,56 @@
set allow_8bit
set smart_wrap
set reverse_name
set reverse_realname
#set sidebar_visible
set wait_key = no
set confirm_append = no
set editor = vim
set sort_aux = last-date-received
set mailcap_path = "$XDG_CONFIG_HOME/mutt/mailcap"
auto_view text/plain text/html text/calendar application/ics
alternative_order text/plain text/html text/calendar application/ics
bind index 0 first-entry
bind index G last-entry
bind pager 0 top
bind pager G bottom
bind pager j next-line
bind pager k previous-line
bind pager <Backspace> previous-entry
bind pager <Enter> next-entry
bind pager <Return> next-entry
bind pager,index \ch sidebar-toggle-visible
bind pager,index \cj sidebar-next
bind pager,index \ck sidebar-prev
bind pager,index \co sidebar-open
bind pager,index c mail
bind pager,index g noop # unbind g to be used with macros, e.g. gg
bind pager,index m noop # unbind M to be used with macros, e.g. mv
macro index gg "<first-entry>"
macro index gr "<imap-fetch-mail>"
macro pager gg "<top>"
macro pager gn "<next-entry>"
macro pager gp "<previous-entry>"
macro pager gr "<group-reply>"
# Use urlscan instead to follow links instead of the builtin urlview
macro pager \cb '<pipe-message>urlscan -W<enter>' "Follow links with urlscan"
macro index,pager mv "<tag-prefix><save-message>" "move message to chosen folder"
# I prefer so see the IMAP folders instead of my mailboxes by default
macro index,pager y "<change-folder>?<toggle-mailboxes><change-dir>$folder<enter>" "show incoming mailboxes list"
# Switch between accounts
macro index <f2> "<sync-mailbox><enter>source $XDG_CONFIG_HOME/mutt/account.info.nehrke_felix.muttrc<enter><change-folder>=INBOX<enter>"
macro index <f3> "<sync-mailbox><enter>source $XDG_CONFIG_HOME/mutt/account.com.gmail_nemoinho.muttrc<enter><change-folder>=INBOX<enter>"
# Source my default account
source "$XDG_CONFIG_HOME/mutt/account.info.nehrke_felix.muttrc"
#source "$XDG_CONFIG_HOME/mutt/account.com.gmail_nemoinho.muttrc"

View File

@@ -0,0 +1,43 @@
[general]
accounts = felix_nehrke_info_gmail,nemoinho_gmail
pythonfile = $XDG_CONFIG_HOME/offlineimap/utils.py
[Account felix_nehrke_info_gmail]
localrepository = felix_nehrke_info_gmail-Local
remoterepository = felix_nehrke_info_gmail-Remote
[Repository felix_nehrke_info_gmail-Local]
type = Maildir
localfolders = $XDG_STATE_HOME/offlineimap/felix_nehrke_info_gmail/
sep = /
[Repository felix_nehrke_info_gmail-Remote]
maxconnections = 2
type = Gmail
remoteuser = felix@nehrke.info
remotepasseval = get_gmail_pass("felix@nehrke.info")
realdelete = no
# Necessary for SSL connections, if using offlineimap version > 6.5.4
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
# Necessary to work around https://github.com/OfflineIMAP/offlineimap/issues/573 (versions 7.0.12, 7.2.1)
ssl_version = tls1_2
[Account nemoinho_gmail]
localrepository = nemoinho_gmail-Local
remoterepository = nemoinho_gmail-Remote
[Repository nemoinho_gmail-Local]
type = Maildir
localfolders = $XDG_STATE_HOME/offlineimap/nemoinho_gmail/
sep = /
[Repository nemoinho_gmail-Remote]
maxconnections = 2
type = Gmail
remoteuser = nemoinho@gmail.com
remotepasseval = get_gmail_pass("nemoinho@gmail.com")
realdelete = no
# Necessary for SSL connections, if using offlineimap version > 6.5.4
sslcacertfile = /etc/ssl/certs/ca-certificates.crt
# Necessary to work around https://github.com/OfflineIMAP/offlineimap/issues/573 (versions 7.0.12, 7.2.1)
ssl_version = tls1_2

View File

@@ -0,0 +1,5 @@
#!/usr/bin/env python
from subprocess import check_output
def get_gmail_pass(account):
return check_output("gmail-app-credentials pass " + account, shell=True).splitlines()[0]

2
.gitignore vendored
View File

@@ -1,2 +1,4 @@
README.*
!README.adoc
__pycache__

View File

@@ -0,0 +1,36 @@
#!/usr/bin/env bash
type="$1"
account="$2"
jq_chain="."
vault_type="text"
case "$type" in
pass)
jq_chain='select(.label == "gmail app-password") | .password'
;;
user)
jq_chain='select(.label == "gmail app-password") | .login'
;;
realname)
jq_chain='select(.label == "Real Name") | .password'
;;
email)
vault_type="email"
jq_chain='select(.password != "") | .password'
;;
smtp)
vault_type="email"
jq_chain='select(.password != "") | "smtp://" + .password + "@smtp.gmail.com:587/"'
;;
*)
exit 1
;;
esac
enpasscli \
-vault ~/Documents/Enpass/Vaults/primary \
-json \
--type "$vault_type" \
show "Google ($account)" \
| jq -r '.[] | '"$jq_chain"