]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
send_digest: convert to mlmmj_list
authorBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 3 Nov 2021 08:08:30 +0000 (09:08 +0100)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Wed, 3 Nov 2021 13:10:28 +0000 (14:10 +0100)
While here use at function to open archives directly

src/send_digest.c

index 96e959ffcd5f277df488dcd7ddd1ff1ff50bbee1..833ee2819606b157539650cdfdd0f02ee0434f83 100644 (file)
@@ -59,7 +59,7 @@ struct thread {
 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;
@@ -70,12 +70,12 @@ struct thread_list_state {
 
 
 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;
@@ -93,7 +93,6 @@ static void rewind_thread_list(void * state)
        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 */
@@ -103,11 +102,8 @@ static void rewind_thread_list(void * state)
        }
 
        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)
@@ -161,7 +157,7 @@ static void rewind_thread_list(void * state)
                        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;
@@ -181,8 +177,8 @@ static void rewind_thread_list(void * state)
                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);
@@ -298,7 +294,7 @@ int send_digest(struct mlmmj_list *list, int firstindex, int lastindex,
 
        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);
 
@@ -437,19 +433,17 @@ errdighdrs:
        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);