X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=nntp%2Fnntp.c;h=64a64340c0d40bf8fa6526362a77dfab9b09dba6;hp=de689161f80b6fb0eb97748a8398dfe1d1f7b038;hb=10847442af799c403bd67bf0291cc119e55d72ce;hpb=ca1036a5694287e6ccf6d95af9e33a7e1d5a75fd diff --git a/nntp/nntp.c b/nntp/nntp.c index de68916..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; @@ -641,6 +680,7 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first, { char buf[HUGE_STRING]; char *msg = _("Fetching message headers..."); + char *msg2 = _("Fetching headers from cache..."); NNTP_DATA *nntp_data = ((NNTP_DATA *) ctx->data); int ret; int num; @@ -682,10 +722,10 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first, num = nntp_data->lastCached - first + 1; if (option (OPTNEWSCACHE) && nntp_data->cache && num > 0) { nntp_cache_expand (buf, nntp_data->cache); - mutt_message _("Fetching headers from cache..."); + mutt_message (msg2); if ((f = safe_fopen (buf, "r"))) { - int r = 0; + int r = 0, c = 0; /* counting number of lines */ while (fgets (buf, sizeof (buf), f) != NULL) @@ -697,8 +737,11 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first, fc.first = first; fc.last = first + num - 1; fc.msg = NULL; - while (fgets (buf, sizeof (buf), f) != NULL) + while (fgets (buf, sizeof (buf), f) != NULL) { + if (ReadInc && ((++c) % ReadInc == 0)) + mutt_message ("%s %d/%d", msg2, c, r); add_xover_line (buf, &fc); + } fclose (f); nntp_data->lastLoaded = fc.last; first = fc.last + 1; @@ -788,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); @@ -1091,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 */ @@ -1177,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); @@ -1265,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;