Skip to content

Commit

Permalink
Added "OnRecipientUnknown(oClient, oMessage) and OnTooManyInvalidComm…
Browse files Browse the repository at this point in the history
…ands(oClient, oMessage)"
  • Loading branch information
SorenRR committed Nov 9, 2023
1 parent f3f3076 commit 168994b
Show file tree
Hide file tree
Showing 27 changed files with 247 additions and 79 deletions.
10 changes: 5 additions & 5 deletions hmailserver/installation/hMailServer.iss
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[Setup]
AppName=hMailServer
AppVerName=hMailServer 5.6.9-B2641.84 (x86)
AppVerName=hMailServer 5.6.9-B2641.85 (x86)
AppCopyright=Copyright (C) 2023
DefaultDirName={pf}\hMailServer
DefaultGroupName=hMailServer
PrivilegesRequired=admin
OutputBaseFilename=hMailServer-5.6.9-B2641.84-(x86)
OutputBaseFilename=hMailServer-5.6.9-B2641.85-(x86)
SolidCompression=yes
WizardImageFile=setup.bmp
LicenseFile=license.rtf
Expand Down Expand Up @@ -75,8 +75,8 @@ Source: "System files\dnsapi.dll"; DestDir: "{sys}"; Flags: uninsneveruninstall
Source: "System files\ATL\atl70.dll"; DestDir: "{sys}"; Components: server;
Source: "SQLCE\SSCERuntime-ENU.msi"; Flags: deleteafterinstall ; Excludes: ".svn"; DestDir: "{tmp}"; Components: server;
Source: ".\Extras\7za.exe"; DestDir: "{app}\Bin"; Flags: ignoreversion; Components: server;
Source: "..\..\..\Libs\openssl-3.0.12\out32\bin\libcrypto-3.dll"; DestDir: "{app}\Bin"; Flags: ignoreversion; Components: server admintools;
Source: "..\..\..\Libs\openssl-3.0.12\out32\bin\libssl-3.dll"; DestDir: "{app}\Bin"; Flags: ignoreversion; Components: server admintools;
Source: "{#GetEnv("HMAILSERVERLIBS")}\openssl-3.0.12\out32\bin\libcrypto-3.dll"; DestDir: "{app}\Bin"; Flags: ignoreversion; Components: server admintools;
Source: "{#GetEnv("HMAILSERVERLIBS")}\openssl-3.0.12\out32\bin\libssl-3.dll"; DestDir: "{app}\Bin"; Flags: ignoreversion; Components: server admintools;
Source: "Microsoft.VC120.CRT\*"; DestDir: "{app}\Bin"; Flags: ignoreversion; Components: server admintools;

; Main server
Expand All @@ -100,7 +100,7 @@ Source: "..\source\Tools\DataDirectorySynchronizer\Bin\Release\*.exe"; DestDir:
Source: "..\source\tools\Administrator\bin\Release\Interop.hMailServer.dll"; DestDir: "{app}\Addons\DataDirectorySynchronizer"; Flags: ignoreversion; Components: admintools;
Source: "..\source\Tools\Shared\Bin\Release\*.dll"; DestDir: "{app}\Addons\DataDirectorySynchronizer"; Flags: ignoreversion recursesubdirs;Components: server;

Source: "..\source\Addons\*.*"; DestDir: "{app}\Addons"; Flags: ignoreversion recursesubdirs; Excludes: "Events"; Components: server;
Source: "..\source\Addons\*.*"; DestDir: "{app}\Addons"; Flags: onlyifdoesntexist recursesubdirs; Excludes: "Events"; Components: server;
Source: "..\source\Addons\Events\*.*"; DestDir: "{app}\Events"; Flags: onlyifdoesntexist uninsneveruninstall; Components: server;

Source: "..\source\WebAdmin\*.*"; DestDir: "{app}\PHPWebAdmin"; Flags: recursesubdirs; Components: admintools;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

#include "../../BO/Message.h"
#include "../../BO/Domain.h"
#include "../../BO/DomainAliases.h"
#include "../../BO/Alias.h"
#include "../../Application/ObjectCache.h"
#include "../../Cache/CacheContainer.h"
#include "../../Util/Hashing/HashCreator.h"
#include "../../BO/DomainAliases.h"

#ifdef _DEBUG
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
Expand Down Expand Up @@ -51,7 +51,6 @@ namespace HM
if (!(pDomain->GetDKIMAliasesEnabled() || sameDomain))
return;


LOG_DEBUG("Signing message using DKIM...");

AnsiString selector = pDomain->GetDKIMSelector();
Expand Down
29 changes: 22 additions & 7 deletions hmailserver/source/Server/Common/AntiSpam/SpamTestSpamAssassin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,31 @@ namespace HM
std::shared_ptr<Message> pMessage = pTestData->GetMessageData()->GetMessage();
const String sFilename = PersistentMessage::GetFileName(pMessage);

// Add Return-Path as topmost header if none exist (ExternalAccount download?)
// For SpamAssassin default rules and custom rules that rely on Return-Path header being present
if (pTestData->GetMessageData()->GetReturnPath().IsEmpty())
// // Add Return-Path as topmost header if none exist (ExternalAccount download?)
// // For SpamAssassin default rules and custom rules that rely on Return-Path header being present
// if (pTestData->GetMessageData()->GetReturnPath().IsEmpty())
// {
// std::vector<std::pair<AnsiString, AnsiString> > fieldsToWrite;
// fieldsToWrite.push_back(std::make_pair("Return-Path", pTestData->GetEnvelopeFrom()));
// TraceHeaderWriter writer;
// writer.Write(sFilename, pMessage, fieldsToWrite);
// }

// SMTP servers making final delivery MAY/SHOULD remove Return-path header fields before adding their own. See: rfc2821 and rfc5321
while (!pTestData->GetMessageData()->GetReturnPath().IsEmpty())
{
std::vector<std::pair<AnsiString, AnsiString> > fieldsToWrite;
fieldsToWrite.push_back(std::make_pair("Return-Path", pTestData->GetEnvelopeFrom()));
TraceHeaderWriter writer;
writer.Write(sFilename, pMessage, fieldsToWrite);
pTestData->GetMessageData()->DeleteField("Return-Path");
}

// Add Return-Path as topmost header to help SpamAssassin with its SPF checks.
// SpamAssassin default rules and custom rules also rely on Return-Path header being present
// We delete this header again after SpamAssassin checking has completed
std::vector<std::pair<AnsiString, AnsiString>> fieldsToWrite;
fieldsToWrite.push_back(std::make_pair("Return-Path", "<" + pTestData->GetEnvelopeFrom() + ">"));

TraceHeaderWriter writer;
writer.Write(sFilename, pMessage, fieldsToWrite);

std::shared_ptr<IOService> pIOService = Application::Instance()->GetIOService();

bool testCompleted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,9 @@ namespace HM
{
std::shared_ptr<ScriptObjectContainer> pContainer = std::shared_ptr<ScriptObjectContainer>(new ScriptObjectContainer);
std::shared_ptr<Result> pResult = std::shared_ptr<Result>(new Result);

pContainer->AddObject("Result", pResult, ScriptObject::OTResult);

String sEventCaller = "OnBackupCompleted()";
ScriptServer::Instance()->FireEvent(ScriptServer::EventOnBackupCompleted, sEventCaller, pContainer);
}
Expand Down
11 changes: 11 additions & 0 deletions hmailserver/source/Server/Common/Application/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,15 @@
#define PROPERTY_CLAMAV_PORT _T("ClamAVPort")
#define PROPERTY_IPV6_PREFERRED _T("IPv6Preferred")

/*
I added 5 setting properties so REQUIRED_DB_VERSION 5601 + 5 = 5606
[list]
[*]PROPERTY_TLSOPTIONS
[*]PROPERTY_AS_CHECKPTR
[*]PROPERTY_AS_CHECKPTRSCORE
[*]PROPERTY_IPV6_PREFERRED
[*]PersistentFetchAccount -> famimerecipientheaders
[/list]
*/

#define REQUIRED_DB_VERSION 5606
11 changes: 11 additions & 0 deletions hmailserver/source/Server/Common/Application/ErrorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ namespace HM
sEventCaller.Format(_T("OnError(%d, %d, '%s', '%s')"),
iSeverity, iErrorID, tempSource.c_str(), tempDescription.c_str());
}
// else if (sScriptLanguage == _T("LuaScript"))
// {
// String tempSource = sSource;
// String tempDescription = sDescription;
//
// tempSource.Replace(_T("\""), _T("\"\""));
// tempDescription.Replace(_T("\""), _T("\"\""));
//
// sEventCaller.Format(_T("OnError(%d, %d, \"%s\", \"%s\")"),
// iSeverity, iErrorID, tempSource.c_str(), tempDescription.c_str());
// }

std::shared_ptr<ScriptObjectContainer> pContainer = std::shared_ptr<ScriptObjectContainer>(new ScriptObjectContainer);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace HM
greylisting_enabled_during_record_expiration_(true),
greylisting_expiration_interval_(240),
preferred_hash_algorithm_(3),
dnsbl_checks_after_mail_from_(true),
dnsbl_checks_after_mail_from_(false),
log_level_(9),
max_log_line_len_(500),
quick_retries_(0),
Expand Down Expand Up @@ -59,7 +59,7 @@ namespace HM
blocked_iphold_seconds_(0),
smtpdmax_size_drop_(0),
backup_messages_dbonly_(false),
add_xauth_user_ip_(0),
add_xauth_user_ip_(false),
use_dns_cache_(true),
add_received_spf_header_(false)
{
Expand Down
7 changes: 7 additions & 0 deletions hmailserver/source/Server/Common/Application/Logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ namespace HM

}

int
Logger::GetProcessID_()
{
DWORD dwProcessID = GetCurrentProcessId();
return dwProcessID;
}

int
Logger::GetThreadID_()
{
Expand Down
3 changes: 2 additions & 1 deletion hmailserver/source/Server/Common/Application/Version.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#define HMAILSERVER_VERSION "5.6.9"
#define HMAILSERVER_BUILD "2641.84 (x86)"
#define HMAILSERVER_BUILD "2641.85 (x86)"

/*
[list=1]
Expand Down Expand Up @@ -82,5 +82,6 @@
[*]Update: Adjusted the number of triggers of "invalid command" in SMTPConnection.cpp
[*]Fix: RFC822.SIZE https://github.com/hmailserver/hmailserver/issues/476
[*]Update: OpenSSL 3.0.12
[*]Added: OnRecipientUnknown(oClient, oMessage) and OnTooManyInvalidCommands(oClient, oMessage)
[/list]
*/
2 changes: 1 addition & 1 deletion hmailserver/source/Server/Common/BO/MessageData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ namespace HM
void
MessageData::SetReturnPath(const String &sReturnPath)
{
SetFieldValue("Return-Path", sReturnPath);
SetFieldValue("Return-Path", "<" + sReturnPath + ">");
}

String
Expand Down
3 changes: 2 additions & 1 deletion hmailserver/source/Server/Common/SQL/ADOConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ namespace HM
else
{
sProvider = "sqloledb";
} }
}
}
else
{
sProvider = "SQLNCLI";
Expand Down
33 changes: 27 additions & 6 deletions hmailserver/source/Server/Common/Scripting/Events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ namespace HM
{
std::shared_ptr<ScriptObjectContainer> pContainer = std::shared_ptr<ScriptObjectContainer>(new ScriptObjectContainer);
std::shared_ptr<Result> pResult = std::shared_ptr<Result>(new Result);

pContainer->AddObject("HMAILSERVER_MESSAGE", pMessage, ScriptObject::OTMessage);
pContainer->AddObject("Result", pResult, ScriptObject::OTResult);

String sEventCaller = "OnDeliverMessage(HMAILSERVER_MESSAGE)";
ScriptServer::Instance()->FireEvent(ScriptServer::EventOnDeliverMessage, sEventCaller, pContainer);

Expand Down Expand Up @@ -110,13 +112,14 @@ namespace HM
// Send an event
if (Configuration::Instance()->GetUseScriptServer())
{
String sEventCaller;

String sRecipientCopy = sRecipient;
String sErrorMessageCopy = sErrorMessage;

String sScriptLanguage = Configuration::Instance()->GetScriptLanguage();
std::shared_ptr<ScriptObjectContainer> pContainer = std::shared_ptr<ScriptObjectContainer>(new ScriptObjectContainer);
pContainer->AddObject("HMAILSERVER_MESSAGE", pMessage, ScriptObject::OTMessage);

String sEventCaller;
String sScriptLanguage = Configuration::Instance()->GetScriptLanguage();
if (sScriptLanguage == _T("VBScript"))
{
sRecipientCopy.Replace(_T("\""), _T(""));
Expand All @@ -141,9 +144,18 @@ namespace HM

sEventCaller.Format(_T("OnDeliveryFailed(HMAILSERVER_MESSAGE, '%s', '%s')"), sRecipientCopy.c_str(), sErrorMessageCopy.c_str());
}

std::shared_ptr<ScriptObjectContainer> pContainer = std::shared_ptr<ScriptObjectContainer>(new ScriptObjectContainer);
pContainer->AddObject("HMAILSERVER_MESSAGE", pMessage, ScriptObject::OTMessage);
// else if (sScriptLanguage == _T("LuaScript"))
// {
// sRecipientCopy.Replace(_T("\""), _T(""));
// sErrorMessageCopy.Replace(_T("\""), _T(""));
//
// sErrorMessageCopy.Replace(_T("\r\n"), _T("\" + vbCRLF + \""));
//
// sErrorMessageCopy.TrimLeft();
// sErrorMessageCopy.TrimRight();
//
// sEventCaller.Format(_T("OnDeliveryFailed(HMAILSERVER_MESSAGE, \"%s\", \"%s\")"), sRecipientCopy.c_str(), sErrorMessageCopy.c_str());
// }

ScriptServer::Instance()->FireEvent(ScriptServer::EventOnDeliveryFailed, sEventCaller, pContainer);
}
Expand Down Expand Up @@ -187,6 +199,15 @@ namespace HM
else
sEventCaller.Format(_T("OnExternalAccountDownload(HMAILSERVER_FETCHACCOUNT, null, '%s')"), sRemoteUIDCopy.c_str());
}
// else if (sScriptLanguage == _T("LuaScript"))
// {
// sRemoteUIDCopy.Replace(_T("\""), _T("\"\""));
//
// if (pMessage)
// sEventCaller.Format(_T("OnExternalAccountDownload(HMAILSERVER_FETCHACCOUNT, HMAILSERVER_MESSAGE, \"%s\")"), sRemoteUIDCopy.c_str());
// else
// sEventCaller.Format(_T("OnExternalAccountDownload(HMAILSERVER_FETCHACCOUNT, Nothing, \"%s\")"), sRemoteUIDCopy.c_str());
// }

std::shared_ptr<ScriptObjectContainer> pContainer = std::shared_ptr<ScriptObjectContainer>(new ScriptObjectContainer);

Expand Down
26 changes: 25 additions & 1 deletion hmailserver/source/Server/Common/Scripting/ScriptServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ namespace HM
has_on_external_account_download_(false),
has_on_smtpdata_(false),
has_on_helo_(false),
has_on_client_logon_(false)
has_on_client_logon_(false),
has_on_recipient_unknown_(false),
has_on_too_many_invalid_comands_(false)
{

}
Expand All @@ -53,6 +55,8 @@ namespace HM
sExtension = "vbs";
else if (sScriptLanguage == _T("JScript"))
sExtension = "js";
// else if (sScriptLanguage == _T("LuaScript"))
// sExtension = "lua";
else
sExtension = "";

Expand All @@ -72,6 +76,8 @@ namespace HM
script_extension_ = "vbs";
else if (script_language_ == _T("JScript"))
script_extension_ = "js";
// else if (script_language_ == _T("LuaScript"))
// script_extension_ = "lua";
else
script_extension_ = "";

Expand Down Expand Up @@ -101,6 +107,8 @@ namespace HM
has_on_smtpdata_ = DoesFunctionExist_("OnSMTPData");
has_on_helo_ = DoesFunctionExist_("OnHELO");
has_on_client_logon_ = DoesFunctionExist_("OnClientLogon");
has_on_recipient_unknown_ = DoesFunctionExist_("OnRecipientUnknown");
has_on_too_many_invalid_comands_ = DoesFunctionExist_("OnTooManyInvalidCommands");

}
catch (...)
Expand All @@ -121,6 +129,8 @@ namespace HM
sScriptExtension = "vbs";
else if (sScriptLanguage == _T("JScript"))
sScriptExtension = "js";
// else if (sScriptLanguage == _T("LuaScript"))
// sScriptExtension = "lua";
else
sScriptExtension = "";

Expand All @@ -137,6 +147,8 @@ namespace HM
bool
ScriptServer::DoesFunctionExist_(const String &sProcedure)
{
LOG_DEBUG("DoesFunctionExist_ " + sProcedure);

// Create an instance of the script engine and execute the script.
CComObject<CScriptSiteBasic>* pBasic;
CComObject<CScriptSiteBasic>::CreateInstance(&pBasic);
Expand Down Expand Up @@ -264,6 +276,16 @@ namespace HM
return;
event_name = _T("OnHELO");
break;
case EventOnRecipientUnknown:
if (!has_on_recipient_unknown_)
return;
event_name = _T("OnRecipientUnknown");
break;
case EventOnTooManyInvalidCommands:
if (!has_on_too_many_invalid_comands_)
return;
event_name = _T("OnTooManyInvalidCommands");
break;
case EventCustom:
break;
default:
Expand All @@ -282,6 +304,8 @@ namespace HM
sScript = script_contents_ + "\r\n\r\n" + "Call " + sEventCaller + "\r\n";
else if (script_language_ == _T("JScript"))
sScript = script_contents_ + "\r\n\r\n" + sEventCaller + ";\r\n";
// else if (script_language_ == _T("LuaScript"))
// sScript = script_contents_ + "\r\n\r\n" + sEventCaller + ";\r\n";

CComObject<CScriptSiteBasic>* pBasic;
CComObject<CScriptSiteBasic>::CreateInstance(&pBasic);
Expand Down
4 changes: 4 additions & 0 deletions hmailserver/source/Server/Common/Scripting/ScriptServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace HM
EventOnSMTPData = 1012,
EventOnHELO = 1013,
EventOnClientLogon = 1014,
EventOnRecipientUnknown = 1015,
EventOnTooManyInvalidCommands = 1016
};

ScriptServer(void);
Expand Down Expand Up @@ -68,6 +70,8 @@ namespace HM
bool has_on_smtpdata_;
bool has_on_helo_;
bool has_on_client_logon_;
bool has_on_recipient_unknown_;
bool has_on_too_many_invalid_comands_;

String script_contents_;
String script_extension_;
Expand Down
2 changes: 2 additions & 0 deletions hmailserver/source/Server/Common/Scripting/ScriptSite.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class ATL_NO_VTABLE CScriptSiteImpl : public IActiveScriptSiteImpl, public IActi
USES_CONVERSION;
HR(engine_.CoCreateInstance(T2COLE(pszLanguage)));

/*
if (lstrcmp(pszLanguage, _T("JScript")) == 0)
{
// Set the JScript version to use - see https://docs.microsoft.com/en-us/scripting/winscript/reference/iactivescriptproperty-setproperty
Expand All @@ -239,6 +240,7 @@ class ATL_NO_VTABLE CScriptSiteImpl : public IActiveScriptSiteImpl, public IActi
engineVersion.llVal = SCRIPTLANGUAGEVERSION_5_8;
HR(pScriptProperty->SetProperty(SCRIPTPROP_INVOKEVERSIONING, 0, &engineVersion));
}
*/

// Attach to site
HR(engine_->SetScriptSite(static_cast<IActiveScriptSite*>(this)));
Expand Down
Loading

0 comments on commit 168994b

Please sign in to comment.