1 /*
2 * decode_smtp.c
3 *
4 * Simple Mail Transfer Protocol.
5 *
6 * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
7 *
8 * $Id: decode_smtp.c,v 1.3 2001/03/15 08:33:02 dugsong Exp $
9 */
10
11 #include "config.h"
12
13 #include <sys/types.h>
14
15 #include <stdio.h>
16 #include <string.h>
17
18 #include "base64.h"
19 #include "options.h"
20 #include "decode.h"
21
22 int
decode_smtp(u_char * buf,int len,u_char * obuf,int olen)23 decode_smtp(u_char *buf, int len, u_char *obuf, int olen)
24 {
25 char *p;
26 int i, j, login = 0;
27
28 obuf[0] = '\0';
29
30 for (p = strtok(buf, "\r\n"); p != NULL; p = strtok(NULL, "\r\n")) {
31 if (login == 1) {
32 strlcat(obuf, p, olen);
33 i = base64_pton(p, p, strlen(p));
34 p[i] = '\0';
35 j = strlen(obuf);
36 snprintf(obuf + j, olen - j, " [%s]\n", p);
37 login = 0;
38 }
39 else if (strncmp(p, "AUTH LOGIN ", 11) == 0) {
40 strlcat(obuf, p, olen);
41 p += 11;
42 i = base64_pton(p, p, strlen(p));
43 p[i] = '\0';
44 j = strlen(obuf);
45 snprintf(obuf + j, olen - j, " [%s]\n", p);
46 login = 1;
47 }
48 else if (strncmp(p, "MAIL ", 5) == 0 ||
49 strncmp(p, "RCPT ", 5) == 0 ||
50 strncmp(p, "DATA", 4) == 0) {
51 break;
52 }
53 }
54 return (strlen(obuf));
55 }
56