]> git.ipfire.org Git - people/ms/dma.git/commitdiff
dma: move sender into queue
authorSimon Schubert <corecode@dragonflybsd.org>
Thu, 27 Aug 2009 14:32:19 +0000 (16:32 +0200)
committerSimon Schubert <corecode@dragonflybsd.org>
Thu, 27 Aug 2009 21:12:43 +0000 (23:12 +0200)
dma.c
dma.h
mail.c
spool.c

diff --git a/dma.c b/dma.c
index d1f2493abeb21968d54ea417d1baed740e4d3ced..037288a900566357e4e949ca17e5c7864211fa44 100644 (file)
--- a/dma.c
+++ b/dma.c
@@ -70,7 +70,7 @@ const char *logident_base;
 static int daemonize = 1;
 
 static char *
-set_from(const char *osender)
+set_from(struct queue *queue, const char *osender)
 {
        struct virtuser *v;
        char *sender;
@@ -101,6 +101,7 @@ set_from(const char *osender)
        }
 
 out:
+       queue->sender = sender;
        return (sender);
 }
 
@@ -117,7 +118,7 @@ read_aliases(void)
 }
 
 int
-add_recp(struct queue *queue, const char *str, const char *sender, int expand)
+add_recp(struct queue *queue, const char *str, int expand)
 {
        struct qitem *it, *tit;
        struct stritem *sit;
@@ -133,7 +134,7 @@ add_recp(struct queue *queue, const char *str, const char *sender, int expand)
        if (it->addr == NULL)
                return (-1);
 
-       it->sender = sender;
+       it->sender = queue->sender;
        host = strrchr(it->addr, '@');
        if (host != NULL &&
            (strcmp(host + 1, hostname()) == 0 ||
@@ -156,7 +157,7 @@ add_recp(struct queue *queue, const char *str, const char *sender, int expand)
                                if (strcmp(al->alias, it->addr) != 0)
                                        continue;
                                SLIST_FOREACH(sit, &al->dests, next) {
-                                       if (add_recp(queue, sit->str, sender, 1) != 0)
+                                       if (add_recp(queue, sit->str, 1) != 0)
                                                return (-1);
                                }
                                aliased = 1;
@@ -482,26 +483,26 @@ skipopts:
        if (read_aliases() != 0)
                errlog(1, "can not read aliases file `%s'", config->aliases);
 
-       if ((sender = set_from(sender)) == NULL)
+       if ((sender = set_from(&queue, sender)) == NULL)
                errlog(1, NULL);
 
        for (i = 0; i < argc; i++) {
-               if (add_recp(&queue, argv[i], sender, 1) != 0)
+               if (add_recp(&queue, argv[i], 1) != 0)
                        errlogx(1, "invalid recipient `%s'", argv[i]);
        }
 
        if (LIST_EMPTY(&queue.queue))
                errlogx(1, "no recipients");
 
-       if (newspoolf(&queue, sender) != 0)
+       if (newspoolf(&queue) != 0)
                errlog(1, "can not create temp file");
 
        setlogident("%s", queue.id);
 
-       if (readmail(&queue, sender, nodot) != 0)
+       if (readmail(&queue, nodot) != 0)
                errlog(1, "can not read mail");
 
-       if (linkspool(&queue, sender) != 0)
+       if (linkspool(&queue) != 0)
                errlog(1, "can not create spools");
 
        /* From here on the mail is safe. */
diff --git a/dma.h b/dma.h
index 04cd28eea6b132f247f118ca65cf1e9951420042..96fd9bde757bab696cc36e3fdbe17b830dff2d39 100644 (file)
--- a/dma.h
+++ b/dma.h
@@ -104,6 +104,7 @@ struct queue {
        char *id;
        FILE *mailf;
        char *tmpf;
+       const char *sender;
 };
 
 struct config {
@@ -174,12 +175,12 @@ int base64_encode(const void *, int, char **);
 int base64_decode(const char *, void *);
 
 /* dma.c */
-int add_recp(struct queue *, const char *, const char *, int);
+int add_recp(struct queue *, const char *, int);
 void run_queue(struct queue *);
 
 /* spool.c */
-int newspoolf(struct queue *, const char *);
-int linkspool(struct queue *, const char *);
+int newspoolf(struct queue *);
+int linkspool(struct queue *);
 int load_queue(struct queue *);
 void delqueue(struct qitem *);
 int aquirespool(struct qitem *);
@@ -190,7 +191,7 @@ int deliver_local(struct qitem *, const char **errmsg);
 
 /* mail.c */
 void bounce(struct qitem *, const char *);
-int readmail(struct queue *, const char *, int);
+int readmail(struct queue *, int);
 
 /* util.c */
 const char *hostname(void);
diff --git a/mail.c b/mail.c
index 7f826b20f0014921ee9411200eebc1e82c9c5ab5..dd317e5b309b9e660cad5ee6a82a0ecbbb1e3613 100644 (file)
--- a/mail.c
+++ b/mail.c
@@ -54,10 +54,11 @@ bounce(struct qitem *it, const char *reason)
 
        bzero(&bounceq, sizeof(bounceq));
        LIST_INIT(&bounceq.queue);
-       if (add_recp(&bounceq, it->sender, "", 1) != 0)
+       bounceq.sender = "";
+       if (add_recp(&bounceq, it->sender, 1) != 0)
                goto fail;
 
-       if (newspoolf(&bounceq, "") != 0)
+       if (newspoolf(&bounceq) != 0)
                goto fail;
 
        syslog(LOG_ERR, "delivery failed, bouncing as %s", bounceq.id);
@@ -117,7 +118,7 @@ bounce(struct qitem *it, const char *reason)
                }
        }
 
-       if (linkspool(&bounceq, "") != 0)
+       if (linkspool(&bounceq) != 0)
                goto fail;
        /* bounce is safe */
 
@@ -133,7 +134,7 @@ fail:
 }
 
 int
-readmail(struct queue *queue, const char *sender, int nodot)
+readmail(struct queue *queue, int nodot)
 {
        char line[1000];        /* by RFC2822 */
        size_t linelen;
@@ -150,7 +151,7 @@ readmail(struct queue *queue, const char *sender, int nodot)
                "\tby %s (%s)\n"
                "\t%s\n",
                username, getuid(),
-               sender,
+               queue->sender,
                queue->id,
                hostname(), VERSION,
                rfc822date());
@@ -186,7 +187,7 @@ readmail(struct queue *queue, const char *sender, int nodot)
                                                 queue->id, hostname());
                                } else if (!had_from) {
                                        had_from = 1;
-                                       snprintf(line, sizeof(line), "From: <%s>\n", sender);
+                                       snprintf(line, sizeof(line), "From: <%s>\n", queue->sender);
                                }
                                if (fwrite(line, strlen(line), 1, queue->mailf) != 1)
                                        return (-1);
diff --git a/spool.c b/spool.c
index 7988a1f1afd41c5dc88a66a494479c099e161955..21818b270a8101b02827467335cdb9825d920c83 100644 (file)
--- a/spool.c
+++ b/spool.c
@@ -62,7 +62,7 @@
  */
 
 int
-newspoolf(struct queue *queue, const char *sender)
+newspoolf(struct queue *queue)
 {
        char fn[PATH_MAX+1];
        struct stat st;
@@ -95,7 +95,7 @@ newspoolf(struct queue *queue, const char *sender)
        if (queue->mailf == NULL)
                goto fail;
 
-       if (fprintf(queue->mailf, "%s\n", sender) < 0)
+       if (fprintf(queue->mailf, "%s\n", queue->sender) < 0)
                goto fail;
 
        hdrlen = ftello(queue->mailf);
@@ -120,7 +120,7 @@ fail:
 }
 
 int
-linkspool(struct queue *queue, const char *sender)
+linkspool(struct queue *queue)
 {
        char line[1000];        /* by RFC2822 */
        struct stat st;
@@ -132,7 +132,7 @@ linkspool(struct queue *queue, const char *sender)
                goto delfiles;
 
        syslog(LOG_INFO, "new mail from user=%s uid=%d envelope_from=<%s>",
-              username, getuid(), sender);
+              username, getuid(), queue->sender);
 
        LIST_FOREACH(it, &queue->queue, next) {
                if (asprintf(&it->queueid, "%s.%"PRIxPTR, queue->id, (uintptr_t)it) <= 0)
@@ -252,10 +252,11 @@ load_queue(struct queue *queue)
                        goto skip_item;
                *addr++ = 0;
 
-               if (add_recp(&itmqueue, addr, sender, 0) != 0)
+               if (add_recp(&itmqueue, addr, 0) != 0)
                        goto skip_item;
 
                it = LIST_FIRST(&itmqueue.queue);
+               it->sender = sender;
                it->queueid = queueid;
                it->queuefn = queuefn;
                it->mailfn = mailfn;