Skip to content

Commit 5dcdc78

Browse files
committed
Merge branch 'br/imap-send-simplify-tunnel-child-process'
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
2 parents 1ebe6a8 + ba9b9e1 commit 5dcdc78

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

imap-send.c

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ struct imap_server_conf {
6969
char *tunnel;
7070
char *host;
7171
int port;
72+
char *folder;
7273
char *user;
7374
char *pass;
7475
int use_ssl;
@@ -82,6 +83,7 @@ static struct imap_server_conf server = {
8283
NULL, /* tunnel */
8384
NULL, /* host */
8485
0, /* port */
86+
NULL, /* folder */
8587
NULL, /* user */
8688
NULL, /* pass */
8789
0, /* use_ssl */
@@ -523,7 +525,7 @@ static struct imap_cmd *issue_imap_cmd(struct imap_store *ctx,
523525
if (Verbose) {
524526
if (imap->num_in_progress)
525527
printf("(%d in progress) ", imap->num_in_progress);
526-
if (memcmp(cmd->cmd, "LOGIN", 5))
528+
if (!starts_with(cmd->cmd, "LOGIN"))
527529
printf(">>> %s", buf);
528530
else
529531
printf(">>> %d LOGIN <user> <pass>\n", cmd->tag);
@@ -791,7 +793,7 @@ static int get_cmd_result(struct imap_store *ctx, struct imap_cmd *tcmd)
791793
else /*if (!strcmp("BAD", arg))*/
792794
resp = RESP_BAD;
793795
fprintf(stderr, "IMAP command '%s' returned response (%s) - %s\n",
794-
memcmp(cmdp->cmd, "LOGIN", 5) ?
796+
!starts_with(cmdp->cmd, "LOGIN") ?
795797
cmdp->cmd : "LOGIN <user> <pass>",
796798
arg, cmd ? cmd : "");
797799
}
@@ -924,17 +926,16 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char *f
924926
/* open connection to IMAP server */
925927

926928
if (srvc->tunnel) {
927-
const char *argv[] = { srvc->tunnel, NULL };
928929
struct child_process tunnel = CHILD_PROCESS_INIT;
929930

930931
imap_info("Starting tunnel '%s'... ", srvc->tunnel);
931932

932-
tunnel.argv = argv;
933+
argv_array_push(&tunnel.args, srvc->tunnel);
933934
tunnel.use_shell = 1;
934935
tunnel.in = -1;
935936
tunnel.out = -1;
936937
if (start_command(&tunnel))
937-
die("cannot start proxy %s", argv[0]);
938+
die("cannot start proxy %s", srvc->tunnel);
938939

939940
imap->buf.sock.fd[0] = tunnel.out;
940941
imap->buf.sock.fd[1] = tunnel.in;
@@ -1306,15 +1307,13 @@ static int split_msg(struct strbuf *all_msgs, struct strbuf *msg, int *ofs)
13061307
return 1;
13071308
}
13081309

1309-
static char *imap_folder;
1310-
13111310
static void git_imap_config(void)
13121311
{
13131312
const char *val = NULL;
13141313

13151314
git_config_get_bool("imap.sslverify", &server.ssl_verify);
13161315
git_config_get_bool("imap.preformattedhtml", &server.use_html);
1317-
git_config_get_string("imap.folder", &imap_folder);
1316+
git_config_get_string("imap.folder", &server.folder);
13181317

13191318
if (!git_config_get_value("imap.host", &val)) {
13201319
if (!val) {
@@ -1362,7 +1361,7 @@ int main(int argc, char **argv)
13621361
if (!server.port)
13631362
server.port = server.use_ssl ? 993 : 143;
13641363

1365-
if (!imap_folder) {
1364+
if (!server.folder) {
13661365
fprintf(stderr, "no imap store specified\n");
13671366
return 1;
13681367
}
@@ -1392,7 +1391,7 @@ int main(int argc, char **argv)
13921391
}
13931392

13941393
/* write it to the imap server */
1395-
ctx = imap_open_store(&server, imap_folder);
1394+
ctx = imap_open_store(&server, server.folder);
13961395
if (!ctx) {
13971396
fprintf(stderr, "failed to open store\n");
13981397
return 1;

0 commit comments

Comments
 (0)