maddr, mhdr: requote display names when needed

This commit is contained in:
Leah Neukirchen 2018-05-23 16:24:48 +02:00
parent b4df5b006b
commit bcd258a8c8
2 changed files with 56 additions and 6 deletions

31
maddr.c
View File

@ -13,6 +13,29 @@ static char defaulthflags[] = "from:sender:reply-to:to:cc:bcc:"
"resent-from:resent-sender:resent-to:resent-cc:resent-bcc:"; "resent-from:resent-sender:resent-to:resent-cc:resent-bcc:";
static char *hflag = defaulthflags; static char *hflag = defaulthflags;
void
print_quoted(char *s)
{
char *t;
for (t = s; *t; t++)
if ((unsigned char)*t < 32 || strchr("()<>[]:;@\\,.\"", *t))
goto quote;
printf("%s", s);
return;
quote:
putchar('"');
for (t = s; *t; t++) {
if (*t == '"' || *t == '\\')
putchar('\\');
putchar(*t);
}
putchar('"');
}
void void
addr(char *file) addr(char *file)
{ {
@ -41,10 +64,12 @@ addr(char *file)
if (disp && addr && strcmp(disp, addr) == 0) if (disp && addr && strcmp(disp, addr) == 0)
disp = 0; disp = 0;
if (disp && addr) { if (disp && addr) {
if (aflag) if (aflag) {
printf("%s\n", addr); printf("%s\n", addr);
else } else {
printf("%s <%s>\n", disp, addr); print_quoted(disp);
printf(" <%s>\n", addr);
}
} else if (addr) { } else if (addr) {
printf("%s\n", addr); printf("%s\n", addr);
} }

31
mhdr.c
View File

@ -58,6 +58,29 @@ headerall(struct message *msg)
blaze822_free(msg); blaze822_free(msg);
} }
void
print_quoted(char *s)
{
char *t;
for (t = s; *t; t++)
if ((unsigned char)*t < 32 || strchr("()<>[]:;@\\,.\"", *t))
goto quote;
printf("%s", s);
return;
quote:
putchar('"');
for (t = s; *t; t++) {
if (*t == '"' || *t == '\\')
putchar('\\');
putchar(*t);
}
putchar('"');
}
void void
print_addresses(char *s) print_addresses(char *s)
{ {
@ -74,11 +97,13 @@ print_addresses(char *s)
if (Hflag && addr) if (Hflag && addr)
printf("%s\t", curfile); printf("%s\t", curfile);
if (disp && addr) if (disp && addr) {
printf("%s <%s>\n", disp, addr); print_quoted(disp);
else if (addr) printf(" <%s>\n", addr);
} else if (addr) {
printf("%s\n", addr); printf("%s\n", addr);
} }
}
} }
void void