aboutsummaryrefslogtreecommitdiffstats
path: root/imap.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1998-03-03 21:54:13 +0000
committerEric S. Raymond <esr@thyrsus.com>1998-03-03 21:54:13 +0000
commit45f5585046d8411c275c5116fff1430e7c458e2f (patch)
treee50ef6b922822d703988ff6a1bade127d69198d2 /imap.c
parent9a70234c1d61dafc5c08f7e861575cd71f06e9dc (diff)
downloadfetchmail-45f5585046d8411c275c5116fff1430e7c458e2f.tar.gz
fetchmail-45f5585046d8411c275c5116fff1430e7c458e2f.tar.bz2
fetchmail-45f5585046d8411c275c5116fff1430e7c458e2f.zip
Implement RFC1730 quoting.
svn path=/trunk/; revision=1684
Diffstat (limited to 'imap.c')
-rw-r--r--imap.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/imap.c b/imap.c
index 66f42c8a..85aea358 100644
--- a/imap.c
+++ b/imap.c
@@ -562,6 +562,28 @@ static int do_gssauth(int sock, char *hostname, char *username)
}
#endif /* GSSAPI */
+static char *canonify_imap_password(char *passwd)
+/* encode an IMAP password as per RFC1730's quoting conventions */
+{
+ char *result;
+ int i, j;
+
+ result = malloc(2*strlen(passwd));
+ if (!result)
+ return 0;
+
+ j=0;
+ for (i=0; i<strlen(passwd); ++i)
+ {
+ if ((passwd[i] == '\\') || (passwd[i] == '"'))
+ result[j++] = '\\';
+ result[j++] = passwd[i];
+ }
+ result[j] = '\0';
+
+ return(result);
+}
+
int imap_getauth(int sock, struct query *ctl, char *greeting)
/* apply for connection authorization */
{
@@ -655,10 +677,20 @@ int imap_getauth(int sock, struct query *ctl, char *greeting)
};
/* try to get authorized in the ordinary (AUTH=LOGIN) way */
- ok = gen_transact(sock, "LOGIN %s \"%s\"", ctl->remotename, ctl->password);
- if (ok)
- return(ok);
-
+ {
+ char *newpass = canonify_imap_password(ctl->password);
+
+ if (!newpass)
+ return(PS_AUTHFAIL); /* should report error better!!!! */
+
+ ok = gen_transact(sock, "LOGIN %s \"%s\"", ctl->remotename, newpass);
+
+ free(newpass);
+
+ if (ok)
+ return(ok);
+ }
+
return(PS_SUCCESS);
}