Discussion:
Question: Gmail how display imap folder in gnus?
(too old to reply)
physiculus
2019-07-29 16:58:14 UTC
Permalink
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
2019-09-16 20:37:38 UTC
Permalink
Post by physiculus
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
m***@gmail.com
2020-06-24 05:45:50 UTC
Permalink
Post by physiculus
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
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
m***@gmail.com
2020-06-26 09:39:11 UTC
Permalink
Post by physiculus
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
... 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

Loading...