]>
git.ipfire.org Git - people/ms/dma.git/blob - local.c
13 deliver_local(struct qitem
*it
)
18 const char *newline
= "\n";
24 time_t now
= time(NULL
);
26 error
= snprintf(fn
, sizeof(fn
), "%s/%s", _PATH_MAILDIR
, it
->addr
);
27 if (error
< 0 || (size_t)error
>= sizeof(fn
)) {
28 syslog(LOG_NOTICE
, "local delivery deferred: %m");
32 /* wait for a maximum of 100s to get the lock to the file */
35 /* mailx removes users mailspool file if empty, so open with O_CREAT */
36 mbox
= open_locked(fn
, O_WRONLY
|O_APPEND
|O_CREAT
, 0660);
42 syslog(LOG_NOTICE
, "local delivery deferred: can not lock `%s'", fn
);
44 syslog(LOG_NOTICE
, "local delivery deferred: can not open `%s': %m", fn
);
49 mboxlen
= lseek(mbox
, 0, SEEK_END
);
51 /* New mails start with \nFrom ...., unless we're at the beginning of the mbox */
55 /* If we're bouncing a message, claim it comes from MAILER-DAEMON */
57 if (strcmp(sender
, "") == 0)
58 sender
= "MAILER-DAEMON";
60 if (fseek(it
->mailf
, 0, SEEK_SET
) != 0) {
61 syslog(LOG_NOTICE
, "local delivery deferred: can not seek: %m");
65 error
= snprintf(line
, sizeof(line
), "%sFrom %s\t%s", newline
, sender
, ctime(&now
));
66 if (error
< 0 || (size_t)error
>= sizeof(line
)) {
67 syslog(LOG_NOTICE
, "local delivery deferred: can not write header: %m");
70 if (write(mbox
, line
, error
) != error
)
73 while (!feof(it
->mailf
)) {
74 if (fgets(line
, sizeof(line
), it
->mailf
) == NULL
)
76 linelen
= strlen(line
);
77 if (linelen
== 0 || line
[linelen
- 1] != '\n') {
78 syslog(LOG_CRIT
, "local delivery failed: corrupted queue file");
79 snprintf(errmsg
, sizeof(errmsg
), "corrupted queue file");
84 if (hadnl
&& strncmp(line
, "From ", 5) == 0) {
87 if (write(mbox
, gt
, 1) != 1)
90 } else if (strcmp(line
, "\n") == 0) {
95 if ((size_t)write(mbox
, line
, linelen
) != linelen
)
102 syslog(LOG_ERR
, "local delivery failed: write error: %m");
105 if (ftruncate(mbox
, mboxlen
) != 0)
106 syslog(LOG_WARNING
, "error recovering mbox `%s': %m", fn
);