]> git.eshelyaron.com Git - dotfiles.git/commitdiff
Update Emacs configuration
authorEshel Yaron <me@eshelyaron.com>
Fri, 25 Aug 2023 17:03:18 +0000 (19:03 +0200)
committerEshel Yaron <me@eshelyaron.com>
Fri, 25 Aug 2023 17:03:18 +0000 (19:03 +0200)
.emacs.d/init.el

index fd7d3d5816605d89036f7747b587bbbadf683791..106f2f0453b58f60c7da2f946dcf86e73e25c58c 100644 (file)
          :repo "git://git.eshelyaron.com/esy-publish.git"))
 (elpaca embark-consult)
 (elpaca emms)
+;; (elpaca expreg)
 (elpaca gnu-elpa-keyring-update)
+;; (elpaca (gnus-o365-oauth2
+;;          :repo "https://gitlab.com/qha/gnus-o365-oauth2.git"))
 (elpaca graphql-mode)
 (elpaca htmlize)
 (elpaca ialign)
 (elpaca keycast)
 (elpaca kubernetes)
+(elpaca (oauth2
+         :repo "git://git.sv.gnu.org/emacs/elpa"
+         :local-repo "oauth2"
+         :branch "externals/oauth2"))
 (elpaca (ledger-mode
          :files (:defaults)))
 (elpaca (lin
 (elpaca orderless)
 (elpaca org)
 (elpaca org-transclusion)
+(elpaca (marginalia
+         :pre-build (("emacs" "--batch" "-l" "ox-texinfo" "README.org"
+                      "--eval" "(setq org-babel-confirm-evaluate-answer-no t)"
+                      "-f" "org-texinfo-export-to-texinfo"))
+         :repo "https://github.com/minad/marginalia.git"))
+;; (elpaca (org-glossary
+;;          :repo "https://github.com/tecosaur/org-glossary.git"
+;;          :files ("org-glossary.el" "org-glossary.texi")))
 (elpaca (osm
          :pre-build (("emacs" "--batch" "-l" "ox-texinfo" "README.org"
                       "--eval" "(setq org-babel-confirm-evaluate-answer-no t)"
                       "--entry" "* vterm::"
                       "--section=Emacs" "--dir=dir" "vterm.info"))))
 (elpaca whitespace-cleanup-mode)
+;; (elpaca (xref-union
+;;          :repo "https://git.sr.ht/~pkal/xref-union"
+;;          :pre-build (("pandoc" "-o" "xref-union.texi" "README.md"))))
 
 (elpaca-wait)
 
                                    587
                                    "me@eshelyaron.com"
                                    starttls nil nil nil))
-                           ;; (uva  . ("eshel.yaron@student.uva.nl"
-                           ;;         "smtp.office365.com"
-                           ;;         587
-                           ;;         "eshel.yaron@student.uva.nl"
-                           ;;         starttls nil nil nil))
-                           )
+                           (uva  . ("eshel.yaron@student.uva.nl"
+                                   "smtp.office365.com"
+                                   587
+                                   "eshel.yaron@student.uva.nl"
+                                   starttls nil nil nil)))
  ;; associate email addresses with SMTP accounts
  smtpmail-multi-associations '(("eshelshay\.yaron@gmail\.com"   esy)
                                ("eshel@swi-prolog\.org"         swp)
                                ("me@eshelyaron\.com"             me)
-                               ;; ("eshel\.yaron@student\.uva\.nl" uva)
-                               )
+                               ("eshel\.yaron@student\.uva\.nl" uva))
  ;; set function for sending email
  send-mail-function #'smtpmail-multi-send-it
  message-send-mail-function #'smtpmail-multi-send-it
                                          (nnimap-address "mail.swi-prolog.com")
                                          (nnimap-server-port "imaps")
                                          (nnimap-stream ssl))
-                                 ;; (nnimap "uva"
-                                 ;;         (nnimap-address "outlook.office365.com")
-                                 ;;         (nnimap-server-port "imaps")
-                                 ;;         (nnimap-stream ssl))
+                                 (nnimap "uva"
+                                         (nnimap-address "outlook.office365.com")
+                                         (nnimap-server-port "imaps")
+                                         (nnimap-stream ssl)
+                                         (nnimap-authenticator xoauth2))
                                  )
  ;; simpler message
  gnus-no-groups-message "No new articles"
@@ -1115,11 +1132,43 @@ as the initial input for completion, and return that directory."
   (add-to-list 'org-agenda-custom-commands
                '("h" "Holland TODOs" tags-todo "+holland")))
 
+;;; Outlook OAuth 2.0 setup
+
+(defvar esy/o365-token-last-refresh-time 0)
+(defvar esy/o365-token-directory "~/checkouts/M365-IMAP/")
+
+(add-to-list 'auth-sources (expand-file-name ".authinfo"
+                                             esy/o365-token-directory))
+
+(add-to-list 'savehist-additional-variables 'esy/o365-token-last-refresh-time)
+
+(defun esy/refresh-o365-token ()
+  (interactive)
+  (files--ensure-directory esy/o365-token-directory)
+  (when-let ((default-directory esy/o365-token-directory)
+             (token (car (process-lines "python3" "refresh_token.py"))))
+    (with-temp-buffer
+      (insert "machine smtp.office365.com smtp-auth xoauth2 login eshel.yaron@student.uva.nl port 587 password \""
+              token
+              "\"\nmachine outlook.office365.com login eshel.yaron@student.uva.nl port imaps password \""
+              token
+              "\"\n")
+      (write-region (point-min) (point-max) ".authinfo"))
+    (auth-source-forget-all-cached)))
+
+(defun esy/maybe-refresh-o365-token ()
+  (let ((now (float-time)))
+    (when (< (* 60 45) (- now esy/o365-token-last-refresh-time))
+      (esy/refresh-o365-token)
+      (setq esy/o365-token-last-refresh-time now))))
+
 ;;; Configure email via `gnus'
 
 (with-eval-after-load 'gnus
   (require 'gnus-icalendar)
   (add-hook 'gnus-group-mode-hook #'gnus-topic-mode)
+  (add-hook 'gnus-before-resume-hook #'esy/maybe-refresh-o365-token)
+  (add-hook 'gnus-before-startup-hook #'esy/maybe-refresh-o365-token)
   (gnus-icalendar-setup)
   (gnus-icalendar-org-setup)
   (bbdb-initialize 'gnus 'mail 'message))
@@ -1249,6 +1298,7 @@ as the initial input for completion, and return that directory."
                 global-diff-hl-mode
                 global-whitespace-cleanup-mode
                 lin-global-mode
+                marginalia-mode
                 minibuffer-depth-indicate-mode
                 mouse-avoidance-mode
                 pixel-scroll-precision-mode