I'm trying to patch mutt so that I can see each message's labels. The
gmail imap extension I want to use is described here:
http://code.google.com/apis/gmail/imap/#x-gm-labels
It seems like it would be easiest to just put the labels in the x-label
field. I started digging into the mutt code to implement this and
encountered some issues. The patch I've included does make the labels
appear in the message index if I include %y in the index_format setting,
but some seem to be encoded. I tried to figure out if I need to use
rfc2047_decode or something, but I haven't gotten anything to work so
far. Worse still, it segfaults when changing from the inbox to some (not
all) other imap folders.
Can anyone give me some suggestions? Am I going about this the
completely wrong way?
diff -udprP mutt-1.5.21/imap/message.c mutt-1.5.21-patched/imap/message.c
--- mutt-1.5.21/imap/message.c 2010-08-24 09:34:21.000000000 -0700
+++ mutt-1.5.21-patched/imap/message.c 2012-01-29 00:05:29.000000000 -0700
@@ -242,7 +242,7 @@ int imap_read_headers (IMAP_DATA* idata,
char *cmd;
fetchlast = msgend + 1;
- safe_asprintf (&cmd, "FETCH %d:%d (UID FLAGS INTERNALDATE RFC822.SIZE
%s)",
+ safe_asprintf (&cmd, "FETCH %d:%d (UID FLAGS INTERNALDATE RFC822.SIZE
X-GM-LABELS %s)",
msgno + 1, fetchlast, hdrreq);
imap_cmd_start (idata, cmd);
FREE (&cmd);
@@ -320,6 +320,7 @@ int imap_read_headers (IMAP_DATA* idata,
0, 0);
/* content built as a side-effect of mutt_read_rfc822_header */
ctx->hdrs[idx]->content->length = h.content_length;
+ ctx->hdrs[idx]->env->x_label = h.data->labels;
ctx->size += h.content_length;
#if USE_HCACHE
@@ -1128,6 +1129,7 @@ static int msg_fetch_header (CONTEXT* ct
static int msg_parse_fetch (IMAP_HEADER *h, char *s)
{
char tmp[SHORT_STRING];
+ char buffer[LONG_STRING];
char *ptmp;
if (!s)
@@ -1137,6 +1139,22 @@ static int msg_parse_fetch (IMAP_HEADER
{
SKIPWS (s);
+ if (ascii_strncasecmp ("X-GM-LABELS", s, 11) == 0)
+ {
+ s += 11;
+ SKIPWS (s);
+ ptmp = buffer;
+ s++; /* skip ( */
+ while (*s && *s != ')')
+ *ptmp++ = *s++;
+ if (*s != ')')
+ return -1;
+ s++; /* skip ) */
+ *ptmp = 0;
+ h->data->labels = buffer;
+ SKIPWS (s);
+ }
+
if (ascii_strncasecmp ("FLAGS", s, 5) == 0)
{
if ((s = msg_parse_flags (h, s)) == NULL)
diff -udprP mutt-1.5.21/imap/message.h mutt-1.5.21-patched/imap/message.h
--- mutt-1.5.21/imap/message.h 2009-01-05 12:20:53.000000000 -0700
+++ mutt-1.5.21-patched/imap/message.h 2012-01-28 21:51:44.000000000 -0700
@@ -37,6 +37,8 @@ typedef struct imap_header_data
unsigned int parsed : 1;
unsigned int uid; /* 32-bit Message UID */
+ char *labels;
+
LIST *keywords;
} IMAP_HEADER_DATA;