From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.user/16543 Path: news.gmane.org!not-for-mail From: mikael.svahnberg@gmail.com Newsgroups: gmane.emacs.gnus.user Subject: Re: Display X-GM-LABELS in Summary Buffer/Artice Buffer Date: Fri, 11 Oct 2013 04:26:20 -0700 (PDT) Message-ID: <763d665b-a1e3-49b3-8745-deceae885091@googlegroups.com> References: <380faf10-e298-41cd-a0f4-9e94b7666689@googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1381491002 23367 80.91.229.3 (11 Oct 2013 11:30:02 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 11 Oct 2013 11:30:02 +0000 (UTC) To: info-gnus-english@gnu.org Original-X-From: info-gnus-english-bounces+gegu-info-gnus-english=m.gmane.org@gnu.org Fri Oct 11 13:30:07 2013 Return-path: Envelope-to: gegu-info-gnus-english@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VUav0-0005lR-Et for gegu-info-gnus-english@m.gmane.org; Fri, 11 Oct 2013 13:30:06 +0200 Original-Received: from localhost ([::1]:53689 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUav0-0000Qk-1L for gegu-info-gnus-english@m.gmane.org; Fri, 11 Oct 2013 07:30:06 -0400 X-Received: by 10.236.167.138 with SMTP id i10mr19703518yhl.9.1381490780988; Fri, 11 Oct 2013 04:26:20 -0700 (PDT) X-Received: by 10.49.48.68 with SMTP id j4mr145436qen.13.1381490780964; Fri, 11 Oct 2013 04:26:20 -0700 (PDT) Original-Path: usenet.stanford.edu!i2no6257509qav.0!news-out.google.com!9ni29475qaf.0!nntp.google.com!i2no6257508qav.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.gnus In-Reply-To: <380faf10-e298-41cd-a0f4-9e94b7666689@googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=213.67.233.187; posting-account=IOBunwoAAACfl5iZYKlvkMNaEfd0O_mW Original-NNTP-Posting-Host: 213.67.233.187 User-Agent: G2/1.0 Injection-Date: Fri, 11 Oct 2013 11:26:20 +0000 Original-Xref: usenet.stanford.edu gnu.emacs.gnus:87670 X-BeenThere: info-gnus-english@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Announcements and discussions for GNUS, the GNU Emacs Usenet newsreader \(in English\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: info-gnus-english-bounces+gegu-info-gnus-english=m.gmane.org@gnu.org Original-Sender: info-gnus-english-bounces+gegu-info-gnus-english=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.gnus.user:16543 Archived-At: 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