diff options
Diffstat (limited to 'imap.c')
| -rw-r--r-- | imap.c | 40 | 
1 files changed, 36 insertions, 4 deletions
| @@ -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);  } | 
