Synchronet now requires the libarchive development package (e.g. libarchive-dev on Debian-based Linux distros, libarchive.org for more info) to build successfully.

Commit 9c8d7588 authored by Rob Swindell's avatar Rob Swindell 💬

Better charset handling of outbound mail

The default character set for outbound mail is now auto-determined (when not explicitly specified for a message) between UTF-8, ASCII, and CP437. The [mail] DefaultCharset setting (which fell-back to iso-8859-1 if blank) is no longer "a thing".

Also: specify 8-bit content-transfer-encoding for the (potentially UTF-8 or CP-437) plain text portion of a MIME-encoded message with file attachment (7-bit was wrong) and pass down the text sub-type (e.g. could be "html") for inclusion in the mime-part header (don't assume text/plain, but still use that as default).

Also: log an error when failing to delete an attached file (e.g. from data/file/*.out).
parent 1c1e8d2e
Pipeline #1206 failed with stage
in 16 minutes and 49 seconds
/* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */
/* $Id: MailCfgDlgUnit.cpp,v 1.34 2018/03/05 05:35:13 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
* *
* Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* Copyright Rob Swindell - http://www.synchro.net/copyright.html *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
......@@ -15,21 +13,9 @@
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -107,7 +93,6 @@ void __fastcall TMailCfgDlg::FormShow(TObject *Sender)
UseSubPortCheckBox->Checked=MainForm->mail_startup.options&MAIL_OPT_USE_SUBMISSION_PORT;
TLSSubPortCheckBox->Checked=MainForm->mail_startup.options&MAIL_OPT_TLS_SUBMISSION;
DefCharsetEdit->Text=AnsiString(MainForm->mail_startup.default_charset);
RelayServerEdit->Text=AnsiString(MainForm->mail_startup.relay_server);
RelayAuthNameEdit->Text=AnsiString(MainForm->mail_startup.relay_user);
RelayAuthPassEdit->Text=AnsiString(MainForm->mail_startup.relay_pass);
......@@ -236,8 +221,6 @@ void __fastcall TMailCfgDlg::OKBtnClick(TObject *Sender)
MainForm->mail_startup.rescan_frequency=RescanFreqEdit->Text.ToIntDef(MAIL_DEFAULT_RESCAN_FREQUENCY);
MainForm->mail_startup.max_concurrent_connections=MaxConConEdit->Text.ToIntDef(0);
SAFECOPY(MainForm->mail_startup.default_charset
,DefCharsetEdit->Text.c_str());
SAFECOPY(MainForm->mail_startup.default_user
,DefaultUserEdit->Text.c_str());
if(isalnum(*DNSServerEdit->Text.c_str()))
......@@ -434,8 +417,6 @@ void __fastcall TMailCfgDlg::SendMailCheckBoxClick(TObject *Sender)
OutboundSoundEdit->Enabled=checked;
OutboundSoundLabel->Enabled=checked;
OutboundSoundButton->Enabled=checked;
DefCharsetLabel->Enabled=checked;
DefCharsetEdit->Enabled=checked;
ConnectTimeoutLabel->Enabled=checked;
ConnectTimeoutEdit->Enabled=checked;
......
......@@ -482,14 +482,6 @@ object MailCfgDlg: TMailCfgDlg
Height = 13
Caption = 'DNS Server'
end
object DefCharsetLabel: TLabel
Left = 7
Top = 62
Width = 85
Height = 19
AutoSize = False
Caption = 'Default Charset'
end
object ConnectTimeoutLabel: TLabel
Left = 7
Top = 146
......@@ -579,16 +571,6 @@ object MailCfgDlg: TMailCfgDlg
TabOrder = 0
OnClick = SendMailCheckBoxClick
end
object DefCharsetEdit: TEdit
Left = 92
Top = 62
Width = 65
Height = 21
Hint = 'Character set specified for locally generated e-mail messages'
ParentShowHint = False
ShowHint = True
TabOrder = 3
end
object ConnectTimeoutEdit: TEdit
Left = 92
Top = 146
......
/* Synchronet Control Panel (GUI Borland C++ Builder Project for Win32) */
/* $Id: MailCfgDlgUnit.h,v 1.22 2018/07/24 01:11:29 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -15,21 +13,9 @@
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -140,8 +126,6 @@ __published:
TEdit *RelayAuthPassEdit;
TTabSheet *AdvancedTabSheet;
TCheckListBox *AdvancedCheckListBox;
TLabel *DefCharsetLabel;
TEdit *DefCharsetEdit;
TLabel *SubPortLabel;
TEdit *SubPortEdit;
TCheckBox *DebugHeadersCheckBox;
......
......@@ -665,7 +665,6 @@ static ulong sockmimetext(SOCKET socket, const char* prot, CRYPT_SESSION sess, s
char date[64];
char* p;
char* np;
char* content_type=NULL;
int i;
int s;
ulong lines;
......@@ -798,18 +797,24 @@ static ulong sockmimetext(SOCKET socket, const char* prot, CRYPT_SESSION sess, s
}
for(i=0;i<msg->total_hfields;i++) {
if(msg->hfield[i].type==RFC822HEADER) {
if(strnicmp((char*)msg->hfield_dat[i],"Content-Type:",13)==0)
content_type=msg->hfield_dat[i];
if(!sockprintf(socket,prot, sess,"%s",(char*)msg->hfield_dat[i]))
return(0);
}
}
const char* charset = msg->text_charset;
if(charset == NULL) {
if(smb_msg_is_utf8(msg) || (msg->hdr.auxattr & MSG_HFIELDS_UTF8))
charset = "UTF-8";
else if(str_is_ascii(msgtxt))
charset = "US-ASCII";
else
charset = "IBM437";
}
/* Default MIME Content-Type for non-Internet messages */
if(msg->from_net.type!=NET_INTERNET && content_type==NULL) {
const char* charset = smb_msg_is_utf8(msg) ? "UTF-8" : startup->default_charset;
if(*charset)
sockprintf(socket,prot,sess,"Content-Type: text/plain; charset=%s", charset);
sockprintf(socket,prot,sess,"Content-Transfer-Encoding: 8bit");
if(msg->from_net.type!=NET_INTERNET && msg->content_type==NULL) {
sockprintf(socket,prot,sess, "Content-Type: text/plain; charset=%s", charset);
sockprintf(socket,prot,sess, "Content-Transfer-Encoding: 8bit");
}
if(strListCount(file_list)) { /* File attachments */
......@@ -817,7 +822,7 @@ static ulong sockmimetext(SOCKET socket, const char* prot, CRYPT_SESSION sess, s
sockprintf(socket,prot,sess,"");
mimeblurb(socket,prot,sess,mime_boundary);
sockprintf(socket,prot,sess,"");
mimetextpartheader(socket,prot,sess,mime_boundary, startup->default_charset);
mimetextpartheader(socket,prot,sess,mime_boundary, msg->text_subtype, charset);
}
if(!sockprintf(socket,prot,sess,"")) /* Header Terminator */
return(0);
......@@ -1690,8 +1695,11 @@ static void pop3_thread(void* arg)
}
msg.hdr.attr|=MSG_DELETE;
if((i=smb_putmsg(&smb,&msg))==SMB_SUCCESS && msg.hdr.auxattr&MSG_FILEATTACH)
delfattach(&scfg,&msg);
if((i=smb_putmsg(&smb,&msg))==SMB_SUCCESS && msg.hdr.auxattr&MSG_FILEATTACH) {
if(!delfattach(&scfg,&msg))
lprintf(LOG_ERR, "%04d %s <%s> !ERROR %d deleting attachment: %s"
,socket, client.protocol, user.alias, errno, msg.subj);
}
smb_unlockmsghdr(&smb,&msg);
smb_unlocksmbhdr(&smb);
smb_freemsgmem(&msg);
......@@ -5041,8 +5049,11 @@ BOOL bounce(SOCKET sock, smb_t* smb, smbmsg_t* msg, char* err, BOOL immediate)
msg->hdr.attr|=MSG_DELETE;
i=smb_updatemsg(smb,msg);
if(msg->hdr.auxattr&MSG_FILEATTACH)
delfattach(&scfg,msg);
if(msg->hdr.auxattr&MSG_FILEATTACH) {
if(!delfattach(&scfg,msg))
lprintf(LOG_ERR, "%04d SEND !ERROR %d deleting attachment: %s"
,sock, errno, msg->subj);
}
if(i!=SMB_SUCCESS) {
lprintf(LOG_ERR,"%04d SEND !BOUNCE ERROR %d (%s) deleting message"
,sock, i, smb->last_error);
......@@ -5805,8 +5816,11 @@ static void sendmail_thread(void* arg)
if((i=smb_updatemsg(&smb,&msg))!=SMB_SUCCESS)
lprintf(LOG_ERR,"%04d %s !ERROR %d (%s) deleting message #%u"
,sock, prot, i, smb.last_error, msg.hdr.number);
if(msg.hdr.auxattr&MSG_FILEATTACH)
delfattach(&scfg,&msg);
if(msg.hdr.auxattr&MSG_FILEATTACH) {
if(!delfattach(&scfg,&msg))
lprintf(LOG_ERR, "%04d %s !ERROR %d deleting attachment: %s"
,sock, prot, errno, msg.subj);
}
/* QUIT */
sockprintf(sock,prot,session,"QUIT");
......
/* Synchronet Mail (SMTP/POP3/SendMail) server */
/* $Id: mailsrvr.h,v 1.88 2019/03/22 21:28:27 rswindell Exp $ */
// vi: tabstop=4
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -16,21 +13,9 @@
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -102,7 +87,6 @@ typedef struct {
char inbound_sound[128];
char outbound_sound[128];
char pop3_sound[128];
char default_charset[128];
char newmail_notice[256];
char forward_notice[256];
......
/* Synchronet MIME functions, originally written/submitted by Marc Lanctot */
/* $Id: mime.c,v 1.12 2018/07/20 01:34:36 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -15,21 +13,9 @@
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -81,14 +67,15 @@ void mimeblurb(SOCKET socket, const char* prot, int sess, char* boundary)
sockprintf(socket,prot,sess,"");
}
void mimetextpartheader(SOCKET socket, const char* prot, int sess, char* boundary, const char* charset)
void mimetextpartheader(SOCKET socket, const char* prot, int sess, char* boundary
,const char* text_subtype, const char* charset)
{
if(charset == NULL || *charset == 0)
charset = "iso-8859-1";
if(text_subtype == NULL || *text_subtype == '\0')
text_subtype = "plain";
sockprintf(socket,prot,sess,"--%s",boundary);
sockprintf(socket,prot,sess,"Content-Type: text/plain;");
sockprintf(socket,prot,sess,"Content-Type: text/%s;", text_subtype);
sockprintf(socket,prot,sess," charset=\"%s\"", charset);
sockprintf(socket,prot,sess,"Content-Transfer-Encoding: 7bit");
sockprintf(socket,prot,sess,"Content-Transfer-Encoding: 8bit");
}
BOOL base64out(SOCKET socket, const char* prot, int sess, char* pathfile)
......
/* Synchronet MIME functions, originally written/submitted by Marc Lanctot */
/* $Id: mime.h,v 1.6 2018/07/20 01:34:36 rswindell Exp $ */
/****************************************************************************
* @format.tab-size 4 (Plain Text/Source Code File Header) *
* @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
......@@ -15,21 +13,9 @@
* See the GNU General Public License for more details: gpl.txt or *
* http://www.fsf.org/copyleft/gpl.html *
* *
* Anonymous FTP access to the most recent released source is available at *
* ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
* *
* Anonymous CVS access to the development source and modification history *
* is available at cvs.synchro.net:/cvsroot/sbbs, example: *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs login *
* (just hit return, no password is necessary) *
* cvs -d :pserver:anonymous@cvs.synchro.net:/cvsroot/sbbs checkout src *
* *
* For Synchronet coding style and modification guidelines, see *
* http://www.synchro.net/source.html *
* *
* You are encouraged to submit any modifications (preferably in Unix diff *
* format) via e-mail to mods@synchro.net *
* *
* Note: If this box doesn't appear square, then you need to fix your tabs. *
****************************************************************************/
......@@ -40,7 +26,7 @@
char * mimegetboundary(void);
void mimeheaders(SOCKET socket, const char* prot, int sess, char * boundary);
void mimeblurb(SOCKET socket, const char* prot, int sess, char * boundary);
void mimetextpartheader(SOCKET socket, const char* prot, int sess, char * boundary, const char* charset);
void mimetextpartheader(SOCKET socket, const char* prot, int sess, char * boundary, const char* text_subtype, const char* charset);
BOOL mimeattach(SOCKET socket, const char* prot, int sess, char * boundary, char * pathfile);
void endmime(SOCKET socket, const char* prot, int sess, char * boundary);
......
......@@ -533,9 +533,6 @@ void sbbs_read_ini(
SAFECOPY(mail->default_user
,iniGetString(list,section,"DefaultUser",nulstr,value));
SAFECOPY(mail->default_charset
,iniGetString(list,section,"DefaultCharset",nulstr,value));
SAFECOPY(mail->dnsbl_hdr
,iniGetString(list,section,"DNSBlacklistHeader","X-DNSBL",value));
SAFECOPY(mail->dnsbl_tag
......@@ -1038,9 +1035,6 @@ BOOL sbbs_write_ini(
if(!iniSetString(lp,section,"DNSServer",mail->dns_server,&style))
break;
if(!iniSetString(lp,section,"DefaultCharset",mail->default_charset,&style))
break;
if(!iniSetString(lp,section,"DefaultUser",mail->default_user,&style))
break;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment