config/emacs: terrible

This commit is contained in:
Sakooooo 2024-09-25 11:49:55 +04:00
parent d235c7f66c
commit 6a2a914ec4
Signed by: sako
GPG key ID: 3FD715D87D7725E0

View file

@ -1162,6 +1162,102 @@ GNU patch review metho dor sometihng idk
;; sending mail
(setq message-send-mail-function 'smtpmail-send-it)
;; refresh token for stmpmail
(cl-defmethod smtpmail-try-auth-method
(process (_mech (eql xoauth2)) user password)
(cond
((or (equal user ,outlook-mail-address ))
;; from https://github.com/UvA-FNWI/M365-IMAP/issues/3
(let ((token (gethash "access_token"
(let ((url-request-method "POST")
(url-request-extra-headers `(("Content-Type" . "application/x-www-form-urlencoded")))
(url-request-data (concat "client_id=" "9e5f94bc-e8a4-4e73-b8be-63364c29d753")
"&client_secret="
"&refresh_token=" (password-store-get-field "Microsoft" "client_refresh_token")
"&grant_type=refresh_token")))
(with-temp-buffer (url-insert-file-contents
"https://login.microsoftonline.com/common/oauth2/v2.0/token")
(json-parse-buffer :object-type 'hash-table)))
)))
(smtpmail-command-or-throw
process
(concat "AUTH XOAUTH2 "
(base64-encode-string
(concat "user=" user "\1auth=Bearer " token "\1\1") t)))))
((equal user ,gmail-1-mail-address)
(let ((token (gethash "access_token"
(let ((url-request-method "POST")
(url-request-extra-headers `(("Content-Type" . "application/x-www-form-urlencoded")))
(url-request-data (concat "client_id=" (password-store-get-field "email/oauth/gmail" "client_id")
"&client_secret=" (password-store-get-field "email/oauth/gmail" "client_secret")
"&refresh_token=" (password-store-get-field "accounts.google.com/one" "client_refresh_token")
"&grant_type=refresh_token")))
(with-temp-buffer (url-insert-file-contents
"https://oauth2.googleapis.com/token")
(json-parse-buffer :object-type 'hash-table)))
)))
(smtpmail-command-or-throw
process
(concat "AUTH XOAUTH2 "
(base64-encode-string
(concat "user=" user "\1auth=Bearer " token "\1\1") t)))))
((equal user ,gmail-2-mail-address)
(let ((token (gethash "access_token"
(let ((url-request-method "POST")
(url-request-extra-headers `(("Content-Type" . "application/x-www-form-urlencoded")))
(url-request-data (concat "client_id=" (password-store-get-field "email/oauth/gmail" "client_id")
"&client_secret=" (password-store-get-field "email/oauth/gmail" "client_secret")
"&refresh_token=" (password-store-get-field "accounts.google.com/two" "client_refresh_token")
"&grant_type=refresh_token")))
(with-temp-buffer (url-insert-file-contents
"https://oauth2.googleapis.com/token")
(json-parse-buffer :object-type 'hash-table)))
)))
(smtpmail-command-or-throw
process
(concat "AUTH XOAUTH2 "
(base64-encode-string
(concat "user=" user "\1auth=Bearer " token "\1\1") t)))))
((equal user ,gmail-1-mail-address)
(let ((token (gethash "access_token"
(let ((url-request-method "POST")
(url-request-extra-headers `(("Content-Type" . "application/x-www-form-urlencoded")))
(url-request-data (concat "client_id=" (password-store-get-field "email/oauth/gmail" "client_id")
"&client_secret=" (password-store-get-field "email/oauth/gmail" "client_secret")
"&refresh_token=" (password-store-get-field "accounts.google.com/two" "client_refresh_token")
"&grant_type=refresh_token")))
(with-temp-buffer (url-insert-file-contents
"https://oauth2.googleapis.com/token")
(json-parse-buffer :object-type 'hash-table)))
)))
(smtpmail-command-or-throw
process
(concat "AUTH XOAUTH2 "
(base64-encode-string
(concat "user=" user "\1auth=Bearer " token "\1\1") t)))))
((equal user ,gmail-2-mail-address)
(let ((token (gethash "access_token"
(let ((url-request-method "POST")
(url-request-extra-headers `(("Content-Type" . "application/x-www-form-urlencoded")))
(url-request-data (concat "client_id=" (password-store-get-field "email/oauth/gmail" "client_id")
"&client_secret=" (password-store-get-field "email/oauth/gmail" "client_secret")
"&refresh_token=" (password-store-get-field "accounts.google.com/one" "client_refresh_token")
"&grant_type=refresh_token")))
(with-temp-buffer (url-insert-file-contents
"https://oauth2.googleapis.com/token")
(json-parse-buffer :object-type 'hash-table)))
)))
(smtpmail-command-or-throw
process
(concat "AUTH XOAUTH2 "
(base64-encode-string
(concat "user=" user "\1auth=Bearer " token "\1\1") t)))))
(t nil)))
(setq mu4e-update-interval (* 10 60))
(setq mu4e-get-mail-command "offlineimap")
(setq mu4e-maildir "~/Mail")
@ -1177,7 +1273,7 @@ GNU patch review metho dor sometihng idk
(setq output (string-trim output))
(setq proton-mail-address (concat "@proton.me" output))))
(get-proton-mail-address-from-pass "pass Proton Account | awk 'BEGIN {ORS=\"\"} FNR == 2{gsub(\"login: \", \"\"); gsub(/ /, \"\"); print}'")
(get-proton-mail-address-from-pass "pass 'Proton Account' | awk 'BEGIN {ORS=\"\"} FNR == 2{gsub(\"login: \", \"\"); gsub(/ /, \"\"); print}'")
(setq gmail-1-mail-address
(string-trim (shell-command-to-string "pass accounts.google.com/one | awk 'BEGIN {ORS=\"\"} FNR == 2{gsub(\"login: \", \"\"); gsub(/ /, \"\"); print}'")))