aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--imap.c40
2 files changed, 39 insertions, 4 deletions
diff --git a/NEWS b/NEWS
index fbebfaf5..3d44c352 100644
--- a/NEWS
+++ b/NEWS
@@ -20,6 +20,9 @@ fetchmail-4.4.0 ():
under Red Hat 5.0.
* Kerberos V support from Jon Dugan <jdugan@ncsa.uiuc.edu> and
Von Welch <vwelch@ncsa.uiuc.edu>.
+* Ron Kaminsky <kam@Orbotech.Co.IL> sent a patch to RFC1730-encode passwords
+ sent to IMAP servers. This allows them to contain doublequotes and
+ backslashes.
There are 269 people on fetchmail-friends and 144 on fetchmail-announce.
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);
}