X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=nntp%2Fnewsrc.c;h=e9709f74f15a4748a9a5e237fbc9c25ee494f4b3;hp=4dadc20ab85d09d0fafadb500c0e8861e1c7c9e3;hb=ac813896ca32d850febc2d95065ac4fa040f11f9;hpb=96d53ff49c308769efbf708e1e65819077cb7af6 diff --git a/nntp/newsrc.c b/nntp/newsrc.c index 4dadc20..e9709f7 100644 --- a/nntp/newsrc.c +++ b/nntp/newsrc.c @@ -13,35 +13,37 @@ #include #endif -#include "mutt.h" -#include "mutt_curses.h" -#include "sort.h" -#include "mx.h" -#include "mime.h" -#include "nntp.h" -#include "rfc822.h" -#include "rfc1524.h" -#include "rfc2047.h" - -#include "lib/mem.h" -#include "lib/str.h" -#include "lib/intl.h" -#include "lib/debug.h" - #include #include #include #include +#include #include +#include +#include +#include +#include +#include + +#include + +#include + +#include "mutt.h" +#include "sort.h" +#include "mx.h" +#include "nntp.h" +#include "rfc1524.h" + void nntp_add_to_list (NNTP_SERVER * s, NNTP_DATA * d) { - LIST *l; + string_list_t *l; if (!s || !d) return; - l = safe_calloc (1, sizeof (LIST)); + l = p_new(string_list_t, 1); if (s->list) s->tail->next = l; else @@ -56,7 +58,7 @@ static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line) char group[LONG_STRING]; int x = 1; char *p = line, *b, *h; - size_t len; + ssize_t len; while (*p) { if (*p++ == ',') @@ -71,10 +73,9 @@ static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line) len = p + 1 - line; if (len > sizeof (group)) len = sizeof (group); - strfcpy (group, line, len); + m_strcpy(group, len, line); if ((data = (NNTP_DATA *) hash_find (news->newsgroups, group)) == NULL) { - data = - (NNTP_DATA *) safe_calloc (1, sizeof (NNTP_DATA) + mutt_strlen (group) + 1); + data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1); data->group = (char *) data + sizeof (NNTP_DATA); strcpy (data->group, group); data->nserv = news; @@ -86,10 +87,10 @@ static int nntp_parse_newsrc_line (NNTP_SERVER * news, char *line) nntp_add_to_list (news, data); } else - FREE ((void **) &data->entries); + p_delete(&data->entries); data->rc = 1; - data->entries = safe_calloc (x * 2, sizeof (NEWSRC_ENTRY)); + data->entries = p_new(NEWSRC_ENTRY, x * 2); data->max = x * 2; if (*p == ':') @@ -148,10 +149,10 @@ static int slurp_newsrc (NNTP_SERVER * news) return -1; } - buf = safe_malloc (sb.st_size + 1); + buf = p_new(char, sb.st_size + 1); while (fgets (buf, sb.st_size + 1, fp)) nntp_parse_newsrc_line (news, buf); - FREE (&buf); + p_delete(&buf); mx_unlock_file (news->newsrc, fileno (fp), 0); fclose (fp); @@ -171,7 +172,7 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news) struct stat st; char buf[HUGE_STRING], *cp; char dir[_POSIX_PATH_MAX], file[_POSIX_PATH_MAX]; - FILE *index; + FILE *idx; NNTP_DATA *data; int l, m, t; @@ -182,7 +183,7 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news) if (!NewsCacheDir || !*NewsCacheDir) return 0; - strfcpy (dir, NewsCacheDir, sizeof (dir)); + m_strcpy(dir, sizeof(dir), NewsCacheDir); mutt_expand_path (dir, sizeof (dir)); if (lstat (dir, &st) || (st.st_mode & S_IFDIR) == 0) { @@ -199,36 +200,34 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news) set_option (OPTNEWSCACHE); - FREE (&news->cache); + p_delete(&news->cache); snprintf (buf, sizeof (buf), "%s/.index", dir); - if (!(index = safe_fopen (buf, "a+"))) + if (!(idx = safe_fopen (buf, "a+"))) return 0; - rewind (index); - while (fgets (buf, sizeof (buf), index)) { - buf[mutt_strlen (buf) - 1] = 0; /* strip ending '\n' */ - if (!safe_strncmp (buf, "#: ", 3) && - !safe_strcasecmp (buf + 3, news->conn->account.host)) + rewind (idx); + while (fgets (buf, sizeof (buf), idx)) { + buf[m_strlen(buf) - 1] = 0; /* strip ending '\n' */ + if (!m_strncmp(buf, "#: ", 3) && + !m_strcasecmp(buf + 3, news->conn->account.host)) break; } - while (fgets (buf, sizeof (buf), index)) { + while (fgets (buf, sizeof (buf), idx)) { cp = buf; while (*cp && *cp != ' ') cp++; if (!*cp) continue; cp[0] = 0; - if (!mutt_strcmp (buf, "#:")) + if (!m_strcmp(buf, "#:")) break; sscanf (cp + 1, "%s %d %d", file, &l, &m); - if (!mutt_strcmp (buf, "ALL")) { - news->cache = safe_strdup (file); + if (!m_strcmp(buf, "ALL")) { + news->cache = m_strdup(file); news->newgroups_time = m; } else if (news->newsgroups) { if ((data = (NNTP_DATA *) hash_find (news->newsgroups, buf)) == NULL) { - data = - (NNTP_DATA *) safe_calloc (1, - sizeof (NNTP_DATA) + mutt_strlen (buf) + 1); + data = xmalloc(sizeof(NNTP_DATA) + m_strlen(buf) + 1); data->group = (char *) data + sizeof (NNTP_DATA); strcpy (data->group, buf); data->nserv = news; @@ -239,7 +238,7 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news) hash_insert (news->newsgroups, data->group, data, 0); nntp_add_to_list (news, data); } - data->cache = safe_strdup (file); + data->cache = m_strdup(file); t = 0; if (!data->firstMessage || data->lastMessage < m) t = 1; @@ -252,11 +251,11 @@ static int nntp_parse_cacheindex (NNTP_SERVER * news) mutt_newsgroup_stat (data); } } - fclose (index); + fclose (idx); return 0; } -const char *nntp_format_str (char *dest, size_t destlen, char op, +const char *nntp_format_str (char *dest, ssize_t destlen, char op, const char *src, const char *fmt, const char *ifstring, const char *elsestring, unsigned long data, format_flag flags) @@ -265,8 +264,8 @@ const char *nntp_format_str (char *dest, size_t destlen, char op, switch (op) { case 's': - strncpy (fn, NewsServer, sizeof (fn) - 1); - str_tolower (fn); + m_strcpy(fn, sizeof (fn), NewsServer); + m_strtolower(fn); snprintf (tmp, sizeof (tmp), "%%%ss", fmt); snprintf (dest, destlen, tmp, fn); break; @@ -276,46 +275,46 @@ const char *nntp_format_str (char *dest, size_t destlen, char op, /* nntp_parse_url: given an NNPT URL, return host, port, * username, password and newsgroup will recognise. */ -int nntp_parse_url (const char *server, ACCOUNT * acct, - char *group, size_t group_len) +int nntp_parse_url (const char *server, ACCOUNT * act, + char *group, ssize_t group_len) { ciss_url_t url; char *c; int ret = -1; /* Defaults */ - acct->flags = 0; - acct->port = NNTP_PORT; - acct->type = M_ACCT_TYPE_NNTP; + act->flags = 0; + act->port = NNTP_PORT; + act->type = M_ACCT_TYPE_NNTP; - c = safe_strdup (server); + c = m_strdup(server); url_parse_ciss (&url, c); if (url.scheme == U_NNTP || url.scheme == U_NNTPS) { if (url.scheme == U_NNTPS) { - acct->flags |= M_ACCT_SSL; - acct->port = NNTP_SSL_PORT; + act->flags |= M_ACCT_SSL; + act->port = NNTP_SSL_PORT; } *group = '\0'; if (url.path) - strfcpy (group, url.path, group_len); + m_strcpy(group, group_len, url.path); - ret = mutt_account_fromurl (acct, &url); + ret = mutt_account_fromurl (act, &url); } - FREE (&c); + p_delete(&c); return ret; } -void nntp_expand_path (char *line, size_t len, ACCOUNT * acct) +void nntp_expand_path (char *line, ssize_t len, ACCOUNT * act) { ciss_url_t url; - url.path = safe_strdup (line); - mutt_account_tourl (acct, &url); + url.path = m_strdup(line); + mutt_account_tourl (act, &url); url_ciss_tostring (&url, line, len, 0); - FREE (&url.path); + p_delete(&url.path); } /* @@ -332,32 +331,34 @@ NNTP_SERVER *mutt_select_newsserver (char *server) { char file[_POSIX_PATH_MAX]; char *buf, *p; - LIST *list; - ACCOUNT acct; + string_list_t *list; + ACCOUNT act; NNTP_SERVER *serv; CONNECTION *conn; + p_clear(&act, 1); + if (!server || !*server) { mutt_error _("No newsserver defined!"); return NULL; } - buf = p = safe_calloc (mutt_strlen (server) + 10, sizeof (char)); + buf = p = p_new(char, m_strlen(server) + 10); if (url_check_scheme (server) == U_UNKNOWN) { strcpy (buf, "nntp://"); p = strchr (buf, '\0'); } strcpy (p, server); - if ((nntp_parse_url (buf, &acct, file, sizeof (file))) < 0 || *file) { - FREE (&buf); + if ((nntp_parse_url (buf, &act, file, sizeof (file))) < 0 || *file) { + p_delete(&buf); mutt_error (_("%s is an invalid newsserver specification!"), server); return NULL; } - FREE (&buf); + p_delete(&buf); - conn = mutt_conn_find (NULL, &acct); + conn = mutt_conn_find (NULL, &act); if (!conn) return NULL; @@ -393,9 +394,9 @@ NNTP_SERVER *mutt_select_newsserver (char *server) } /* New newsserver */ - serv = safe_calloc (1, sizeof (NNTP_SERVER)); + serv = p_new(NNTP_SERVER, 1); serv->conn = conn; - serv->newsrc = safe_strdup (file); + serv->newsrc = m_strdup(file); serv->newsgroups = hash_create (1009); slurp_newsrc (serv); /* load .newsrc */ nntp_parse_cacheindex (serv); /* load .index */ @@ -405,10 +406,10 @@ NNTP_SERVER *mutt_select_newsserver (char *server) hash_destroy (&serv->newsgroups, nntp_delete_data); for (list = serv->list; list; list = list->next) list->data = NULL; - mutt_free_list (&serv->list); - FREE (&serv->newsrc); - FREE (&serv->cache); - FREE (&serv); + string_list_wipe(&serv->list); + p_delete(&serv->newsrc); + p_delete(&serv->cache); + p_delete(&serv); return NULL; } nntp_clear_cacheindex (serv); @@ -498,22 +499,22 @@ static int puti (char *line, int num) } static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf, - char **pline, size_t * buflen) + char **pline, ssize_t * buflen) { char *line = *pline; - size_t len = *buflen - (*pline - *buf); + ssize_t len = *buflen - (*pline - *buf); int x, i; if (len < LONG_STRING * 10) { len += *buflen; *buflen *= 2; line = *buf; - safe_realloc (buf, *buflen); + p_realloc(buf, *buflen); line = *buf + (*pline - line); } strcpy (line, data->group); - len -= mutt_strlen (line) + 1; - line += mutt_strlen (line); + len -= m_strlen(line) + 1; + line += m_strlen(line); *line++ = data->subscribed ? ':' : '!'; *line++ = ' '; *line = '\0'; @@ -524,7 +525,7 @@ static void nntp_create_newsrc_line (NNTP_DATA * data, char **buf, *buflen *= 2; *pline = line; line = *buf; - safe_realloc (buf, *buflen); + p_realloc(buf, *buflen); line = *buf + (*pline - line); } if (x) { @@ -572,7 +573,7 @@ void newsrc_gen_entries (CONTEXT * ctx) } if (!data->max) { - data->entries = safe_calloc (5, sizeof (NEWSRC_ENTRY)); + data->entries = p_new(NEWSRC_ENTRY, 5); data->max = 5; } @@ -594,7 +595,7 @@ void newsrc_gen_entries (CONTEXT * ctx) !ctx->hdrs[x]->read) { if (data->num >= data->max) { data->max = data->max * 2; - safe_realloc (&data->entries, data->max * sizeof (NEWSRC_ENTRY)); + p_realloc(&data->entries, data->max); } data->entries[data->num].first = first; data->entries[data->num].last = last - 1; @@ -614,7 +615,7 @@ void newsrc_gen_entries (CONTEXT * ctx) if (series && first <= data->lastLoaded) { if (data->num >= data->max) { data->max = data->max * 2; - safe_realloc (&data->entries, data->max * sizeof (NEWSRC_ENTRY)); + p_realloc(&data->entries, data->max); } data->entries[data->num].first = first; data->entries[data->num].last = data->lastLoaded; @@ -627,18 +628,131 @@ void newsrc_gen_entries (CONTEXT * ctx) } } +static int mutt_update_list_file (char *filename, char *section, + const char *key, char *line) { + FILE *ifp; + FILE *ofp; + char buf[HUGE_STRING]; + char tmpfile[_POSIX_PATH_MAX], link[_POSIX_PATH_MAX]; + char *c; + int ext = 0, done = 0, r = 0, l = 0; + + /* if file not exist, create it */ + if ((ifp = safe_fopen (filename, "a"))) + fclose (ifp); + debug_print (1, ("Opening %s\n", filename)); + if (!(ifp = safe_fopen (filename, "r"))) { + mutt_error (_("Unable to open %s for reading"), filename); + return -1; + } + if (mx_lock_file (filename, fileno (ifp), 0, 0, 1)) { + fclose (ifp); + mutt_error (_("Unable to lock %s"), filename); + return -1; + } + /* use mutt_adv_mktemp() to get a tempfile in the same + * directory as filename is so that we can follow symlinks + * via rename(2); as dirname(2) may modify its argument, + * temporarily use buf as copy of it + */ + m_strcpy(buf, sizeof(buf), filename); + m_strcpy(tmpfile, sizeof(tmpfile), basename(filename)); + mutt_adv_mktemp ((const char*) dirname (buf), tmpfile, sizeof (tmpfile)); + debug_print (1, ("Opening %s\n", tmpfile)); + if (!(ofp = fopen (tmpfile, "w"))) { + fclose (ifp); + mutt_error (_("Unable to open %s for writing"), tmpfile); + return -1; + } + + if (section) { + while (r != EOF && !done && fgets (buf, sizeof (buf), ifp)) { + r = fputs (buf, ofp); + c = buf; + while (*c && *c != '\n') c++; + c[0] = 0; /* strip EOL */ + if (!strncmp (buf, "#: ", 3) && !m_strcasecmp(buf+3, section)) + done++; + } + if (r != EOF && !done) { + snprintf (buf, sizeof(buf), "#: %s\n", section); + r = fputs (buf, ofp); + } + done = 0; + } + + while (r != EOF && fgets (buf, sizeof (buf), ifp)) { + if (ext) { + c = buf; + while (*c && (*c != '\r') && (*c != '\n')) c++; + c--; + if (*c != '\\') ext = 0; + } else if ((section && !strncmp (buf, "#: ", 3))) { + if (!done && line) { + fputs (line, ofp); + fputc ('\n', ofp); + } + r = fputs (buf, ofp); + done++; + break; + } else if (key && !strncmp (buf, key, strlen(key)) && + (!*key || buf[strlen(key)] == ' ')) { + c = buf; + ext = 0; + while (*c && (*c != '\r') && (*c != '\n')) c++; + c--; + if (*c == '\\') ext = 1; + if (!done && line) { + r = fputs (line, ofp); + if (*key) + r = fputc ('\n', ofp); + done++; + } + } else { + r = fputs (buf, ofp); + } + } + + while (r != EOF && fgets (buf, sizeof (buf), ifp)) + r = fputs (buf, ofp); + + /* If there wasn't a line to replace, put it on the end of the file */ + if (r != EOF && !done && line) { + fputs (line, ofp); + r = fputc ('\n', ofp); + } + mx_unlock_file (filename, fileno (ifp), 0); + fclose (ofp); + fclose (ifp); + if (r == EOF) { + unlink (tmpfile); + mutt_error (_("Can't write %s"), tmpfile); + return -1; + } + link[0] = '\0'; + if ((l = readlink (filename, link, sizeof (link)-1)) > 0) + link[l] = '\0'; + debug_print (1, ("Renaming %s to %s\n",tmpfile, l > 0 ? link : filename)); + if (rename (tmpfile, l > 0 ? link : filename) < 0) { + unlink (tmpfile); + mutt_error (_("Can't rename %s to %s"), tmpfile, l > 0 ? link : filename); + return -1; + } + return 0; +} + int mutt_newsrc_update (NNTP_SERVER * news) { char *buf, *line; NNTP_DATA *data; - LIST *tmp; + string_list_t *tmp; int r = -1; - size_t len, llen; + ssize_t len, llen; if (!news) return -1; llen = len = 10 * LONG_STRING; - line = buf = safe_calloc (1, len); + line = buf = p_new(char, len); /* we will generate full newsrc here */ for (tmp = news->list; tmp; tmp = tmp->next) { data = (NNTP_DATA *) tmp->data; @@ -646,18 +760,18 @@ int mutt_newsrc_update (NNTP_SERVER * news) continue; nntp_create_newsrc_line (data, &buf, &line, &llen); debug_print (2, ("Added to newsrc: %s\n", line)); - line += mutt_strlen (line); + line += m_strlen(line); } /* newrc being fully rewritten */ if (news->newsrc && - (r = mutt_update_list_file (news->newsrc, NULL, "", buf)) == 0) { + (r = mutt_update_list_file(news->newsrc, NULL, "", buf)) == 0) { struct stat st; stat (news->newsrc, &st); news->size = st.st_size; news->mtime = st.st_mtime; } - FREE (&buf); + p_delete(&buf); return r; } @@ -672,7 +786,7 @@ static FILE *mutt_mkname (char *s) return fp; nntp_cache_expand (buf, "cache-XXXXXX"); - pc = buf + mutt_strlen (buf) - 12; /* positioning to "cache-XXXXXX" */ + pc = buf + m_strlen(buf) - 12; /* positioning to "cache-XXXXXX" */ if ((fd = mkstemp (buf)) == -1) return NULL; strcpy (s, pc); /* generated name */ @@ -682,8 +796,9 @@ static FILE *mutt_mkname (char *s) /* Updates info into .index file: ALL or about selected newsgroup */ static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data) { - char buf[LONG_STRING], *key = "ALL"; + char buf[LONG_STRING]; char file[_POSIX_PATH_MAX]; + const char *key = "ALL"; if (!serv || !serv->conn || !serv->conn->account.host) return -1; @@ -694,7 +809,7 @@ static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data) data->firstMessage, data->lastLoaded); } else { - strfcpy (file, serv->cache, sizeof (file)); + m_strcpy(file, sizeof(file), serv->cache); snprintf (buf, sizeof (buf), "ALL %s 0 %d", file, (int) serv->newgroups_time); } @@ -706,7 +821,7 @@ static int nntp_update_cacheindex (NNTP_SERVER * serv, NNTP_DATA * data) void nntp_clear_cacheindex (NNTP_SERVER * news) { NNTP_DATA *data; - LIST *tmp; + string_list_t *tmp; if (option (OPTSAVEUNSUB) || !news) return; @@ -727,7 +842,7 @@ int nntp_save_cache_index (NNTP_SERVER * news) char file[_POSIX_PATH_MAX]; NNTP_DATA *d; FILE *f; - LIST *l; + string_list_t *l; if (!news || !news->newsgroups) return -1; @@ -740,9 +855,9 @@ int nntp_save_cache_index (NNTP_SERVER * news) f = safe_fopen (file, "w"); } else { - strfcpy (buf, news->conn->account.host, sizeof (buf)); + m_strcpy(buf, sizeof(buf), news->conn->account.host); f = mutt_mkname (buf); - news->cache = safe_strdup (buf); + news->cache = m_strdup(buf); nntp_cache_expand (file, buf); } if (!f) @@ -798,7 +913,7 @@ int nntp_save_cache_group (CONTEXT * ctx) ((NNTP_DATA *) ctx->data)->nserv->conn->account.host, ((NNTP_DATA *) ctx->data)->group); f = mutt_mkname (buf); - ((NNTP_DATA *) ctx->data)->cache = safe_strdup (buf); + ((NNTP_DATA *) ctx->data)->cache = m_strdup(buf); nntp_cache_expand (file, buf); } if (!f) @@ -828,7 +943,7 @@ int nntp_save_cache_group (CONTEXT * ctx) fputs (buf, f); if (h->env->references) mutt_write_references (h->env->references, f); - snprintf (buf, sizeof (buf), "\t%ld\t%d\tXref: %s\n", + snprintf (buf, sizeof (buf), "\t%zd\t%d\tXref: %s\n", h->content->length, h->lines, NONULL (h->env->xref)); if (fputs (buf, f) == EOF) { fclose (f); @@ -864,7 +979,7 @@ void nntp_delete_cache (NNTP_DATA * data) nntp_cache_expand (buf, data->cache); unlink (buf); - FREE (&data->cache); + p_delete(&data->cache); data->lastCached = 0; nntp_cache_expand (buf, ".index"); mutt_update_list_file (buf, data->nserv->conn->account.host, data->group, @@ -878,8 +993,7 @@ NNTP_DATA *mutt_newsgroup_subscribe (NNTP_SERVER * news, char *group) if (!news || !news->newsgroups || !group || !*group) return NULL; if (!(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) { - data = - (NNTP_DATA *) safe_calloc (1, sizeof (NNTP_DATA) + mutt_strlen (group) + 1); + data = xmalloc(sizeof(NNTP_DATA) + m_strlen(group) + 1); data->group = (char *) data + sizeof (NNTP_DATA); strcpy (data->group, group); data->nserv = news; @@ -920,7 +1034,7 @@ NNTP_DATA *mutt_newsgroup_catchup (NNTP_SERVER * news, char *group) !(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) return NULL; if (!data->max) { - data->entries = safe_calloc (5, sizeof (NEWSRC_ENTRY)); + data->entries = p_new(NEWSRC_ENTRY, 5); data->max = 5; } data->num = 1; @@ -944,7 +1058,7 @@ NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group) !(data = (NNTP_DATA *) hash_find (news->newsgroups, group))) return NULL; if (!data->max) { - data->entries = safe_calloc (5, sizeof (NEWSRC_ENTRY)); + data->entries = p_new(NEWSRC_ENTRY, 5); data->max = 5; } data->num = 1; @@ -963,26 +1077,50 @@ NNTP_DATA *mutt_newsgroup_uncatchup (NNTP_SERVER * news, char *group) } /* this routine gives the first newsgroup with new messages */ -void nntp_buffy (char *s) -{ - LIST *list; +void nntp_buffy (char* dst, ssize_t dstlen) { + string_list_t *list; + int count = 0; + /* forward to current group */ for (list = CurrentNewsSrv->list; list; list = list->next) { NNTP_DATA *data = (NNTP_DATA *) list->data; + if (data && data->subscribed && data->unread && + Context && Context->magic == M_NNTP && + m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group) == 0) { + list = list->next; + break; + } + } - if (data && data->subscribed && data->unread) { - if (Context && Context->magic == M_NNTP && - !mutt_strcmp (data->group, ((NNTP_DATA *) Context->data)->group)) { - unsigned int i, unread = 0; + *dst = '\0'; - for (i = 0; i < Context->msgcount; i++) - if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted) - unread++; - if (!unread) - continue; + while (count < 2) { + + if (!list) + list = CurrentNewsSrv->list; + + for (; list; list = list->next) { + NNTP_DATA *data = (NNTP_DATA *) list->data; + + if (data && data->subscribed && data->unread) { + if (Context && Context->magic == M_NNTP && + !m_strcmp(data->group, ((NNTP_DATA *) Context->data)->group)) { + unsigned int i, unread = 0; + + for (i = 0; i < Context->msgcount; i++) + if (!Context->hdrs[i]->read && !Context->hdrs[i]->deleted) + unread++; + if (!unread) + continue; + } + m_strcpy(dst, dstlen, data->group); + break; } - strcpy (s, data->group); - break; } + /* done if found */ + if (dst && *dst) + return; + count++; } + *dst = '\0'; }