From 93abaf90ea5f5ccd0150034fe560b930e86618b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Ch=C3=A2teauneuf?= Date: Fri, 30 Aug 2024 11:15:19 +0200 Subject: [PATCH] email_lib: delete unused MAIL::emit, MIME::emit --- include/gromox/mail.hpp | 1 - include/gromox/mime.hpp | 1 - lib/email/mail.cpp | 8 -- lib/email/mime.cpp | 167 ---------------------------------------- 4 files changed, 177 deletions(-) diff --git a/include/gromox/mail.hpp b/include/gromox/mail.hpp index ecde205dc..ba7d40ff0 100644 --- a/include/gromox/mail.hpp +++ b/include/gromox/mail.hpp @@ -21,7 +21,6 @@ struct GX_EXPORT MAIL { void clear(); bool load_from_str_move(char *in_buff, size_t length); bool serialize(STREAM *) const; - bool emit(MIME::write_func, void *) const; gromox::errno_t to_fd(int) const; gromox::errno_t to_str(std::string &) const; ssize_t get_length() const; diff --git a/include/gromox/mime.hpp b/include/gromox/mime.hpp index 64fb4fb42..b49db7224 100644 --- a/include/gromox/mime.hpp +++ b/include/gromox/mime.hpp @@ -44,7 +44,6 @@ struct GX_EXPORT MIME { int make_mimes_digest(const char *, size_t *, Json::Value &) const; int make_structure_digest(const char *, size_t *, Json::Value &) const; bool serialize(STREAM *) const; - bool emit(write_func, void *) const; ssize_t get_length() const; bool get_filename(char *file_name, size_t) const; MIME *get_child(); diff --git a/lib/email/mail.cpp b/lib/email/mail.cpp index 35e1afd66..6ee962487 100644 --- a/lib/email/mail.cpp +++ b/lib/email/mail.cpp @@ -212,14 +212,6 @@ bool MAIL::serialize(STREAM *pstream) const return static_cast(pnode->pdata)->serialize(pstream); } -bool MAIL::emit(MIME::write_func xw, void *fd) const -{ - auto nd = tree.get_root(); - if (nd == nullptr) - return false; - return static_cast(nd->pdata)->emit(xw, fd); -} - errno_t MAIL::to_fd(int fd) const { STREAM st; diff --git a/lib/email/mime.cpp b/lib/email/mime.cpp index 376e3c13e..aed09cb06 100644 --- a/lib/email/mime.cpp +++ b/lib/email/mime.cpp @@ -1084,173 +1084,6 @@ bool MIME::read_content(char *out_buff, size_t *plength) const try return false; } -bool MIME::emit(write_func write, void *fd) const -{ - auto pmime = this; - BOOL has_submime; - size_t len, tmp_len; - char tmp_buff[MIME_FIELD_LEN + MIME_NAME_LEN + 4]; - - if (pmime->mime_type == mime_type::none) { -#ifdef _DEBUG_UMTA - mlog(LV_DEBUG, "mime: mime content type is not set"); -#endif - return false; - } - if (!pmime->head_touched) { - /* the original buffer contains \r\n */ - if (pmime->head_begin + pmime->head_length - + 2 == pmime->content_begin) { - auto wrlen = write(fd, pmime->head_begin, pmime->head_length + 2); - if (wrlen < 0 || static_cast(wrlen) != pmime->head_length + 2) - return false; - } else { - auto wrlen = write(fd, pmime->head_begin, pmime->head_length); - if (wrlen < 0 || static_cast(wrlen) != pmime->head_length) - return false; - if (write(fd, "\r\n", 2) != 2) - return false; - } - } else { - for (const auto &[k, v] : f_other_fields) { - /* xxxxx: yyyyy */ - auto wrlen = write(fd, k.c_str(), k.size()); - if (wrlen < 0 || static_cast(wrlen) != k.size()) - return false; - wrlen = write(fd, ": ", 2); - if (wrlen < 0 || static_cast(wrlen) != 2) - return false; - wrlen = write(fd, v.c_str(), v.size()); - if (wrlen < 0 || static_cast(wrlen) != v.size()) - return false; - wrlen = write(fd, "\r\n", 2); - if (wrlen < 0 || static_cast(wrlen) != 2) - return false; - } - - /* Content-Type: xxxxx */ - memcpy(tmp_buff, "Content-Type: ", 14); - len = 14; - auto val_len = strlen(pmime->content_type); - memcpy(tmp_buff + len, pmime->content_type, val_len); - len += val_len; - /* Content-Type: xxxxx;\r\n\tyyyyy=zzzzz */ - for (const auto &[k, v] : f_type_params) { - /* content-type: xxxxx"; \r\n\t"yyyyy */ - if (len > MIME_FIELD_LEN + MIME_NAME_LEN - k.size()) - return false; - memcpy(tmp_buff + len, ";\r\n\t", 4); - len += 4; - memcpy(&tmp_buff[len], k.c_str(), k.size()); - len += k.size(); - if (len > MIME_FIELD_LEN + MIME_NAME_LEN + 3 - v.size()) - return false; - /* content_type: xxxxx; \r\n\tyyyyy=zzz */ - if (v.empty()) - continue; - memcpy(tmp_buff + len, "=", 1); - len += 1; - memcpy(&tmp_buff[len], v.c_str(), v.size()); - len += v.size(); - } - if (len > MIME_FIELD_LEN + MIME_NAME_LEN) - return false; - /* \r\n for separate head and content */ - memcpy(tmp_buff + len, "\r\n\r\n", 4); - len += 4; - auto wrlen = write(fd, tmp_buff, len); - if (wrlen < 0 || static_cast(wrlen) != len) - return false; - } - if (pmime->mime_type == mime_type::single) { - if (NULL != pmime->content_begin) { - auto wrlen = write(fd, pmime->content_begin, pmime->content_length); - if (wrlen < 0 || static_cast(wrlen) != pmime->content_length) - return false; - } else { - /* if there's nothing, just append an empty line */ - if (write(fd, "\r\n", 2) != 2) - return false; - } - return true; - } else if (pmime->mime_type == mime_type::single_obj) { - if (pmime->content_begin != nullptr) { - if (!reinterpret_cast(pmime->content_begin)->emit(write, fd)) - return false; - } else { - /* if there's nothing, just append an empty line */ - if (write(fd, "\r\n", 2) != 2) - return false; - } - return true; - } - if (NULL == pmime->first_boundary) { - if (write(fd, "This is a multi-part message " - "in MIME format.\r\n\r\n", 48) != 48) - return false; - } else if (write(fd, pmime->content_begin, pmime->first_boundary - pmime->content_begin) != - pmime->first_boundary - pmime->content_begin) { - return false; - } - auto pnode = pmime->stree.get_child(); - has_submime = FALSE; - while (NULL != pnode) { - has_submime = TRUE; - memcpy(tmp_buff, "--", 2); - len = 2; - memcpy(tmp_buff + len, pmime->boundary_string, - pmime->boundary_len); - len += pmime->boundary_len; - memcpy(tmp_buff + len, "\r\n", 2); - len += 2; - auto wrlen = write(fd, tmp_buff, len); - if (wrlen < 0 || static_cast(wrlen) != len) - return false; - if (!static_cast(pnode->pdata)->emit(write, fd)) - return false; - pnode = pnode->get_sibling(); - } - if (!has_submime) { - memcpy(tmp_buff, "--", 2); - len = 2; - memcpy(tmp_buff + len, pmime->boundary_string, - pmime->boundary_len); - len += pmime->boundary_len; - memcpy(tmp_buff + len, "\r\n\r\n", 4); - len += 4; - auto wrlen = write(fd, tmp_buff, len); - if (wrlen < 0 || static_cast(wrlen) != len) - return false; - } - memcpy(tmp_buff, "--", 2); - len = 2; - memcpy(tmp_buff + len, pmime->boundary_string, pmime->boundary_len); - len += pmime->boundary_len; - memcpy(tmp_buff + len, "--", 2); - len += 2; - if (NULL == pmime->last_boundary) { - memcpy(tmp_buff + len, "\r\n", 2); - len += 2; - } else { - tmp_len = pmime->content_length - - (pmime->last_boundary - pmime->content_begin); - if (tmp_len > 0 && tmp_len < sizeof(tmp_buff) - len) { - memcpy(tmp_buff + len, pmime->last_boundary, tmp_len); - len += tmp_len; - } else if (0 == tmp_len) { - memcpy(tmp_buff + len, "\r\n", 2); - len += 2; - } else { - mlog(LV_ERR, "E-1640"); - return false; - } - } - auto wrlen = write(fd, tmp_buff, len); - if (wrlen < 0 || static_cast(wrlen) != len) - return false; - return true; -} - /* * calculate MIME length in bytes (no trailing \0 included) * @param