From 5716774a66e8f8fdb42cc7a626baa38b9b3ff295 Mon Sep 17 00:00:00 2001 From: rswindell <> Date: Mon, 2 Sep 2019 05:42:14 +0000 Subject: [PATCH] Automatic UTF-8 header field detection in savemsg(): if the to, from, or subject header fields are non-ASCII yet valid UTF-8, set the auxattr flag indicating that the msg header is in UTF-8. This function is used by JS MsgBase.save_msg(), so any scripts/services that use it (e.g. nntpservice, newslink, imapservice, etc.) to save messages with header fields that may be UTF-8 encoded will automatically benefit from this detection. Mixing CP437 (the default) with UTF-8 encoded header fields is not supported, so if one header field is valid UTF-8 (not plain US-ASCII), then they had better all be either plain US-ASCII or UTF-8 or there will be UTF-8 decoding issues when attempting to display or convert later. --- src/sbbs3/postmsg.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sbbs3/postmsg.cpp b/src/sbbs3/postmsg.cpp index e952e22486..977d36c90d 100644 --- a/src/sbbs3/postmsg.cpp +++ b/src/sbbs3/postmsg.cpp @@ -35,6 +35,7 @@ ****************************************************************************/ #include "sbbs.h" +#include "utf8.h" int msgbase_open(scfg_t* cfg, smb_t* smb, unsigned int subnum, int* storage, long* dupechk_hashes, uint16_t* xlat) { @@ -456,6 +457,11 @@ extern "C" int DLLCALL savemsg(scfg_t* cfg, smb_t* smb, smbmsg_t* msg, client_t* add_msg_ids(cfg, smb, msg, remsg); + if((msg->to != NULL && !str_is_ascii(msg->to) && utf8_str_is_valid(msg->to)) + || (msg->from != NULL && !str_is_ascii(msg->from) && utf8_str_is_valid(msg->from)) + || (msg->subj != NULL && !str_is_ascii(msg->subj) && utf8_str_is_valid(msg->subj))) + msg->hdr.auxattr |= MSG_HFIELDS_UTF8; + if((i=smb_addmsg(smb,msg,smb_storage_mode(cfg, smb),dupechk_hashes,xlat,(uchar*)msgbuf, /* tail: */NULL))==SMB_SUCCESS && msg->to!=NULL /* no recipient means no header created at this stage */) { if(smb->subnum == INVALID_SUB) { -- GitLab