-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathdecode_imap.c
46 lines (36 loc) · 834 Bytes
/
decode_imap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*
* decode_imap.c
*
* Internet Mail Access Protocol.
*
* Copyright (c) 2000 Dug Song <[email protected]>
*
* $Id: decode_imap.c,v 1.5 2001/03/15 08:33:00 dugsong Exp $
*/
#include "config.h"
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include "decode.h"
#include "buf.h"
int
decode_imap(u_char *buf, int len, u_char *obuf, int olen)
{
struct buf *line, inbuf, outbuf;
int i;
buf_init(&inbuf, buf, len);
buf_init(&outbuf, obuf, olen);
while ((i = buf_index(&inbuf, "\r\n", 2)) != -1) {
line = buf_tok(&inbuf, NULL, i);
buf_skip(&inbuf, 2);
if ((i = buf_index(line, " ", 1)) != -1) {
buf_skip(line, i + 1);
if (buf_cmp(line, "LOGIN ", 6) == 0) {
buf_putf(&outbuf, "%.*s\n",
buf_len(line), buf_ptr(line));
}
}
}
buf_end(&outbuf);
return (buf_len(&outbuf));
}