commit ef736fd: [Minor] Slightly refactor the code
Vsevolod Stakhov
vsevolod at highsecure.ru
Sun Oct 10 11:35:04 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-10-10 12:31:08 +0100
URL: https://github.com/rspamd/rspamd/commit/ef736fdb0326145665c7a844bd683d7e7176efc1 (HEAD -> master)
[Minor] Slightly refactor the code
---
src/libmime/received.cxx | 59 +++++++++---------------------------------------
src/libmime/received.hxx | 45 ++++++++++++++++++++++++++++++++++--
2 files changed, 54 insertions(+), 50 deletions(-)
diff --git a/src/libmime/received.cxx b/src/libmime/received.cxx
index 6d3e7b796..c06331de4 100644
--- a/src/libmime/received.cxx
+++ b/src/libmime/received.cxx
@@ -258,12 +258,15 @@ received_spill(const std::string_view &in,
const auto *p = in.data();
const auto *end = p + in.size();
- /* Skip spaces */
- while (p < end && g_ascii_isspace (*p)) {
- p++;
- }
+ auto skip_spaces = [&p, end]() {
+ while (p < end && g_ascii_isspace (*p)) {
+ p++;
+ }
+ };
+
+ skip_spaces();
- /* And SMTP comments */
+ /* Skip SMTP comments */
if (*p == '(') {
auto obraces = 0, ebraces = 0;
@@ -279,9 +282,7 @@ received_spill(const std::string_view &in,
if (obraces == ebraces) {
/* Skip spaces after */
- while (p < end && g_ascii_isspace (*p)) {
- p++;
- }
+ skip_spaces();
break;
}
}
@@ -290,7 +291,7 @@ received_spill(const std::string_view &in,
auto len = end - p;
if (len == 0) {
- return {};
+ return parts;
}
auto maybe_process_part = [&](received_part_type what) -> bool {
@@ -824,45 +825,7 @@ received_export_to_lua(received_header_chain *chain, lua_State *L) -> bool
}
lua_setfield(L, -2, "real_ip");
- const auto *proto = "unknown";
-
- switch (received_type_apply_maks(rh.flags)) {
- case received_flags::SMTP:
- proto = "smtp";
- break;
- case received_flags::ESMTP:
- proto = "esmtp";
- break;
- case received_flags::ESMTPS:
- proto = "esmtps";
- break;
- case received_flags::ESMTPA:
- proto = "esmtpa";
- break;
- case received_flags::ESMTPSA:
- proto = "esmtpsa";
- break;
- case received_flags::LMTP:
- proto = "lmtp";
- break;
- case received_flags::IMAP:
- proto = "imap";
- break;
- case received_flags::HTTP:
- proto = "http";
- break;
- case received_flags::LOCAL:
- proto = "local";
- break;
- case received_flags::MAPI:
- proto = "mapi";
- break;
- default:
- proto = "unknown";
- break;
- }
-
- lua_pushstring(L, proto);
+ lua_pushstring(L, received_protocol_to_string(rh.flags));
lua_setfield(L, -2, "proto");
lua_pushinteger(L, rh.timestamp);
diff --git a/src/libmime/received.hxx b/src/libmime/received.hxx
index e4d8d8713..2edf628cc 100644
--- a/src/libmime/received.hxx
+++ b/src/libmime/received.hxx
@@ -84,7 +84,7 @@ constexpr bool operator !(received_flags fl)
return fl == received_flags::DEFAULT;
}
-constexpr received_flags received_type_apply_maks(received_flags fl) {
+constexpr received_flags received_type_apply_protocols_mask(received_flags fl) {
return fl & (received_flags::SMTP|
received_flags::ESMTP|
received_flags::ESMTPA|
@@ -97,6 +97,47 @@ constexpr received_flags received_type_apply_maks(received_flags fl) {
received_flags::LMTP);
}
+constexpr const char *received_protocol_to_string(received_flags fl) {
+ const auto *proto = "unknown";
+
+ switch (received_type_apply_protocols_mask(fl)) {
+ case received_flags::SMTP:
+ proto = "smtp";
+ break;
+ case received_flags::ESMTP:
+ proto = "esmtp";
+ break;
+ case received_flags::ESMTPS:
+ proto = "esmtps";
+ break;
+ case received_flags::ESMTPA:
+ proto = "esmtpa";
+ break;
+ case received_flags::ESMTPSA:
+ proto = "esmtpsa";
+ break;
+ case received_flags::LMTP:
+ proto = "lmtp";
+ break;
+ case received_flags::IMAP:
+ proto = "imap";
+ break;
+ case received_flags::HTTP:
+ proto = "http";
+ break;
+ case received_flags::LOCAL:
+ proto = "local";
+ break;
+ case received_flags::MAPI:
+ proto = "mapi";
+ break;
+ default:
+ break;
+ }
+
+ return proto;
+}
+
struct received_header {
mime_string from_hostname;
mime_string real_hostname;
@@ -251,6 +292,6 @@ private:
std::vector<received_header> headers;
};
-}
+} // namespace rspamd::mime
#endif //RSPAMD_RECEIVED_HXX
More information about the Commits
mailing list