diff options
author | Junio C Hamano <gitster@pobox.com> | 2010-03-08 01:53:57 +0300 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2010-03-08 01:53:57 +0300 |
commit | 47b333f7593d7b1883062d7e6ad4069f0ff19b23 (patch) | |
tree | bbc1ee5713945ee02df4143ecd0456a2b6804339 | |
parent | b7380fa7a9adb52860eef7e8885fb8bc179beae1 (diff) | |
parent | 67d176300c0a79d5cf65402c641fcec7c5388f29 (diff) |
Merge branch 'hm/maint-imap-send-crlf' into maint-1.6.6
* hm/maint-imap-send-crlf:
git-imap-send: Convert LF to CRLF before storing patch to draft box
-rw-r--r-- | imap-send.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/imap-send.c b/imap-send.c index ea769a960a..4ffd583c7e 100644 --- a/imap-send.c +++ b/imap-send.c @@ -91,7 +91,6 @@ struct msg_data { char *data; int len; unsigned char flags; - unsigned int crlf:1; }; static const char imap_send_usage[] = "git imap-send < <mbox>"; @@ -1166,6 +1165,44 @@ static int imap_make_flags(int flags, char *buf) return d; } +static void lf_to_crlf(struct msg_data *msg) +{ + char *new; + int i, j, lfnum = 0; + + if (msg->data[0] == '\n') + lfnum++; + for (i = 1; i < msg->len; i++) { + if (msg->data[i - 1] != '\r' && msg->data[i] == '\n') + lfnum++; + } + + new = xmalloc(msg->len + lfnum); + if (msg->data[0] == '\n') { + new[0] = '\r'; + new[1] = '\n'; + i = 1; + j = 2; + } else { + new[0] = msg->data[0]; + i = 1; + j = 1; + } + for ( ; i < msg->len; i++) { + if (msg->data[i] != '\n') { + new[j++] = msg->data[i]; + continue; + } + if (msg->data[i - 1] != '\r') + new[j++] = '\r'; + /* otherwise it already had CR before */ + new[j++] = '\n'; + } + msg->len += lfnum; + free(msg->data); + msg->data = new; +} + static int imap_store_msg(struct store *gctx, struct msg_data *data) { struct imap_store *ctx = (struct imap_store *)gctx; @@ -1175,6 +1212,7 @@ static int imap_store_msg(struct store *gctx, struct msg_data *data) int ret, d; char flagstr[128]; + lf_to_crlf(data); memset(&cb, 0, sizeof(cb)); cb.dlen = data->len; |