{"thread":{"id":"21118","subject":"[PATCH/RFC 1/7] imap-send: use separate read and write fds","startedAt":"2009-10-03T00:39:39Z","lastAt":"2009-10-09T00:03:50Z","messageCount":18,"participants":["Erik Faye-Lund","Jeff King","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"124160","messageId":"1254530385-2824-1-git-send-email-kusmabite@gmail.com","threadId":"21118","inReplyTo":null,"subject":"[PATCH/RFC 1/7] imap-send: use separate read and write fds","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-10-03T00:39:39Z","receivedAt":"2009-10-03T00:39:39Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n imap-send.c |   37 +++++++++++++++++++++++--------------\n 1 files changed, 23 insertions(+), 14 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 3847fd1..ba50961 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -154,7 +154,7 @@ struct imap_list {\n };\n \n struct imap_socket {\n-\tint fd;\n+\tint fd[2];\n \tSSL *ssl;\n };\n \n@@ -304,8 +304,12 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve\n \t\tssl_socket_perror(\"SSL_new\");\n \t\treturn -1;\n \t}\n-\tif (!SSL_set_fd(sock->ssl, sock->fd)) {\n-\t\tssl_socket_perror(\"SSL_set_fd\");\n+\tif (!SSL_set_rfd(sock->ssl, sock->fd[0])) {\n+\t\tssl_socket_perror(\"SSL_set_rfd\");\n+\t\treturn -1;\n+\t}\n+\tif (!SSL_set_wfd(sock->ssl, sock->fd[1])) {\n+\t\tssl_socket_perror(\"SSL_set_wfd\");\n \t\treturn -1;\n \t}\n \n@@ -327,11 +331,12 @@ static int socket_read(struct imap_socket *sock, char *buf, int len)\n \t\tn = SSL_read(sock->ssl, buf, len);\n \telse\n #endif\n-\t\tn = xread(sock->fd, buf, len);\n+\t\tn = xread(sock->fd[0], buf, len);\n \tif (n <= 0) {\n \t\tsocket_perror(\"read\", sock, n);\n-\t\tclose(sock->fd);\n-\t\tsock->fd = -1;\n+\t\tclose(sock->fd[0]);\n+\t\tclose(sock->fd[1]);\n+\t\tsock->fd[0] = sock->fd[1] = -1;\n \t}\n \treturn n;\n }\n@@ -344,11 +349,12 @@ static int socket_write(struct imap_socket *sock, const char *buf, int len)\n \t\tn = SSL_write(sock->ssl, buf, len);\n \telse\n #endif\n-\t\tn = write_in_full(sock->fd, buf, len);\n+\t\tn = write_in_full(sock->fd[1], buf, len);\n \tif (n != len) {\n \t\tsocket_perror(\"write\", sock, n);\n-\t\tclose(sock->fd);\n-\t\tsock->fd = -1;\n+\t\tclose(sock->fd[0]);\n+\t\tclose(sock->fd[1]);\n+\t\tsock->fd[0] = sock->fd[1] = -1;\n \t}\n \treturn n;\n }\n@@ -361,7 +367,8 @@ static void socket_shutdown(struct imap_socket *sock)\n \t\tSSL_free(sock->ssl);\n \t}\n #endif\n-\tclose(sock->fd);\n+\tclose(sock->fd[0]);\n+\tclose(sock->fd[1]);\n }\n \n /* simple line buffering */\n@@ -960,7 +967,7 @@ static void imap_close_server(struct imap_store *ictx)\n {\n \tstruct imap *imap = ictx->imap;\n \n-\tif (imap->buf.sock.fd != -1) {\n+\tif (imap->buf.sock.fd[0] != -1) {\n \t\timap_exec(ictx, NULL, \"LOGOUT\");\n \t\tsocket_shutdown(&imap->buf.sock);\n \t}\n@@ -988,7 +995,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)\n \tctx = xcalloc(sizeof(*ctx), 1);\n \n \tctx->imap = imap = xcalloc(sizeof(*imap), 1);\n-\timap->buf.sock.fd = -1;\n+\timap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1;\n \timap->in_progress_append = &imap->in_progress;\n \n \t/* open connection to IMAP server */\n@@ -1015,7 +1022,8 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)\n \n \t\tclose(a[0]);\n \n-\t\timap->buf.sock.fd = a[1];\n+\t\timap->buf.sock.fd[0] = a[1];\n+\t\timap->buf.sock.fd[1] = dup(a[1]);\n \n \t\timap_info(\"ok\\n\");\n \t} else {\n@@ -1092,7 +1100,8 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)\n \t\t\tgoto bail;\n \t\t}\n \n-\t\timap->buf.sock.fd = s;\n+\t\timap->buf.sock.fd[0] = s;\n+\t\timap->buf.sock.fd[1] = dup(s);\n \n \t\tif (srvc->use_ssl &&\n \t\t    ssl_socket_connect(&imap->buf.sock, 0, srvc->ssl_verify)) {\n-- \n1.6.5.rc2.7.g4f8d3\n"},{"id":"124161","messageId":"1254530385-2824-2-git-send-email-kusmabite@gmail.com","threadId":"21118","inReplyTo":"1254530385-2824-1-git-send-email-kusmabite@gmail.com","subject":"[PATCH/RFC 2/7] imap-send: use run-command API for tunneling","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-10-03T00:39:40Z","receivedAt":"2009-10-03T00:39:40Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n imap-send.c |   37 ++++++++++++++++---------------------\n 1 files changed, 16 insertions(+), 21 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex ba50961..55a663a 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -24,6 +24,7 @@\n \n #include \"cache.h\"\n #include \"exec_cmd.h\"\n+#include \"run-command.h\"\n #ifdef NO_OPENSSL\n typedef void *SSL;\n #endif\n@@ -989,8 +990,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)\n \tstruct imap_store *ctx;\n \tstruct imap *imap;\n \tchar *arg, *rsp;\n-\tint s = -1, a[2], preauth;\n-\tpid_t pid;\n+\tint s = -1, preauth;\n \n \tctx = xcalloc(sizeof(*ctx), 1);\n \n@@ -1001,29 +1001,24 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)\n \t/* open connection to IMAP server */\n \n \tif (srvc->tunnel) {\n-\t\timap_info(\"Starting tunnel '%s'... \", srvc->tunnel);\n+\t\tconst char *argv[4];\n+\t\tstruct child_process tunnel = {0};\n \n-\t\tif (socketpair(PF_UNIX, SOCK_STREAM, 0, a)) {\n-\t\t\tperror(\"socketpair\");\n-\t\t\texit(1);\n-\t\t}\n+\t\timap_info(\"Starting tunnel '%s'... \", srvc->tunnel);\n \n-\t\tpid = fork();\n-\t\tif (pid < 0)\n-\t\t\t_exit(127);\n-\t\tif (!pid) {\n-\t\t\tif (dup2(a[0], 0) == -1 || dup2(a[0], 1) == -1)\n-\t\t\t\t_exit(127);\n-\t\t\tclose(a[0]);\n-\t\t\tclose(a[1]);\n-\t\t\texecl(\"/bin/sh\", \"sh\", \"-c\", srvc->tunnel, NULL);\n-\t\t\t_exit(127);\n-\t\t}\n+\t\targv[0] = \"/bin/sh\";\n+\t\targv[1] = \"-c\";\n+\t\targv[2] = srvc->tunnel;\n+\t\targv[3] = NULL;\n \n-\t\tclose(a[0]);\n+\t\ttunnel.argv = argv;\n+\t\ttunnel.in = -1;\n+\t\ttunnel.out = -1;\n+\t\tif (start_command(&tunnel))\n+\t\t\tdie(\"cannot start proxy %s\", argv[0]);\n \n-\t\timap->buf.sock.fd[0] = a[1];\n-\t\timap->buf.sock.fd[1] = dup(a[1]);\n+\t\timap->buf.sock.fd[0] = tunnel.out;\n+\t\timap->buf.sock.fd[1] = tunnel.in;\n \n \t\timap_info(\"ok\\n\");\n \t} else {\n-- \n1.6.5.rc2.7.g4f8d3\n"},{"id":"124162","messageId":"1254530385-2824-3-git-send-email-kusmabite@gmail.com","threadId":"21118","inReplyTo":"1254530385-2824-2-git-send-email-kusmabite@gmail.com","subject":"[PATCH/RFC 3/7] imap-send: fix compilation-error on Windows","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-10-03T00:39:41Z","receivedAt":"2009-10-03T00:39:41Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"mmsystem.h (included from windows.h) defines DRV_OK to 1. To avoid\nan error due to DRV_OK redefenition, this patch undefines the old\ndefinition (i.e the one from mmsystem.h) before defining DRV_OK.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n imap-send.c |    4 ++++\n 1 files changed, 4 insertions(+), 0 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 55a663a..8338717 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -94,6 +94,10 @@ struct msg_data {\n \tunsigned int crlf:1;\n };\n \n+#ifdef DRV_OK\n+#undef DRV_OK\n+#endif\n+\n #define DRV_OK          0\n #define DRV_MSG_BAD     -1\n #define DRV_BOX_BAD     -2\n-- \n1.6.5.rc2.7.g4f8d3\n"},{"id":"124163","messageId":"1254530385-2824-4-git-send-email-kusmabite@gmail.com","threadId":"21118","inReplyTo":"1254530385-2824-3-git-send-email-kusmabite@gmail.com","subject":"[PATCH/RFC 4/7] imap-send: build imap-send on Windows","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-10-03T00:39:42Z","receivedAt":"2009-10-03T00:39:42Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Since the POSIX-specific tunneling code has been replaced\nby the run-command API (and a compile-error has been\ncleaned away), we can now enable imap-send on Windows\nbuilds.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n Makefile |    2 +-\n 1 files changed, 1 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 12defd4..8ba789a 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -361,6 +361,7 @@ PROGRAMS += git-show-index$X\n PROGRAMS += git-unpack-file$X\n PROGRAMS += git-upload-pack$X\n PROGRAMS += git-var$X\n+PROGRAMS += git-imap-send$X\n \n # List built-in command $C whose implementation cmd_$C() is not in\n # builtin-$C.o but is linked in as part of some other command.\n@@ -1056,7 +1057,6 @@ EXTLIBS += -lz\n \n ifndef NO_POSIX_ONLY_PROGRAMS\n \tPROGRAMS += git-daemon$X\n-\tPROGRAMS += git-imap-send$X\n endif\n ifndef NO_OPENSSL\n \tOPENSSL_LIBSSL = -lssl\n-- \n1.6.5.rc2.7.g4f8d3\n"},{"id":"124164","messageId":"1254530385-2824-5-git-send-email-kusmabite@gmail.com","threadId":"21118","inReplyTo":"1254530385-2824-4-git-send-email-kusmabite@gmail.com","subject":"[PATCH/RFC 5/7] imap-send: provide fall-back random-source","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-10-03T00:39:43Z","receivedAt":"2009-10-03T00:39:43Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Since some systems (at least Windows) does not have\n/dev/random nor friends, we need another random-source.\n\nThis patch uses the C-runtime's rand()-function as a\npoor-mans random-source.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n imap-send.c |   17 ++++++++++-------\n 1 files changed, 10 insertions(+), 7 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 8338717..dda7b7f 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -511,14 +511,17 @@ static void arc4_init(void)\n \tunsigned char j, si, dat[128];\n \n \tif ((fd = open(\"/dev/urandom\", O_RDONLY)) < 0 && (fd = open(\"/dev/random\", O_RDONLY)) < 0) {\n-\t\tfprintf(stderr, \"Fatal: no random number source available.\\n\");\n-\t\texit(3);\n-\t}\n-\tif (read_in_full(fd, dat, 128) != 128) {\n-\t\tfprintf(stderr, \"Fatal: cannot read random number source.\\n\");\n-\t\texit(3);\n+\t\t/* poor-mans random-source */\n+\t\tsrand(clock());\n+\t\tfor (i = 0; i < 128; ++i)\n+\t\t\tdat[i] = rand() & 0xFF;\n+\t} else {\n+\t\tif (read_in_full(fd, dat, 128) != 128) {\n+\t\t\tfprintf(stderr, \"Fatal: cannot read random number source.\\n\");\n+\t\t\texit(3);\n+\t\t}\n+\t\tclose(fd);\n \t}\n-\tclose(fd);\n \n \tfor (i = 0; i < 256; i++)\n \t\trs.s[i] = i;\n-- \n1.6.5.rc2.7.g4f8d3\n"},{"id":"124165","messageId":"1254530385-2824-6-git-send-email-kusmabite@gmail.com","threadId":"21118","inReplyTo":"1254530385-2824-5-git-send-email-kusmabite@gmail.com","subject":"[PATCH/RFC 6/7] mingw: wrap SSL_set_(w|r)fd to call _get_osfhandle","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-10-03T00:39:44Z","receivedAt":"2009-10-03T00:39:44Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"SSL_set_fd (and friends) expects a OS file handle on Windows, not\na file descriptor as on UNIX(-ish).\n\nThis patch makes the Windows version of SSL_set_fd behave like the\nUNIX versions, by calling _get_osfhandle on it's input.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n compat/mingw.h |   21 +++++++++++++++++++++\n 1 files changed, 21 insertions(+), 0 deletions(-)\n\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex 5b5258b..6907345 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -124,6 +124,27 @@ static inline int waitpid(pid_t pid, int *status, unsigned options)\n \treturn -1;\n }\n \n+#ifndef NO_OPENSSL\n+#include <openssl/ssl.h>\n+static inline int mingw_SSL_set_fd(SSL *ssl, int fd)\n+{\n+\treturn SSL_set_fd(ssl, _get_osfhandle(fd));\n+}\n+#define SSL_set_fd mingw_SSL_set_fd\n+\n+static inline int mingw_SSL_set_rfd(SSL *ssl, int fd)\n+{\n+\treturn SSL_set_rfd(ssl, _get_osfhandle(fd));\n+}\n+#define SSL_set_rfd mingw_SSL_set_rfd\n+\n+static inline int mingw_SSL_set_wfd(SSL *ssl, int fd)\n+{\n+\treturn SSL_set_wfd(ssl, _get_osfhandle(fd));\n+}\n+#define SSL_set_wfd mingw_SSL_set_wfd\n+#endif\n+\n /*\n  * implementations of missing functions\n  */\n-- \n1.6.5.rc2.7.g4f8d3\n"},{"id":"124166","messageId":"1254530385-2824-7-git-send-email-kusmabite@gmail.com","threadId":"21118","inReplyTo":"1254530385-2824-6-git-send-email-kusmabite@gmail.com","subject":"[PATCH/RFC 7/7] mingw: enable OpenSSL","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-10-03T00:39:45Z","receivedAt":"2009-10-03T00:39:45Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"Since we have OpenSSL in msysgit now, enable it to support SSL\nencryption for imap-send.\n\nSigned-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n---\n Makefile |    1 -\n 1 files changed, 0 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 8ba789a..8818f0f 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -933,7 +933,6 @@ else\n ifneq (,$(findstring MINGW,$(uname_S)))\n \tpathsep = ;\n \tNO_PREAD = YesPlease\n-\tNO_OPENSSL = YesPlease\n \tNO_LIBGEN_H = YesPlease\n \tNO_SYMLINK_HEAD = YesPlease\n \tNO_IPV6 = YesPlease\n-- \n1.6.5.rc2.7.g4f8d3\n"},{"id":"124169","messageId":"20091003094049.GA17873@coredump.intra.peff.net","threadId":"21118","inReplyTo":"1254530385-2824-1-git-send-email-kusmabite@gmail.com","subject":"Re: [PATCH/RFC 1/7] imap-send: use separate read and write fds","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-10-03T09:40:49Z","receivedAt":"2009-10-03T09:40:49Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Oct 03, 2009 at 12:39:39AM +0000, Erik Faye-Lund wrote:\n\n> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n\nWhy? Given its presence in this series, I can only assume it has to do\nwith windows portability, but it would be helpful to give a little bit\nof the reasoning in the commit message.\n\n-Peff\n"},{"id":"124170","messageId":"20091003095811.GB17873@coredump.intra.peff.net","threadId":"21118","inReplyTo":"1254530385-2824-5-git-send-email-kusmabite@gmail.com","subject":"Re: [PATCH/RFC 5/7] imap-send: provide fall-back random-source","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-10-03T09:58:11Z","receivedAt":"2009-10-03T09:58:11Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Oct 03, 2009 at 12:39:43AM +0000, Erik Faye-Lund wrote:\n\n> Since some systems (at least Windows) does not have\n> /dev/random nor friends, we need another random-source.\n> \n> This patch uses the C-runtime's rand()-function as a\n> poor-mans random-source.\n\nHmm. It looks like this arc4 RNG is used just for generating a unique\n\"X-TUID\" header. Which seems to be used in isync (from which imap-send\nis derived) to be to avoid duplicates in synchronization. But imap-send\ndoesn't actually use it for anything, as it just blindly pushes the\nmessages.\n\nIn other words, should all of this TUID code (and the arc4 code) simply\nbe ripped out?\n\n-Peff\n"},{"id":"124182","messageId":"40aa078e0910031144r735a6fdq25efc1e57a1d4c33@mail.gmail.com","threadId":"21118","inReplyTo":"20091003094049.GA17873@coredump.intra.peff.net","subject":"Re: [PATCH/RFC 1/7] imap-send: use separate read and write fds","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-10-03T18:44:50Z","receivedAt":"2009-10-03T18:44:50Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"\nOn Sat, Oct 3, 2009 at 2:40 AM, Jeff King <peff@peff.net> wrote:\n> On Sat, Oct 03, 2009 at 12:39:39AM +0000, Erik Faye-Lund wrote:\n>\n>> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>\n>\n> Why? Given its presence in this series, I can only assume it has to do\n> with windows portability, but it would be helpful to give a little bit\n> of the reasoning in the commit message.\n>\n> -Peff\n>\n\nYeah, this is about Windows portability.\n\nI'll add something like \"This is a patch that enables us to use the\nrun-command API, which is supported on Windows.\" to the commit-message\nin the next round. Is that enough?\n\nI also guess I should have made a cover letter for this series, making\nit apparent to reviewers that:\n- This patch series is about supporting imap-send on Windows\n- It needs some additional patching to get tunnelling support working\non Windows, because we can't exec \"/bin/sh\" there. Changing it to\n\"c:\\\\msysgit\\\\bin\\\\sh.exe\" makes tunneling work for me, but isn't\nexactly portable across installations.\n\nI'll write one up for the next round.\n\n-- \nErik \"kusma\" Faye-Lund\nkusmabite@gmail.com\n(+47) 986 59 656\n"},{"id":"124183","messageId":"40aa078e0910031145l2849697ftd2da2f5aaa28d957@mail.gmail.com","threadId":"21118","inReplyTo":"20091003095811.GB17873@coredump.intra.peff.net","subject":"Re: [PATCH/RFC 5/7] imap-send: provide fall-back random-source","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-10-03T18:45:55Z","receivedAt":"2009-10-03T18:45:55Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"\nOn Sat, Oct 3, 2009 at 2:58 AM, Jeff King <peff@peff.net> wrote:\n>\n> Hmm. It looks like this arc4 RNG is used just for generating a unique\n> \"X-TUID\" header. Which seems to be used in isync (from which imap-send\n> is derived) to be to avoid duplicates in synchronization. But imap-send\n> doesn't actually use it for anything, as it just blindly pushes the\n> messages.\n>\n> In other words, should all of this TUID code (and the arc4 code) simply\n> be ripped out?\n\nPossibly. I must admit that I didn't dig far on this one - I just\nadded some randomness, and saw that things worked for me.\n\nI tried to trace this a little bit, but I got lost a bit in the\ncallback-stuff. However, it looks to me like it might get sent to the\nserver: it gets injected into cb.data in imap_store_msg(), and in\nv_issue_imap_cmd() it gets sent to the server if the LITERALPLUS\ncapability is supported. I might be wrong though, as I find this code\nquite confusing.\n\nI CC'ed Mike McCormack, who initially added imap-send (including the\narc4 code), as he *might* have more insight on this. It's a long-shot\nthough, considering that this appears to be code adapted around 3.5\nyears ago.\n\n-- \nErik \"kusma\" Faye-Lund\nkusmabite@gmail.com\n(+47) 986 59 656\n"},{"id":"124184","messageId":"40aa078e0910031159g68aace80oa7c75b4ffb2b9803@mail.gmail.com","threadId":"21118","inReplyTo":"40aa078e0910031145l2849697ftd2da2f5aaa28d957@mail.gmail.com","subject":"Re: [PATCH/RFC 5/7] imap-send: provide fall-back random-source","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-10-03T18:59:31Z","receivedAt":"2009-10-03T18:59:31Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"\nOn Sat, Oct 3, 2009 at 11:45 AM, Erik Faye-Lund\n<kusmabite@googlemail.com> wrote:\n> I CC'ed Mike McCormack, who initially added imap-send (including the\n> arc4 code), as he *might* have more insight on this. It's a long-shot\n> though, considering that this appears to be code adapted around 3.5\n> years ago.\n\nOK, it seems the e-mail address he used for the commit isn't valid any\nmore, and I can't easily find another address for him. So I guess\nwe're out of luck on that front.\n\n-- \nErik \"kusma\" Faye-Lund\nkusmabite@gmail.com\n(+47) 986 59 656\n"},{"id":"124192","messageId":"20091003203448.GA9058@sigill.intra.peff.net","threadId":"21118","inReplyTo":"40aa078e0910031144r735a6fdq25efc1e57a1d4c33@mail.gmail.com","subject":"Re: [PATCH/RFC 1/7] imap-send: use separate read and write fds","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-10-03T20:34:48Z","receivedAt":"2009-10-03T20:34:48Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Oct 03, 2009 at 11:44:50AM -0700, Erik Faye-Lund wrote:\n\n> Yeah, this is about Windows portability.\n> \n> I'll add something like \"This is a patch that enables us to use the\n> run-command API, which is supported on Windows.\" to the commit-message\n> in the next round. Is that enough?\n\nYeah, that would be fine. I was just left scratching my head wondering\nwhat subtle portability difference the two descriptors could have. But\nif it really is just a cleanup for the next patch, that's OK; just say\nso.\n\n-Peff\n"},{"id":"124193","messageId":"20091003204317.GB9058@sigill.intra.peff.net","threadId":"21118","inReplyTo":"40aa078e0910031145l2849697ftd2da2f5aaa28d957@mail.gmail.com","subject":"Re: [PATCH/RFC 5/7] imap-send: provide fall-back random-source","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-10-03T20:43:17Z","receivedAt":"2009-10-03T20:43:17Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Oct 03, 2009 at 11:45:55AM -0700, Erik Faye-Lund wrote:\n\n> I tried to trace this a little bit, but I got lost a bit in the\n> callback-stuff. However, it looks to me like it might get sent to the\n> server: it gets injected into cb.data in imap_store_msg(), and in\n> v_issue_imap_cmd() it gets sent to the server if the LITERALPLUS\n> capability is supported. I might be wrong though, as I find this code\n> quite confusing.\n\nIt does get stored on the server either way (LITERALPLUS is just an imap\nserver extension that gives us different options for how we send). The\ncode actually munges an extra \"X-TUID\" rfc822 header into your message,\nwhich has a randomly generated value. But we never _use_ the value for\nanything. I think it is just inherited via cut-and-paste from the\noriginal isync, which I guess actually does use it for synchronization.\n\nThe patch below rips it (and the arc4 code) out completely. It still\nworks in my simple test case, but I am not really an imap-send user, so\ncaveat emptor.\n\nThe other confusing bit is that the code carefully tracks the \"uid\"\n(deep within the call chain it munges cb.ctx, which is a pointer to uid)\nwhich is assigned to the newly created message by the server. This could\nbe used by a client to later refer to the same message unambiguously.\nBut we never do that, and just throw away the uid value that the server\ngives us.  Again, I suspect this is a holdover from isync wanting to do\nrepeated synchronization (and it looks like this x-tuid stuff may be\nabout working around servers which don't support certain uid\noperations).\n\nSo that could probably be ripped out, too, with no ill effect.\n\nThat's just from looking at the code for a few minutes. I would not be\nsurprised if there is more useless cruft, nor would I be surprised to\nfind that I am totally wrong about something above.\n\nAnyway, here is the patch to rip out the arc4 stuff. It has a very\npleasant diff-stat. :)\n\n---\n imap-send.c |  130 ++--------------------------------------------------------\n 1 files changed, 5 insertions(+), 125 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 3847fd1..d60a0bd 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -123,9 +123,6 @@ static int nfvasprintf(char **strp, const char *fmt, va_list ap)\n \treturn len;\n }\n \n-static void arc4_init(void);\n-static unsigned char arc4_getbyte(void);\n-\n struct imap_server_conf {\n \tchar *name;\n \tchar *tunnel;\n@@ -489,52 +486,6 @@ static int nfsnprintf(char *buf, int blen, const char *fmt, ...)\n \treturn ret;\n }\n \n-static struct {\n-\tunsigned char i, j, s[256];\n-} rs;\n-\n-static void arc4_init(void)\n-{\n-\tint i, fd;\n-\tunsigned char j, si, dat[128];\n-\n-\tif ((fd = open(\"/dev/urandom\", O_RDONLY)) < 0 && (fd = open(\"/dev/random\", O_RDONLY)) < 0) {\n-\t\tfprintf(stderr, \"Fatal: no random number source available.\\n\");\n-\t\texit(3);\n-\t}\n-\tif (read_in_full(fd, dat, 128) != 128) {\n-\t\tfprintf(stderr, \"Fatal: cannot read random number source.\\n\");\n-\t\texit(3);\n-\t}\n-\tclose(fd);\n-\n-\tfor (i = 0; i < 256; i++)\n-\t\trs.s[i] = i;\n-\tfor (i = j = 0; i < 256; i++) {\n-\t\tsi = rs.s[i];\n-\t\tj += si + dat[i & 127];\n-\t\trs.s[i] = rs.s[j];\n-\t\trs.s[j] = si;\n-\t}\n-\trs.i = rs.j = 0;\n-\n-\tfor (i = 0; i < 256; i++)\n-\t\tarc4_getbyte();\n-}\n-\n-static unsigned char arc4_getbyte(void)\n-{\n-\tunsigned char si, sj;\n-\n-\trs.i++;\n-\tsi = rs.s[rs.i];\n-\trs.j += si;\n-\tsj = rs.s[rs.j];\n-\trs.s[rs.i] = sj;\n-\trs.s[rs.j] = si;\n-\treturn rs.s[(si + sj) & 0xff];\n-}\n-\n static struct imap_cmd *v_issue_imap_cmd(struct imap_store *ctx,\n \t\t\t\t\t struct imap_cmd_cb *cb,\n \t\t\t\t\t const char *fmt, va_list ap)\n@@ -1198,88 +1149,20 @@ static int imap_make_flags(int flags, char *buf)\n \treturn d;\n }\n \n-#define TUIDL 8\n-\n static int imap_store_msg(struct store *gctx, struct msg_data *data, int *uid)\n {\n \tstruct imap_store *ctx = (struct imap_store *)gctx;\n \tstruct imap *imap = ctx->imap;\n \tstruct imap_cmd_cb cb;\n-\tchar *fmap, *buf;\n \tconst char *prefix, *box;\n-\tint ret, i, j, d, len, extra, nocr;\n-\tint start, sbreak = 0, ebreak = 0;\n-\tchar flagstr[128], tuid[TUIDL * 2 + 1];\n+\tint ret, d;\n+\tchar flagstr[128];\n \n \tmemset(&cb, 0, sizeof(cb));\n \n-\tfmap = data->data;\n-\tlen = data->len;\n-\tnocr = !data->crlf;\n-\textra = 0, i = 0;\n-\tif (!CAP(UIDPLUS) && uid) {\n-\tnloop:\n-\t\tstart = i;\n-\t\twhile (i < len)\n-\t\t\tif (fmap[i++] == '\\n') {\n-\t\t\t\textra += nocr;\n-\t\t\t\tif (i - 2 + nocr == start) {\n-\t\t\t\t\tsbreak = ebreak = i - 2 + nocr;\n-\t\t\t\t\tgoto mktid;\n-\t\t\t\t}\n-\t\t\t\tif (!memcmp(fmap + start, \"X-TUID: \", 8)) {\n-\t\t\t\t\textra -= (ebreak = i) - (sbreak = start) + nocr;\n-\t\t\t\t\tgoto mktid;\n-\t\t\t\t}\n-\t\t\t\tgoto nloop;\n-\t\t\t}\n-\t\t/* invalid message */\n-\t\tfree(fmap);\n-\t\treturn DRV_MSG_BAD;\n-\tmktid:\n-\t\tfor (j = 0; j < TUIDL; j++)\n-\t\t\tsprintf(tuid + j * 2, \"%02x\", arc4_getbyte());\n-\t\textra += 8 + TUIDL * 2 + 2;\n-\t}\n-\tif (nocr)\n-\t\tfor (; i < len; i++)\n-\t\t\tif (fmap[i] == '\\n')\n-\t\t\t\textra++;\n-\n-\tcb.dlen = len + extra;\n-\tbuf = cb.data = xmalloc(cb.dlen);\n-\ti = 0;\n-\tif (!CAP(UIDPLUS) && uid) {\n-\t\tif (nocr) {\n-\t\t\tfor (; i < sbreak; i++)\n-\t\t\t\tif (fmap[i] == '\\n') {\n-\t\t\t\t\t*buf++ = '\\r';\n-\t\t\t\t\t*buf++ = '\\n';\n-\t\t\t\t} else\n-\t\t\t\t\t*buf++ = fmap[i];\n-\t\t} else {\n-\t\t\tmemcpy(buf, fmap, sbreak);\n-\t\t\tbuf += sbreak;\n-\t\t}\n-\t\tmemcpy(buf, \"X-TUID: \", 8);\n-\t\tbuf += 8;\n-\t\tmemcpy(buf, tuid, TUIDL * 2);\n-\t\tbuf += TUIDL * 2;\n-\t\t*buf++ = '\\r';\n-\t\t*buf++ = '\\n';\n-\t\ti = ebreak;\n-\t}\n-\tif (nocr) {\n-\t\tfor (; i < len; i++)\n-\t\t\tif (fmap[i] == '\\n') {\n-\t\t\t\t*buf++ = '\\r';\n-\t\t\t\t*buf++ = '\\n';\n-\t\t\t} else\n-\t\t\t\t*buf++ = fmap[i];\n-\t} else\n-\t\tmemcpy(buf, fmap + i, len - i);\n-\n-\tfree(fmap);\n+\tcb.dlen = data->len;\n+\tcb.data = xmalloc(cb.dlen);\n+\tmemcpy(cb.data, data->data, data->len);\n \n \td = 0;\n \tif (data->flags) {\n@@ -1491,9 +1374,6 @@ int main(int argc, char **argv)\n \n \tgit_extract_argv0_path(argv[0]);\n \n-\t/* init the random number generator */\n-\tarc4_init();\n-\n \tsetup_git_directory_gently(&nongit_ok);\n \tgit_config(git_imap_config, NULL);\n \n"},{"id":"124194","messageId":"20091003205217.GC9058@sigill.intra.peff.net","threadId":"21118","inReplyTo":"20091003204317.GB9058@sigill.intra.peff.net","subject":"Re: [PATCH/RFC 5/7] imap-send: provide fall-back random-source","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-10-03T20:52:18Z","receivedAt":"2009-10-03T20:52:18Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Oct 03, 2009 at 04:43:17PM -0400, Jeff King wrote:\n\n> The other confusing bit is that the code carefully tracks the \"uid\"\n> (deep within the call chain it munges cb.ctx, which is a pointer to uid)\n> which is assigned to the newly created message by the server. This could\n> be used by a client to later refer to the same message unambiguously.\n> But we never do that, and just throw away the uid value that the server\n> gives us.  Again, I suspect this is a holdover from isync wanting to do\n> repeated synchronization (and it looks like this x-tuid stuff may be\n> about working around servers which don't support certain uid\n> operations).\n> \n> So that could probably be ripped out, too, with no ill effect.\n\nAnd here is a patch (on top of the earlier one) to do that.\n\nEven more can be ripped out from the lower levels, too, I'm not sure if\nit is worth it. Ripping out the arc4 code is worthwhile, because it\nsolves a portability problem. Ripping out more isn't really helping us\nmuch. Less code makes it easier to read, but given our lack of tests and\nmy relatively small knowledge of this code, it is entirely possible I am\nintroducing new bugs.\n\n---\n\n imap-send.c |   25 ++++++-------------------\n 1 files changed, 6 insertions(+), 19 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex d60a0bd..8da7a94 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -1149,7 +1149,7 @@ static int imap_make_flags(int flags, char *buf)\n \treturn d;\n }\n \n-static int imap_store_msg(struct store *gctx, struct msg_data *data, int *uid)\n+static int imap_store_msg(struct store *gctx, struct msg_data *data)\n {\n \tstruct imap_store *ctx = (struct imap_store *)gctx;\n \tstruct imap *imap = ctx->imap;\n@@ -1171,26 +1171,14 @@ static int imap_store_msg(struct store *gctx, struct msg_data *data, int *uid)\n \t}\n \tflagstr[d] = 0;\n \n-\tif (!uid) {\n-\t\tbox = gctx->conf->trash;\n-\t\tprefix = ctx->prefix;\n-\t\tcb.create = 1;\n-\t\tif (ctx->trashnc)\n-\t\t\timap->caps = imap->rcaps & ~(1 << LITERALPLUS);\n-\t} else {\n-\t\tbox = gctx->name;\n-\t\tprefix = !strcmp(box, \"INBOX\") ? \"\" : ctx->prefix;\n-\t\tcb.create = 0;\n-\t}\n-\tcb.ctx = uid;\n+\tbox = gctx->name;\n+\tprefix = !strcmp(box, \"INBOX\") ? \"\" : ctx->prefix;\n+\tcb.create = 0;\n \tret = imap_exec_m(ctx, &cb, \"APPEND \\\"%s%s\\\" %s\", prefix, box, flagstr);\n \timap->caps = imap->rcaps;\n \tif (ret != DRV_OK)\n \t\treturn ret;\n-\tif (!uid)\n-\t\tctx->trashnc = 0;\n-\telse\n-\t\tgctx->count++;\n+\tgctx->count++;\n \n \treturn DRV_OK;\n }\n@@ -1366,7 +1354,6 @@ int main(int argc, char **argv)\n {\n \tstruct msg_data all_msgs, msg;\n \tstruct store *ctx = NULL;\n-\tint uid = 0;\n \tint ofs = 0;\n \tint r;\n \tint total, n = 0;\n@@ -1420,7 +1407,7 @@ int main(int argc, char **argv)\n \t\t\tbreak;\n \t\tif (server.use_html)\n \t\t\twrap_in_html(&msg);\n-\t\tr = imap_store_msg(ctx, &msg, &uid);\n+\t\tr = imap_store_msg(ctx, &msg);\n \t\tif (r != DRV_OK)\n \t\t\tbreak;\n \t\tn++;\n"},{"id":"124195","messageId":"200910032334.16757.j6t@kdbg.org","threadId":"21118","inReplyTo":"40aa078e0910031144r735a6fdq25efc1e57a1d4c33@mail.gmail.com","subject":"Re: [PATCH/RFC 1/7] imap-send: use separate read and write fds","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2009-10-03T21:34:15Z","receivedAt":"2009-10-03T21:34:15Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"\nOn Samstag, 3. Oktober 2009, Erik Faye-Lund wrote:\n> - It needs some additional patching to get tunnelling support working\n> on Windows, because we can't exec \"/bin/sh\" there. Changing it to\n> \"c:\\\\msysgit\\\\bin\\\\sh.exe\" makes tunneling work for me, but isn't\n> exactly portable across installations.\n\nIt should be fine to just exec \"sh\" (without a path).\n\n-- Hannes\n"},{"id":"124409","messageId":"40aa078e0910081616wc1129edr2e1397964a0e6ae5@mail.gmail.com","threadId":"21118","inReplyTo":"20091003205217.GC9058@sigill.intra.peff.net","subject":"Re: [PATCH/RFC 5/7] imap-send: provide fall-back random-source","fromName":"Erik Faye-Lund","fromEmail":"kusmabite@googlemail.com","sentAt":"2009-10-08T23:16:50Z","receivedAt":"2009-10-08T23:16:50Z","isPatch":true,"sender":{"key":"kusmabite@gmail.com","avatar":"https://avatars.githubusercontent.com/u/47073?v=4"},"body":"\nOn Sat, Oct 3, 2009 at 10:52 PM, Jeff King <peff@peff.net> wrote:\n>> So that could probably be ripped out, too, with no ill effect.\n>\n> And here is a patch (on top of the earlier one) to do that.\n\nAlright, so I'm spinning a new version of this series, and I'm\nwondering a bit how to include patches like these, where there's no\ncommit message (because it was a sketch or something, I guess) or\nsign-off. Should I send the commit-messages to the author and have the\nhim/her sign off on them, or should I set me as author and credit the\nreal author for the actual work in the commit message? I see the\nlatter have been done quite a bit in git.git already. The benefit of\nthe first one is of course that authorship is retained, but the\nbackside is that it incorrectly looks like the author wrote the commit\nmessage.\n\nAre there any preferences?\n\n-- \nErik \"kusma\" Faye-Lund\nkusmabite@gmail.com\n(+47) 986 59 656\n"},{"id":"124410","messageId":"20091009000350.GA5217@coredump.intra.peff.net","threadId":"21118","inReplyTo":"40aa078e0910081616wc1129edr2e1397964a0e6ae5@mail.gmail.com","subject":"Re: [PATCH/RFC 5/7] imap-send: provide fall-back random-source","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2009-10-09T00:03:50Z","receivedAt":"2009-10-09T00:03:50Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Oct 09, 2009 at 01:16:50AM +0200, Erik Faye-Lund wrote:\n\n> > And here is a patch (on top of the earlier one) to do that.\n> \n> Alright, so I'm spinning a new version of this series, and I'm\n> wondering a bit how to include patches like these, where there's no\n> commit message (because it was a sketch or something, I guess) or\n> sign-off. Should I send the commit-messages to the author and have the\n> him/her sign off on them, or should I set me as author and credit the\n> real author for the actual work in the commit message? I see the\n> latter have been done quite a bit in git.git already. The benefit of\n> the first one is of course that authorship is retained, but the\n> backside is that it incorrectly looks like the author wrote the commit\n> message.\n> \n> Are there any preferences?\n\nUsually a \"something like this\" patch means it is not very well tested,\nand that was certainly the case here (I don't even used imap-send). But\nif somebody else (like you) concurs that it is the sane thing to do and\nhas tested or run with it for a while, then maybe it is time to promote\nit.\n\nAs for how to do that, both of your proposed solutions happen in\npractice. Usually I would only mark myself as author if I picked up\nsomebody's \"how about this\" and tweaked it significantly or added\nsomething to it. If you write the commit message, or add tests, or\nwhatever, then usually it is a good idea to just say so in the commit\nmessage.\n\nBut when in doubt, ask the original author what they want to do. In this\ncase, I think it is best for me to write the message, as I did a fair\nbit of looking into the reasons for this code.\n\nSo here goes. It's still only lightly tested by me, but we have no test\nscripts at all for imap-send. I suspect getting it into 'next' is the\nbest way to actually get it tested.\n\n-- >8 --\nSubject: [PATCH] imap-send: remove useless uid code\n\nThe imap-send code is based on code from isync, a program\nfor syncing imap mailboxes. Because of this, it has\ninherited some code that makes sense for isync, but not for\nimap-send.\n\nIn particular, when storing a message, it does one of:\n\n  - if the server supports it, note the server-assigned\n    unique identifier (UID) given to each message\n\n  - otherwise, assigned a random UID and store it in the\n    message header as X-TUID\n\nPresumably this is used in isync to be able to synchronize\nmailstores multiple times without duplication. But for\nimap-send, it the values are useless; we never do anything\nwith them and simply forget them at the end of the program.\n\nThis patch removes the useless code. Not only is it nice for\nmaintainability to get rid of dead code, but the removed\ncode relied on the existence of /dev/urandom, which made it\na portability problem for non-Unix platforms.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\nAs you may be able to tell from the commit message, this is both of the\npatches rolled into one. I could probably rip out even more, but it's\nnot really worth the time. This one solves the portability issue.\n\n imap-send.c |  155 ++++------------------------------------------------------\n 1 files changed, 11 insertions(+), 144 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 3847fd1..8da7a94 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -123,9 +123,6 @@ static int nfvasprintf(char **strp, const char *fmt, va_list ap)\n \treturn len;\n }\n \n-static void arc4_init(void);\n-static unsigned char arc4_getbyte(void);\n-\n struct imap_server_conf {\n \tchar *name;\n \tchar *tunnel;\n@@ -489,52 +486,6 @@ static int nfsnprintf(char *buf, int blen, const char *fmt, ...)\n \treturn ret;\n }\n \n-static struct {\n-\tunsigned char i, j, s[256];\n-} rs;\n-\n-static void arc4_init(void)\n-{\n-\tint i, fd;\n-\tunsigned char j, si, dat[128];\n-\n-\tif ((fd = open(\"/dev/urandom\", O_RDONLY)) < 0 && (fd = open(\"/dev/random\", O_RDONLY)) < 0) {\n-\t\tfprintf(stderr, \"Fatal: no random number source available.\\n\");\n-\t\texit(3);\n-\t}\n-\tif (read_in_full(fd, dat, 128) != 128) {\n-\t\tfprintf(stderr, \"Fatal: cannot read random number source.\\n\");\n-\t\texit(3);\n-\t}\n-\tclose(fd);\n-\n-\tfor (i = 0; i < 256; i++)\n-\t\trs.s[i] = i;\n-\tfor (i = j = 0; i < 256; i++) {\n-\t\tsi = rs.s[i];\n-\t\tj += si + dat[i & 127];\n-\t\trs.s[i] = rs.s[j];\n-\t\trs.s[j] = si;\n-\t}\n-\trs.i = rs.j = 0;\n-\n-\tfor (i = 0; i < 256; i++)\n-\t\tarc4_getbyte();\n-}\n-\n-static unsigned char arc4_getbyte(void)\n-{\n-\tunsigned char si, sj;\n-\n-\trs.i++;\n-\tsi = rs.s[rs.i];\n-\trs.j += si;\n-\tsj = rs.s[rs.j];\n-\trs.s[rs.i] = sj;\n-\trs.s[rs.j] = si;\n-\treturn rs.s[(si + sj) & 0xff];\n-}\n-\n static struct imap_cmd *v_issue_imap_cmd(struct imap_store *ctx,\n \t\t\t\t\t struct imap_cmd_cb *cb,\n \t\t\t\t\t const char *fmt, va_list ap)\n@@ -1198,88 +1149,20 @@ static int imap_make_flags(int flags, char *buf)\n \treturn d;\n }\n \n-#define TUIDL 8\n-\n-static int imap_store_msg(struct store *gctx, struct msg_data *data, int *uid)\n+static int imap_store_msg(struct store *gctx, struct msg_data *data)\n {\n \tstruct imap_store *ctx = (struct imap_store *)gctx;\n \tstruct imap *imap = ctx->imap;\n \tstruct imap_cmd_cb cb;\n-\tchar *fmap, *buf;\n \tconst char *prefix, *box;\n-\tint ret, i, j, d, len, extra, nocr;\n-\tint start, sbreak = 0, ebreak = 0;\n-\tchar flagstr[128], tuid[TUIDL * 2 + 1];\n+\tint ret, d;\n+\tchar flagstr[128];\n \n \tmemset(&cb, 0, sizeof(cb));\n \n-\tfmap = data->data;\n-\tlen = data->len;\n-\tnocr = !data->crlf;\n-\textra = 0, i = 0;\n-\tif (!CAP(UIDPLUS) && uid) {\n-\tnloop:\n-\t\tstart = i;\n-\t\twhile (i < len)\n-\t\t\tif (fmap[i++] == '\\n') {\n-\t\t\t\textra += nocr;\n-\t\t\t\tif (i - 2 + nocr == start) {\n-\t\t\t\t\tsbreak = ebreak = i - 2 + nocr;\n-\t\t\t\t\tgoto mktid;\n-\t\t\t\t}\n-\t\t\t\tif (!memcmp(fmap + start, \"X-TUID: \", 8)) {\n-\t\t\t\t\textra -= (ebreak = i) - (sbreak = start) + nocr;\n-\t\t\t\t\tgoto mktid;\n-\t\t\t\t}\n-\t\t\t\tgoto nloop;\n-\t\t\t}\n-\t\t/* invalid message */\n-\t\tfree(fmap);\n-\t\treturn DRV_MSG_BAD;\n-\tmktid:\n-\t\tfor (j = 0; j < TUIDL; j++)\n-\t\t\tsprintf(tuid + j * 2, \"%02x\", arc4_getbyte());\n-\t\textra += 8 + TUIDL * 2 + 2;\n-\t}\n-\tif (nocr)\n-\t\tfor (; i < len; i++)\n-\t\t\tif (fmap[i] == '\\n')\n-\t\t\t\textra++;\n-\n-\tcb.dlen = len + extra;\n-\tbuf = cb.data = xmalloc(cb.dlen);\n-\ti = 0;\n-\tif (!CAP(UIDPLUS) && uid) {\n-\t\tif (nocr) {\n-\t\t\tfor (; i < sbreak; i++)\n-\t\t\t\tif (fmap[i] == '\\n') {\n-\t\t\t\t\t*buf++ = '\\r';\n-\t\t\t\t\t*buf++ = '\\n';\n-\t\t\t\t} else\n-\t\t\t\t\t*buf++ = fmap[i];\n-\t\t} else {\n-\t\t\tmemcpy(buf, fmap, sbreak);\n-\t\t\tbuf += sbreak;\n-\t\t}\n-\t\tmemcpy(buf, \"X-TUID: \", 8);\n-\t\tbuf += 8;\n-\t\tmemcpy(buf, tuid, TUIDL * 2);\n-\t\tbuf += TUIDL * 2;\n-\t\t*buf++ = '\\r';\n-\t\t*buf++ = '\\n';\n-\t\ti = ebreak;\n-\t}\n-\tif (nocr) {\n-\t\tfor (; i < len; i++)\n-\t\t\tif (fmap[i] == '\\n') {\n-\t\t\t\t*buf++ = '\\r';\n-\t\t\t\t*buf++ = '\\n';\n-\t\t\t} else\n-\t\t\t\t*buf++ = fmap[i];\n-\t} else\n-\t\tmemcpy(buf, fmap + i, len - i);\n-\n-\tfree(fmap);\n+\tcb.dlen = data->len;\n+\tcb.data = xmalloc(cb.dlen);\n+\tmemcpy(cb.data, data->data, data->len);\n \n \td = 0;\n \tif (data->flags) {\n@@ -1288,26 +1171,14 @@ static int imap_store_msg(struct store *gctx, struct msg_data *data, int *uid)\n \t}\n \tflagstr[d] = 0;\n \n-\tif (!uid) {\n-\t\tbox = gctx->conf->trash;\n-\t\tprefix = ctx->prefix;\n-\t\tcb.create = 1;\n-\t\tif (ctx->trashnc)\n-\t\t\timap->caps = imap->rcaps & ~(1 << LITERALPLUS);\n-\t} else {\n-\t\tbox = gctx->name;\n-\t\tprefix = !strcmp(box, \"INBOX\") ? \"\" : ctx->prefix;\n-\t\tcb.create = 0;\n-\t}\n-\tcb.ctx = uid;\n+\tbox = gctx->name;\n+\tprefix = !strcmp(box, \"INBOX\") ? \"\" : ctx->prefix;\n+\tcb.create = 0;\n \tret = imap_exec_m(ctx, &cb, \"APPEND \\\"%s%s\\\" %s\", prefix, box, flagstr);\n \timap->caps = imap->rcaps;\n \tif (ret != DRV_OK)\n \t\treturn ret;\n-\tif (!uid)\n-\t\tctx->trashnc = 0;\n-\telse\n-\t\tgctx->count++;\n+\tgctx->count++;\n \n \treturn DRV_OK;\n }\n@@ -1483,7 +1354,6 @@ int main(int argc, char **argv)\n {\n \tstruct msg_data all_msgs, msg;\n \tstruct store *ctx = NULL;\n-\tint uid = 0;\n \tint ofs = 0;\n \tint r;\n \tint total, n = 0;\n@@ -1491,9 +1361,6 @@ int main(int argc, char **argv)\n \n \tgit_extract_argv0_path(argv[0]);\n \n-\t/* init the random number generator */\n-\tarc4_init();\n-\n \tsetup_git_directory_gently(&nongit_ok);\n \tgit_config(git_imap_config, NULL);\n \n@@ -1540,7 +1407,7 @@ int main(int argc, char **argv)\n \t\t\tbreak;\n \t\tif (server.use_html)\n \t\t\twrap_in_html(&msg);\n-\t\tr = imap_store_msg(ctx, &msg, &uid);\n+\t\tr = imap_store_msg(ctx, &msg);\n \t\tif (r != DRV_OK)\n \t\t\tbreak;\n \t\tn++;\n-- \n1.6.5.rc3.206.g63d9c\n"}]}