Skip to content

Commit

Permalink
email_lib: switch cu_send_mail to use MAIL::to_str
Browse files Browse the repository at this point in the history
Perform an indirect write, which will help us getting rid of
MIME::emit.
  • Loading branch information
fcneuf committed Aug 30, 2024
1 parent 8358916 commit 969a566
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions lib/email/send.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,9 @@ ec_error_t cu_send_mail(MAIL &mail, const char *smtp_url, const char *sender,
for (const auto &r : rcpt_list)
vrcpt_list.appendMailbox(vmime::make_shared<vmime::mailbox>(r));
std::string content;
auto xwrite = +[](void *fd, const void *buf, size_t z) -> ssize_t {
try {
static_cast<std::string *>(fd)->append(static_cast<const char *>(buf), z);
} catch (const std::bad_alloc &) {
errno = ENOMEM;
return -1;
}
return z;
};
if (!mail.emit(xwrite, &content)) {
mlog(LV_ERR, "cu_send_mail: mail.serialize failed");
auto err = mail.to_str(content);
if (err != 0) {
mlog(LV_ERR, "cu_send_mail: mail.serialize failed: %s", strerror(errno));
return MAPI_W_NO_SERVICE;
}
vmime::utility::inputStreamStringAdapter ct_adap(content); /* copies */
Expand Down

0 comments on commit 969a566

Please sign in to comment.