Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
From: mikael.svahnberg@gmail.com
To: info-gnus-english@gnu.org
Subject: Re: Display X-GM-LABELS in Summary Buffer/Artice Buffer
Date: Fri, 11 Oct 2013 04:26:20 -0700 (PDT)	[thread overview]
Message-ID: <763d665b-a1e3-49b3-8745-deceae885091@googlegroups.com> (raw)
In-Reply-To: <380faf10-e298-41cd-a0f4-9e94b7666689@googlegroups.com>

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

      parent reply	other threads:[~2013-10-11 11:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-23  9:20 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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=763d665b-a1e3-49b3-8745-deceae885091@googlegroups.com \
    --to=mikael.svahnberg@gmail.com \
    --cc=info-gnus-english@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).