From 9566ac53a429546b3f9c1ae5fca76edbd526865c Mon Sep 17 00:00:00 2001 From: Jens Luedicke Date: Mon, 8 Sep 2025 07:32:48 +0200 Subject: [PATCH] Tweaks for mail processing with mu4e --- mu4e-config.el | 63 +++++++++++++++++++++++++++++++++++++++++-------- process-mail.sh | 62 +++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 109 insertions(+), 16 deletions(-) diff --git a/mu4e-config.el b/mu4e-config.el index 3dab993..8855d33 100644 --- a/mu4e-config.el +++ b/mu4e-config.el @@ -2,7 +2,7 @@ ;; mu4e should already be loaded from .emacs before this file is loaded ;; If not loaded, try to load it -(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu4e/") +(add-to-list 'load-path "/opt/homebrew/Cellar/mu/1.12.12/share/emacs/site-lisp/mu/mu4e") (require 'mu4e) ;; HTML rendering configuration for mu4e 1.12 @@ -16,6 +16,14 @@ ;; (setq shr-width 80) ; 80 column width (setq shr-bullet "• ") ; Nice bullet +;; Increase font size in SHR (HTML rendering) +(defun my-shr-rescale-font () + "Increase font size in SHR rendered content." + (text-scale-set 1)) ; Increase by 1 step, adjust as needed (2, 3, etc.) + +;; Apply font scaling to mu4e HTML viewing +(add-hook 'mu4e-view-mode-hook 'my-shr-rescale-font) + ;; Create a custom command to view HTML with pandoc (defun mu4e-view-html-with-pandoc () "View the HTML part of the current message using pandoc." @@ -134,7 +142,7 @@ :key ?i) (:name "📰 Newsletters" - :query "(from:/newsletter|news|digest|update|weekly|daily|monthly|bulletin|announcement/ OR subject:/newsletter|digest|update|weekly|edition/) AND NOT flag:trashed AND NOT flag:flagged" + :query "(from:/nytimes|newyorktimes|atlantic|politico/ OR from:nytimes.com OR from:theatlantic.com OR from:politico.com OR from:politico.eu) AND NOT flag:trashed AND NOT flag:flagged" :key ?n) (:name "🛍️ Purchases & Orders" @@ -166,7 +174,7 @@ :query "list:std-discussion.lists.isocpp.org AND NOT flag:trashed" :key ?C) - (:name "📋 Qt Interest" + (:name "📋 Qt Interest" :query "list:interest.qt-project.org AND NOT flag:trashed" :key ?q) @@ -175,7 +183,7 @@ :key ?b) (:name "📋 GCC" - :query "list:gcc.gnu.gcc.org AND NOT flag:trashed" + :query "list:gcc.gcc.gnu.org AND NOT flag:trashed" :key ?G) (:name "📋 LKML" @@ -196,12 +204,47 @@ ("/IONOS/Drafts" . ?D) ("/IONOS/Archive" . ?A))) -;; UI Configuration - use default headers for now -;; (setq mu4e-headers-fields -;; '((:human-date . 12) -;; (:flags . 6) -;; (:from-or-to . 22) -;; (:subject))) +;; Custom function for fuzzy relative timestamps +(defun my-mu4e-format-date (date) + "Format DATE as a fuzzy relative time string." + (let* ((now (float-time)) + (time (float-time date)) + (diff (- now time)) + (sec diff) + (min (/ diff 60)) + (hour (/ diff 3600)) + (day (/ diff 86400)) + (week (/ diff 604800)) + (month (/ diff 2592000)) + (year (/ diff 31536000))) + (cond + ((< sec 60) "just now") + ((< min 2) "1 min ago") + ((< min 60) (format "%d mins ago" (truncate min))) + ((< hour 2) "1 hour ago") + ((< hour 24) (format "%d hours ago" (truncate hour))) + ((< day 2) "yesterday") + ((< day 7) (format "%d days ago" (truncate day))) + ((< week 2) "1 week ago") + ((< week 4) (format "%d weeks ago" (truncate week))) + ((< month 2) "1 month ago") + ((< month 12) (format "%d months ago" (truncate month))) + ((< year 2) "1 year ago") + (t (format "%d years ago" (truncate year)))))) + +;; Custom header field for fuzzy date +(add-to-list 'mu4e-header-info-custom + '(:fuzzy-date . (:name "Date" + :shortname "Date" + :function (lambda (msg) + (my-mu4e-format-date (mu4e-message-field msg :date)))))) + +;; UI Configuration - use fuzzy dates in headers +(setq mu4e-headers-fields + '((:fuzzy-date . 15) ; Fuzzy date with 15 char width + (:flags . 6) + (:from-or-to . 22) + (:subject))) ;; Make mu4e respect the current color theme (setq mu4e-view-use-gnus t) ; Use Gnus article mode for better theme support diff --git a/process-mail.sh b/process-mail.sh index 10a7f66..740d67b 100755 --- a/process-mail.sh +++ b/process-mail.sh @@ -6,6 +6,51 @@ MAILDIR="$HOME/Maildir" ARCHIVE_LISTS=true # Set to false if you don't want local date-based archives +# Function to fix List-Id headers for SimpleLogin forwarded messages +fix_list_headers() { + echo "Processing mailing list messages to fix List-Id headers..." + + local count=0 + local fixed=0 + + # Process all messages in Lists folder and subfolders + # This includes both /Personal/Lists/{new,cur} and /Personal/Lists/*/{new,cur} + find "$MAILDIR/Personal/Lists" -type f \( -path "*/new/*" -o -path "*/cur/*" \) | while read -r msg; do + ((count++)) + + # Check if this message has X-Simplelogin-Original-List-Id but no List-Id + if grep -q "^X-Simplelogin-Original-List-Id:" "$msg" 2>/dev/null && ! grep -q "^List-Id:" "$msg" 2>/dev/null; then + # Extract the original List-Id value + LIST_ID=$(grep "^X-Simplelogin-Original-List-Id:" "$msg" | sed 's/^X-Simplelogin-Original-List-Id: //') + + if [ -n "$LIST_ID" ]; then + # Create a temporary file with the new header + TEMP_FILE=$(mktemp) + + # Add List-Id header after the first occurrence of X-Simplelogin headers + awk -v list_id="$LIST_ID" ' + !added && /^X-Simplelogin-Original-List-Id:/ { + print "List-Id: " list_id + added = 1 + } + { print } + ' "$msg" > "$TEMP_FILE" + + # Replace the original file + mv "$TEMP_FILE" "$msg" + ((fixed++)) + + # Show progress every 100 messages + if [ $((fixed % 100)) -eq 0 ]; then + echo " Fixed $fixed messages so far..." + fi + fi + fi + done + + echo " Processed $count messages, fixed $fixed missing List-Id headers" +} + # Function to create date-based archive of Lists folder archive_lists() { if [ "$ARCHIVE_LISTS" != "true" ]; then @@ -84,22 +129,27 @@ if [ $SYNC_STATUS -ne 0 ]; then echo "This can be normal if some folders are not yet created on the server." fi -# Step 2: Create local archives (optional) +# Step 2: Fix List-Id headers for SimpleLogin forwarded messages +echo "" +echo "Step 2: Fixing List-Id headers for mailing lists..." +fix_list_headers + +# Step 3: Create local archives (optional) if [ "$ARCHIVE_LISTS" = "true" ]; then echo "" - echo "Step 2: Creating local date-based archives..." + echo "Step 3: Creating local date-based archives..." archive_lists else echo "" - echo "Step 2: Skipping local archives (disabled)" + echo "Step 3: Skipping local archives (disabled)" fi -# Step 3: Update mu index +# Step 4: Update mu index echo "" -echo "Step 3: Updating mu index..." +echo "Step 4: Updating mu index..." mu index --quiet -# Step 4: Show summary +# Step 5: Show summary echo "" echo "==========================================" echo "Mail Processing Complete: $(date)"