imap-send: add wrapper to get server credentials if needed
Signed-off-by: Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nicolas Morey-Chaisemartin committed
Sep 14, 2017 at 09:52 UTC
690307f3d1ae127e0ecb6198aeb44936c8dd9330
1 file changed
+20
-14
imap-send.c
+20
-14
@@ -926,6 +926,25 @@ static int auth_cram_md5(struct imap_store *ctx, struct imap_cmd *cmd, const cha
926
return 0;
927
}
928
929
+static void server_fill_credential(struct imap_server_conf *srvc, struct credential *cred)
930
+{
931
+ if (srvc->user && srvc->pass)
932
+ return;
933
+
934
+ cred->protocol = xstrdup(srvc->use_ssl ? "imaps" : "imap");
935
+ cred->host = xstrdup(srvc->host);
936
+
937
+ cred->username = xstrdup_or_null(srvc->user);
938
+ cred->password = xstrdup_or_null(srvc->pass);
939
+
940
+ credential_fill(cred);
941
+
942
+ if (!srvc->user)
943
+ srvc->user = xstrdup(cred->username);
944
+ if (!srvc->pass)
945
+ srvc->pass = xstrdup(cred->password);
946
+}
947
+
948
static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char *folder)
949
{
950
struct credential cred = CREDENTIAL_INIT;
@@ -1078,20 +1097,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char *f
1097
}
1098
#endif
1099
imap_info("Logging in...\n");
1081
- if (!srvc->user || !srvc->pass) {
1082
- cred.protocol = xstrdup(srvc->use_ssl ? "imaps" : "imap");
1083
- cred.host = xstrdup(srvc->host);
1084
-
1085
- cred.username = xstrdup_or_null(srvc->user);
1086
- cred.password = xstrdup_or_null(srvc->pass);
1087
-
1088
- credential_fill(&cred);
1089
-
1090
- if (!srvc->user)
1091
- srvc->user = xstrdup(cred.username);
1092
- if (!srvc->pass)
1093
- srvc->pass = xstrdup(cred.password);
1094
- }
1100
+ server_fill_credential(srvc, &cred);
1101
1102
if (srvc->auth_method) {
1103
struct imap_cmd_cb cb;