static int daemonize = 1;
static char *
-set_from(const char *osender)
+set_from(struct queue *queue, const char *osender)
{
struct virtuser *v;
char *sender;
}
out:
+ queue->sender = sender;
return (sender);
}
}
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;
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 ||
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;
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. */
char *id;
FILE *mailf;
char *tmpf;
+ const char *sender;
};
struct config {
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 *);
/* 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);
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);
}
}
- if (linkspool(&bounceq, "") != 0)
+ if (linkspool(&bounceq) != 0)
goto fail;
/* bounce is safe */
}
int
-readmail(struct queue *queue, const char *sender, int nodot)
+readmail(struct queue *queue, int nodot)
{
char line[1000]; /* by RFC2822 */
size_t linelen;
"\tby %s (%s)\n"
"\t%s\n",
username, getuid(),
- sender,
+ queue->sender,
queue->id,
hostname(), VERSION,
rfc822date());
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);
*/
int
-newspoolf(struct queue *queue, const char *sender)
+newspoolf(struct queue *queue)
{
char fn[PATH_MAX+1];
struct stat st;
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);
}
int
-linkspool(struct queue *queue, const char *sender)
+linkspool(struct queue *queue)
{
char line[1000]; /* by RFC2822 */
struct stat st;
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)
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;