struct thread_list_state;
typedef struct thread_list_state thread_list_state;
struct thread_list_state {
- const char *listdir;
+ struct mlmmj_list *list;
int firstindex;
int lastindex;
int num_threads;
static thread_list_state *init_thread_list(
- const char *listdir, int firstindex, int lastindex)
+ struct mlmmj_list *list, int firstindex, int lastindex)
{
/* We use a static variable rather than dynamic allocation as
* there will never be two lists in use simultaneously */
static thread_list_state s;
- s.listdir = listdir;
+ s.list = list;
s.firstindex = firstindex;
s.lastindex = lastindex;
s.num_threads = 0;
char *archivename;
int num_threads = 0;
struct thread *threads = NULL;
- char buf[45];
if (s->cur_thread != -1) {
/* We have gathered the data already; just rewind */
}
for (i=s->firstindex; i<=s->lastindex; i++) {
-
- snprintf(buf, sizeof(buf), "%d", i);
-
- archivename = concatstr(3, s->listdir, "/archive/", buf);
- archivefd = open(archivename, O_RDONLY);
+ myasprintf(&archivename, "archive/%d", i);
+ archivefd = openat(s->list->fd, archivename, O_RDONLY|O_CLOEXEC);
myfree(archivename);
if (archivefd < 0)
num_threads++;
threads = myrealloc(threads,
num_threads*sizeof(struct thread));
- threads[num_threads-1].subject = concatstr(2,tmp,"\n");
+ myasprintf(&(threads[num_threads-1].subject), "%s\n", tmp);
threads[num_threads-1].num_mails = 0;
threads[num_threads-1].mails = NULL;
thread_idx = num_threads-1;
threads[thread_idx].mails = myrealloc(threads[thread_idx].mails,
threads[thread_idx].num_mails*sizeof(struct mail));
threads[thread_idx].mails[threads[thread_idx].num_mails-1].idx = i;
- threads[thread_idx].mails[threads[thread_idx].num_mails-1].from =
- concatstr(5, " ", buf, " - ", tmp, "\n");
+ myasprintf(&(threads[thread_idx].mails[threads[thread_idx].num_mails-1].from),
+ " %d - %s\n", i, tmp);
myfree(subj);
myfree(from);
register_unformatted(txt, "digestthreads", "%digestthreads%"); /* DEPRECATED */
- tls = init_thread_list(list->dir, firstindex, lastindex);
+ tls = init_thread_list(list, firstindex, lastindex);
register_formatted(txt, "digestthreads", rewind_thread_list,
get_thread_list_line, tls);
if (line != NULL) myfree(line);
for (i=firstindex; i<=lastindex; i++) {
- snprintf(buf, sizeof(buf), "%d", i);
-
- archivename = concatstr(3, list->dir, "/archive/", buf);
- archivefd = open(archivename, O_RDONLY);
+ myasprintf(&archivename, "archive/%d", i);
+ archivefd = openat(list->fd, archivename, O_RDONLY|O_CLOEXEC);
myfree(archivename);
-
+
if (archivefd < 0)
continue;
if (dprintf(fd, "\n--%s"
"\nContent-Type: message/rfc822"
- "\nContent-Disposition: inline; filename=\"%s_%s.eml\"",
- boundary, list->name, buf) == -1) {
+ "\nContent-Disposition: inline; filename=\"%s_%d.eml\"",
+ boundary, list->name, i) == -1) {
log_error(LOG_ARGS, "Could not write digest part "
"headers for archive index %d to "
"'%s'", i, queuename);