4static const char qptab[] =
7 0, 0, 0, 0, 0, 0, 0, 0, 0,
'\t',
'\n', 0, 0, 0, 0, 0,
8 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0 , 0, 0, 0, 0, 0,
9 ' ' ,
'!',
'"',
'#',
'$',
'%',
'&',
'\'',
'(',
')' ,
'*' ,
'+',
',',
'-',
'.',
'/',
10 '0' ,
'1',
'2',
'3',
'4',
'5',
'6',
'7' ,
'8',
'9' ,
':' ,
';',
'<', 0,
'>',
'?',
11 '@' ,
'A',
'B',
'C',
'D',
'E',
'F',
'G' ,
'H',
'I' ,
'J' ,
'K',
'L',
'M',
'N',
'O',
12 'P' ,
'Q',
'R',
'S',
'T',
'U',
'V',
'W' ,
'X',
'Y' ,
'Z' ,
'[',
'\\',
']',
'^',
'_',
13 '`' ,
'a',
'b',
'c',
'd',
'e',
'f',
'g' ,
'h',
'i' ,
'j' ,
'k',
'l',
'm',
'n',
'o',
14 'p' ,
'q',
'r',
's',
't',
'u',
'v',
'w' ,
'x',
'y' ,
'z' ,
'{',
'|',
'}',
'~', 0,
17static const char hextab[] =
"0123456789abcdef";
18static const char qpok[] =
"0123456789abcdef ";
19static const char QPok[] =
"0123456789ABCDEF ";
23 unsigned char c, dec = 0;
25 for (
int i = 0; i < 2; i++) {
28 if (
c >=
'0' &&
c <=
'9') dec +=
c -
'0';
29 else if (
c >=
'A' &&
c <=
'F') dec +=
c - 55;
30 else if (
c >=
'a' &&
c <=
'f') dec +=
c - 87;
36static int decode_qp(
const char *s)
39 if (*s ==
'\n') s + 1;
67 if (!stralloc_copys(
out,
""))
return -1;
70 if (!stralloc_copys(
out,
""))
return -1;
72 for (
int i = 0; i < in->len - 1; i++) {
74 if ((ch & 0x80) || (ch ==
'.') || (qptab[ch] == 0)) {
75 if (!stralloc_append(
out,
"="))
return -1;
77 xch[0] = hextab[(ch >> 4) & 0x0f];
78 xch[1] = hextab[(ch & 0x0f)];
79 if (!stralloc_catb(
out,xch,2))
return -1;
82 if (!stralloc_append(
out,in->s + i))
return -1;
85 if (r % 76 == 0)
if (!stralloc_catb(
out,
"=\n",2))
return -1;
109 if (!stralloc_copys(
out,
""))
return -1;
112 if (!stralloc_readyplus(
out,len))
return -1;
115 if (*in ==
'\0')
return r;
116 if (
flag == 2047 && *in ==
'_') {
117 if (!stralloc_append(
out,
" "))
return -1;
118 r++, in++; len--;
continue;
121 if (*(in + 1) ==
'\n') { in += 2; len -= 2;
continue; }
122 if ((str_chr(QPok,*(in + 1)) < 16 && str_chr(QPok,*(in + 2)) < 16) ||
123 (str_chr(qpok,*(in + 1)) < 16 && str_chr(qpok,*(in + 2)) < 16)) {
125 if (!stralloc_append(
out,&ch))
return -1;
126 r++; in += 3; len -= 3;
127 }
else { r += 2; in += 2; len -= 2;
continue; }
130 if (!stralloc_append(
out,in))
return -1;
134 if (!stralloc_0(
out))
return -1;
void c(char *, char *, char *, int, int, int)
int mess822_qpdecode(stralloc *out, const char *in, int len, int flag)
int mess822_qpencode(stralloc *out, stralloc *in)