#include "config.h"
#include <stddef.h>
#include <stdbool.h>
+#include <string.h>
#include "mutt/mutt.h"
#include "address/lib.h"
#include "envelope.h"
FREE(&(*p)->x_comment_to);
#endif
- mutt_buffer_free(&(*p)->spam);
+ mutt_buffer_dealloc(&(*p)->spam);
mutt_list_free(&(*p)->references);
mutt_list_free(&(*p)->in_reply_to);
#define MOVE_STAILQ(member) \
if (STAILQ_EMPTY(&base->member)) \
{ \
- STAILQ_SWAP(&base->member, &((*extra))->member, ListNode); \
+ STAILQ_SWAP(&base->member, &(*extra)->member, ListNode); \
}
#define MOVE_ADDRESSLIST(member) \
if (TAILQ_EMPTY(&base->member)) \
{ \
- TAILQ_SWAP(&base->member, &((*extra))->member, Address, entries); \
+ TAILQ_SWAP(&base->member, &(*extra)->member, Address, entries); \
+ }
+
+#define MOVE_BUFFER(member) \
+ if (mutt_buffer_len(&base->member) == 0) \
+ { \
+ memcpy(&base->member, &(*extra)->member, sizeof(struct Buffer)); \
+ mutt_buffer_init(&(*extra)->member); \
}
MOVE_ADDRESSLIST(return_path);
}
/* spam and user headers should never be hashed, and the new envelope may
* have better values. Use new versions regardless. */
- mutt_buffer_free(&base->spam);
+ mutt_buffer_dealloc(&base->spam);
mutt_list_free(&base->userhdrs);
- MOVE_ELEM(spam);
+ MOVE_BUFFER(spam);
MOVE_STAILQ(userhdrs);
#undef MOVE_ELEM
+#undef MOVE_STAILQ
+#undef MOVE_ADDRESSLIST
+#undef MOVE_BUFFER
mutt_env_free(extra);
}
char *followup_to; ///< List of 'followup-to' fields
char *x_comment_to; ///< List of 'X-comment-to' fields
#endif
- struct Buffer *spam; ///< Spam header
+ struct Buffer spam; ///< Spam header
struct ListHead references; ///< message references (in reverse order)
struct ListHead in_reply_to; ///< in-reply-to header content
struct ListHead userhdrs; ///< user defined headers
if (!mutt_regexlist_match(&NoSpamList, line))
{
/* if spam tag already exists, figure out how to amend it */
- if (env->spam && (*buf != '\0'))
+ if ((mutt_buffer_len(&env->spam) != 0) && (*buf != '\0'))
{
/* If C_SpamSeparator defined, append with separator */
if (C_SpamSeparator)
{
- mutt_buffer_addstr(env->spam, C_SpamSeparator);
- mutt_buffer_addstr(env->spam, buf);
+ mutt_buffer_addstr(&env->spam, C_SpamSeparator);
+ mutt_buffer_addstr(&env->spam, buf);
}
else /* overwrite */
{
- mutt_buffer_reset(env->spam);
- mutt_buffer_addstr(env->spam, buf);
+ mutt_buffer_reset(&env->spam);
+ mutt_buffer_addstr(&env->spam, buf);
}
}
/* spam tag is new, and match expr is non-empty; copy */
- else if (!env->spam && (*buf != '\0'))
+ else if ((mutt_buffer_len(&env->spam) == 0) && (*buf != '\0'))
{
- env->spam = mutt_buffer_from(buf);
+ mutt_buffer_addstr(&env->spam, buf);
}
/* match expr is empty; plug in null string if no existing tag */
- else if (!env->spam)
+ else if (mutt_buffer_len(&env->spam) == 0)
{
- env->spam = mutt_buffer_from("");
+ mutt_buffer_addstr(&env->spam, "");
}
- if (env->spam && env->spam->data)
- mutt_debug(LL_DEBUG5, "spam = %s\n", env->spam->data);
+ if (mutt_buffer_len(&env->spam) != 0)
+ mutt_debug(LL_DEBUG5, "spam = %s\n", env->spam.data);
}
}
* @param[out] off Offset into the blob
* @param[in] convert If true, the strings will be converted from utf-8
*/
-void serial_restore_buffer(struct Buffer **b, const unsigned char *d, int *off, bool convert)
+void serial_restore_buffer(struct Buffer *b, const unsigned char *d, int *off, bool convert)
{
unsigned int used;
unsigned int offset;
return;
}
- *b = mutt_mem_malloc(sizeof(struct Buffer));
-
- serial_restore_char(&(*b)->data, d, off, convert);
+ serial_restore_char(&b->data, d, off, convert);
serial_restore_int(&offset, d, off);
- (*b)->dptr = (*b)->data + offset;
+ b->dptr = b->data + offset;
serial_restore_int(&used, d, off);
- (*b)->dsize = used;
+ b->dsize = used;
}
/**
d = serial_dump_char(env->x_label, d, off, convert);
d = serial_dump_char(env->organization, d, off, convert);
- d = serial_dump_buffer(env->spam, d, off, convert);
+ d = serial_dump_buffer(&env->spam, d, off, convert);
d = serial_dump_stailq(&env->references, d, off, false);
d = serial_dump_stailq(&env->in_reply_to, d, off, false);
void serial_restore_address(struct Address **a, const unsigned char *d, int *off, bool convert);
void serial_restore_body(struct Body *c, const unsigned char *d, int *off, bool convert);
-void serial_restore_buffer(struct Buffer **b, const unsigned char *d, int *off, bool convert);
+void serial_restore_buffer(struct Buffer *b, const unsigned char *d, int *off, bool convert);
void serial_restore_char(char **c, const unsigned char *d, int *off, bool convert);
void serial_restore_envelope(struct Envelope *e, const unsigned char *d, int *off, bool convert);
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off);
case 'H':
/* (Hormel) spam score */
if (optional)
- optional = e->env->spam;
+ optional = mutt_buffer_len(&e->env->spam) != 0;
- if (e->env->spam)
- mutt_format_s(buf, buflen, prec, NONULL(e->env->spam->data));
- else
- mutt_format_s(buf, buflen, prec, "");
+ mutt_format_s(buf, buflen, prec, mutt_b2s(&e->env->spam));
break;
case 'i':
case 'y':
if (optional)
- optional = e->env->x_label;
+ optional = (e->env->x_label != NULL);
colorlen = add_index_color(buf, buflen, flags, MT_COLOR_INDEX_LABEL);
mutt_format_s(buf + colorlen, buflen - colorlen, prec, NONULL(e->env->x_label));
case MUTT_PAT_HORMEL:
if (!e->env)
return 0;
- return pat->pat_not ^ (e->env->spam && e->env->spam->data &&
- patmatch(pat, e->env->spam->data));
+ return pat->pat_not ^ (e->env->spam.data && patmatch(pat, e->env->spam.data));
case MUTT_PAT_DUPLICATED:
return pat->pat_not ^ (e->thread && e->thread->duplicate_thread);
case MUTT_PAT_MIMEATTACH:
/* Firstly, require spam attributes for both msgs */
/* to compare. Determine which msgs have one. */
- ahas = (*ppa)->env && (*ppa)->env->spam;
- bhas = (*ppb)->env && (*ppb)->env->spam;
+ ahas = (*ppa)->env && mutt_buffer_len(&(*ppa)->env->spam) != 0;
+ bhas = (*ppb)->env && mutt_buffer_len(&(*ppb)->env->spam) != 0;
/* If one msg has spam attr but other does not, sort the one with first. */
if (ahas && !bhas)
/* preliminary numeric examination */
difference =
- (strtod((*ppa)->env->spam->data, &aptr) - strtod((*ppb)->env->spam->data, &bptr));
+ (strtod((*ppa)->env->spam.data, &aptr) - strtod((*ppb)->env->spam.data, &bptr));
/* map double into comparison (-1, 0, or 1) */
result = ((difference < 0.0) ? -1 : (difference > 0.0) ? 1 : 0);
/* If either aptr or bptr is equal to data, there is no numeric */
/* value for that spam attribute. In this case, compare lexically. */
- if ((aptr == (*ppa)->env->spam->data) || (bptr == (*ppb)->env->spam->data))
+ if ((aptr == (*ppa)->env->spam.data) || (bptr == (*ppb)->env->spam.data))
return SORT_CODE(strcmp(aptr, bptr));
/* Otherwise, we have numeric value for both attrs. If these values */
test/buffer/mutt_buffer_concat_path.o \
test/buffer/mutt_buffer_fix_dptr.o \
test/buffer/mutt_buffer_free.o \
- test/buffer/mutt_buffer_from.o \
test/buffer/mutt_buffer_init.o \
test/buffer/mutt_buffer_is_empty.o \
test/buffer/mutt_buffer_len.o \
+++ /dev/null
-/**
- * @file
- * Test code for mutt_buffer_from()
- *
- * @authors
- * Copyright (C) 2019 Richard Russon <rich@flatcap.org>
- *
- * @copyright
- * This program is free software: you can redistribute it and/or modify it under
- * the terms of the GNU General Public License as published by the Free Software
- * Foundation, either version 2 of the License, or (at your option) any later
- * version.
- *
- * 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 General Public License for more
- * details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#define TEST_NO_MAIN
-#include "acutest.h"
-#include "config.h"
-#include "mutt/mutt.h"
-
-void test_mutt_buffer_from(void)
-{
- // struct Buffer *mutt_buffer_from(const char *seed);
-
- {
- TEST_CHECK(!mutt_buffer_from(NULL));
- }
-
- {
- struct Buffer *buf = NULL;
- const char *str = "";
-
- TEST_CHECK((buf = mutt_buffer_from(str)) != NULL);
- TEST_CHECK(buf->data == NULL);
- TEST_CHECK(buf->dptr == NULL);
- TEST_CHECK(buf->dsize == 0);
-
- mutt_buffer_free(&buf);
- }
-
- {
- struct Buffer *buf = NULL;
- const char *str = "test";
-
- TEST_CHECK((buf = mutt_buffer_from(str)) != NULL);
- TEST_CHECK(buf->data != NULL);
- TEST_CHECK(buf->dptr != NULL);
- TEST_CHECK(buf->dsize != 0);
-
- mutt_buffer_free(&buf);
- }
-}
NEOMUTT_TEST_ITEM(test_mutt_buffer_concat_path) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_fix_dptr) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_free) \
- NEOMUTT_TEST_ITEM(test_mutt_buffer_from) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_init) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_is_empty) \
NEOMUTT_TEST_ITEM(test_mutt_buffer_len) \