Question: Gmail how display imap folder in gnus?

11 views
Skip to first unread message

physiculus

unread,
Jul 29, 2019, 12:58:23 PM7/29/19
to gnus
Hello,

i created several imap folders inside my Gmail account. i use them to
save my mails with splitting.
As usual if i view Gmail folder "All Messages" i see all my mails. So
far so good.
Is it possible to see the "folder" name from my Gmail account in
gnus-summary-line during inside "All Messages" folder?
Or is it nearly impossible, because "folder" names are tags in real.

Regards
Poul


Lars Ingebrigtsen

unread,
Sep 16, 2019, 4:37:51 PM9/16/19
to physiculus, gnus
physiculus <physi...@gmail.com> writes:

> Is it possible to see the "folder" name from my Gmail account in
> gnus-summary-line during inside "All Messages" folder?
> Or is it nearly impossible, because "folder" names are tags in real.

Hm... I think that sounds difficult to achieve (unless Gmail puts that
data in the message headers; I don't know.

--
(domestic pets only, the antidote for overdose, milk.)
bloggy blog: http://lars.ingebrigtsen.no

mikael.s...@gmail.com

unread,
Jun 24, 2020, 1:45:51 AM6/24/20
to
Hi,

Only one year after your original post (that tells you how often I frequent this group -- sadly). Here is what I do:


;; --------------------
;; Display GMail labels in Summary
;; --------------------
(setq gmail-label-length 1)

(defun gmail-parse-labels (lbls)
(if (not (= (length lbls) 0))
(let ((lbl (car lbls)))
(setq lbl (replace-regexp-in-string "[\"\(\)]" "" lbl))
(if (not (= (length lbl) 0))
(if (not (string= (substring lbl 0 1) "\\"))
(concat
(substring lbl 0 gmail-label-length)
(gmail-parse-labels (cdr lbls))
)
(gmail-parse-labels (cdr lbls)) ;; Else, just go for the next label
)
(gmail-parse-labels (cdr lbls)) ;; Else, just go for the next label (to be on the safe side)
)
)
)
)

(defun nnimap-fetch-gmail-labels (number)
;;(message "Requesting Gmail labels for message #%s..." number)
(with-current-buffer (nnimap-buffer)
(let ((result (nnimap-command "UID FETCH %d (%s)" number 'X-GM-LABELS))
lbls lbl)
;; This gives me a response looking like
;; (t (OK Success) (11 FETCH (X-GM-LABELS ("\\Important" "\\Starred") UID 12641)))
;; (message "Result: %s" result)
(setq lbls (nthcdr 2 result))
(setq lbls (nthcdr 2 (car lbls)))
(setq lbls (nthcdr 1 (car lbls)))
(gmail-parse-labels lbls)
)))

(defun gnus-user-format-function-g (headers)
(concat
(if (boundp 'group)
(if (string= group "INBOX")
(nnimap-fetch-gmail-labels number)
(concat "-")))
"")
)


Summary: I use a "user-format-function" to get the data into the line for each e-mail (Relevant part of gnus-summary-line-format is "%2,2ug"). I use very few labels so one letter is sufficient for me.

Cave: This was, I think, my first ever foray into elisp and I haven't touched this in maybe eight years. There is a metric ton of refactorings that could be made.

/Mikael

mikael.s...@gmail.com

unread,
Jun 26, 2020, 5:39:12 AM6/26/20
to
On Monday, 29 July 2019 18:58:23 UTC+2, physiculus wrote:
... And now that I had a reason to revisit this; the following is even reasonably quick since I don't have to refetch every message again (clues were already in the gnus doc, but putting the doc to practice is as usual an exercise left to the reader):

(setq gnus-extra-headers '(To Cc Content-Type X-GM-LABELS))
(setq nnmail-extra-headers gnus-extra-headers)
(setq gmail-label-length 1)

(defun gmail-filter-shorten-labels (lbls)
(mapconcat (lambda (item)
(setq item (replace-regexp-in-string "[()]" "" item))
(unless (string= "\\" (substring item 0 1))
(substring item 0 gmail-label-length))) (split-string lbls) ""))

;; <2020-06-26 Fri> Playing with a maybe simpler way of displaying gmail headers
(defun gnus-user-format-function-m (header)
"Display gmail labels. Requires nnmail-extra-headers to include X-GM-LABELS"
(gmail-filter-shorten-labels (gnus-extra-header 'X-GM-LABELS)))



/M
Reply all
Reply to author
Forward
0 new messages