X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=nntp%2Fnntp.c;h=64a64340c0d40bf8fa6526362a77dfab9b09dba6;hp=29ac491b6928ac4e9d88f027ff630ca98efb9869;hb=10847442af799c403bd67bf0291cc119e55d72ce;hpb=86d529600952d1b3606e2b163a4edefbf988d1b9 diff --git a/nntp/nntp.c b/nntp/nntp.c index 29ac491..64a6434 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -22,6 +22,8 @@ #include "rfc1524.h" #include "rfc2047.h" #include "nntp.h" +#include "sidebar.h" +#include "buffy.h" #include "mutt_crypt.h" @@ -37,6 +39,46 @@ static unsigned int _checked = 0; +void nntp_sync_sidebar (NNTP_DATA* data) { + int i = 0; + BUFFY* tmp = NULL; + char buf[STRING]; + + if (list_empty (Incoming)) + return; + + /* unfortunately, NNTP_DATA::group only is the plain + * group name, so for every single update, we need to + * compose the full string which must be defined via + * mailboxes command ;-((( FIXME + */ + buf[0] = '\0'; + snprintf (buf, sizeof (buf), "nntp%s://%s%s%s%s/%s", + (data->nserv->conn->account.flags & M_ACCT_SSL) ? "s" : "", + NONULL (data->nserv->conn->account.user), + *data->nserv->conn->account.pass ? ":" : "", + *data->nserv->conn->account.pass ? data->nserv->conn->account.pass : "", + data->nserv->conn->account.host, + data->group); + debug_print (4, ("group == '%s'\n", buf)); + + /* bail out if group not found via mailboxes */ + if ((i = buffy_lookup (buf)) < 0) + return; + + tmp = (BUFFY*) Incoming->data[i]; + /* copied from browser.c */ + if (option (OPTMARKOLD) && + data->lastCached >= data->firstMessage && + data->lastCached <= data->lastMessage) + tmp->msg_unread = data->lastMessage - data->lastCached; + else + tmp->msg_unread = data->unread; + tmp->new = data->unread > 0; + /* this is closest to a "total" count we can get */ + tmp->msgcount = data->lastMessage - data->firstMessage; +} + static void nntp_error (const char *where, const char *msg) { debug_print (1, ("unexpected response in %s: %s\n", where, msg)); } @@ -387,7 +429,7 @@ static void nntp_parse_xref (CONTEXT * ctx, char *group, char *xref, if (colon) { *colon = '\0'; colon++; - nntp_get_status (ctx, h, p, atoi (colon)); + nntp_get_status (ctx, h, b, atoi (colon)); if (h && h->article_num == 0 && str_cmp (group, b) == 0) h->article_num = atoi (colon); } @@ -528,23 +570,19 @@ static int nntp_parse_xover (CONTEXT * ctx, char *buf, HEADER * hdr) break; case 1: hdr->env->subject = str_dup (b); - /* Now we need to do the things which would normally be done in - * mutt_read_rfc822_header() */ - if (hdr->env->subject) { - regmatch_t pmatch[1]; - - rfc2047_decode (&hdr->env->subject); - - if (regexec (ReplyRegexp.rx, hdr->env->subject, 1, pmatch, 0) == 0) - hdr->env->real_subj = hdr->env->subject + pmatch[0].rm_eo; - else - hdr->env->real_subj = hdr->env->subject; - } break; case 2: rfc822_free_address (&hdr->env->from); hdr->env->from = rfc822_parse_adrlist (hdr->env->from, b); - rfc2047_decode_adrlist (hdr->env->from); + /* same as for mutt_parse_rfc822_line(): + * don't leave from info NULL if there's an invalid address (or + * whatever) in From: field; mutt would just display it as empty + * and mark mail/(esp.) news article as your own. aaargh! this + * bothered me for _years_ */ + if (!hdr->env->from) { + hdr->env->from = rfc822_new_address (); + hdr->env->from->personal = str_dup (b); + } break; case 3: hdr->date_sent = mutt_parse_date (b, hdr); @@ -571,6 +609,7 @@ static int nntp_parse_xover (CONTEXT * ctx, char *buf, HEADER * hdr) hdr->env->xref = str_dup (b); nntp_parse_xref (ctx, nntp_data->group, b, hdr); } + rfc2047_decode_envelope (hdr->env); if (!*p) return -1; b = p; @@ -792,6 +831,8 @@ int nntp_open_mailbox (CONTEXT * ctx) unsigned int first; ACCOUNT acct; + memset (&acct, 0, sizeof (ACCOUNT)); + if (nntp_parse_url (ctx->path, &acct, buf, sizeof (buf)) < 0 || !*buf) { mutt_error (_("%s is an invalid newsgroup specification!"), ctx->path); mutt_sleep (2); @@ -1095,6 +1136,8 @@ void nntp_fastclose_mailbox (CONTEXT * ctx) if ((tmp = hash_find (data->nserv->newsgroups, data->group)) == NULL || tmp != data) nntp_delete_data (data); + else + nntp_sync_sidebar (data); } /* commit changes and terminate connection */ @@ -1181,6 +1224,7 @@ static int _nntp_check_mailbox (CONTEXT * ctx, NNTP_DATA * nntp_data) nntp_data->entries[0].first = 1; nntp_data->entries[0].last = 0; } + nntp_sync_sidebar (nntp_data); } time (&nntp_data->nserv->check_time); @@ -1269,6 +1313,7 @@ int nntp_check_newgroups (NNTP_SERVER * serv, int force) if (l->data && ((NNTP_DATA *) l->data)->subscribed) _nntp_check_mailbox (NULL, (NNTP_DATA *) l->data); } + sidebar_draw (CurrentMenu); } else if (!force) return 0;