From: Junio C Hamano Date: Wed, 3 Mar 2010 06:55:03 +0000 (-0800) Subject: Merge branch 'hm/maint-imap-send-crlf' into maint X-Git-Tag: v1.7.0.2~18 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/be8198b236e2eeaf08618185f4f7ad83896bb704?ds=inline;hp=-c Merge branch 'hm/maint-imap-send-crlf' into maint * hm/maint-imap-send-crlf: git-imap-send: Convert LF to CRLF before storing patch to draft box --- be8198b236e2eeaf08618185f4f7ad83896bb704 diff --combined imap-send.c index ba72fa4b6e,3527b56d5d..5631930bc3 --- a/imap-send.c +++ b/imap-send.c @@@ -91,7 -91,6 +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 < "; @@@ -965,13 -964,17 +964,13 @@@ static struct store *imap_open_store(st /* open connection to IMAP server */ if (srvc->tunnel) { - const char *argv[4]; + const char *argv[] = { srvc->tunnel, NULL }; struct child_process tunnel = {0}; imap_info("Starting tunnel '%s'... ", srvc->tunnel); - argv[0] = "sh"; - argv[1] = "-c"; - argv[2] = srvc->tunnel; - argv[3] = NULL; - tunnel.argv = argv; + tunnel.use_shell = 1; tunnel.in = -1; tunnel.out = -1; if (start_command(&tunnel)) @@@ -1162,6 -1165,44 +1161,44 @@@ static int imap_make_flags(int flags, c 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; @@@ -1171,6 -1212,7 +1208,7 @@@ int ret, d; char flagstr[128]; + lf_to_crlf(data); memset(&cb, 0, sizeof(cb)); cb.dlen = data->len; @@@ -1331,16 -1373,11 +1369,16 @@@ static int git_imap_config(const char * if (strncmp(key, imap_key, sizeof imap_key - 1)) return 0; - if (!val) - return config_error_nonbool(key); - key += sizeof imap_key - 1; + /* check booleans first, and barf on others */ + if (!strcmp("sslverify", key)) + server.ssl_verify = git_config_bool(key, val); + else if (!strcmp("preformattedhtml", key)) + server.use_html = git_config_bool(key, val); + else if (!val) + return config_error_nonbool(key); + if (!strcmp("folder", key)) { imap_folder = xstrdup(val); } else if (!strcmp("host", key)) { @@@ -1361,6 -1398,10 +1399,6 @@@ server.port = git_config_int(key, val); else if (!strcmp("tunnel", key)) server.tunnel = xstrdup(val); - else if (!strcmp("sslverify", key)) - server.ssl_verify = git_config_bool(key, val); - else if (!strcmp("preformattedHTML", key)) - server.use_html = git_config_bool(key, val); return 0; }