From b82c5857364a129c30e1f483763412141792d88b Mon Sep 17 00:00:00 2001 From: Mehdi Abaakouk Date: Wed, 20 Sep 2017 14:54:06 +0200 Subject: [PATCH] tags: don't depends on header.c --- copy.c | 2 +- curs_main.c | 2 +- hdrline.c | 16 ++++----- header.h | 3 +- imap/imap.c | 10 +++--- imap/message.c | 10 +++--- mutt_notmuch.c | 14 ++++---- mutt_tags.c | 89 ++++++++++++++++++++++++-------------------------- mutt_tags.h | 30 ++++++++--------- muttlib.c | 2 +- pattern.c | 2 +- 11 files changed, 88 insertions(+), 92 deletions(-) diff --git a/copy.c b/copy.c index c4300c5d6..f3ceaa70a 100644 --- a/copy.c +++ b/copy.c @@ -465,7 +465,7 @@ int mutt_copy_header(FILE *in, struct Header *h, FILE *out, int flags, const cha fputs(buf, out); fputc('\n', out); } - const char *tags = driver_tags_get(h); + const char *tags = driver_tags_get(h->tags); if (tags && !(option(OPT_WEED) && mutt_matches_ignore("tags"))) { fputs("Tags: ", out); diff --git a/curs_main.c b/curs_main.c index 9298b9e29..85fdcc2a5 100644 --- a/curs_main.c +++ b/curs_main.c @@ -1866,7 +1866,7 @@ int mutt_index_menu(void) CHECK_VISIBLE; CHECK_READONLY; - rc = mx_tags_editor(Context, tag ? NULL : driver_tags_get_with_hidden(CURHDR), buf, sizeof(buf)); + rc = mx_tags_editor(Context, tag ? NULL : driver_tags_get_with_hidden(CURHDR->tags), buf, sizeof(buf)); if (rc < 0) break; else if (rc == 0) diff --git a/hdrline.c b/hdrline.c index d3bd88e67..7b96913bf 100644 --- a/hdrline.c +++ b/hdrline.c @@ -845,10 +845,10 @@ static const char *hdr_format_str(char *dest, size_t destlen, size_t col, int co { colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_TAGS); mutt_format_s(dest + colorlen, destlen - colorlen, prefix, - driver_tags_get_transformed(hdr)); + driver_tags_get_transformed(hdr->tags)); add_index_color(dest + colorlen, destlen - colorlen, flags, MT_COLOR_INDEX); } - else if (!driver_tags_get_transformed(hdr)) + else if (!driver_tags_get_transformed(hdr->tags)) optional = 0; break; @@ -866,7 +866,7 @@ static const char *hdr_format_str(char *dest, size_t destlen, size_t col, int co tag = hash_find(TagFormats, format); if (tag) { - tag_transformed = driver_tags_get_transformed_for(tag, hdr); + tag_transformed = driver_tags_get_transformed_for(tag, hdr->tags); colorlen = add_index_color(dest, destlen, flags, MT_COLOR_INDEX_TAG); mutt_format_s(dest + colorlen, destlen - colorlen, prefix, (tag_transformed) ? tag_transformed : ""); @@ -882,7 +882,7 @@ static const char *hdr_format_str(char *dest, size_t destlen, size_t col, int co tag = hash_find(TagFormats, format); if (tag) - if (driver_tags_get_transformed_for(tag, hdr) == NULL) + if (driver_tags_get_transformed_for(tag, hdr->tags) == NULL) optional = 0; } break; @@ -904,7 +904,7 @@ static const char *hdr_format_str(char *dest, size_t destlen, size_t col, int co break; case 'J':; - const char *tags = driver_tags_get_transformed(hdr); + const char *tags = driver_tags_get_transformed(hdr->tags); if (tags) { i = 1; /* reduce reuse recycle */ @@ -912,13 +912,13 @@ static const char *hdr_format_str(char *dest, size_t destlen, size_t col, int co if (flags & MUTT_FORMAT_TREE && (hdr->thread->prev && hdr->thread->prev->message && - driver_tags_get_transformed(hdr->thread->prev->message))) + driver_tags_get_transformed(hdr->thread->prev->message->tags))) htmp = hdr->thread->prev->message; else if (flags & MUTT_FORMAT_TREE && (hdr->thread->parent && hdr->thread->parent->message && - driver_tags_get_transformed(hdr->thread->parent->message))) + driver_tags_get_transformed(hdr->thread->parent->message->tags))) htmp = hdr->thread->parent->message; - if (htmp && mutt_strcasecmp(tags, driver_tags_get_transformed(htmp)) == 0) + if (htmp && mutt_strcasecmp(tags, driver_tags_get_transformed(htmp->tags)) == 0) i = 0; } else diff --git a/header.h b/header.h index f476a2cf7..278ff3e6f 100644 --- a/header.h +++ b/header.h @@ -28,6 +28,7 @@ #include #include "lib/lib.h" #include "list.h" +#include "mutt_tags.h" /** * struct Header - The header/envelope of an email @@ -108,7 +109,7 @@ struct Header int refno; /**< message number on server */ #endif - struct HeaderTags *tags; /**< for drivers that support server tagging */ + struct TagHead *tags; /**< for drivers that support server tagging */ #if defined(USE_POP) || defined(USE_IMAP) || defined(USE_NNTP) || defined(USE_NOTMUCH) void *data; /**< driver-specific data */ void (*free_cb)(struct Header *); /**< driver-specific data free function */ diff --git a/imap/imap.c b/imap/imap.c index 5cc37763e..cb06916e4 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1172,8 +1172,8 @@ int imap_sync_message_for_copy(struct ImapData *idata, struct Header *hdr, if (HEADER_DATA(hdr)->flags_system) safe_strcat(flags, sizeof(flags), HEADER_DATA(hdr)->flags_system); /* set custom flags */ - if (driver_tags_get_with_hidden(hdr)) - safe_strcat(flags, sizeof(flags), driver_tags_get_with_hidden(hdr)); + if (driver_tags_get_with_hidden(hdr->tags)) + safe_strcat(flags, sizeof(flags), driver_tags_get_with_hidden(hdr->tags)); } mutt_remove_trailing_ws(flags); @@ -1221,7 +1221,7 @@ int imap_sync_message_for_copy(struct ImapData *idata, struct Header *hdr, /* server have now the updated flags */ FREE(&HEADER_DATA(hdr)->flags_remote); - HEADER_DATA(hdr)->flags_remote = safe_strdup(driver_tags_get_with_hidden(hdr)); + HEADER_DATA(hdr)->flags_remote = safe_strdup(driver_tags_get_with_hidden(hdr->tags)); hdr->active = true; if (hdr->deleted == HEADER_DATA(hdr)->deleted) @@ -1427,9 +1427,9 @@ static int imap_commit_message_tags(struct Context *ctx, struct Header *h, char /* We are good sync them */ mutt_debug(1, "NEW TAGS: %d\n", tags); - driver_tags_replace(h, tags); + driver_tags_replace(h->tags, tags); FREE(&HEADER_DATA(h)->flags_remote); - HEADER_DATA(h)->flags_remote = safe_strdup(driver_tags_get_with_hidden(h)); + HEADER_DATA(h)->flags_remote = safe_strdup(driver_tags_get_with_hidden(h->tags)); return 0; } diff --git a/imap/message.c b/imap/message.c index 60aef1ca7..319129b8e 100644 --- a/imap/message.c +++ b/imap/message.c @@ -636,8 +636,8 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i ctx->hdrs[idx]->changed = h.data->changed; /* ctx->hdrs[msgno]->received is restored from mutt_hcache_restore */ ctx->hdrs[idx]->data = (void *) (h.data); - driver_tags_init(ctx->hdrs[idx]); - driver_tags_replace(ctx->hdrs[idx], safe_strdup(h.data->flags_remote)); + driver_tags_init(ctx->hdrs[idx]->tags); + driver_tags_replace(ctx->hdrs[idx]->tags, safe_strdup(h.data->flags_remote)); ctx->msgcount++; ctx->size += ctx->hdrs[idx]->content->length; @@ -756,8 +756,8 @@ int imap_read_headers(struct ImapData *idata, unsigned int msn_begin, unsigned i ctx->hdrs[idx]->changed = h.data->changed; ctx->hdrs[idx]->received = h.received; ctx->hdrs[idx]->data = (void *) (h.data); - driver_tags_init(ctx->hdrs[idx]); - driver_tags_replace(ctx->hdrs[idx], safe_strdup(h.data->flags_remote)); + driver_tags_init(ctx->hdrs[idx]->tags); + driver_tags_replace(ctx->hdrs[idx]->tags, safe_strdup(h.data->flags_remote)); if (maxuid < h.data->uid) maxuid = h.data->uid; @@ -1480,7 +1480,7 @@ char *imap_set_flags(struct ImapData *idata, struct Header *h, char *s, int *ser return NULL; /* Update tags system */ - driver_tags_replace(h, safe_strdup(hd->flags_remote)); + driver_tags_replace(h->tags, safe_strdup(hd->flags_remote)); /* YAUH (yet another ugly hack): temporarily set context to * read-write even if it's read-only, so *server* updates of diff --git a/mutt_notmuch.c b/mutt_notmuch.c index 7e80bafd2..a8015603c 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -856,7 +856,7 @@ static int update_header_tags(struct Header *h, notmuch_message_t *msg) mutt_str_append_item(&new_tags, t, ' '); } - if (driver_tags_get(h) && new_tags && (strcmp(driver_tags_get(h), new_tags) == 0)) + if (driver_tags_get(h->tags) && new_tags && (strcmp(driver_tags_get(h->tags), new_tags) == 0)) { FREE(&new_tags); mutt_debug(2, "nm: tags unchanged\n"); @@ -864,9 +864,9 @@ static int update_header_tags(struct Header *h, notmuch_message_t *msg) } /* new version */ - driver_tags_replace(h, new_tags); - mutt_debug(2, "nm: new tags: '%s'\n", driver_tags_get(h)); - mutt_debug(2, "nm: new tag transforms: '%s'\n", driver_tags_get_transformed(h)); + driver_tags_replace(h->tags, new_tags); + mutt_debug(2, "nm: new tags: '%s'\n", driver_tags_get(h->tags)); + mutt_debug(2, "nm: new tag transforms: '%s'\n", driver_tags_get_transformed(h->tags)); return 0; } @@ -962,7 +962,7 @@ static int init_header(struct Header *h, const char *path, notmuch_message_t *ms h->data = safe_calloc(1, sizeof(struct NmHdrData)); h->free_cb = deinit_header; - driver_tags_init(h); + driver_tags_init(h->tags); /* * Notmuch ensures that message Id exists (if not notmuch Notmuch will @@ -1597,7 +1597,7 @@ static int rename_filename(struct NmCtxData *data, const char *old, { notmuch_message_maildir_flags_to_tags(msg); update_header_tags(h, msg); - update_tags(msg, driver_tags_get(h)); + update_tags(msg, driver_tags_get(h->tags)); } rc = 0; @@ -2117,7 +2117,7 @@ int nm_record_message(struct Context *ctx, char *path, struct Header *h) { notmuch_message_maildir_flags_to_tags(msg); if (h) - update_tags(msg, driver_tags_get(h)); + update_tags(msg, driver_tags_get(h->tags)); if (NmRecordTags) update_tags(msg, NmRecordTags); } diff --git a/mutt_tags.c b/mutt_tags.c index d6957f585..0ead62048 100644 --- a/mutt_tags.c +++ b/mutt_tags.c @@ -25,7 +25,6 @@ #include "globals.h" #include "lib/hash.h" #include "lib/string2.h" -#include "header.h" #include "mx.h" /** @@ -34,9 +33,9 @@ * * Free tag */ -static void driver_tags_free_tag_list(struct TagList **kw_list) +static void driver_tags_free_tag_list(struct TagNode **kw_list) { - struct TagList *tmp = NULL; + struct TagNode *tmp = NULL; while ((tmp = *kw_list) != NULL) { @@ -55,15 +54,15 @@ static void driver_tags_free_tag_list(struct TagList **kw_list) * * Free the whole tags structure */ -void driver_tags_free(struct Header *h) +void driver_tags_free(struct TagHead *head) { - if (!h->tags) + if (!head) return; - FREE(&h->tags->tags); - FREE(&h->tags->tags_transformed); - FREE(&h->tags->tags_with_hidden); - driver_tags_free_tag_list(&h->tags->tag_list); - FREE(h->tags); + FREE(&head->tags); + FREE(&head->tags_transformed); + FREE(&head->tags_with_hidden); + driver_tags_free_tag_list(&head->tag_list); + FREE(head); } /** @@ -75,13 +74,13 @@ void driver_tags_free(struct Header *h) * Return a string containing all transformed tags separated by space * without hidden tags */ -const char *driver_tags_get_transformed(struct Header *h) +const char *driver_tags_get_transformed(struct TagHead *head) { - if (!h || !h->tags) + if (!head) return NULL; - if(!h->tags->tags_transformed) - return h->tags->tags; - return h->tags->tags_transformed; + if(!head->tags_transformed) + return head->tags; + return head->tags_transformed; } /** @@ -93,11 +92,11 @@ const char *driver_tags_get_transformed(struct Header *h) * Return a string containing all tags separated by space with * hidden tags */ -const char *driver_tags_get(struct Header *h) +const char *driver_tags_get(struct TagHead *head) { - if (!h || !h->tags || !h->tags->tags) + if (!head || !head->tags) return NULL; - return h->tags->tags; + return head->tags; } /** @@ -109,11 +108,11 @@ const char *driver_tags_get(struct Header *h) * Return a string containing all tags separated by space * even the hiddens. */ -const char *driver_tags_get_with_hidden(struct Header *h) +const char *driver_tags_get_with_hidden(struct TagHead *head) { - if (!h || !h->tags || !h->tags->tags_with_hidden) + if (!head || !head->tags_with_hidden) return NULL; - return h->tags->tags_with_hidden; + return head->tags_with_hidden; } /** @@ -126,12 +125,12 @@ const char *driver_tags_get_with_hidden(struct Header *h) * Return a string containing transformed tag that match the tag * even if this is a hidden tags */ -const char *driver_tags_get_transformed_for(char *name, struct Header *h) +const char *driver_tags_get_transformed_for(char *name, struct TagHead *head) { - if (!h || !h->tags || !h->tags->tag_list) + if (!head || !head->tag_list) return NULL; - struct TagList *tag = h->tags->tag_list; + struct TagNode *tag = head->tag_list; while (tag) { if (strcmp(tag->name, name) == 0) { @@ -145,13 +144,13 @@ const char *driver_tags_get_transformed_for(char *name, struct Header *h) return NULL; } -void driver_tags_init(struct Header *h) +void driver_tags_init(struct TagHead *head) { - h->tags = safe_calloc(1, sizeof(struct HeaderTags)); - h->tags->tags = NULL; - h->tags->tags_transformed = NULL; - h->tags->tags_with_hidden = NULL; - h->tags->tag_list = NULL; + head = safe_calloc(1, sizeof(struct TagHead)); + head->tags = NULL; + head->tags_transformed = NULL; + head->tags_with_hidden = NULL; + head->tag_list = NULL; } /** @@ -161,9 +160,9 @@ void driver_tags_init(struct Header *h) * * Add a tag to the header tags */ -static void driver_tags_add(struct Header *h, char *new_tag) +static void driver_tags_add(struct TagHead *head, char *new_tag) { - struct TagList *ttmp = NULL; + struct TagNode *ttmp = NULL; char *new_tag_transformed = NULL; new_tag_transformed = hash_find(TagTransforms, new_tag); @@ -172,11 +171,11 @@ static void driver_tags_add(struct Header *h, char *new_tag) ttmp->name = safe_strdup(new_tag); if (new_tag_transformed) ttmp->transformed = safe_strdup(new_tag_transformed); - ttmp->next = h->tags->tag_list; - h->tags->tag_list = ttmp; + ttmp->next = head->tag_list; + head->tag_list = ttmp; /* expand the all un-transformed tag string */ - mutt_str_append_item(&h->tags->tags_with_hidden, new_tag, ' '); + mutt_str_append_item(&head->tags_with_hidden, new_tag, ' '); /* filter out hidden tags */ if (HiddenTags) @@ -190,13 +189,13 @@ static void driver_tags_add(struct Header *h, char *new_tag) } /* expand the visible un-transformed tag string */ - mutt_str_append_item(&h->tags->tags, new_tag, ' '); + mutt_str_append_item(&head->tags, new_tag, ' '); /* expand the transformed tag string */ if (new_tag_transformed) - mutt_str_append_item(&h->tags->tags_transformed, new_tag_transformed, ' '); + mutt_str_append_item(&head->tags_transformed, new_tag_transformed, ' '); else - mutt_str_append_item(&h->tags->tags_transformed, new_tag, ' '); + mutt_str_append_item(&head->tags_transformed, new_tag, ' '); } /** @@ -210,22 +209,20 @@ static void driver_tags_add(struct Header *h, char *new_tag) * Free current tags structures and replace it by * new tags */ -int driver_tags_replace(struct Header *h, char *tags) +int driver_tags_replace(struct TagHead *head, char *tags) { - if (!h) - return 0; - if (tags && h->tags && h->tags->tags && - mutt_strcmp(h->tags->tags, tags) == 0) + if (tags && head && head->tags && + mutt_strcmp(head->tags, tags) == 0) return 0; - driver_tags_free(h); - driver_tags_init(h); + driver_tags_free(head); + driver_tags_init(head); if (tags) { char *tag; while ((tag = strsep(&tags, " "))) - driver_tags_add(h, tag); + driver_tags_add(head, tag); FREE(&tags); } return 1; diff --git a/mutt_tags.h b/mutt_tags.h index 717614930..38006fdc0 100644 --- a/mutt_tags.h +++ b/mutt_tags.h @@ -23,29 +23,27 @@ #ifndef _MUTT_TAG_H #define _MUTT_TAG_H -#include "header.h" - /** - * struct TagList - Mail Header Tags + * struct TagNode - Tag element * * Keep a linked list of header tags and their transformed values. * Textual tags can be transformed to symbols to save space. * - * @sa TagLists#tag_list + * @sa TagNodes */ -struct TagList +struct TagNode { char *name; char *transformed; - struct TagList *next; + struct TagNode *next; }; /** - * struct HeaderTags - tags data attached to an email + * struct TagHead - tags data attached to an email * * This stores all tags data associated with an email. */ -struct HeaderTags +struct TagHead { /* Without hidden tags */ char *tags; @@ -53,15 +51,15 @@ struct HeaderTags /* With hidden tags */ char *tags_with_hidden; - struct TagList *tag_list; + struct TagNode *tag_list; }; -void driver_tags_free(struct Header *h); -const char *driver_tags_get(struct Header *h); -const char *driver_tags_get_with_hidden(struct Header *h); -const char *driver_tags_get_transformed(struct Header *h); -const char *driver_tags_get_transformed_for(char *name, struct Header *h); -void driver_tags_init(struct Header *h); -int driver_tags_replace(struct Header *h, char *tags); +void driver_tags_free(struct TagHead *head); +const char *driver_tags_get(struct TagHead *head); +const char *driver_tags_get_with_hidden(struct TagHead *head); +const char *driver_tags_get_transformed(struct TagHead *head); +const char *driver_tags_get_transformed_for(char *name, struct TagHead *head); +void driver_tags_init(struct TagHead *head); +int driver_tags_replace(struct TagHead *head, char *tags); #endif /* _MUTT_TAG_H */ diff --git a/muttlib.c b/muttlib.c index 06e3e61ee..f6acfb1a8 100644 --- a/muttlib.c +++ b/muttlib.c @@ -167,7 +167,7 @@ void mutt_free_header(struct Header **h) #ifdef MIXMASTER mutt_list_free(&(*h)->chain); #endif - driver_tags_free(*h); + driver_tags_free((*h)->tags); #if defined(USE_POP) || defined(USE_IMAP) || defined(USE_NNTP) || defined(USE_NOTMUCH) if ((*h)->free_cb) (*h)->free_cb(*h); diff --git a/pattern.c b/pattern.c index 35ebc3d07..4ada30d87 100644 --- a/pattern.c +++ b/pattern.c @@ -1714,7 +1714,7 @@ int mutt_pattern_exec(struct Pattern *pat, enum PatternExecFlag flags, return (pat->not ^ (h->env->x_label && patmatch(pat, h->env->x_label) == 0)); case MUTT_DRIVER_LABEL: { - const char *tags = driver_tags_get(h); + const char *tags = driver_tags_get(h->tags); return (pat->not ^ (tags && patmatch(pat, tags) == 0)); } case MUTT_HORMEL: -- 2.40.0