maxk
maxk

Reputation: 642

how to get x-gm-labels for email

I am trying to understand how can I get gmail labels (x-gm-labels) for an email in C. I checked, that builds of libetpan support x-gm-labels extension.

Any idea how to write a sample code to put it all together?

Upvotes: 1

Views: 1298

Answers (2)

MrGomez
MrGomez

Reputation: 23886

Got it. From tracing this check-in from the original author, I discovered the code welded into the default handling behavior of libetpan's IMAP support.

Well, it turns out the author provides an example of how to set up an IMAP connection successfully. Instead of spooling out all of the code, here's the bit you should be concerned with:

static char * get_msg_att_msg_content(struct mailimap_msg_att * msg_att,
  size_t * p_msg_size)
{
    clistiter * cur;

    /* iterate on each result of one given message */
    for(cur = clist_begin(msg_att->att_list) ; cur != NULL ;
      cur = clist_next(cur)) {
        struct mailimap_msg_att_item * item;

        item = clist_content(cur);
        if (item->att_type != MAILIMAP_MSG_ATT_ITEM_STATIC) {
            continue;
        }

    ...

According to my backtrace of the code, your ticket is struct mailimap_msg_att_item. The att_type you're looking for here is MAILIMAP_MSG_ATT_ITEM_EXTENSION, and from there, you should walk the data structures until you find MAILIMAP_EXTENSION_XGMLABELS.

Something like this should isolate them:

if (item->att_type == MAILIMAP_MSG_ATT_ITEM_EXTENSION) {
    if (item->att_data.att_extension_data->ext_type == 
      MAILIMAP_EXTENSION_XGMLABELS) {
        // ... do something ...
    }
}

(Warning: untested code.)

From here, you can perform more deeply interrogative inspection of the structs being used. The salient files are all contained in src/low-level/imap, except for the test file. Good luck!

Upvotes: 3

Voislav Sauca
Voislav Sauca

Reputation: 3075

There are a lot of IMAP extensions .. see Gmail IMAP Extensions and Gmail Labels

a few examples:

List all Gmail labels

Label message with Gmail system label

Also check the comment of MrGomez that gives a good explination about the functionality that you're asking.

Upvotes: 0

Related Questions