Merge branch 'br/imap-send-simplify-tunnel-child-process'
authorJunio C Hamano <gitster@pobox.com>
Thu, 11 Sep 2014 17:33:37 +0000 (10:33 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Sep 2014 17:33:37 +0000 (10:33 -0700)
Code clean-up.

* br/imap-send-simplify-tunnel-child-process:
imap-send: simplify v_issue_imap_cmd() and get_cmd_result() using starts_with()
imap-send.c: imap_folder -> imap_server_conf.folder
git-imap-send: simplify tunnel construction

1  2 
imap-send.c
diff --cc imap-send.c
index b7601f6359987ec4c414c9bc295f9b40fcd51e97,44fd5249e2afd5c73552c5537101e1fc99158ce4..f33e56dba1e06cd61448069e3d300e3650477320
@@@ -786,12 -803,33 +788,12 @@@ static int get_cmd_result(struct imap_s
                        if (!strcmp("OK", arg))
                                resp = DRV_OK;
                        else {
 -                              if (!strcmp("NO", arg)) {
 -                                      if (cmdp->cb.create && cmd && (cmdp->cb.trycreate || !memcmp(cmd, "[TRYCREATE]", 11))) { /* SELECT, APPEND or UID COPY */
 -                                              p = strchr(cmdp->cmd, '"');
 -                                              if (!issue_imap_cmd(ctx, NULL, "CREATE \"%.*s\"", (int)(strchr(p + 1, '"') - p + 1), p)) {
 -                                                      resp = RESP_BAD;
 -                                                      goto normal;
 -                                              }
 -                                              /* not waiting here violates the spec, but a server that does not
 -                                                 grok this nonetheless violates it too. */
 -                                              cmdp->cb.create = 0;
 -                                              if (!(ncmdp = issue_imap_cmd(ctx, &cmdp->cb, "%s", cmdp->cmd))) {
 -                                                      resp = RESP_BAD;
 -                                                      goto normal;
 -                                              }
 -                                              free(cmdp->cmd);
 -                                              free(cmdp);
 -                                              if (!tcmd)
 -                                                      return 0;       /* ignored */
 -                                              if (cmdp == tcmd)
 -                                                      tcmd = ncmdp;
 -                                              continue;
 -                                      }
 +                              if (!strcmp("NO", arg))
                                        resp = RESP_NO;
 -                              else /*if (!strcmp("BAD", arg))*/
 +                              else /*if (!strcmp("BAD", arg))*/
                                        resp = RESP_BAD;
                                fprintf(stderr, "IMAP command '%s' returned response (%s) - %s\n",
-                                        memcmp(cmdp->cmd, "LOGIN", 5) ?
+                                       !starts_with(cmdp->cmd, "LOGIN") ?
                                                        cmdp->cmd : "LOGIN <user> <pass>",
                                                        arg, cmd ? cmd : "");
                        }
@@@ -924,8 -963,7 +926,7 @@@ static struct imap_store *imap_open_sto
        /* open connection to IMAP server */
  
        if (srvc->tunnel) {
-               const char *argv[] = { srvc->tunnel, NULL };
 -              struct child_process tunnel = {NULL};
 +              struct child_process tunnel = CHILD_PROCESS_INIT;
  
                imap_info("Starting tunnel '%s'... ", srvc->tunnel);
  
@@@ -1306,37 -1325,43 +1307,35 @@@ static int split_msg(struct strbuf *all
        return 1;
  }
  
- static char *imap_folder;
 -static int git_imap_config(const char *key, const char *val, void *cb)
 +static void git_imap_config(void)
  {
 -      if (!skip_prefix(key, "imap.", &key))
 -              return 0;
 +      const char *val = NULL;
  
 -      /* check booleans first, and barf on others */
 -      if (!strcmp("sslverify", key))
 -              server.ssl_verify = git_config_bool(key, val);
 -      else if (!strcmp("preformattedhtml", key))
 -              server.use_html = git_config_bool(key, val);
 -      else if (!val)
 -              return config_error_nonbool(key);
 -
 -      if (!strcmp("folder", key)) {
 -              server.folder = xstrdup(val);
 -      } else if (!strcmp("host", key)) {
 -              if (starts_with(val, "imap:"))
 -                      val += 5;
 -              else if (starts_with(val, "imaps:")) {
 -                      val += 6;
 -                      server.use_ssl = 1;
 +      git_config_get_bool("imap.sslverify", &server.ssl_verify);
 +      git_config_get_bool("imap.preformattedhtml", &server.use_html);
-       git_config_get_string("imap.folder", &imap_folder);
++      git_config_get_string("imap.folder", &server.folder);
 +
 +      if (!git_config_get_value("imap.host", &val)) {
 +              if (!val) {
 +                      git_die_config("imap.host", "Missing value for 'imap.host'");
 +              } else {
 +                      if (starts_with(val, "imap:"))
 +                              val += 5;
 +                      else if (starts_with(val, "imaps:")) {
 +                              val += 6;
 +                              server.use_ssl = 1;
 +                      }
 +                      if (starts_with(val, "//"))
 +                              val += 2;
 +                      server.host = xstrdup(val);
                }
 -              if (starts_with(val, "//"))
 -                      val += 2;
 -              server.host = xstrdup(val);
 -      } else if (!strcmp("user", key))
 -              server.user = xstrdup(val);
 -      else if (!strcmp("pass", key))
 -              server.pass = xstrdup(val);
 -      else if (!strcmp("port", key))
 -              server.port = git_config_int(key, val);
 -      else if (!strcmp("tunnel", key))
 -              server.tunnel = xstrdup(val);
 -      else if (!strcmp("authmethod", key))
 -              server.auth_method = xstrdup(val);
 +      }
  
 -      return 0;
 +      git_config_get_string("imap.user", &server.user);
 +      git_config_get_string("imap.pass", &server.pass);
 +      git_config_get_int("imap.port", &server.port);
 +      git_config_get_string("imap.tunnel", &server.tunnel);
 +      git_config_get_string("imap.authmethod", &server.auth_method);
  }
  
  int main(int argc, char **argv)
        }
  
        /* write it to the imap server */
-       ctx = imap_open_store(&server, imap_folder);
 -      ctx = imap_open_store(&server);
++      ctx = imap_open_store(&server, server.folder);
        if (!ctx) {
                fprintf(stderr, "failed to open store\n");
                return 1;