Skip to content
Snippets Groups Projects
Commit d9e5dc8b authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Convert CP437 message subject to UTF-8 when posting a UTF-8 encoded message

This is a solution for issue #842, but only for messages posted/sent from the
terminal server using built-in functions and not via JS or other means. A more
universal/generic solution would be nice (beyond just always storing message
headers and bodies in UTF-8), but nothing has come to mind.
parent 65ff68a0
No related branches found
No related tags found
No related merge requests found
......@@ -280,6 +280,8 @@ bool sbbs_t::email(int usernumber, const char *top, const char *subj, int mode,
msg_client_hfields(&msg,&client);
smb_hfield_str(&msg,SENDERSERVER,server_host_name());
normalize_msg_hfield_encoding(charset, title, sizeof title);
smb_hfield_str(&msg,SUBJECT,title);
add_msg_ids(&cfg, &smb, &msg, remsg);
......
......@@ -309,6 +309,8 @@ bool sbbs_t::netmail(const char *into, const char *title, int mode, smb_t* resmb
smb_hfield(&msg,RECIPIENTNETTYPE, sizeof(nettype), &nettype);
smb_hfield(&msg,RECIPIENTNETADDR, sizeof(dest_addr), &dest_addr);
normalize_msg_hfield_encoding(charset, subj, sizeof subj);
smb_hfield_str(&msg,SUBJECT, subj);
editor_info_to_msg(&msg, editor, charset);
......@@ -1138,6 +1140,8 @@ bool sbbs_t::inetmail(const char *into, const char *subj, int mode, smb_t* resmb
msg_client_hfields(&msg,&client);
smb_hfield_str(&msg,SENDERSERVER, server_host_name());
normalize_msg_hfield_encoding(charset, title, sizeof title);
smb_hfield_str(&msg,SUBJECT,title);
editor_info_to_msg(&msg, editor, charset);
......@@ -1422,6 +1426,8 @@ bool sbbs_t::qnetmail(const char *into, const char *subj, int mode, smb_t* resmb
msg_client_hfields(&msg,&client);
smb_hfield_str(&msg,SENDERSERVER, server_host_name());
normalize_msg_hfield_encoding(charset, title, sizeof title);
smb_hfield_str(&msg,SUBJECT,title);
add_msg_ids(&cfg, &smb, &msg, /* remsg: */NULL);
......
......@@ -304,6 +304,7 @@ bool sbbs_t::postmsg(int subnum, int wm_mode, smb_t* resmb, smbmsg_t* remsg)
if(remsg != NULL && remsg->subj != NULL && strcmp(title, org_title) == 0)
SAFECOPY(title, remsg->subj); // If msg subject not changed by user, use original (possibly UTF-8 encoded) subject
normalize_msg_hfield_encoding(charset, title, sizeof title);
smb_hfield_str(&msg,SUBJECT,title);
add_msg_ids(&cfg, &smb, &msg, remsg);
......@@ -369,6 +370,18 @@ bool sbbs_t::postmsg(int subnum, int wm_mode, smb_t* resmb, smbmsg_t* remsg)
return(true);
}
// When message body is UTF-8 encoded, insure header files are UTF-8 (not CP437) encoded too
extern "C" void normalize_msg_hfield_encoding(const char* charset, char* str, size_t size)
{
char utf8_str[128];
if(charset != NULL && strcmp(charset, FIDO_CHARSET_UTF8) == 0) {
if(!str_is_ascii(str) && !utf8_str_is_valid(str))
if(cp437_to_utf8_str(str, utf8_str, sizeof utf8_str, '\x80') > 1)
strlcpy(str, utf8_str, size);
}
}
extern "C" void signal_sub_sem(scfg_t* cfg, int subnum)
{
char str[MAX_PATH+1];
......
......@@ -1401,6 +1401,7 @@ extern "C" {
DLLEXPORT void signal_sub_sem(scfg_t*, int subnum);
DLLEXPORT int msg_client_hfields(smbmsg_t*, client_t*);
DLLEXPORT int notify(scfg_t*, uint usernumber, const char* subject, const char* msg);
DLLEXPORT void normalize_msg_hfield_encoding(const char* charset, char* str, size_t size);
/* logfile.cpp */
DLLEXPORT int errorlog(scfg_t* cfg, struct mqtt*, int level, const char* host, const char* text);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment