Skip to content

Commit

Permalink
https://www.hmailserver.com/forum/viewtopic.php?f=10&p=214033#p214033
Browse files Browse the repository at this point in the history
SMTP multiply max message size with 1024 issue hmailserver#267
Add email address variable to SignatureAdder.cpp pull hmailserver#265
DKIM on acccount-rule 'reply' not applied hmailserver#172 issue hmailserver#172
preserve RewriteEnvelopeFromWhenForwarding setting when forwarding from account rule
The logical flow should be to disregard "Require SMTP authentication" if "Allow deliveries from" is unselected issue hmailserver#287
  • Loading branch information
RvdHout committed Aug 16, 2019
1 parent 2f53214 commit 4ec08f8
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 67 deletions.
2 changes: 2 additions & 0 deletions hmailserver/source/Server/Common/Util/SignatureAdder.cpp
Expand Up @@ -142,9 +142,11 @@ namespace HM
{
signature_plain_text.ReplaceNoCase(_T("%User.FirstName%"), sender_account->GetPersonFirstName());
signature_plain_text.ReplaceNoCase(_T("%User.LastName%"), sender_account->GetPersonLastName());
signature_plain_text.ReplaceNoCase(_T("%User.Address%"), sender_account->GetAddress());

signature_html.ReplaceNoCase(_T("%User.FirstName%"), sender_account->GetPersonFirstName());
signature_html.ReplaceNoCase(_T("%User.LastName%"), sender_account->GetPersonLastName());
signature_html.ReplaceNoCase(_T("%User.Address%"), sender_account->GetAddress());
}

auto text_plain_body_part = message_data->GetBodyTextPlainPart();
Expand Down
98 changes: 53 additions & 45 deletions hmailserver/source/Server/SMTP/RuleApplier.cpp
Expand Up @@ -176,7 +176,7 @@ namespace HM
}
case RuleAction::Reply:
{
ApplyAction_Reply(pAction, pMsgData);
ApplyAction_Reply(pAction, account, pMsgData);
break;
}
case RuleAction::ScriptFunction:
Expand Down Expand Up @@ -248,7 +248,7 @@ namespace HM
// We need to update the SMTP envelope from address, if this
// message is forwarded by a user-level account.
std::shared_ptr<CONST Account> pAccount = CacheContainer::Instance()->GetAccount(rule_account_id_);
if (pAccount)
if (pAccount && IniFileSettings::Instance()->GetRewriteEnvelopeFromWhenForwarding())
pMsg->SetFromAddress(pAccount->GetAddress());

// Add new recipients
Expand Down Expand Up @@ -375,50 +375,58 @@ namespace HM
}

void
RuleApplier::ApplyAction_Reply(std::shared_ptr<RuleAction> pAction, std::shared_ptr<MessageData> pMsgData) const
RuleApplier::ApplyAction_Reply(std::shared_ptr<RuleAction> pAction, std::shared_ptr<const Account> account, std::shared_ptr<MessageData> pMsgData) const
{
// true = check AutoSubmitted header and do not respond if set
if (!IsGeneratedResponseAllowed(pMsgData, true))
{
ErrorManager::Instance()->ReportError(ErrorManager::Medium, 5065, "RuleApplier::ApplyAction_Reply", "Could not reply message. Maximum rule loop count reached or Auto-Submitted header.");
return;
}

String sReplyRecipientAddress = pMsgData->GetMessage()->GetFromAddress();

if (sReplyRecipientAddress.IsEmpty())
{
// We need a recipient address to be able to
// send the message..
return;
}

std::shared_ptr<Account> emptyAccount;

// Sen d a copy of this email.
std::shared_ptr<Message> pMsg = std::shared_ptr<Message>(new Message());
pMsg->SetState(Message::Delivering);

String newMessageFileName = PersistentMessage::GetFileName(pMsg);

std::shared_ptr<MessageData> pNewMsgData = std::shared_ptr<MessageData>(new MessageData());
pNewMsgData->LoadFromMessage(newMessageFileName, pMsg);
pNewMsgData->SetReturnPath("");
pNewMsgData->GenerateMessageID();
pNewMsgData->SetTo(sReplyRecipientAddress);
pNewMsgData->SetFrom(pAction->GetFromName() + " <" + pAction->GetFromAddress() + ">");
pNewMsgData->SetSubject(pAction->GetSubject());
pNewMsgData->SetBody(pAction->GetBody());
pNewMsgData->SetSentTime(Time::GetCurrentMimeDate());
pNewMsgData->SetAutoReplied();
pNewMsgData->IncreaseRuleLoopCount();
pNewMsgData->Write(newMessageFileName);


// Add recipients.
bool recipientOK = false;
RecipientParser recipientParser;
recipientParser.CreateMessageRecipientList(sReplyRecipientAddress, pMsg->GetRecipients(), recipientOK);
// true = check AutoSubmitted header and do not respond if set
if (!IsGeneratedResponseAllowed(pMsgData, true))
{
ErrorManager::Instance()->ReportError(ErrorManager::Medium, 5065, "RuleApplier::ApplyAction_Reply", "Could not reply message. Maximum rule loop count reached or Auto-Submitted header.");
return;
}

String sReplyRecipientAddress = pMsgData->GetMessage()->GetFromAddress();

if (sReplyRecipientAddress.IsEmpty())
{
// We need a recipient address to be able to
// send the message..
return;
}

std::shared_ptr<Account> emptyAccount;

// Send a copy of this email.
std::shared_ptr<Message> pMsg = std::shared_ptr<Message>(new Message());
pMsg->SetState(Message::Delivering);

String newMessageFileName = PersistentMessage::GetFileName(pMsg);

// check if this us a user-level account rule or global rule.
std::shared_ptr<CONST Account> pAccount = CacheContainer::Instance()->GetAccount(rule_account_id_);

std::shared_ptr<MessageData> pNewMsgData = std::shared_ptr<MessageData>(new MessageData());
pNewMsgData->LoadFromMessage(newMessageFileName, pMsg);
if (!pAccount)
pNewMsgData->SetReturnPath("");
pNewMsgData->GenerateMessageID();
pNewMsgData->SetTo(sReplyRecipientAddress);
pNewMsgData->SetFrom(pAction->GetFromName() + " <" + pAction->GetFromAddress() + ">");
pNewMsgData->SetSubject(pAction->GetSubject());
pNewMsgData->SetBody(pAction->GetBody());
pNewMsgData->SetSentTime(Time::GetCurrentMimeDate());
pNewMsgData->SetAutoReplied();
pNewMsgData->IncreaseRuleLoopCount();
pNewMsgData->Write(newMessageFileName);

// We need to update the SMTP envelope from address, if this
// message is replied to by a user-level account.
if (pAccount)
pMsg->SetFromAddress(pAccount->GetAddress());

// Add recipients.
bool recipientOK = false;
RecipientParser recipientParser;
recipientParser.CreateMessageRecipientList(sReplyRecipientAddress, pMsg->GetRecipients(), recipientOK);

PersistentMessage::SaveObject(pMsg);

Expand Down
2 changes: 1 addition & 1 deletion hmailserver/source/Server/SMTP/RuleApplier.h
Expand Up @@ -46,7 +46,7 @@ namespace HM
// Actions
void ApplyAction_Forward(std::shared_ptr<RuleAction> pAction, std::shared_ptr<const Account> account, std::shared_ptr<MessageData> pMsgData) const;
void ApplyAction_Copy(std::shared_ptr<Rule> rule, std::shared_ptr<const Account> account, std::shared_ptr<MessageData> pMsgData) const;
void ApplyAction_Reply(std::shared_ptr<RuleAction> pAction, std::shared_ptr<MessageData> pMsgData) const;
void ApplyAction_Reply(std::shared_ptr<RuleAction> pAction, std::shared_ptr<const Account> account, std::shared_ptr<MessageData> pMsgData) const;
void ApplyAction_ScriptFunction(std::shared_ptr<RuleAction> pAction, std::shared_ptr<const Account> account, std::shared_ptr<MessageData> pMsgData) const;
void ApplyAction_SetHeader(std::shared_ptr<RuleAction> pAction, std::shared_ptr<const Account> account, std::shared_ptr<MessageData> pMsgData) const;

Expand Down
42 changes: 21 additions & 21 deletions hmailserver/source/Server/SMTP/SMTPConnection.cpp
Expand Up @@ -659,6 +659,26 @@ namespace HM

bool localSender = GetIsLocalSender_();

int iRelayOption = 0;
if (localSender && localDelivery)
iRelayOption = SecurityRange::IPRANGE_RELAY_LOCAL_TO_LOCAL;
else if (localSender && !localDelivery)
iRelayOption = SecurityRange::IPRANGE_RELAY_LOCAL_TO_REMOTE;
else if (!localSender && localDelivery)
iRelayOption = SecurityRange::IPRANGE_RELAY_REMOTE_TO_LOCAL;
else if (!localSender && !localDelivery)
iRelayOption = SecurityRange::IPRANGE_RELAY_REMOTE_TO_REMOTE;

bool bAllowRelay = GetSecurityRange()->GetAllowOption(iRelayOption);

if (bAllowRelay == false)
{
// User is not allowed to send this email.
SendErrorResponse_(550, "Delivery is not allowed to this address.");
AWStats::LogDeliveryFailure(GetIPAddressString(), current_message_->GetFromAddress(), sRecipientAddress, 550);
return;
}

bool authenticationRequired = true;
if (localSender && localDelivery)
authenticationRequired = GetSecurityRange()->GetRequireSMTPAuthLocalToLocal();
Expand All @@ -678,26 +698,6 @@ namespace HM
return;
}

int iRelayOption = 0;
if (localSender && localDelivery)
iRelayOption = SecurityRange::IPRANGE_RELAY_LOCAL_TO_LOCAL;
else if (localSender && !localDelivery)
iRelayOption = SecurityRange::IPRANGE_RELAY_LOCAL_TO_REMOTE;
else if (!localSender && localDelivery)
iRelayOption = SecurityRange::IPRANGE_RELAY_REMOTE_TO_LOCAL;
else if (!localSender && !localDelivery)
iRelayOption = SecurityRange::IPRANGE_RELAY_REMOTE_TO_REMOTE;

bool bAllowRelay = GetSecurityRange()->GetAllowOption(iRelayOption);

if (bAllowRelay == false)
{
// User is not allowed to send this email.
SendErrorResponse_(550, "Delivery is not allowed to this address.");
AWStats::LogDeliveryFailure(GetIPAddressString(), current_message_->GetFromAddress(), sRecipientAddress, 550);
return;
}


// Pre-transmission spam protection.
if (type_ == SPPreTransmission)
Expand Down Expand Up @@ -1451,7 +1451,7 @@ namespace HM
// Append size keyword
{
String sSizeKeyword;
int iMaxSize = smtpconf_->GetMaxMessageSize() * 1000;
int iMaxSize = smtpconf_->GetMaxMessageSize() * 1024;
if (iMaxSize > 0)
sSizeKeyword.Format(_T("\r\n250-SIZE %d"), iMaxSize);
else
Expand Down

0 comments on commit 4ec08f8

Please sign in to comment.