Source
static char *smtp_prepare_payload(zbx_vector_ptr_t *from_mails, zbx_vector_ptr_t *to_mails, const char *inreplyto,
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/* number of characters per line when wrapping Base64 data in Email */
/* number of characters per "encoded-word" in RFC-2047 message header */
/* multiple 'encoded-word's should be separated by <CR><LF><SPACE> */
/* separator for multipart mixed messages */
/******************************************************************************
* *
* Purpose: Encode a string into a base64 string as required by rfc2047. *
* Used for encoding e-mail headers. *
* *
* Parameters: src - [IN] a null-terminated UTF-8 string to encode *
* p_base64 - [OUT] a pointer to the encoded string *
* *
* Comments: Based on the patch submitted by *
* Jairo Eduardo Lopez Fuentes Nacarino *
* *
******************************************************************************/
static void str_base64_encode_rfc2047(const char *src, char **p_base64)
{
const char *p0; /* pointer in src to start encoding from */
const char *p1; /* pointer in src: 1st byte of UTF-8 character */
size_t c_len; /* length of UTF-8 character sequence */
size_t p_base64_alloc; /* allocated memory size for subject */
size_t p_base64_offset = 0; /* offset for writing into subject */
assert(src);
assert(NULL == *p_base64); /* do not accept already allocated memory */
p_base64_alloc = ZBX_EMAIL_B64_MAXWORD_RFC2047 + sizeof(ZBX_EMAIL_ENCODED_WORD_SEPARATOR);
*p_base64 = (char *)zbx_malloc(NULL, p_base64_alloc);
**p_base64 = '\0';