Skip to content

Commit

Permalink
email_lib: delete unused MAIL::emit, MIME::emit
Browse files Browse the repository at this point in the history
  • Loading branch information
fcneuf committed Aug 30, 2024
1 parent 969a566 commit 93abaf9
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 177 deletions.
1 change: 0 additions & 1 deletion include/gromox/mail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion include/gromox/mime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 0 additions & 8 deletions lib/email/mail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,6 @@ bool MAIL::serialize(STREAM *pstream) const
return static_cast<const MIME *>(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<const MIME *>(nd->pdata)->emit(xw, fd);
}

errno_t MAIL::to_fd(int fd) const
{
STREAM st;
Expand Down
167 changes: 0 additions & 167 deletions lib/email/mime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<size_t>(wrlen) != pmime->head_length + 2)
return false;
} else {
auto wrlen = write(fd, pmime->head_begin, pmime->head_length);
if (wrlen < 0 || static_cast<size_t>(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<size_t>(wrlen) != k.size())
return false;
wrlen = write(fd, ": ", 2);
if (wrlen < 0 || static_cast<size_t>(wrlen) != 2)
return false;
wrlen = write(fd, v.c_str(), v.size());
if (wrlen < 0 || static_cast<size_t>(wrlen) != v.size())
return false;
wrlen = write(fd, "\r\n", 2);
if (wrlen < 0 || static_cast<size_t>(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<size_t>(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<size_t>(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<MAIL *>(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<size_t>(wrlen) != len)
return false;
if (!static_cast<const MIME *>(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<size_t>(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<size_t>(wrlen) != len)
return false;
return true;
}

/*
* calculate MIME length in bytes (no trailing \0 included)
* @param
Expand Down

0 comments on commit 93abaf9

Please sign in to comment.