{"thread":{"id":"32620","subject":"[PATCH 02/14] imap-send.c: remove struct msg_data","startedAt":"2013-01-14T05:32:32Z","lastAt":"2013-01-14T19:02:11Z","messageCount":27,"participants":["Michael Haggerty","Jonathan Nieder","Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":14},"messages":[{"id":"206747","messageId":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":null,"subject":"[PATCH 00/14] Remove unused code from imap-send.c","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:32Z","receivedAt":"2013-01-14T05:32:32Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"As discussed before [1], imap-send.c was copied from isync, including\na lot of code that is not used within the git project.  This patch\nseries rips a bunch of it out.\n\n[1] http://comments.gmane.org/gmane.comp.version-control.git/210355\n\nMichael Haggerty (14):\n  imap-send.c: remove msg_data::flags, which was always zero\n  imap-send.c: remove struct msg_data\n  iamp-send.c: remove unused struct imap_store_conf\n  imap-send.c: remove struct store_conf\n  imap-send.c: remove struct message\n  imap-send.c: remove some unused fields from struct store\n  imap-send.c: inline imap_parse_list() in imap_list()\n  imap-send.c: remove struct imap argument to parse_imap_list_l()\n  imap-send.c: remove namespace fields from struct imap\n  imap-send.c: remove unused field imap_store::trashnc\n  imap-send.c: simplify logic in lf_to_crlf()\n  imap-send.c: use struct imap_store instead of struct store\n  imap-send.c: remove unused field imap_store::uidvalidity\n  imap-send.c: fold struct store into struct imap_store\n\n imap-send.c | 286 +++++++++---------------------------------------------------\n 1 file changed, 39 insertions(+), 247 deletions(-)\n\n-- \n1.8.0.3\n"},{"id":"206754","messageId":"1358141566-26081-2-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 01/14] imap-send.c: remove msg_data::flags, which was always zero","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:33Z","receivedAt":"2013-01-14T05:32:33Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"This removes the need for function imap_make_flags(), so delete it,\ntoo.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 40 +++-------------------------------------\n 1 file changed, 3 insertions(+), 37 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex e521e2f..451d502 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -70,7 +70,6 @@ struct store {\n \n struct msg_data {\n \tstruct strbuf data;\n-\tunsigned char flags;\n };\n \n static const char imap_send_usage[] = \"git imap-send < <mbox>\";\n@@ -225,14 +224,6 @@ static const char *cap_list[] = {\n static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd);\n \n \n-static const char *Flags[] = {\n-\t\"Draft\",\n-\t\"Flagged\",\n-\t\"Answered\",\n-\t\"Seen\",\n-\t\"Deleted\",\n-};\n-\n #ifndef NO_OPENSSL\n static void ssl_socket_perror(const char *func)\n {\n@@ -1246,23 +1237,6 @@ bail:\n \treturn NULL;\n }\n \n-static int imap_make_flags(int flags, char *buf)\n-{\n-\tconst char *s;\n-\tunsigned i, d;\n-\n-\tfor (i = d = 0; i < ARRAY_SIZE(Flags); i++)\n-\t\tif (flags & (1 << i)) {\n-\t\t\tbuf[d++] = ' ';\n-\t\t\tbuf[d++] = '\\\\';\n-\t\t\tfor (s = Flags[i]; *s; s++)\n-\t\t\t\tbuf[d++] = *s;\n-\t\t}\n-\tbuf[0] = '(';\n-\tbuf[d++] = ')';\n-\treturn d;\n-}\n-\n static void lf_to_crlf(struct strbuf *msg)\n {\n \tsize_t new_len;\n@@ -1311,8 +1285,7 @@ static int imap_store_msg(struct store *gctx, struct msg_data *msg)\n \tstruct imap *imap = ctx->imap;\n \tstruct imap_cmd_cb cb;\n \tconst char *prefix, *box;\n-\tint ret, d;\n-\tchar flagstr[128];\n+\tint ret;\n \n \tlf_to_crlf(&msg->data);\n \tmemset(&cb, 0, sizeof(cb));\n@@ -1320,17 +1293,10 @@ static int imap_store_msg(struct store *gctx, struct msg_data *msg)\n \tcb.dlen = msg->data.len;\n \tcb.data = strbuf_detach(&msg->data, NULL);\n \n-\td = 0;\n-\tif (msg->flags) {\n-\t\td = imap_make_flags(msg->flags, flagstr);\n-\t\tflagstr[d++] = ' ';\n-\t}\n-\tflagstr[d] = 0;\n-\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+\tret = imap_exec_m(ctx, &cb, \"APPEND \\\"%s%s\\\"\", prefix, box);\n \timap->caps = imap->rcaps;\n \tif (ret != DRV_OK)\n \t\treturn ret;\n@@ -1483,7 +1449,7 @@ static int git_imap_config(const char *key, const char *val, void *cb)\n int main(int argc, char **argv)\n {\n \tstruct strbuf all_msgs = STRBUF_INIT;\n-\tstruct msg_data msg = {STRBUF_INIT, 0};\n+\tstruct msg_data msg = {STRBUF_INIT};\n \tstruct store *ctx = NULL;\n \tint ofs = 0;\n \tint r;\n-- \n1.8.0.3\n"},{"id":"206745","messageId":"1358141566-26081-3-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 02/14] imap-send.c: remove struct msg_data","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:34Z","receivedAt":"2013-01-14T05:32:34Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"Now that its flags member has been deleted, all that is left is a\nstrbuf.  So use a strbuf directly.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 18 +++++++-----------\n 1 file changed, 7 insertions(+), 11 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 451d502..a8cb66a 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -68,10 +68,6 @@ struct store {\n \tint recent; /* # of recent messages - don't trust this beyond the initial read */\n };\n \n-struct msg_data {\n-\tstruct strbuf data;\n-};\n-\n static const char imap_send_usage[] = \"git imap-send < <mbox>\";\n \n #undef DRV_OK\n@@ -1279,7 +1275,7 @@ static void lf_to_crlf(struct strbuf *msg)\n  * Store msg to IMAP.  Also detach and free the data from msg->data,\n  * leaving msg->data empty.\n  */\n-static int imap_store_msg(struct store *gctx, struct msg_data *msg)\n+static int imap_store_msg(struct store *gctx, struct strbuf *msg)\n {\n \tstruct imap_store *ctx = (struct imap_store *)gctx;\n \tstruct imap *imap = ctx->imap;\n@@ -1287,11 +1283,11 @@ static int imap_store_msg(struct store *gctx, struct msg_data *msg)\n \tconst char *prefix, *box;\n \tint ret;\n \n-\tlf_to_crlf(&msg->data);\n+\tlf_to_crlf(msg);\n \tmemset(&cb, 0, sizeof(cb));\n \n-\tcb.dlen = msg->data.len;\n-\tcb.data = strbuf_detach(&msg->data, NULL);\n+\tcb.dlen = msg->len;\n+\tcb.data = strbuf_detach(msg, NULL);\n \n \tbox = gctx->name;\n \tprefix = !strcmp(box, \"INBOX\") ? \"\" : ctx->prefix;\n@@ -1449,7 +1445,7 @@ static int git_imap_config(const char *key, const char *val, void *cb)\n int main(int argc, char **argv)\n {\n \tstruct strbuf all_msgs = STRBUF_INIT;\n-\tstruct msg_data msg = {STRBUF_INIT};\n+\tstruct strbuf msg = STRBUF_INIT;\n \tstruct store *ctx = NULL;\n \tint ofs = 0;\n \tint r;\n@@ -1511,10 +1507,10 @@ int main(int argc, char **argv)\n \t\tunsigned percent = n * 100 / total;\n \n \t\tfprintf(stderr, \"%4u%% (%d/%d) done\\r\", percent, n, total);\n-\t\tif (!split_msg(&all_msgs, &msg.data, &ofs))\n+\t\tif (!split_msg(&all_msgs, &msg, &ofs))\n \t\t\tbreak;\n \t\tif (server.use_html)\n-\t\t\twrap_in_html(&msg.data);\n+\t\t\twrap_in_html(&msg);\n \t\tr = imap_store_msg(ctx, &msg);\n \t\tif (r != DRV_OK)\n \t\t\tbreak;\n-- \n1.8.0.3\n"},{"id":"206755","messageId":"1358141566-26081-4-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 03/14] iamp-send.c: remove unused struct imap_store_conf","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:35Z","receivedAt":"2013-01-14T05:32:35Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 5 -----\n 1 file changed, 5 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex a8cb66a..d675e70 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -130,11 +130,6 @@ static struct imap_server_conf server = {\n \tNULL,\t/* auth_method */\n };\n \n-struct imap_store_conf {\n-\tstruct store_conf gen;\n-\tstruct imap_server_conf *server;\n-};\n-\n #define NIL\t(void *)0x1\n #define LIST\t(void *)0x2\n \n-- \n1.8.0.3\n"},{"id":"206746","messageId":"1358141566-26081-5-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 04/14] imap-send.c: remove struct store_conf","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:36Z","receivedAt":"2013-01-14T05:32:36Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"It was never used.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 11 -----------\n 1 file changed, 11 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex d675e70..3177361 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -33,15 +33,6 @@ typedef void *SSL;\n #include <openssl/hmac.h>\n #endif\n \n-struct store_conf {\n-\tchar *name;\n-\tconst char *path; /* should this be here? its interpretation is driver-specific */\n-\tchar *map_inbox;\n-\tchar *trash;\n-\tunsigned max_size; /* off_t is overkill */\n-\tunsigned trash_remote_new:1, trash_only_new:1;\n-};\n-\n /* For message->status */\n #define M_RECENT       (1<<0) /* unsyncable flag; maildir_* depend on this being 1<<0 */\n #define M_DEAD         (1<<1) /* expunged */\n@@ -55,8 +46,6 @@ struct message {\n };\n \n struct store {\n-\tstruct store_conf *conf; /* foreign */\n-\n \t/* currently open mailbox */\n \tconst char *name; /* foreign! maybe preset? */\n \tchar *path; /* own */\n-- \n1.8.0.3\n"},{"id":"206750","messageId":"1358141566-26081-6-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 05/14] imap-send.c: remove struct message","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:37Z","receivedAt":"2013-01-14T05:32:37Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"It was never used.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 26 --------------------------\n 1 file changed, 26 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 3177361..a47008b 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -33,23 +33,10 @@ typedef void *SSL;\n #include <openssl/hmac.h>\n #endif\n \n-/* For message->status */\n-#define M_RECENT       (1<<0) /* unsyncable flag; maildir_* depend on this being 1<<0 */\n-#define M_DEAD         (1<<1) /* expunged */\n-#define M_FLAGS        (1<<2) /* flags fetched */\n-\n-struct message {\n-\tstruct message *next;\n-\tsize_t size; /* zero implies \"not fetched\" */\n-\tint uid;\n-\tunsigned char flags, status;\n-};\n-\n struct store {\n \t/* currently open mailbox */\n \tconst char *name; /* foreign! maybe preset? */\n \tchar *path; /* own */\n-\tstruct message *msgs; /* own */\n \tint uidvalidity;\n \tunsigned char opts; /* maybe preset? */\n \t/* note that the following do _not_ reflect stats from msgs, but mailbox totals */\n@@ -74,8 +61,6 @@ static void imap_warn(const char *, ...);\n \n static char *next_arg(char **);\n \n-static void free_generic_messages(struct message *);\n-\n __attribute__((format (printf, 3, 4)))\n static int nfsnprintf(char *buf, int blen, const char *fmt, ...);\n \n@@ -447,16 +432,6 @@ static char *next_arg(char **s)\n \treturn ret;\n }\n \n-static void free_generic_messages(struct message *msgs)\n-{\n-\tstruct message *tmsg;\n-\n-\tfor (; msgs; msgs = tmsg) {\n-\t\ttmsg = msgs->next;\n-\t\tfree(msgs);\n-\t}\n-}\n-\n static int nfsnprintf(char *buf, int blen, const char *fmt, ...)\n {\n \tint ret;\n@@ -914,7 +889,6 @@ static void imap_close_server(struct imap_store *ictx)\n static void imap_close_store(struct store *ctx)\n {\n \timap_close_server((struct imap_store *)ctx);\n-\tfree_generic_messages(ctx->msgs);\n \tfree(ctx);\n }\n \n-- \n1.8.0.3\n"},{"id":"206749","messageId":"1358141566-26081-7-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 06/14] imap-send.c: remove some unused fields from struct store","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:38Z","receivedAt":"2013-01-14T05:32:38Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 15 +++------------\n 1 file changed, 3 insertions(+), 12 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex a47008b..fe2bfab 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -36,12 +36,7 @@ typedef void *SSL;\n struct store {\n \t/* currently open mailbox */\n \tconst char *name; /* foreign! maybe preset? */\n-\tchar *path; /* own */\n \tint uidvalidity;\n-\tunsigned char opts; /* maybe preset? */\n-\t/* note that the following do _not_ reflect stats from msgs, but mailbox totals */\n-\tint count; /* # of messages */\n-\tint recent; /* # of recent messages - don't trust this beyond the initial read */\n };\n \n static const char imap_send_usage[] = \"git imap-send < <mbox>\";\n@@ -772,13 +767,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)\n \t\t\t\t   !strcmp(\"NO\", arg) || !strcmp(\"BYE\", arg)) {\n \t\t\t\tif ((resp = parse_response_code(ctx, NULL, cmd)) != RESP_OK)\n \t\t\t\t\treturn resp;\n-\t\t\t} else if (!strcmp(\"CAPABILITY\", arg))\n+\t\t\t} else if (!strcmp(\"CAPABILITY\", arg)) {\n \t\t\t\tparse_capability(imap, cmd);\n-\t\t\telse if ((arg1 = next_arg(&cmd))) {\n-\t\t\t\tif (!strcmp(\"EXISTS\", arg1))\n-\t\t\t\t\tctx->gen.count = atoi(arg);\n-\t\t\t\telse if (!strcmp(\"RECENT\", arg1))\n-\t\t\t\t\tctx->gen.recent = atoi(arg);\n+\t\t\t} else if ((arg1 = next_arg(&cmd))) {\n+\t\t\t\t/* unused */\n \t\t\t} else {\n \t\t\t\tfprintf(stderr, \"IMAP error: unable to parse untagged response\\n\");\n \t\t\t\treturn RESP_BAD;\n@@ -1254,7 +1246,6 @@ static int imap_store_msg(struct store *gctx, struct strbuf *msg)\n \timap->caps = imap->rcaps;\n \tif (ret != DRV_OK)\n \t\treturn ret;\n-\tgctx->count++;\n \n \treturn DRV_OK;\n }\n-- \n1.8.0.3\n"},{"id":"206756","messageId":"1358141566-26081-8-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 07/14] imap-send.c: inline imap_parse_list() in imap_list()","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:39Z","receivedAt":"2013-01-14T05:32:39Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"The function is only called from here.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 9 ++-------\n 1 file changed, 2 insertions(+), 7 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex fe2bfab..452e73e 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -669,21 +669,16 @@ bail:\n \treturn -1;\n }\n \n-static struct imap_list *parse_imap_list(struct imap *imap, char **sp)\n+static struct imap_list *parse_list(char **sp)\n {\n \tstruct imap_list *head;\n \n-\tif (!parse_imap_list_l(imap, sp, &head, 0))\n+\tif (!parse_imap_list_l(NULL, sp, &head, 0))\n \t\treturn head;\n \tfree_list(head);\n \treturn NULL;\n }\n \n-static struct imap_list *parse_list(char **sp)\n-{\n-\treturn parse_imap_list(NULL, sp);\n-}\n-\n static void parse_capability(struct imap *imap, char *cmd)\n {\n \tchar *arg;\n-- \n1.8.0.3\n"},{"id":"206748","messageId":"1358141566-26081-9-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 08/14] imap-send.c: remove struct imap argument to parse_imap_list_l()","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:40Z","receivedAt":"2013-01-14T05:32:40Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"It was always set to NULL.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 39 +++------------------------------------\n 1 file changed, 3 insertions(+), 36 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 452e73e..5238c74 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -578,11 +578,10 @@ static void free_list(struct imap_list *list)\n \t}\n }\n \n-static int parse_imap_list_l(struct imap *imap, char **sp, struct imap_list **curp, int level)\n+static int parse_imap_list_l(char **sp, struct imap_list **curp, int level)\n {\n \tstruct imap_list *cur;\n \tchar *s = *sp, *p;\n-\tint n, bytes;\n \n \tfor (;;) {\n \t\twhile (isspace((unsigned char)*s))\n@@ -598,39 +597,7 @@ static int parse_imap_list_l(struct imap *imap, char **sp, struct imap_list **cu\n \t\t\t/* sublist */\n \t\t\ts++;\n \t\t\tcur->val = LIST;\n-\t\t\tif (parse_imap_list_l(imap, &s, &cur->child, level + 1))\n-\t\t\t\tgoto bail;\n-\t\t} else if (imap && *s == '{') {\n-\t\t\t/* literal */\n-\t\t\tbytes = cur->len = strtol(s + 1, &s, 10);\n-\t\t\tif (*s != '}')\n-\t\t\t\tgoto bail;\n-\n-\t\t\ts = cur->val = xmalloc(cur->len);\n-\n-\t\t\t/* dump whats left over in the input buffer */\n-\t\t\tn = imap->buf.bytes - imap->buf.offset;\n-\n-\t\t\tif (n > bytes)\n-\t\t\t\t/* the entire message fit in the buffer */\n-\t\t\t\tn = bytes;\n-\n-\t\t\tmemcpy(s, imap->buf.buf + imap->buf.offset, n);\n-\t\t\ts += n;\n-\t\t\tbytes -= n;\n-\n-\t\t\t/* mark that we used part of the buffer */\n-\t\t\timap->buf.offset += n;\n-\n-\t\t\t/* now read the rest of the message */\n-\t\t\twhile (bytes > 0) {\n-\t\t\t\tif ((n = socket_read(&imap->buf.sock, s, bytes)) <= 0)\n-\t\t\t\t\tgoto bail;\n-\t\t\t\ts += n;\n-\t\t\t\tbytes -= n;\n-\t\t\t}\n-\n-\t\t\tif (buffer_gets(&imap->buf, &s))\n+\t\t\tif (parse_imap_list_l(&s, &cur->child, level + 1))\n \t\t\t\tgoto bail;\n \t\t} else if (*s == '\"') {\n \t\t\t/* quoted string */\n@@ -673,7 +640,7 @@ static struct imap_list *parse_list(char **sp)\n {\n \tstruct imap_list *head;\n \n-\tif (!parse_imap_list_l(NULL, sp, &head, 0))\n+\tif (!parse_imap_list_l(sp, &head, 0))\n \t\treturn head;\n \tfree_list(head);\n \treturn NULL;\n-- \n1.8.0.3\n"},{"id":"206758","messageId":"1358141566-26081-10-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 09/14] imap-send.c: remove namespace fields from struct imap","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:41Z","receivedAt":"2013-01-14T05:32:41Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"They are unused, and their removal means that a bunch of list-related\ninfrastructure can be disposed of.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 74 +++++++------------------------------------------------------\n 1 file changed, 8 insertions(+), 66 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 5238c74..9616e80 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -99,15 +99,6 @@ static struct imap_server_conf server = {\n \tNULL,\t/* auth_method */\n };\n \n-#define NIL\t(void *)0x1\n-#define LIST\t(void *)0x2\n-\n-struct imap_list {\n-\tstruct imap_list *next, *child;\n-\tchar *val;\n-\tint len;\n-};\n-\n struct imap_socket {\n \tint fd[2];\n \tSSL *ssl;\n@@ -124,7 +115,6 @@ struct imap_cmd;\n \n struct imap {\n \tint uidnext; /* from SELECT responses */\n-\tstruct imap_list *ns_personal, *ns_other, *ns_shared; /* NAMESPACE info */\n \tunsigned caps, rcaps; /* CAPABILITY results */\n \t/* command queue */\n \tint nexttag, num_in_progress, literal_pending;\n@@ -554,34 +544,9 @@ static int imap_exec_m(struct imap_store *ctx, struct imap_cmd_cb *cb,\n \t}\n }\n \n-static int is_atom(struct imap_list *list)\n-{\n-\treturn list && list->val && list->val != NIL && list->val != LIST;\n-}\n-\n-static int is_list(struct imap_list *list)\n-{\n-\treturn list && list->val == LIST;\n-}\n-\n-static void free_list(struct imap_list *list)\n-{\n-\tstruct imap_list *tmp;\n-\n-\tfor (; list; list = tmp) {\n-\t\ttmp = list->next;\n-\t\tif (is_list(list))\n-\t\t\tfree_list(list->child);\n-\t\telse if (is_atom(list))\n-\t\t\tfree(list->val);\n-\t\tfree(list);\n-\t}\n-}\n-\n-static int parse_imap_list_l(char **sp, struct imap_list **curp, int level)\n+static int skip_imap_list_l(char **sp, int level)\n {\n-\tstruct imap_list *cur;\n-\tchar *s = *sp, *p;\n+\tchar *s = *sp;\n \n \tfor (;;) {\n \t\twhile (isspace((unsigned char)*s))\n@@ -590,36 +555,23 @@ static int parse_imap_list_l(char **sp, struct imap_list **curp, int level)\n \t\t\ts++;\n \t\t\tbreak;\n \t\t}\n-\t\t*curp = cur = xmalloc(sizeof(*cur));\n-\t\tcurp = &cur->next;\n-\t\tcur->val = NULL; /* for clean bail */\n \t\tif (*s == '(') {\n \t\t\t/* sublist */\n \t\t\ts++;\n-\t\t\tcur->val = LIST;\n-\t\t\tif (parse_imap_list_l(&s, &cur->child, level + 1))\n+\t\t\tif (skip_imap_list_l(&s, level + 1))\n \t\t\t\tgoto bail;\n \t\t} else if (*s == '\"') {\n \t\t\t/* quoted string */\n \t\t\ts++;\n-\t\t\tp = s;\n \t\t\tfor (; *s != '\"'; s++)\n \t\t\t\tif (!*s)\n \t\t\t\t\tgoto bail;\n-\t\t\tcur->len = s - p;\n \t\t\ts++;\n-\t\t\tcur->val = xmemdupz(p, cur->len);\n \t\t} else {\n \t\t\t/* atom */\n-\t\t\tp = s;\n \t\t\tfor (; *s && !isspace((unsigned char)*s); s++)\n \t\t\t\tif (level && *s == ')')\n \t\t\t\t\tbreak;\n-\t\t\tcur->len = s - p;\n-\t\t\tif (cur->len == 3 && !memcmp(\"NIL\", p, 3))\n-\t\t\t\tcur->val = NIL;\n-\t\t\telse\n-\t\t\t\tcur->val = xmemdupz(p, cur->len);\n \t\t}\n \n \t\tif (!level)\n@@ -628,22 +580,15 @@ static int parse_imap_list_l(char **sp, struct imap_list **curp, int level)\n \t\t\tgoto bail;\n \t}\n \t*sp = s;\n-\t*curp = NULL;\n \treturn 0;\n \n bail:\n-\t*curp = NULL;\n \treturn -1;\n }\n \n-static struct imap_list *parse_list(char **sp)\n+static void skip_list(char **sp)\n {\n-\tstruct imap_list *head;\n-\n-\tif (!parse_imap_list_l(sp, &head, 0))\n-\t\treturn head;\n-\tfree_list(head);\n-\treturn NULL;\n+\tskip_imap_list_l(sp, 0);\n }\n \n static void parse_capability(struct imap *imap, char *cmd)\n@@ -722,9 +667,9 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)\n \t\t\t}\n \n \t\t\tif (!strcmp(\"NAMESPACE\", arg)) {\n-\t\t\t\timap->ns_personal = parse_list(&cmd);\n-\t\t\t\timap->ns_other = parse_list(&cmd);\n-\t\t\t\timap->ns_shared = parse_list(&cmd);\n+\t\t\t\tskip_list(&cmd);\n+\t\t\t\tskip_list(&cmd);\n+\t\t\t\tskip_list(&cmd);\n \t\t\t} else if (!strcmp(\"OK\", arg) || !strcmp(\"BAD\", arg) ||\n \t\t\t\t   !strcmp(\"NO\", arg) || !strcmp(\"BYE\", arg)) {\n \t\t\t\tif ((resp = parse_response_code(ctx, NULL, cmd)) != RESP_OK)\n@@ -834,9 +779,6 @@ static void imap_close_server(struct imap_store *ictx)\n \t\timap_exec(ictx, NULL, \"LOGOUT\");\n \t\tsocket_shutdown(&imap->buf.sock);\n \t}\n-\tfree_list(imap->ns_personal);\n-\tfree_list(imap->ns_other);\n-\tfree_list(imap->ns_shared);\n \tfree(imap);\n }\n \n-- \n1.8.0.3\n"},{"id":"206751","messageId":"1358141566-26081-11-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 10/14] imap-send.c: remove unused field imap_store::trashnc","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:42Z","receivedAt":"2013-01-14T05:32:42Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 2 --\n 1 file changed, 2 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 9616e80..70abe9b 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -127,7 +127,6 @@ struct imap_store {\n \tint uidvalidity;\n \tstruct imap *imap;\n \tconst char *prefix;\n-\tunsigned /*currentnc:1,*/ trashnc:1;\n };\n \n struct imap_cmd_cb {\n@@ -1079,7 +1078,6 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)\n \t} /* !preauth */\n \n \tctx->prefix = \"\";\n-\tctx->trashnc = 1;\n \treturn (struct store *)ctx;\n \n bail:\n-- \n1.8.0.3\n"},{"id":"206759","messageId":"1358141566-26081-12-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 11/14] imap-send.c: simplify logic in lf_to_crlf()","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:43Z","receivedAt":"2013-01-14T05:32:43Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 31 ++++++++-----------------------\n 1 file changed, 8 insertions(+), 23 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 70abe9b..3167dcc 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -1089,36 +1089,21 @@ static void lf_to_crlf(struct strbuf *msg)\n {\n \tsize_t new_len;\n \tchar *new;\n-\tint i, j, lfnum = 0;\n+\tint i, j = 0, lfnum = 0;\n+\tchar lastc;\n \n-\tif (msg->buf[0] == '\\n')\n-\t\tlfnum++;\n-\tfor (i = 1; i < msg->len; i++) {\n-\t\tif (msg->buf[i - 1] != '\\r' && msg->buf[i] == '\\n')\n+\tfor (i = 0, lastc = '\\0'; i < msg->len; i++) {\n+\t\tif (msg->buf[i] == '\\n' && lastc != '\\r')\n \t\t\tlfnum++;\n+\t\tlastc = msg->buf[i];\n \t}\n \n \tnew_len = msg->len + lfnum;\n \tnew = xmalloc(new_len + 1);\n-\tif (msg->buf[0] == '\\n') {\n-\t\tnew[0] = '\\r';\n-\t\tnew[1] = '\\n';\n-\t\ti = 1;\n-\t\tj = 2;\n-\t} else {\n-\t\tnew[0] = msg->buf[0];\n-\t\ti = 1;\n-\t\tj = 1;\n-\t}\n-\tfor ( ; i < msg->len; i++) {\n-\t\tif (msg->buf[i] != '\\n') {\n-\t\t\tnew[j++] = msg->buf[i];\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (msg->buf[i - 1] != '\\r')\n+\tfor (i = 0, lastc = '\\0'; i < msg->len; i++) {\n+\t\tif (msg->buf[i] == '\\n' && lastc != '\\r')\n \t\t\tnew[j++] = '\\r';\n-\t\t/* otherwise it already had CR before */\n-\t\tnew[j++] = '\\n';\n+\t\tlastc = new[j++] = msg->buf[i];\n \t}\n \tstrbuf_attach(msg, new, new_len, new_len + 1);\n }\n-- \n1.8.0.3\n"},{"id":"206757","messageId":"1358141566-26081-13-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 12/14] imap-send.c: use struct imap_store instead of struct store","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:44Z","receivedAt":"2013-01-14T05:32:44Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"In fact, all struct store instances are upcasts of struct imap_store\nanyway, so stop making the distinction.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 19 +++++++++----------\n 1 file changed, 9 insertions(+), 10 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 3167dcc..31fdbf3 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -781,9 +781,9 @@ static void imap_close_server(struct imap_store *ictx)\n \tfree(imap);\n }\n \n-static void imap_close_store(struct store *ctx)\n+static void imap_close_store(struct imap_store *ctx)\n {\n-\timap_close_server((struct imap_store *)ctx);\n+\timap_close_server(ctx);\n \tfree(ctx);\n }\n \n@@ -868,7 +868,7 @@ static int auth_cram_md5(struct imap_store *ctx, struct imap_cmd *cmd, const cha\n \treturn 0;\n }\n \n-static struct store *imap_open_store(struct imap_server_conf *srvc)\n+static struct imap_store *imap_open_store(struct imap_server_conf *srvc)\n {\n \tstruct imap_store *ctx;\n \tstruct imap *imap;\n@@ -1078,10 +1078,10 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)\n \t} /* !preauth */\n \n \tctx->prefix = \"\";\n-\treturn (struct store *)ctx;\n+\treturn ctx;\n \n bail:\n-\timap_close_store(&ctx->gen);\n+\timap_close_store(ctx);\n \treturn NULL;\n }\n \n@@ -1112,9 +1112,8 @@ static void lf_to_crlf(struct strbuf *msg)\n  * Store msg to IMAP.  Also detach and free the data from msg->data,\n  * leaving msg->data empty.\n  */\n-static int imap_store_msg(struct store *gctx, struct strbuf *msg)\n+static int imap_store_msg(struct imap_store *ctx, struct strbuf *msg)\n {\n-\tstruct imap_store *ctx = (struct imap_store *)gctx;\n \tstruct imap *imap = ctx->imap;\n \tstruct imap_cmd_cb cb;\n \tconst char *prefix, *box;\n@@ -1126,7 +1125,7 @@ static int imap_store_msg(struct store *gctx, struct strbuf *msg)\n \tcb.dlen = msg->len;\n \tcb.data = strbuf_detach(msg, NULL);\n \n-\tbox = gctx->name;\n+\tbox = ctx->gen.name;\n \tprefix = !strcmp(box, \"INBOX\") ? \"\" : ctx->prefix;\n \tcb.create = 0;\n \tret = imap_exec_m(ctx, &cb, \"APPEND \\\"%s%s\\\"\", prefix, box);\n@@ -1282,7 +1281,7 @@ int main(int argc, char **argv)\n {\n \tstruct strbuf all_msgs = STRBUF_INIT;\n \tstruct strbuf msg = STRBUF_INIT;\n-\tstruct store *ctx = NULL;\n+\tstruct imap_store *ctx = NULL;\n \tint ofs = 0;\n \tint r;\n \tint total, n = 0;\n@@ -1338,7 +1337,7 @@ int main(int argc, char **argv)\n \t}\n \n \tfprintf(stderr, \"sending %d message%s\\n\", total, (total != 1) ? \"s\" : \"\");\n-\tctx->name = imap_folder;\n+\tctx->gen.name = imap_folder;\n \twhile (1) {\n \t\tunsigned percent = n * 100 / total;\n \n-- \n1.8.0.3\n"},{"id":"206752","messageId":"1358141566-26081-14-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 13/14] imap-send.c: remove unused field imap_store::uidvalidity","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:45Z","receivedAt":"2013-01-14T05:32:45Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"I suspect that the existence of both imap_store::uidvalidity and\nstore::uidvalidity was an accident.\n\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 1 -\n 1 file changed, 1 deletion(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 31fdbf3..4d24faf 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -124,7 +124,6 @@ struct imap {\n \n struct imap_store {\n \tstruct store gen;\n-\tint uidvalidity;\n \tstruct imap *imap;\n \tconst char *prefix;\n };\n-- \n1.8.0.3\n"},{"id":"206753","messageId":"1358141566-26081-15-git-send-email-mhagger@alum.mit.edu","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"[PATCH 14/14] imap-send.c: fold struct store into struct imap_store","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T05:32:46Z","receivedAt":"2013-01-14T05:32:46Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"\nSigned-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n---\n imap-send.c | 18 +++++++-----------\n 1 file changed, 7 insertions(+), 11 deletions(-)\n\ndiff --git a/imap-send.c b/imap-send.c\nindex 4d24faf..1b665bb 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -33,12 +33,6 @@ typedef void *SSL;\n #include <openssl/hmac.h>\n #endif\n \n-struct store {\n-\t/* currently open mailbox */\n-\tconst char *name; /* foreign! maybe preset? */\n-\tint uidvalidity;\n-};\n-\n static const char imap_send_usage[] = \"git imap-send < <mbox>\";\n \n #undef DRV_OK\n@@ -123,7 +117,9 @@ struct imap {\n };\n \n struct imap_store {\n-\tstruct store gen;\n+\t/* currently open mailbox */\n+\tconst char *name; /* foreign! maybe preset? */\n+\tint uidvalidity;\n \tstruct imap *imap;\n \tconst char *prefix;\n };\n@@ -618,7 +614,7 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,\n \t*p++ = 0;\n \targ = next_arg(&s);\n \tif (!strcmp(\"UIDVALIDITY\", arg)) {\n-\t\tif (!(arg = next_arg(&s)) || !(ctx->gen.uidvalidity = atoi(arg))) {\n+\t\tif (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg))) {\n \t\t\tfprintf(stderr, \"IMAP error: malformed UIDVALIDITY status\\n\");\n \t\t\treturn RESP_BAD;\n \t\t}\n@@ -636,7 +632,7 @@ static int parse_response_code(struct imap_store *ctx, struct imap_cmd_cb *cb,\n \t\tfor (; isspace((unsigned char)*p); p++);\n \t\tfprintf(stderr, \"*** IMAP ALERT *** %s\\n\", p);\n \t} else if (cb && cb->ctx && !strcmp(\"APPENDUID\", arg)) {\n-\t\tif (!(arg = next_arg(&s)) || !(ctx->gen.uidvalidity = atoi(arg)) ||\n+\t\tif (!(arg = next_arg(&s)) || !(ctx->uidvalidity = atoi(arg)) ||\n \t\t    !(arg = next_arg(&s)) || !(*(int *)cb->ctx = atoi(arg))) {\n \t\t\tfprintf(stderr, \"IMAP error: malformed APPENDUID status\\n\");\n \t\t\treturn RESP_BAD;\n@@ -1124,7 +1120,7 @@ static int imap_store_msg(struct imap_store *ctx, struct strbuf *msg)\n \tcb.dlen = msg->len;\n \tcb.data = strbuf_detach(msg, NULL);\n \n-\tbox = ctx->gen.name;\n+\tbox = ctx->name;\n \tprefix = !strcmp(box, \"INBOX\") ? \"\" : ctx->prefix;\n \tcb.create = 0;\n \tret = imap_exec_m(ctx, &cb, \"APPEND \\\"%s%s\\\"\", prefix, box);\n@@ -1336,7 +1332,7 @@ int main(int argc, char **argv)\n \t}\n \n \tfprintf(stderr, \"sending %d message%s\\n\", total, (total != 1) ? \"s\" : \"\");\n-\tctx->gen.name = imap_folder;\n+\tctx->name = imap_folder;\n \twhile (1) {\n \t\tunsigned percent = n * 100 / total;\n \n-- \n1.8.0.3\n"},{"id":"206760","messageId":"20130114055721.GD3125@elie.Belkin","threadId":"32620","inReplyTo":"1358141566-26081-2-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH 01/14] imap-send.c: remove msg_data::flags, which was always zero","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-01-14T05:57:21Z","receivedAt":"2013-01-14T05:57:21Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi,\n\nMichael Haggerty wrote:\n\n> This removes the need for function imap_make_flags(), so delete it,\n> too.\n[...]\n> --- a/imap-send.c\n> +++ b/imap-send.c\n[...]\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> +\tret = imap_exec_m(ctx, &cb, \"APPEND \\\"%s%s\\\"\", prefix, box);\n\nBefore this change, the command is\n\n\t\"APPEND\" SP mailbox SP \"{\" msglen \"}\" CRLF\n\n.  After this change, it leaves out the space before the brace.  If I\nunderstand RFC3501 correctly, the space is required.  Intentional?\n\nWith the below squashed in,\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n\ndiff --git i/imap-send.c w/imap-send.c\nindex 451d5027..f1c8f5a5 100644\n--- i/imap-send.c\n+++ w/imap-send.c\n@@ -1296,7 +1296,7 @@ static int imap_store_msg(struct store *gctx, struct msg_data *msg)\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\\\"\", prefix, box);\n+\tret = imap_exec_m(ctx, &cb, \"APPEND \\\"%s%s\\\" \", prefix, box);\n \timap->caps = imap->rcaps;\n \tif (ret != DRV_OK)\n \t\treturn ret;\n"},{"id":"206761","messageId":"20130114060647.GA4359@sigill.intra.peff.net","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH 00/14] Remove unused code from imap-send.c","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-01-14T06:06:47Z","receivedAt":"2013-01-14T06:06:47Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jan 14, 2013 at 06:32:32AM +0100, Michael Haggerty wrote:\n\n> As discussed before [1], imap-send.c was copied from isync, including\n> a lot of code that is not used within the git project.  This patch\n> series rips a bunch of it out.\n\nThanks, this looks like a good direction.\n\nI did not notice any problems reading through the patches, but my brain\nis frazzled from a day of flying. I missed the problem Jonathan noticed.\n:)\n\nSome of the things you are removing are for advanced IMAP features that\nimap-send does not need. In theory, somebody might extend it to use them\nin the future. But since it has not seen any active feature development\nin years, and since anybody could resurrect the code by reverting your\ncommits, I don't think it is a big risk.\n\nI suspect you could go even further in ripping things out (e.g., I do\nnot think a server will generate an untagged namespace response at all\nif we do not ask for it by issuing a namespace command). But you've\ncertainly grabbed the low-hanging fruit that can mostly be verified by\nthe compiler, and I don't know if it's worth the effort to go much\nfurther, as it would require a lot of manual verification (and\nunderstanding of IMAP, which will rot your brain).\n\n-Peff\n"},{"id":"206763","messageId":"20130114061920.GE3125@elie.Belkin","threadId":"32620","inReplyTo":"1358141566-26081-7-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH 06/14] imap-send.c: remove some unused fields from struct store","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-01-14T06:19:20Z","receivedAt":"2013-01-14T06:19:20Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Michael Haggerty wrote:\n\n> --- a/imap-send.c\n> +++ b/imap-send.c\n[...]\n> @@ -772,13 +767,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)\n>  \t\t\t\t   !strcmp(\"NO\", arg) || !strcmp(\"BYE\", arg)) {\n>  \t\t\t\tif ((resp = parse_response_code(ctx, NULL, cmd)) != RESP_OK)\n>  \t\t\t\t\treturn resp;\n> -\t\t\t} else if (!strcmp(\"CAPABILITY\", arg))\n> +\t\t\t} else if (!strcmp(\"CAPABILITY\", arg)) {\n>  \t\t\t\tparse_capability(imap, cmd);\n> -\t\t\telse if ((arg1 = next_arg(&cmd))) {\n> -\t\t\t\tif (!strcmp(\"EXISTS\", arg1))\n> -\t\t\t\t\tctx->gen.count = atoi(arg);\n> -\t\t\t\telse if (!strcmp(\"RECENT\", arg1))\n> -\t\t\t\t\tctx->gen.recent = atoi(arg);\n> +\t\t\t} else if ((arg1 = next_arg(&cmd))) {\n> +\t\t\t\t/* unused */\n\nNeat.  Let me try to understand what was going on here:\n\nWhen opening a mailbox with the SELECT command, an IMAP server\nresponds with tagged data indicating how many messages exist and how\nmany are marked Recent.  But git imap-send never reads mailboxes and\nin particular never uses the SELECT command, so there is no need for\nus to parse or record such responses.\n\nOut of paranoia we are keeping the parsing for now, but the parsed\nresponse is unused, hence the comment above.\n\nIf I've understood correctly so far (a big assumption), I still am not\nsure what it would mean if we hit this ((arg1 = next_arg(&cmd))) case.\nDoes it mean:\n\n A. The server has gone haywire and given a tagged response where\n    one is not allowed, but let's tolerate it because we always have\n    done so?  Or\n\n B. This is a perfectly normal response to some of the commands we\n    send, and we have always been deliberately ignoring it because it\n    is not important for what imap-send does?\n\nCurious,\nJonathan\n"},{"id":"206765","messageId":"20130114064347.GH3125@elie.Belkin","threadId":"32620","inReplyTo":"1358141566-26081-10-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH 09/14] imap-send.c: remove namespace fields from struct imap","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-01-14T06:43:47Z","receivedAt":"2013-01-14T06:43:47Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Michael Haggerty wrote:\n\n[...]\n> @@ -722,9 +667,9 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)\n>  \t\t\t}\n>  \n>  \t\t\tif (!strcmp(\"NAMESPACE\", arg)) {\n> -\t\t\t\timap->ns_personal = parse_list(&cmd);\n> -\t\t\t\timap->ns_other = parse_list(&cmd);\n> -\t\t\t\timap->ns_shared = parse_list(&cmd);\n> +\t\t\t\tskip_list(&cmd);\n> +\t\t\t\tskip_list(&cmd);\n> +\t\t\t\tskip_list(&cmd);\n\nThis codepath would only be triggered if we emit a NAMESPACE command,\nright?  If I am understanding correctly, a comment could make this\nless mystifying:\n\n\t\t\t\t/* rfc2342 NAMESPACE response. */\n\t\t\t\tskip_list(&cmd);\t/* Personal mailboxes */\n\t\t\t\tskip_list(&cmd);\t/* Others' mailboxes */\n\t\t\t\tskip_list(&cmd);\t/* Shared mailboxes */\n\nThough that's probably academic since hopefully this if branch\nwill die soon. :)\n\nThe rest of the patch is clear and pleasant and also looks correct.\n\nWith the above change,\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n\nThanks.\n"},{"id":"206766","messageId":"20130114064759.GI3125@elie.Belkin","threadId":"32620","inReplyTo":"1358141566-26081-12-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH 11/14] imap-send.c: simplify logic in lf_to_crlf()","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-01-14T06:47:59Z","receivedAt":"2013-01-14T06:47:59Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Michael Haggerty wrote:\n\n> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>\n> ---\n>  imap-send.c | 31 ++++++++-----------------------\n>  1 file changed, 8 insertions(+), 23 deletions(-)\n\nI like the code reduction, but my nighttime brain doesn't have the\npatience to understand the preimage or postimage, and the above\ndescription doesn't give any hints.  Maybe a comment right above the\nfunction definition describing its contract would help to prepare the\ndaunted reader (and to let the uninterested understand call sites\nwithout reading the implementation).\n\nThanks,\nJonathan\n"},{"id":"206767","messageId":"20130114065227.GJ3125@elie.Belkin","threadId":"32620","inReplyTo":"1358141566-26081-13-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH 12/14] imap-send.c: use struct imap_store instead of struct store","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-01-14T06:52:27Z","receivedAt":"2013-01-14T06:52:27Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Michael Haggerty wrote:\n\n> In fact, all struct store instances are upcasts of struct imap_store\n> anyway, so stop making the distinction.\n\nNice.\n\nIt is tempting to fold \"struct store\" into \"struct imap_store\" at the same\ntime, as in\n\n\tstruct imap_store {\n\t\tstruct {\n\t\t\tstruct store_conf *conf; /* foreign */\n\n\t\t\t/* currently open mailbox */\n\t\t\tconst char *name; /* foreign! maybe preset? */\n\t\t\tchar *path; /* own */\n\t\t\tstruct message *msgs; /* own */\n\t\t\tint uidvalidity;\n\t\t\tunsigned char opts; /* maybe preset? */\n\t\t\t/* note that the following do _not_ reflect stats from msgs, but mailbox totals */\n\t\t\tint count; /* # of messages */\n\t\t\tint recent; /* # of recent messages - don't trust this beyond the initial read */\n\t\t} gen;\n\t\tint uidvalidity;\n\t\tstruct imap *imap;\n\t\tconst char *prefix;\n\t\tunsigned /*currentnc:1,*/ trashnc:1;\n\t};\n\nto help the reader verify that objects of type \"struct store\" are not\nused except through the gen field of imap_store after this change.\nBut verifying directly worked fine, so never mind. ;-)\n"},{"id":"206768","messageId":"20130114065757.GK3125@elie.Belkin","threadId":"32620","inReplyTo":"1358141566-26081-1-git-send-email-mhagger@alum.mit.edu","subject":"Re: [PATCH 00/14] Remove unused code from imap-send.c","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2013-01-14T06:57:57Z","receivedAt":"2013-01-14T06:57:57Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Michael Haggerty wrote:\n\n>  imap-send.c | 286 +++++++++---------------------------------------------------\n>  1 file changed, 39 insertions(+), 247 deletions(-)\n\nSee my replies for comments on patches 1, 6, 9, 11, and 12.  The rest\nare\n\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n\nThe series is tasteful and easy to follow and it's hard to argue with\nthe resulting code reduction.  Thanks for a pleasant read.\n"},{"id":"206784","messageId":"50F3CB6A.40203@alum.mit.edu","threadId":"32620","inReplyTo":"20130114055721.GD3125@elie.Belkin","subject":"Re: [PATCH 01/14] imap-send.c: remove msg_data::flags, which was always zero","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T09:10:02Z","receivedAt":"2013-01-14T09:10:02Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 01/14/2013 06:57 AM, Jonathan Nieder wrote:\n> Michael Haggerty wrote:\n> \n>> This removes the need for function imap_make_flags(), so delete it,\n>> too.\n> [...]\n>> --- a/imap-send.c\n>> +++ b/imap-send.c\n> [...]\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>> +\tret = imap_exec_m(ctx, &cb, \"APPEND \\\"%s%s\\\"\", prefix, box);\n> \n> Before this change, the command is\n> \n> \t\"APPEND\" SP mailbox SP \"{\" msglen \"}\" CRLF\n> \n> .  After this change, it leaves out the space before the brace.  If I\n> understand RFC3501 correctly, the space is required.  Intentional?\n\nNo, not intentional.  I simply didn't follow far enough how the string\nwas used and mistakenly thought it was an entire command.  Thanks for\nfinding and fixing this.\n\n(It probably would be less error-prone if v_issue_imap_cmd() would be\nresponsible for adding the extra space in the second branch of the\nfollowing if statement:\n\n    if (!cmd->cb.data)\n            bufl = nfsnprintf(buf, sizeof(buf), \"%d %s\\r\\n\", cmd->tag,\ncmd->cmd);\n    else\n            bufl = nfsnprintf(buf, sizeof(buf), \"%d %s{%d%s}\\r\\n\",\n                              cmd->tag, cmd->cmd, cmd->cb.dlen,\n                              CAP(LITERALPLUS) ? \"+\" : \"\");\n\nbut that's a design choice that was already in the original version and\nI don't care enough to change it.)\n\n> With the below squashed in,\n> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n> \n> diff --git i/imap-send.c w/imap-send.c\n> index 451d5027..f1c8f5a5 100644\n> --- i/imap-send.c\n> +++ w/imap-send.c\n> @@ -1296,7 +1296,7 @@ static int imap_store_msg(struct store *gctx, struct msg_data *msg)\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\\\"\", prefix, box);\n> +\tret = imap_exec_m(ctx, &cb, \"APPEND \\\"%s%s\\\" \", prefix, box);\n>  \timap->caps = imap->rcaps;\n>  \tif (ret != DRV_OK)\n>  \t\treturn ret;\n> \n\nACK.\n\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\nhttp://softwareswirl.blogspot.com/\n"},{"id":"206786","messageId":"50F3CF10.3000602@alum.mit.edu","threadId":"32620","inReplyTo":"20130114061920.GE3125@elie.Belkin","subject":"Re: [PATCH 06/14] imap-send.c: remove some unused fields from struct store","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T09:25:36Z","receivedAt":"2013-01-14T09:25:36Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 01/14/2013 07:19 AM, Jonathan Nieder wrote:\n> Michael Haggerty wrote:\n> \n>> --- a/imap-send.c\n>> +++ b/imap-send.c\n> [...]\n>> @@ -772,13 +767,10 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)\n>>  \t\t\t\t   !strcmp(\"NO\", arg) || !strcmp(\"BYE\", arg)) {\n>>  \t\t\t\tif ((resp = parse_response_code(ctx, NULL, cmd)) != RESP_OK)\n>>  \t\t\t\t\treturn resp;\n>> -\t\t\t} else if (!strcmp(\"CAPABILITY\", arg))\n>> +\t\t\t} else if (!strcmp(\"CAPABILITY\", arg)) {\n>>  \t\t\t\tparse_capability(imap, cmd);\n>> -\t\t\telse if ((arg1 = next_arg(&cmd))) {\n>> -\t\t\t\tif (!strcmp(\"EXISTS\", arg1))\n>> -\t\t\t\t\tctx->gen.count = atoi(arg);\n>> -\t\t\t\telse if (!strcmp(\"RECENT\", arg1))\n>> -\t\t\t\t\tctx->gen.recent = atoi(arg);\n>> +\t\t\t} else if ((arg1 = next_arg(&cmd))) {\n>> +\t\t\t\t/* unused */\n> \n> Neat.  Let me try to understand what was going on here:\n> \n> When opening a mailbox with the SELECT command, an IMAP server\n> responds with tagged data indicating how many messages exist and how\n> many are marked Recent.  But git imap-send never reads mailboxes and\n> in particular never uses the SELECT command, so there is no need for\n> us to parse or record such responses.\n> \n> Out of paranoia we are keeping the parsing for now, but the parsed\n> response is unused, hence the comment above.\n> \n> If I've understood correctly so far (a big assumption), I still am not\n> sure what it would mean if we hit this ((arg1 = next_arg(&cmd))) case.\n> Does it mean:\n> \n>  A. The server has gone haywire and given a tagged response where\n>     one is not allowed, but let's tolerate it because we always have\n>     done so?  Or\n> \n>  B. This is a perfectly normal response to some of the commands we\n>     send, and we have always been deliberately ignoring it because it\n>     is not important for what imap-send does?\n\nHonestly, I didn't bother to look into this.  I was just doing some\nbrainless elimination of obviously unused code.\n\nNo doubt a deeper analysis (like yours) could find more code to discard,\nbut I didn't want to invest that much time and this code has absolutely\nno tests, so I stuck to the obvious (and even then you found a mistake\nin my changes :-( ).\n\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\nhttp://softwareswirl.blogspot.com/\n"},{"id":"206787","messageId":"50F3D085.9080102@alum.mit.edu","threadId":"32620","inReplyTo":"20130114064347.GH3125@elie.Belkin","subject":"Re: [PATCH 09/14] imap-send.c: remove namespace fields from struct imap","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T09:31:49Z","receivedAt":"2013-01-14T09:31:49Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 01/14/2013 07:43 AM, Jonathan Nieder wrote:\n> Michael Haggerty wrote:\n> \n> [...]\n>> @@ -722,9 +667,9 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)\n>>  \t\t\t}\n>>  \n>>  \t\t\tif (!strcmp(\"NAMESPACE\", arg)) {\n>> -\t\t\t\timap->ns_personal = parse_list(&cmd);\n>> -\t\t\t\timap->ns_other = parse_list(&cmd);\n>> -\t\t\t\timap->ns_shared = parse_list(&cmd);\n>> +\t\t\t\tskip_list(&cmd);\n>> +\t\t\t\tskip_list(&cmd);\n>> +\t\t\t\tskip_list(&cmd);\n> \n> This codepath would only be triggered if we emit a NAMESPACE command,\n> right?  If I am understanding correctly, a comment could make this\n> less mystifying:\n> \n> \t\t\t\t/* rfc2342 NAMESPACE response. */\n> \t\t\t\tskip_list(&cmd);\t/* Personal mailboxes */\n> \t\t\t\tskip_list(&cmd);\t/* Others' mailboxes */\n> \t\t\t\tskip_list(&cmd);\t/* Shared mailboxes */\n\nYes, the comments are useful.\n\n> Though that's probably academic since hopefully this if branch\n> will die soon. :)\n\nNot by my hand :-)  Maybe somebody more familiar with the IMAP protocol\nwants to take the code culling further...\n\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\nhttp://softwareswirl.blogspot.com/\n"},{"id":"206788","messageId":"50F3D0ED.5030103@alum.mit.edu","threadId":"32620","inReplyTo":"20130114065757.GK3125@elie.Belkin","subject":"Re: [PATCH 00/14] Remove unused code from imap-send.c","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2013-01-14T09:33:33Z","receivedAt":"2013-01-14T09:33:33Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 01/14/2013 07:57 AM, Jonathan Nieder wrote:\n> Michael Haggerty wrote:\n> \n>>  imap-send.c | 286 +++++++++---------------------------------------------------\n>>  1 file changed, 39 insertions(+), 247 deletions(-)\n> \n> See my replies for comments on patches 1, 6, 9, 11, and 12.  The rest\n> are\n> \n> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n> \n> The series is tasteful and easy to follow and it's hard to argue with\n> the resulting code reduction.  Thanks for a pleasant read.\n\nThanks for your careful review.  I will re-roll the patch series as soon\nas I get the chance.\n\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\nhttp://softwareswirl.blogspot.com/\n"},{"id":"206824","messageId":"7va9sbbnbg.fsf@alter.siamese.dyndns.org","threadId":"32620","inReplyTo":"50F3D0ED.5030103@alum.mit.edu","subject":"Re: [PATCH 00/14] Remove unused code from imap-send.c","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-01-14T19:02:11Z","receivedAt":"2013-01-14T19:02:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Haggerty <mhagger@alum.mit.edu> writes:\n\n> On 01/14/2013 07:57 AM, Jonathan Nieder wrote:\n>> Michael Haggerty wrote:\n>> \n>>>  imap-send.c | 286 +++++++++---------------------------------------------------\n>>>  1 file changed, 39 insertions(+), 247 deletions(-)\n>> \n>> See my replies for comments on patches 1, 6, 9, 11, and 12.  The rest\n>> are\n>> \n>> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n>> \n>> The series is tasteful and easy to follow and it's hard to argue with\n>> the resulting code reduction.  Thanks for a pleasant read.\n>\n> Thanks for your careful review.  I will re-roll the patch series as soon\n> as I get the chance.\n\nThanks, all of you.  The numbers and the graph look very nice indeed\n;-)\n"}]}