1 diff --git a/decode_pop.c b/decode_pop.c
2 index 04044f5..767da41 100644
6 * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
8 * $Id: decode_pop.c,v 1.4 2001/03/15 08:33:02 dugsong Exp $
10 + * Rewritten by Stefan Tomanek 2011 <stefan@pico.ruhr.de>
14 @@ -45,32 +47,88 @@ int
15 decode_pop(u_char *buf, int len, u_char *obuf, int olen)
33 for (p = strtok(buf, "\r\n"); p != NULL; p = strtok(NULL, "\r\n")) {
34 - if (strncasecmp(p, "AUTH PLAIN", 10) == 0 ||
35 - strncasecmp(p, "AUTH LOGIN", 10) == 0) {
36 - strlcat(obuf, p, olen);
37 - strlcat(obuf, "\n", olen);
39 - /* Decode SASL auth. */
40 - for (i = 0; i < 2 && (p = strtok(NULL, "\r\n")); i++) {
41 - strlcat(obuf, p, olen);
42 - j = base64_pton(p, p, strlen(p));
44 - strlcat(obuf, " [", olen);
45 - strlcat(obuf, p, olen);
46 - strlcat(obuf, "]\n", olen);
50 + if (strncasecmp(p, "AUTH PLAIN", 10) == 0) {
54 + if (strncasecmp(p, "AUTH LOGIN", 10) == 0) {
58 + if (strncasecmp(p, "USER ", 5) == 0) {
60 + /* the traditional login cuts right to the case,
61 + * so no continue here
65 - /* Save regular POP2, POP3 auth info. */
66 - else if (strncasecmp(p, "USER ", 5) == 0 ||
67 - strncasecmp(p, "PASS ", 5) == 0 ||
68 - strncasecmp(p, "HELO ", 5) == 0) {
69 - strlcat(obuf, p, olen);
70 - strlcat(obuf, "\n", olen);
71 + printf("(%d) %s\n", mode, p);
72 + if (mode == USERPASS) {
73 + if (strncasecmp(p, "USER ", 5) == 0) {
75 + } else if (strncasecmp(p, "PASS ", 5) == 0) {
80 + if (mode == AUTHPLAIN) {
81 + j = base64_pton(p, p, strlen(p));
85 + /* p consists of three parts, divided by \0 */
86 + while (s <= &p[j] && n<=3) {
88 + /* we do not process this portion yet */
89 + } else if (n == 1) {
91 + } else if (n == 2) {
100 + if (mode == AUTHLOGIN) {
101 + j = base64_pton(p, p, strlen(p));
107 + /* got everything we need :-) */
111 + if (user && password) {
112 + strlcat(obuf, "\nusername [", olen);
113 + strlcat(obuf, user, olen);
114 + strlcat(obuf, "] password [", olen);
115 + strlcat(obuf, password, olen);
116 + strlcat(obuf, "]\n", olen);
121 return (strlen(obuf));