imap-send: parse default git config
git imap-send does not parse the default git config settings and thus ignore core.askpass value. Rewrite config parsing to support core settings. Reported-by: Philippe Blain <levraiphilippeblain@gmail.com> Signed-off-by: Nicolas Morey-Chaisemartin <nmoreychaisemartin@suse.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nicolas Morey-Chaisemartin committed
Dec 1, 2020 at 08:38 UTC
50212361d9487ac3005c3041fac0d6b4d999807a
1 file changed
+30
-22
imap-send.c
+30
-22
@@ -84,17 +84,17 @@ static int nfvasprintf(char **strp, const char *fmt, va_list ap)
84
}
85
86
struct imap_server_conf {
87
- char *name;
88
- char *tunnel;
89
- char *host;
87
+ const char *name;
88
+ const char *tunnel;
89
+ const char *host;
90
int port;
91
- char *folder;
92
- char *user;
93
- char *pass;
91
+ const char *folder;
92
+ const char *user;
93
+ const char *pass;
94
int use_ssl;
95
int ssl_verify;
96
int use_html;
97
- char *auth_method;
97
+ const char *auth_method;
98
};
99
100
static struct imap_server_conf server = {
@@ -955,7 +955,7 @@ static void server_fill_credential(struct imap_server_conf *srvc, struct credent
955
srvc->pass = xstrdup(cred->password);
956
}
957
958
-static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char *folder)
958
+static struct imap_store *imap_open_store(struct imap_server_conf *srvc, const char *folder)
959
{
960
struct credential cred = CREDENTIAL_INIT;
961
struct imap_store *ctx;
@@ -1338,15 +1338,26 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
1338
return 1;
1339
}
1340
1341
-static void git_imap_config(void)
1341
+static int git_imap_config(const char *var, const char *val, void *cb)
1342
{
1343
- const char *val = NULL;
1343
1345
- git_config_get_bool("imap.sslverify", &server.ssl_verify);
1346
- git_config_get_bool("imap.preformattedhtml", &server.use_html);
1347
- git_config_get_string("imap.folder", &server.folder);
1348
-
1349
- if (!git_config_get_value("imap.host", &val)) {
1344
+ if (!strcmp("imap.sslverify", var))
1345
+ server.ssl_verify = git_config_bool(var, val);
1346
+ else if (!strcmp("imap.preformattedhtml", var))
1347
+ server.use_html = git_config_bool(var, val);
1348
+ else if (!strcmp("imap.folder", var))
1349
+ return git_config_string(&server.folder, var, val);
1350
+ else if (!strcmp("imap.user", var))
1351
+ return git_config_string(&server.user, var, val);
1352
+ else if (!strcmp("imap.pass", var))
1353
+ return git_config_string(&server.pass, var, val);
1354
+ else if (!strcmp("imap.tunnel", var))
1355
+ return git_config_string(&server.tunnel, var, val);
1356
+ else if (!strcmp("imap.authmethod", var))
1357
+ return git_config_string(&server.auth_method, var, val);
1358
+ else if (!strcmp("imap.port", var))
1359
+ server.port = git_config_int(var, val);
1360
+ else if (!strcmp("imap.host", var)) {
1361
if (!val) {
1362
git_die_config("imap.host", "Missing value for 'imap.host'");
1363
} else {
@@ -1360,13 +1371,10 @@ static void git_imap_config(void)
1371
val += 2;
1372
server.host = xstrdup(val);
1373
}
1363
- }
1374
+ } else
1375
+ return git_default_config(var, val, cb);
1376
1365
- git_config_get_string("imap.user", &server.user);
1366
- git_config_get_string("imap.pass", &server.pass);
1367
- git_config_get_int("imap.port", &server.port);
1368
- git_config_get_string("imap.tunnel", &server.tunnel);
1369
- git_config_get_string("imap.authmethod", &server.auth_method);
1377
+ return 0;
1378
}
1379
1380
static int append_msgs_to_imap(struct imap_server_conf *server,
@@ -1539,7 +1547,7 @@ int cmd_main(int argc, const char **argv)
1547
int nongit_ok;
1548
1549
setup_git_directory_gently(&nongit_ok);
1542
- git_imap_config();
1550
+ git_config(git_imap_config, NULL);
1551
1552
argc = parse_options(argc, (const char **)argv, "", imap_send_options, imap_send_usage, 0);
1553