Skip to content

Commit

Permalink
Do not remove newlines at the end of messages (preserve double newlin…
Browse files Browse the repository at this point in the history
…es) in

mboxes, from Martin Brandenburg.
  • Loading branch information
nicm committed Jan 4, 2017
1 parent 17bb530 commit dceda2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
9 changes: 2 additions & 7 deletions deliver-mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,8 @@ deliver_mbox_deliver(struct deliver_ctx *dctx, struct actitem *ti)
}

/* Append newlines. */
if (m->data[m->size - 1] == '\n') {
if (deliver_mbox_write(f, gzf, "\n", 1) < 0)
goto error_unblock;
} else {
if (deliver_mbox_write(f, gzf, "\n\n", 2) < 0)
goto error_unblock;
}
if (deliver_mbox_write(f, gzf, "\n\n", 2) < 0)
goto error_unblock;

/* Flush buffers and sync. */
if (gzf == NULL) {
Expand Down
15 changes: 9 additions & 6 deletions fetch-mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ fetch_mbox_save(struct account *a, struct fetch_mbox_mbox *fmbox)
{
struct fetch_mbox_data *data = a->data;
struct fetch_mbox_mail *aux, *this;
char path[MAXPATHLEN], saved[MAXPATHLEN], c;
char path[MAXPATHLEN], saved[MAXPATHLEN];
static const char c[2] = "\n\n";
int fd;
ssize_t n;
struct iovec iov[2];
Expand Down Expand Up @@ -170,14 +171,13 @@ fetch_mbox_save(struct account *a, struct fetch_mbox_mbox *fmbox)

log_debug2("%s: writing message from %zu, size %zu",
a->name, this->off, this->size);
c = '\n';
iov[0].iov_base = fmbox->base + this->off;
iov[0].iov_len = this->size;
iov[1].iov_base = &c;
iov[1].iov_len = 1;
iov[1].iov_base = c;
iov[1].iov_len = 2;
if ((n = writev(fd, iov, 2)) < 0)
goto error;
if ((size_t) n != this->size + 1) {
if ((size_t) n != this->size + 2) {
errno = EIO;
goto error;
}
Expand Down Expand Up @@ -520,7 +520,10 @@ fetch_mbox_state_mail(struct account *a, struct fetch_ctx *fctx)
}
fmbox->total++;

/* data->off has counted the From line of the next message */
/*
* Since data->off has already counted the "From " line of the next
* message, must reset data->off to be the exact message size.
*/
data->off = aux->off + aux->size;

/*
Expand Down

0 comments on commit dceda2c

Please sign in to comment.