4static int needquote(
char *buf,
int len)
10 if (buf[0] ==
'.')
return 1;
11 if (buf[len - 1] ==
'.')
return 1;
13 for (i = 0;i < len - 1;++i)
14 if ((buf[i] ==
'.') && (buf[i + 1] ==
'.'))
return 1;
16 for (i = 0; i < len; ++i) {
18 if (ch < 33)
return 1;
19 if (ch > 126)
return 1;
20 if (ch ==
'@')
return 1;
21 if (ch ==
'<')
return 1;
22 if (ch ==
'>')
return 1;
23 if (ch ==
'[')
return 1;
24 if (ch ==
']')
return 1;
25 if (ch ==
'(')
return 1;
26 if (ch ==
')')
return 1;
27 if (ch ==
',')
return 1;
28 if (ch ==
';')
return 1;
29 if (ch ==
':')
return 1;
30 if (ch ==
'"')
return 1;
31 if (ch ==
'\\')
return 1;
37static int doit(stralloc *
out,
char *buf,
int len,
char *pre,
char *post)
41 if (!stralloc_cats(
out,pre))
return 0;
45 if (ch ==
'\n') ch = 0;
46 if ((ch == 0) || (ch ==
'\r') || (ch ==
'"') || (ch ==
'\\') || (ch ==
'[') || (ch ==
']'))
47 if (!stralloc_append(
out,
"\\"))
return 0;
48 if (!stralloc_append(
out,&ch))
return 0;
51 if (!stralloc_cats(
out,post))
return 0;
63 if (str_equal(
addr,
"")) flagempty = 1;
64 if (str_equal(
addr,
"@")) flagempty = 1;
66 flagbracket = flagempty;
73 if (flagbracket)
if (!stralloc_cats(
out,
"<"))
return 0;
76 i = str_rchr(
addr,
'@');
77 quote = needquote(
addr,i) ?
"\"" :
"";
78 if (!doit(
out,
addr,i,quote,quote))
return 0;
85 if (!stralloc_append(
out,
"@"))
return 0;
87 quote = needquote(
addr,i) ?
"\"" :
"";
89 if (*quote && (i >= 2) && (
addr[0] ==
'[') && (
addr[i - 1] ==
']')) {
90 if (!doit(
out,
addr + 1,i - 2,
"[",
"]"))
return 0;
93 if (!doit(
out,
addr,i,quote,quote))
return 0;
97 if (flagbracket)
if (!stralloc_cats(
out,
">"))
return 0;
104 if (!stralloc_copys(
out,
""))
return 0;
114 if (!stralloc_copys(
out,
""))
return 0;
118 for (j = i = 0;j < in->len;++j)
120 if (in->s[i] ==
'(') {
122 if (!doit(
out,in->s +
comment,str_len(in->s +
comment),
"\"",
"\": ;,\n "))
return 0;
125 else if (in->s[i] ==
'+') {
127 if (!stralloc_cats(
out,
",\n "))
return 0;
134 if (!doit(
out,in->s +
comment,str_len(in->s +
comment),
"\"",
"\": ;,\n "))
return 0;
136 if (
out->len && (
out->s[
out->len - 1] ==
' ')) --
out->len;
137 if (
out->len && (
out->s[
out->len - 1] ==
' ')) --
out->len;
138 if (
out->len && (
out->s[
out->len - 1] ==
'\n')) --
out->len;
139 if (
out->len && (
out->s[
out->len - 1] ==
',')) --
out->len;
int mess822_quote(stralloc *out, char *addr, char *comment)
int mess822_quotelist(stralloc *out, stralloc *in)
int mess822_quoteplus(stralloc *out, char *addr, char *comment)