Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* Display X-GM-LABELS in Summary Buffer/Artice Buffer
@ 2013-09-23  9:20 mikael.svahnberg
  2013-10-11  9:41 ` mikael.svahnberg
  0 siblings, 1 reply; 4+ messages in thread
From: mikael.svahnberg @ 2013-09-23  9:20 UTC (permalink / raw)
  To: info-gnus-english

Hi,

Are there any ready-made scripts that will allow me to display the labels already attached to a (gmail) message?

Preferrably, I would like it to be shown as a header line in the article buffer, but perhaps also as a user-defined field in the summary buffer.

/Mikael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Display X-GM-LABELS in Summary Buffer/Artice Buffer
  2013-09-23  9:20 Display X-GM-LABELS in Summary Buffer/Artice Buffer mikael.svahnberg
@ 2013-10-11  9:41 ` mikael.svahnberg
  2013-10-11 10:34   ` Rainer M Krug
  2013-10-11 11:26   ` mikael.svahnberg
  0 siblings, 2 replies; 4+ messages in thread
From: mikael.svahnberg @ 2013-10-11  9:41 UTC (permalink / raw)
  To: info-gnus-english

On Monday, 23 September 2013 11:20:00 UTC+2, mikael.s...@gmail.com  wrote:
> Hi,
> 
> 
> 
> Are there any ready-made scripts that will allow me to display the labels already attached to a (gmail) message?
> 
> 
> 
> Preferrably, I would like it to be shown as a header line in the article buffer, but perhaps also as a user-defined field in the summary buffer.
> 
> 
> 
> /Mikael

There I was with a successful research career when on a whim I decided to read my emails in gnus. "Join the hurd", they said. "See the world", they said.

This is my first foray into lisp, so I beg for some indulgence. Also, it ought to be possible to speed things up by requesting the labels for all messages in one go and then sort things out, but at least it does something like showing the gmail labels.

;; ---
(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
   (nnimap-fetch-gmail-labels number)
   ""
   ))
;; ---

/Mikael

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Display X-GM-LABELS in Summary Buffer/Artice Buffer
  2013-10-11  9:41 ` mikael.svahnberg
@ 2013-10-11 10:34   ` Rainer M Krug
  2013-10-11 11:26   ` mikael.svahnberg
  1 sibling, 0 replies; 4+ messages in thread
From: Rainer M Krug @ 2013-10-11 10:34 UTC (permalink / raw)
  To: info-gnus-english

mikael.svahnberg@gmail.com writes:

> On Monday, 23 September 2013 11:20:00 UTC+2, mikael.s...@gmail.com  wrote:

[snip:  some stuff (15 lines)]
>
> There I was with a successful research career when on a whim I decided
> to read my emails in gnus. "Join the hurd", they said. "See the
> world", they said.
>

I like this - very true.

Rainer


[snip: Some code  (42 lines)]

> ;; ---
>
> /Mikael
<#secure method=pgpmime mode=sign>

-- 
Rainer M. Krug

email: RMKrug<at>gmail<dot>com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Display X-GM-LABELS in Summary Buffer/Artice Buffer
  2013-10-11  9:41 ` mikael.svahnberg
  2013-10-11 10:34   ` Rainer M Krug
@ 2013-10-11 11:26   ` mikael.svahnberg
  1 sibling, 0 replies; 4+ messages in thread
From: mikael.svahnberg @ 2013-10-11 11:26 UTC (permalink / raw)
  To: info-gnus-english

On Friday, 11 October 2013 11:41:59 UTC+2, mikael.s...@gmail.com  wrote:
> On Monday, 23 September 2013 11:20:00 UTC+2, mikael.s...@gmail.com  wrote:
> 
> > Hi,
> 
> > 
> 
> > 
> 
> > 
> 
> > Are there any ready-made scripts that will allow me to display the labels already attached to a (gmail) message?
> 
> > 
> 
> > 
> 
> > 
> 
> > Preferrably, I would like it to be shown as a header line in the article buffer, but perhaps also as a user-defined field in the summary buffer.
> 
> > 
> 
> > 
> 
> > 
> 
> > /Mikael
> 
> 
> 
> There I was with a successful research career when on a whim I decided to read my emails in gnus. "Join the hurd", they said. "See the world", they said.
> 
> 
> 
> This is my first foray into lisp, so I beg for some indulgence. Also, it ought to be possible to speed things up by requesting the labels for all messages in one go and then sort things out, but at least it does something like showing the gmail labels.
> 
> 
> 
> ;; ---
> 
> (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
> 
>    (nnimap-fetch-gmail-labels number)
> 
>    ""
> 
>    ))
> 
> ;; ---
> 
> 
> 
> /Mikael

... And immediately I realised that if I do this on the "All Mail" group, I will kill emacs, imap, and myself before getting to the list of mails. The main reason for why I wanted to display the labels in the first place was so that I would not have to re-label all mails whenever I was done with them and wanted to archive them away from the inbox. Hence, it makes (most) sense to use this in the INBOX group:

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

/Mikael

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-10-11 11:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-23  9:20 Display X-GM-LABELS in Summary Buffer/Artice Buffer mikael.svahnberg
2013-10-11  9:41 ` mikael.svahnberg
2013-10-11 10:34   ` Rainer M Krug
2013-10-11 11:26   ` mikael.svahnberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).