diff -ruP mutt-1.3/OPS mutt-1.3-dgc/OPS --- mutt-1.3/OPS Tue Feb 15 10:28:45 2000 +++ mutt-1.3-dgc/OPS Wed May 10 11:58:23 2000 @@ -83,6 +83,7 @@ OP_HALF_UP "scroll up 1/2 page" OP_HELP "this screen" OP_JUMP "jump to an index number" +OP_LABEL "add or change a message's label" OP_LAST_ENTRY "move to the last entry" OP_LIST_REPLY "reply to specified mailing list" OP_MACRO "execute a macro" diff -ruP mutt-1.3/copy.c mutt-1.3-dgc/copy.c --- mutt-1.3/copy.c Fri Mar 3 04:10:07 2000 +++ mutt-1.3-dgc/copy.c Wed May 10 11:58:23 2000 @@ -95,6 +95,10 @@ ignore = 0; } + if (flags & CH_UPDATE_LABEL && + mutt_strncasecmp ("X-Label:", buf, 8) == 0) + continue; + if (!ignore && fputs (buf, out) == EOF) return (-1); } @@ -343,6 +347,7 @@ if (fputc ('\n', out) == EOF) return (-1); } + } } @@ -354,6 +359,14 @@ fprintf (out, "Lines: %d\n", h->lines); } + if (flags & CH_UPDATE_LABEL && h->xlabel_changed) + { + if (h->env->x_label != NULL) + if (fprintf(out, "X-Label: %s\n", h->env->x_label) != + 10 + strlen(h->env->x_label)) + return -1; + } + if ((flags & CH_NONEWLINE) == 0) { if (flags & CH_PREFIX) @@ -424,6 +437,9 @@ if (flags & M_CM_PREFIX) _mutt_make_string (prefix, sizeof (prefix), NONULL (Prefix), Context, hdr, 0); + + if (hdr->xlabel_changed) + chflags |= CH_UPDATE_LABEL; if ((flags & M_CM_NOHEADER) == 0) { diff -ruP mutt-1.3/curs_main.c mutt-1.3-dgc/curs_main.c --- mutt-1.3/curs_main.c Tue May 9 10:17:03 2000 +++ mutt-1.3-dgc/curs_main.c Wed May 10 11:58:23 2000 @@ -1634,6 +1634,21 @@ menu->redraw = REDRAW_FULL; break; + case OP_LABEL: + + CHECK_MSGCOUNT; + CHECK_READONLY; + rc = mutt_label_message(tag ? NULL : CURHDR); + if (rc > 0) { + Context->changed = 1; + menu->redraw = REDRAW_FULL; + mutt_message ("%d label%s changed.", rc, rc == 1 ? "" : "s"); + } + else { + mutt_message _("No labels changed."); + } + break; + case OP_LIST_REPLY: CHECK_ATTACH; diff -ruP mutt-1.3/functions.h mutt-1.3-dgc/functions.h --- mutt-1.3/functions.h Fri Mar 3 04:10:08 2000 +++ mutt-1.3-dgc/functions.h Wed May 10 11:58:29 2000 @@ -89,6 +89,7 @@ { "next-undeleted", OP_MAIN_NEXT_UNDELETED, "j" }, { "previous-undeleted", OP_MAIN_PREV_UNDELETED, "k" }, { "limit", OP_MAIN_LIMIT, "l" }, + { "label", OP_LABEL, "y" }, { "list-reply", OP_LIST_REPLY, "L" }, { "mail", OP_MAIL, "m" }, { "toggle-new", OP_TOGGLE_NEW, "N" }, @@ -165,6 +166,7 @@ { "next-entry", OP_NEXT_ENTRY, "J" }, { "previous-undeleted",OP_MAIN_PREV_UNDELETED, "k" }, { "previous-entry", OP_PREV_ENTRY, "K" }, + { "label", OP_LABEL, "y" }, { "list-reply", OP_LIST_REPLY, "L" }, { "redraw-screen", OP_REDRAW, "\014" }, { "mail", OP_MAIL, "m" }, diff -ruP mutt-1.3/headers.c mutt-1.3-dgc/headers.c --- mutt-1.3/headers.c Wed Apr 12 11:31:37 2000 +++ mutt-1.3-dgc/headers.c Wed May 10 11:58:32 2000 @@ -206,3 +206,122 @@ if (!in_reply_to) mutt_free_list (&msg->env->references); } + +/* + * dgc: I mistakenly thought this would be used with OP_LABEL. (I wasn't + * thinking on the right track at all.) It's here if you want it, but + * not tested. + * + * Add/modify a user hdr to/in an envelope. If hdr already exists, + * optionally overwrite it. If hdr value is null, optionally remove it. + * + * env: message envelope + * hdr: header field name (e.g., "X-Archive") + * value: header field value (e.g., "no") + * overwrite: if true, overwrite extant values + * empty: if true and value == NULL, remove hdr field from envelope + */ +int mutt_mod_user_hdr (ENVELOPE *env, + char *hdr, + char *value, + int overwrite, + int empty) +{ + LIST *list, *last; + int len; + char *s; + + len = strlen(hdr); + if ((s = safe_malloc(len + 2 + strlen(value) + 1)) == NULL) + return 0; + + last = NULL; /* Shut the compiler up. */ + list = env->userhdrs; + while (list != NULL) { + if (tolower(*list->data) == *hdr) { + if (strncasecmp(list->data, hdr, len) == 0 && + strncmp(&list->data[len], ": ", 2)) { + if (overwrite || empty) + break; + else + return 0; + } + } + last = list; + list = list->next; + } + if (list == NULL) { + list = mutt_new_list(); + if (last != NULL) + last->next = list; + } else if (empty && value == NULL) { + if (last != NULL) + last->next = list->next; + FREE(list->data); + FREE(list); + FREE(&s); + return 1; + } + + list->data = s; + sprintf(list->data, "%s: %s", hdr, value); + + return 1; +} + +/* + * dgc: Add an X-Label: field. There's probably a better module for this, + * but I don't want to presume. + */ +int _mutt_label_message(HEADER *hdr, char *new) +{ + if (hdr == NULL) + return 0; + if (hdr->env->x_label == NULL && new == NULL) + return 0; + if (hdr->env->x_label != NULL && new != NULL && + strcmp(hdr->env->x_label, new) == 0) + return 0; + if (hdr->env->x_label != NULL) + FREE(&hdr->env->x_label); + if (new == NULL) + hdr->env->x_label = NULL; + else + hdr->env->x_label = safe_strdup(new); + return hdr->changed = hdr->xlabel_changed = 1; +} + +int mutt_label_message(HEADER *hdr) +{ + char buf[LONG_STRING], *new; + int i; + int changed; + + *buf = '\0'; + if (hdr != NULL && hdr->env->x_label != NULL) { + strncpy(buf, hdr->env->x_label, LONG_STRING); + } + + mutt_get_field("Label: ", buf, sizeof(buf), M_CLEAR); + new = buf; + SKIPWS(new); + if (*new == '\0') + new = NULL; + + changed = 0; + if (hdr != NULL) { + changed += _mutt_label_message(hdr, new); + } else { +#define HDR_OF(index) Context->hdrs[Context->v2r[(index)]] + for (i = 0; i < Context->vcount; ++i) { + if (HDR_OF(i)->tagged) + if (_mutt_label_message(HDR_OF(i), new)) { + ++changed; + mutt_set_flag(Context, HDR_OF(i), + M_TAG, 0); + } + } + } + + return changed; +} diff -ruP mutt-1.3/mutt.h mutt-1.3-dgc/mutt.h --- mutt-1.3/mutt.h Tue May 9 10:23:01 2000 +++ mutt-1.3-dgc/mutt.h Wed May 10 11:58:32 2000 @@ -67,6 +67,7 @@ #define CH_NOLEN (1<<12) /* don't write Content-Length: and Lines: */ #define CH_WEED_DELIVERED (1<<13) /* weed eventual Delivered-To headers */ #define CH_FORCE_FROM (1<<14) /* give CH_FROM precedence over CH_WEED? */ +#define CH_UPDATE_LABEL (1<<15) /* update X-Label: from hdr->env->x_label? */ /* flags for mutt_enter_string() */ #define M_ALIAS 1 /* do alias "completion" by calling up the alias-menu */ @@ -565,6 +566,7 @@ unsigned int threaded : 1; /* message has been threaded */ unsigned int recip_valid : 1; /* is_recipient is valid */ unsigned int active : 1; /* message is not to be removed */ + unsigned int xlabel_changed : 1; /* editable - used for syncing */ /* timezone of the sender of this message */ unsigned int zhours : 5; diff -ruP mutt-1.3/protos.h mutt-1.3-dgc/protos.h --- mutt-1.3/protos.h Tue May 9 10:47:20 2000 +++ mutt-1.3-dgc/protos.h Wed May 10 11:58:43 2000 @@ -145,6 +145,7 @@ void mutt_edit_content_type (HEADER *, BODY *); void mutt_edit_file (const char *, const char *); void mutt_edit_headers (const char *, const char *, HEADER *, char *, size_t); +int mutt_label_message (HEADER *); void mutt_curses_error (const char *, ...); void mutt_enter_command (void); void mutt_expand_aliases_env (ENVELOPE *);