From 1838158ef19d489e554b3460059fba47d26ba145 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Thu, 16 Mar 2023 19:54:46 +0100 Subject: blaze822_priv.h: use proper lc/uc Mail headers may contain characters where the simple definition breaks, which results in wrong formatting on output. Fixes #235. --- blaze822_priv.h | 6 +++--- rfc2047.c | 3 ++- t/1100-mhdr.t | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100755 t/1100-mhdr.t diff --git a/blaze822_priv.h b/blaze822_priv.h index a84c963..e5f4a09 100644 --- a/blaze822_priv.h +++ b/blaze822_priv.h @@ -12,9 +12,9 @@ struct message { #define isfws(c) (((unsigned char)(c) == ' ' || (unsigned char)(c) == '\t' || (unsigned char)(c) == '\n' || (unsigned char)(c) == '\r')) -// ASCII lowercase/uppercase without alpha check (wrong for "@[\]^_") -#define lc(c) ((c) | 0x20) -#define uc(c) ((c) & 0xdf) +// 7bit-ASCII only lowercase/uppercase +#define lc(c) (((unsigned)(c)-'A') < 26 ? ((c) | 0x20) : (c)) +#define uc(c) (((unsigned)(c)-'a') < 26 ? ((c) & 0xdf) : (c)) // dirent type that can be a mail/dir (following symlinks) #if defined(DT_REG) && defined(DT_LNK) && defined(DT_UNKNOWN) diff --git a/rfc2047.c b/rfc2047.c index 3074b4d..5aec546 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -201,7 +201,8 @@ blaze822_decode_rfc2047(char *dst, char *src, size_t dlen, char *tgtenc) if (ic == (iconv_t)-1) goto nocode; - char enc = lc(*e++); + char enc = lc(*e); + e++; if (*e++ != '?') goto nocode; char *start = e; diff --git a/t/1100-mhdr.t b/t/1100-mhdr.t new file mode 100755 index 0000000..9937041 --- /dev/null +++ b/t/1100-mhdr.t @@ -0,0 +1,26 @@ +#!/bin/sh -e +cd ${0%/*} +. ./lib.sh + +plan 9 + +cat <tmp +Header: foo +Header2: bar +Header-Three: quux +Header_Four: ding + +Body +EOF + +check_same 'Header' 'mhdr -h Header ./tmp' 'echo foo' +check_same 'Header2' 'mhdr -h Header2 ./tmp' 'echo bar' +check_same 'Header-Three' 'mhdr -h Header-Three ./tmp' 'echo quux' +check_same 'Header_Four' 'mhdr -h Header_Four ./tmp' 'echo ding' + +check_same 'header' 'mhdr -h header ./tmp' 'echo foo' +check_same 'header2' 'mhdr -h header2 ./tmp' 'echo bar' +check_same 'header-Three' 'mhdr -h header-Three ./tmp' 'echo quux' +check_same 'header_Four' 'mhdr -h header_Four ./tmp' 'echo ding' + +check 'issue 235' 'mhdr ./tmp |grep -i header_four' -- cgit 1.4.1