NeoMutt  2025-12-11-694-ga89709
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
serialize.h File Reference

Email-object serialiser. More...

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>
+ Include dependency graph for serialize.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

unsigned char * serial_dump_address (const struct AddressList *al, unsigned char *d, int *off, bool convert)
 Pack an Address into a binary blob.
 
unsigned char * serial_dump_body (const struct Body *b, unsigned char *d, int *off, bool convert)
 Pack an Body into a binary blob.
 
unsigned char * serial_dump_tags (const struct TagList *tl, unsigned char *d, int *off)
 Pack a TagList into a binary blob.
 
unsigned char * serial_dump_buffer (const struct Buffer *buf, unsigned char *d, int *off, bool convert)
 Pack a Buffer into a binary blob.
 
unsigned char * serial_dump_char (const char *c, unsigned char *d, int *off, bool convert)
 Pack a variable-length string into a binary blob.
 
unsigned char * serial_dump_char_size (const char *c, ssize_t size, unsigned char *d, int *off, bool convert)
 Pack a fixed-length string into a binary blob.
 
unsigned char * serial_dump_envelope (const struct Envelope *env, unsigned char *d, int *off, bool convert)
 Pack an Envelope into a binary blob.
 
unsigned char * serial_dump_int (const unsigned int i, unsigned char *d, int *off)
 Pack an integer into a binary blob.
 
unsigned char * serial_dump_uint32_t (const uint32_t s, unsigned char *d, int *off)
 Pack a uint32_t into a binary blob.
 
unsigned char * serial_dump_uint64_t (const uint64_t s, unsigned char *d, int *off)
 Pack a uint64_t into a binary blob.
 
unsigned char * serial_dump_parameter (const struct ParameterList *pl, unsigned char *d, int *off, bool convert)
 Pack a Parameter into a binary blob.
 
unsigned char * serial_dump_stailq (const struct ListHead *l, unsigned char *d, int *off, bool convert)
 Pack a STAILQ into a binary blob.
 
void serial_restore_address (struct AddressList *al, const unsigned char *d, int *off, bool convert)
 Unpack an Address from a binary blob.
 
void serial_restore_body (struct Body *b, const unsigned char *d, int *off, bool convert)
 Unpack a Body from a binary blob.
 
void serial_restore_tags (struct TagList *tl, const unsigned char *d, int *off)
 Unpack a TagList from a binary blob.
 
void serial_restore_buffer (struct Buffer *buf, const unsigned char *d, int *off, bool convert)
 Unpack a Buffer from a binary blob.
 
void serial_restore_char (char **c, const unsigned char *d, int *off, bool convert)
 Unpack a variable-length string from a binary blob.
 
void serial_restore_envelope (struct Envelope *env, const unsigned char *d, int *off, bool convert)
 Unpack an Envelope from a binary blob.
 
void serial_restore_int (unsigned int *i, const unsigned char *d, int *off)
 Unpack an integer from a binary blob.
 
void serial_restore_uint32_t (uint32_t *s, const unsigned char *d, int *off)
 Unpack an uint32_t from a binary blob.
 
void serial_restore_uint64_t (uint64_t *s, const unsigned char *d, int *off)
 Unpack an uint64_t from a binary blob.
 
void serial_restore_parameter (struct ParameterList *pl, const unsigned char *d, int *off, bool convert)
 Unpack a Parameter from a binary blob.
 
void serial_restore_stailq (struct ListHead *l, const unsigned char *d, int *off, bool convert)
 Unpack a STAILQ from a binary blob.
 
void lazy_realloc (void *ptr, size_t size)
 Reallocate some memory.
 

Detailed Description

Email-object serialiser.

Authors
  • Richard Russon
  • Pietro Cerutti

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/.

Definition in file serialize.h.

Function Documentation

◆ serial_dump_address()

unsigned char * serial_dump_address ( const struct AddressList * al,
unsigned char * d,
int * off,
bool convert )

Pack an Address into a binary blob.

Parameters
[in]alAddressList to pack
[in]dBinary blob to add to
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted to utf-8
Return values
ptrEnd of the newly packed binary

Definition at line 245 of file serialize.c.

247{
248 unsigned int counter = 0;
249 unsigned int start_off = *off;
250
251 d = serial_dump_int(0xdeadbeef, d, off);
252
253 struct Address *a = NULL;
254 TAILQ_FOREACH(a, al, entries)
255 {
256 d = serial_dump_buffer(a->personal, d, off, convert);
257 d = serial_dump_buffer(a->mailbox, d, off, convert);
258 d = serial_dump_int(a->group, d, off);
259 counter++;
260 }
261
262 memcpy(d + start_off, &counter, sizeof(int));
263
264 return d;
265}
#define TAILQ_FOREACH(var, head, field)
Definition queue.h:782
unsigned char * serial_dump_int(const unsigned int i, unsigned char *d, int *off)
Pack an integer into a binary blob.
Definition serialize.c:73
unsigned char * serial_dump_buffer(const struct Buffer *buf, unsigned char *d, int *off, bool convert)
Pack a Buffer into a binary blob.
Definition serialize.c:371
An email address.
Definition address.h:35
struct Buffer * personal
Real name of address.
Definition address.h:36
bool group
Group mailbox?
Definition address.h:38
struct Buffer * mailbox
Mailbox and host address.
Definition address.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_body()

unsigned char * serial_dump_body ( const struct Body * b,
unsigned char * d,
int * off,
bool convert )

Pack an Body into a binary blob.

Parameters
[in]bBody to pack
[in]dBinary blob to add to
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted to utf-8
Return values
ptrEnd of the newly packed binary

Definition at line 534 of file serialize.c.

535{
536 uint32_t packed = body_pack_flags(b);
537 d = serial_dump_uint32_t(packed, d, off);
538
539 uint64_t big = b->offset;
540 d = serial_dump_uint64_t(big, d, off);
541
542 big = b->length;
543 d = serial_dump_uint64_t(big, d, off);
544
545 d = serial_dump_char(b->xtype, d, off, false);
546 d = serial_dump_char(b->subtype, d, off, false);
547
548 d = serial_dump_parameter(&b->parameter, d, off, convert);
549
550 d = serial_dump_char(b->description, d, off, convert);
551 d = serial_dump_char(b->content_id, d, off, convert);
552 d = serial_dump_char(b->form_name, d, off, convert);
553 d = serial_dump_char(b->filename, d, off, convert);
554 d = serial_dump_char(b->d_filename, d, off, convert);
555
556 return d;
557}
unsigned char * serial_dump_uint64_t(const uint64_t s, unsigned char *d, int *off)
Pack a uint64_t into a binary blob.
Definition serialize.c:105
static uint32_t body_pack_flags(const struct Body *b)
Pack the Body flags into a uint32_t.
Definition serialize.c:474
unsigned char * serial_dump_parameter(const struct ParameterList *pl, unsigned char *d, int *off, bool convert)
Pack a Parameter into a binary blob.
Definition serialize.c:418
unsigned char * serial_dump_uint32_t(const uint32_t s, unsigned char *d, int *off)
Pack a uint32_t into a binary blob.
Definition serialize.c:89
unsigned char * serial_dump_char(const char *c, unsigned char *d, int *off, bool convert)
Pack a variable-length string into a binary blob.
Definition serialize.c:196
char * content_id
Content-Id (RFC2392)
Definition body.h:58
char * d_filename
filename to be used for the content-disposition header If NULL, filename is used instead.
Definition body.h:56
LOFF_T offset
offset where the actual data begins
Definition body.h:52
char * xtype
content-type if x-unknown
Definition body.h:62
LOFF_T length
length (in bytes) of attachment
Definition body.h:53
struct ParameterList parameter
Parameters of the content-type.
Definition body.h:63
char * description
content-description
Definition body.h:55
char * subtype
content-type subtype
Definition body.h:61
char * form_name
Content-Disposition form-data name param.
Definition body.h:60
char * filename
When sending a message, this is the file to which this structure refers.
Definition body.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_tags()

unsigned char * serial_dump_tags ( const struct TagList * tl,
unsigned char * d,
int * off )

Pack a TagList into a binary blob.

Parameters
[in]tlTagList to pack
[in]dBinary blob to add to
[in,out]offOffset into the blob
Return values
ptrEnd of the newly packed binary

Definition at line 703 of file serialize.c.

704{
705 unsigned int counter = 0;
706 unsigned int start_off = *off;
707
708 d = serial_dump_int(0xdeadbeef, d, off);
709
710 struct Tag *tag = NULL;
711 STAILQ_FOREACH(tag, tl, entries)
712 {
713 d = serial_dump_char(tag->name, d, off, false);
714 counter++;
715 }
716
717 memcpy(d + start_off, &counter, sizeof(int));
718
719 return d;
720}
#define STAILQ_FOREACH(var, head, field)
Definition queue.h:390
LinkedList Tag Element.
Definition tags.h:41
char * name
Tag name.
Definition tags.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_buffer()

unsigned char * serial_dump_buffer ( const struct Buffer * buf,
unsigned char * d,
int * off,
bool convert )

Pack a Buffer into a binary blob.

Parameters
[in]bufBuffer to pack
[in]dBinary blob to add to
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted to utf-8
Return values
ptrEnd of the newly packed binary

Definition at line 371 of file serialize.c.

373{
374 if (buf_is_empty(buf))
375 {
376 d = serial_dump_int(0, d, off);
377 return d;
378 }
379
380 d = serial_dump_int(1, d, off);
381
382 d = serial_dump_char(buf->data, d, off, convert);
383
384 return d;
385}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition buffer.c:291
char * data
Pointer to data.
Definition buffer.h:37
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_char()

unsigned char * serial_dump_char ( const char * c,
unsigned char * d,
int * off,
bool convert )

Pack a variable-length string into a binary blob.

Parameters
[in]cString to pack
[in]dBinary blob to add to
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted to utf-8
Return values
ptrEnd of the newly packed binary

Definition at line 196 of file serialize.c.

197{
198 return serial_dump_char_size(c, mutt_str_len(c) + 1, d, off, convert);
199}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:503
unsigned char * serial_dump_char_size(const char *c, ssize_t size, unsigned char *d, int *off, bool convert)
Pack a fixed-length string into a binary blob.
Definition serialize.c:159
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_char_size()

unsigned char * serial_dump_char_size ( const char * c,
ssize_t size,
unsigned char * d,
int * off,
bool convert )

Pack a fixed-length string into a binary blob.

Parameters
[in]cString to pack
[in]dBinary blob to add to
[in]sizeSize of the string
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted to utf-8
Return values
ptrEnd of the newly packed binary

Definition at line 159 of file serialize.c.

161{
162 char *p = NULL;
163
164 if (!c || (*c == '\0') || (size == 0))
165 {
166 return serial_dump_int(0, d, off);
167 }
168
169 if (convert && !mutt_str_is_ascii(c, size))
170 {
171 p = mutt_strn_dup(c, size);
172 if (mutt_ch_convert_string(&p, cc_charset(), "utf-8", MUTT_ICONV_NO_FLAGS) == 0)
173 {
174 size = mutt_str_len(p) + 1;
175 }
176 }
177
178 d = serial_dump_int(size, d, off);
179 lazy_realloc(&d, *off + size);
180 memcpy(d + *off, p ? p : c, size);
181 *off += size;
182
183 FREE(&p);
184
185 return d;
186}
const char * cc_charset(void)
Get the cached value of $charset.
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
Definition charset.c:817
#define MUTT_ICONV_NO_FLAGS
No flags are set.
Definition charset.h:66
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
Definition string.c:384
bool mutt_str_is_ascii(const char *str, size_t len)
Is a string ASCII (7-bit)?
Definition string.c:688
void lazy_realloc(void *ptr, size_t size)
Reallocate some memory.
Definition serialize.c:56
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_envelope()

unsigned char * serial_dump_envelope ( const struct Envelope * env,
unsigned char * d,
int * off,
bool convert )

Pack an Envelope into a binary blob.

Parameters
[in]envEnvelope to pack
[in]dBinary blob to add to
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted to utf-8
Return values
ptrEnd of the newly packed binary

Definition at line 601 of file serialize.c.

603{
604 d = serial_dump_address(&env->return_path, d, off, convert);
605 d = serial_dump_address(&env->from, d, off, convert);
606 d = serial_dump_address(&env->to, d, off, convert);
607 d = serial_dump_address(&env->cc, d, off, convert);
608 d = serial_dump_address(&env->bcc, d, off, convert);
609 d = serial_dump_address(&env->sender, d, off, convert);
610 d = serial_dump_address(&env->reply_to, d, off, convert);
611 d = serial_dump_address(&env->mail_followup_to, d, off, convert);
612
613 d = serial_dump_char(env->list_post, d, off, convert);
614 d = serial_dump_char(env->list_subscribe, d, off, convert);
615 d = serial_dump_char(env->list_unsubscribe, d, off, convert);
616 d = serial_dump_char(env->subject, d, off, convert);
617
618 if (env->real_subj)
619 d = serial_dump_int(env->real_subj - env->subject, d, off);
620 else
621 d = serial_dump_int(-1, d, off);
622
623 d = serial_dump_char(env->message_id, d, off, false);
624 d = serial_dump_char(env->supersedes, d, off, false);
625 d = serial_dump_char(env->date, d, off, false);
626 d = serial_dump_char(env->x_label, d, off, convert);
627 d = serial_dump_char(env->organization, d, off, convert);
628
629 d = serial_dump_buffer(&env->spam, d, off, convert);
630
631 d = serial_dump_stailq(&env->references, d, off, false);
632 d = serial_dump_stailq(&env->in_reply_to, d, off, false);
633 d = serial_dump_stailq(&env->userhdrs, d, off, convert);
634
635 d = serial_dump_char(env->xref, d, off, false);
636 d = serial_dump_char(env->followup_to, d, off, false);
637 d = serial_dump_char(env->x_comment_to, d, off, convert);
638
639 return d;
640}
unsigned char * serial_dump_address(const struct AddressList *al, unsigned char *d, int *off, bool convert)
Pack an Address into a binary blob.
Definition serialize.c:245
unsigned char * serial_dump_stailq(const struct ListHead *l, unsigned char *d, int *off, bool convert)
Pack a STAILQ into a binary blob.
Definition serialize.c:318
struct ListHead userhdrs
user defined headers
Definition envelope.h:85
char * supersedes
Supersedes header.
Definition envelope.h:74
char * list_subscribe
This stores a mailto URL, or nothing.
Definition envelope.h:68
struct AddressList return_path
Return path for the Email.
Definition envelope.h:58
char *const subject
Email's subject.
Definition envelope.h:70
struct AddressList to
Email's 'To' list.
Definition envelope.h:60
char * followup_to
List of 'followup-to' fields.
Definition envelope.h:80
struct AddressList reply_to
Email's 'reply-to'.
Definition envelope.h:64
char * message_id
Message ID.
Definition envelope.h:73
char * x_comment_to
List of 'X-comment-to' fields.
Definition envelope.h:81
struct AddressList mail_followup_to
Email's 'mail-followup-to'.
Definition envelope.h:65
struct AddressList cc
Email's 'Cc' list.
Definition envelope.h:61
struct AddressList sender
Email's sender.
Definition envelope.h:63
struct ListHead references
message references (in reverse order)
Definition envelope.h:83
struct Buffer spam
Spam header.
Definition envelope.h:82
struct ListHead in_reply_to
in-reply-to header content
Definition envelope.h:84
struct AddressList bcc
Email's 'Bcc' list.
Definition envelope.h:62
char * xref
List of cross-references.
Definition envelope.h:79
char * organization
Organisation header.
Definition envelope.h:77
char * x_label
X-Label.
Definition envelope.h:76
char * list_post
This stores a mailto URL, or nothing.
Definition envelope.h:67
char *const real_subj
Offset of the real subject.
Definition envelope.h:71
char * date
Sent date.
Definition envelope.h:75
char * list_unsubscribe
This stores a mailto URL, or nothing.
Definition envelope.h:69
struct AddressList from
Email's 'From' list.
Definition envelope.h:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_int()

unsigned char * serial_dump_int ( const unsigned int i,
unsigned char * d,
int * off )

Pack an integer into a binary blob.

Parameters
[in]iInteger to save
[in]dBinary blob to add to
[in,out]offOffset into the blob
Return values
ptrEnd of the newly packed binary

Definition at line 73 of file serialize.c.

74{
75 lazy_realloc(&d, *off + sizeof(int));
76 memcpy(d + *off, &i, sizeof(int));
77 (*off) += sizeof(int);
78
79 return d;
80}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_uint32_t()

unsigned char * serial_dump_uint32_t ( const uint32_t s,
unsigned char * d,
int * off )

Pack a uint32_t into a binary blob.

Parameters
[in]suint32_t to save
[in]dBinary blob to add to
[in,out]offOffset into the blob
Return values
ptrEnd of the newly packed binary

Definition at line 89 of file serialize.c.

90{
91 lazy_realloc(&d, *off + sizeof(uint32_t));
92 memcpy(d + *off, &s, sizeof(uint32_t));
93 (*off) += sizeof(uint32_t);
94
95 return d;
96}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_uint64_t()

unsigned char * serial_dump_uint64_t ( const uint64_t s,
unsigned char * d,
int * off )

Pack a uint64_t into a binary blob.

Parameters
[in]suint64_t to save
[in]dBinary blob to add to
[in,out]offOffset into the blob
Return values
ptrEnd of the newly packed binary

Definition at line 105 of file serialize.c.

106{
107 lazy_realloc(&d, *off + sizeof(uint64_t));
108 memcpy(d + *off, &s, sizeof(uint64_t));
109 (*off) += sizeof(uint64_t);
110
111 return d;
112}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_parameter()

unsigned char * serial_dump_parameter ( const struct ParameterList * pl,
unsigned char * d,
int * off,
bool convert )

Pack a Parameter into a binary blob.

Parameters
[in]plParameter to pack
[in]dBinary blob to add to
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted to utf-8
Return values
ptrEnd of the newly packed binary

Definition at line 418 of file serialize.c.

420{
421 unsigned int counter = 0;
422 unsigned int start_off = *off;
423
424 d = serial_dump_int(0xdeadbeef, d, off);
425
426 struct Parameter *np = NULL;
427 TAILQ_FOREACH(np, pl, entries)
428 {
429 d = serial_dump_char(np->attribute, d, off, false);
430 d = serial_dump_char(np->value, d, off, convert);
431 counter++;
432 }
433
434 memcpy(d + start_off, &counter, sizeof(int));
435
436 return d;
437}
Attribute associated with a MIME part.
Definition parameter.h:33
char * attribute
Parameter name.
Definition parameter.h:34
char * value
Parameter value.
Definition parameter.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_stailq()

unsigned char * serial_dump_stailq ( const struct ListHead * l,
unsigned char * d,
int * off,
bool convert )

Pack a STAILQ into a binary blob.

Parameters
[in]lList to read from
[in]dBinary blob to add to
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted to utf-8
Return values
ptrEnd of the newly packed binary

Definition at line 318 of file serialize.c.

320{
321 unsigned int counter = 0;
322 unsigned int start_off = *off;
323
324 d = serial_dump_int(0xdeadbeef, d, off);
325
326 struct ListNode *np = NULL;
327 STAILQ_FOREACH(np, l, entries)
328 {
329 d = serial_dump_char(np->data, d, off, convert);
330 counter++;
331 }
332
333 memcpy(d + start_off, &counter, sizeof(int));
334
335 return d;
336}
A List node for strings.
Definition list.h:37
char * data
String.
Definition list.h:38
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_restore_address()

void serial_restore_address ( struct AddressList * al,
const unsigned char * d,
int * off,
bool convert )

Unpack an Address from a binary blob.

Parameters
[out]alStore the unpacked AddressList here
[in]dBinary blob to read from
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted from utf-8

Definition at line 274 of file serialize.c.

276{
277 unsigned int counter = 0;
278 unsigned int g = 0;
279
280 serial_restore_int(&counter, d, off);
281
282 if (counter > SERIAL_MAX_LIST_COUNT)
283 return;
284
285 while (counter > 0)
286 {
287 struct Address *a = mutt_addr_new();
288
289 a->personal = buf_new(NULL);
290 serial_restore_buffer(a->personal, d, off, convert);
291 if (buf_is_empty(a->personal))
292 {
293 buf_free(&a->personal);
294 }
295
296 a->mailbox = buf_new(NULL);
297 serial_restore_buffer(a->mailbox, d, off, false);
298 if (buf_is_empty(a->mailbox))
299 {
300 buf_free(&a->mailbox);
301 }
302
303 serial_restore_int(&g, d, off);
304 a->group = !!g;
306 counter--;
307 }
308}
void mutt_addrlist_append(struct AddressList *al, struct Address *a)
Append an Address to an AddressList.
Definition address.c:1489
struct Address * mutt_addr_new(void)
Create a new Address.
Definition address.c:401
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
Definition buffer.c:319
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition buffer.c:304
void serial_restore_buffer(struct Buffer *buf, const unsigned char *d, int *off, bool convert)
Unpack a Buffer from a binary blob.
Definition serialize.c:394
#define SERIAL_MAX_LIST_COUNT
Max entries in a serialized list (addresses, headers, parameters, tags)
Definition serialize.c:47
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from a binary blob.
Definition serialize.c:120
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_restore_body()

void serial_restore_body ( struct Body * b,
const unsigned char * d,
int * off,
bool convert )

Unpack a Body from a binary blob.

Parameters
[in]bStore the unpacked Body here
[in]dBinary blob to read from
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted from utf-8

Definition at line 566 of file serialize.c.

567{
568 uint32_t packed = 0;
569 serial_restore_uint32_t(&packed, d, off);
570 body_unpack_flags(b, packed);
571
572 uint64_t big = 0;
573 serial_restore_uint64_t(&big, d, off);
574 b->offset = big;
575
576 big = 0;
577 serial_restore_uint64_t(&big, d, off);
578 b->length = big;
579
580 serial_restore_char(&b->xtype, d, off, false);
581 serial_restore_char(&b->subtype, d, off, false);
582
584 serial_restore_parameter(&b->parameter, d, off, convert);
585
586 serial_restore_char(&b->description, d, off, convert);
587 serial_restore_char(&b->content_id, d, off, convert);
588 serial_restore_char(&b->form_name, d, off, convert);
589 serial_restore_char(&b->filename, d, off, convert);
590 serial_restore_char(&b->d_filename, d, off, convert);
591}
#define TAILQ_INIT(head)
Definition queue.h:822
void serial_restore_char(char **c, const unsigned char *d, int *off, bool convert)
Unpack a variable-length string from a binary blob.
Definition serialize.c:208
void serial_restore_uint64_t(uint64_t *s, const unsigned char *d, int *off)
Unpack an uint64_t from a binary blob.
Definition serialize.c:144
void serial_restore_parameter(struct ParameterList *pl, const unsigned char *d, int *off, bool convert)
Unpack a Parameter from a binary blob.
Definition serialize.c:446
static void body_unpack_flags(struct Body *b, uint32_t packed)
Unpack the Body flags from a uint32_t.
Definition serialize.c:504
void serial_restore_uint32_t(uint32_t *s, const unsigned char *d, int *off)
Unpack an uint32_t from a binary blob.
Definition serialize.c:132
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_restore_tags()

void serial_restore_tags ( struct TagList * tl,
const unsigned char * d,
int * off )

Unpack a TagList from a binary blob.

Parameters
[in]tlTagList to unpack
[in]dBinary blob to add to
[in,out]offOffset into the blob

Definition at line 728 of file serialize.c.

729{
730 unsigned int counter = 0;
731
732 serial_restore_int(&counter, d, off);
733
734 if (counter > SERIAL_MAX_LIST_COUNT)
735 return;
736
737 while (counter > 0)
738 {
739 char *name = NULL;
740 serial_restore_char(&name, d, off, false);
741 driver_tags_add(tl, name);
742 counter--;
743 }
744}
void driver_tags_add(struct TagList *tl, char *new_tag)
Add a tag to header.
Definition tags.c:105
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_restore_buffer()

void serial_restore_buffer ( struct Buffer * buf,
const unsigned char * d,
int * off,
bool convert )

Unpack a Buffer from a binary blob.

Parameters
[out]bufStore the unpacked Buffer here
[in]dBinary blob to read from
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted from utf-8

Definition at line 394 of file serialize.c.

395{
396 buf_alloc(buf, 1);
397
398 unsigned int used = 0;
399 serial_restore_int(&used, d, off);
400 if (used == 0)
401 return;
402
403 char *str = NULL;
404 serial_restore_char(&str, d, off, convert);
405
406 buf_addstr(buf, str);
407 FREE(&str);
408}
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition buffer.c:226
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition buffer.c:337
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_restore_char()

void serial_restore_char ( char ** c,
const unsigned char * d,
int * off,
bool convert )

Unpack a variable-length string from a binary blob.

Parameters
[out]cStore the unpacked string here
[in]dBinary blob to read from
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted to utf-8

Definition at line 208 of file serialize.c.

209{
210 unsigned int size = 0;
211 serial_restore_int(&size, d, off);
212
213 if ((size == 0) || (size > SERIAL_MAX_CHAR_SIZE))
214 {
215 *c = NULL;
216 return;
217 }
218
219 *c = MUTT_MEM_MALLOC(size, char);
220 memcpy(*c, d + *off, size);
221 if (convert && !mutt_str_is_ascii(*c, size))
222 {
223 char *tmp = mutt_str_dup(*c);
224 if (mutt_ch_convert_string(&tmp, "utf-8", cc_charset(), MUTT_ICONV_NO_FLAGS) == 0)
225 {
226 FREE(c);
227 *c = tmp;
228 }
229 else
230 {
231 FREE(&tmp);
232 }
233 }
234 *off += size;
235}
#define MUTT_MEM_MALLOC(n, type)
Definition memory.h:53
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
#define SERIAL_MAX_CHAR_SIZE
Max size for a single serialized string field (256 KiB)
Definition serialize.c:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_restore_envelope()

void serial_restore_envelope ( struct Envelope * env,
const unsigned char * d,
int * off,
bool convert )

Unpack an Envelope from a binary blob.

Parameters
[in]envStore the unpacked Envelope here
[in]dBinary blob to read from
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted from utf-8

Definition at line 649 of file serialize.c.

650{
651 int real_subj_off = 0;
652
653 serial_restore_address(&env->return_path, d, off, convert);
654 serial_restore_address(&env->from, d, off, convert);
655 serial_restore_address(&env->to, d, off, convert);
656 serial_restore_address(&env->cc, d, off, convert);
657 serial_restore_address(&env->bcc, d, off, convert);
658 serial_restore_address(&env->sender, d, off, convert);
659 serial_restore_address(&env->reply_to, d, off, convert);
660 serial_restore_address(&env->mail_followup_to, d, off, convert);
661
662 serial_restore_char(&env->list_post, d, off, convert);
663 serial_restore_char(&env->list_subscribe, d, off, convert);
664 serial_restore_char(&env->list_unsubscribe, d, off, convert);
665
666 const bool c_auto_subscribe = cs_subset_bool(NeoMutt->sub, "auto_subscribe");
667 if (c_auto_subscribe)
669
670 serial_restore_char((char **) &env->subject, d, off, convert);
671 serial_restore_int((unsigned int *) (&real_subj_off), d, off);
672
673 size_t len = mutt_str_len(env->subject);
674 if ((real_subj_off < 0) || (real_subj_off >= len))
675 *(char **) &env->real_subj = NULL;
676 else
677 *(char **) &env->real_subj = env->subject + real_subj_off;
678
679 serial_restore_char(&env->message_id, d, off, false);
680 serial_restore_char(&env->supersedes, d, off, false);
681 serial_restore_char(&env->date, d, off, false);
682 serial_restore_char(&env->x_label, d, off, convert);
683 serial_restore_char(&env->organization, d, off, convert);
684
685 serial_restore_buffer(&env->spam, d, off, convert);
686
687 serial_restore_stailq(&env->references, d, off, false);
688 serial_restore_stailq(&env->in_reply_to, d, off, false);
689 serial_restore_stailq(&env->userhdrs, d, off, convert);
690
691 serial_restore_char(&env->xref, d, off, false);
692 serial_restore_char(&env->followup_to, d, off, false);
693 serial_restore_char(&env->x_comment_to, d, off, convert);
694}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
void mutt_auto_subscribe(const char *mailto)
Check if user is subscribed to mailing list.
Definition parse.c:108
void serial_restore_stailq(struct ListHead *l, const unsigned char *d, int *off, bool convert)
Unpack a STAILQ from a binary blob.
Definition serialize.c:345
void serial_restore_address(struct AddressList *al, const unsigned char *d, int *off, bool convert)
Unpack an Address from a binary blob.
Definition serialize.c:274
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_restore_int()

void serial_restore_int ( unsigned int * i,
const unsigned char * d,
int * off )

Unpack an integer from a binary blob.

Parameters
[in]iInteger to write to
[in]dBinary blob to read from
[in,out]offOffset into the blob

Definition at line 120 of file serialize.c.

121{
122 memcpy(i, d + *off, sizeof(int));
123 (*off) += sizeof(int);
124}
+ Here is the caller graph for this function:

◆ serial_restore_uint32_t()

void serial_restore_uint32_t ( uint32_t * s,
const unsigned char * d,
int * off )

Unpack an uint32_t from a binary blob.

Parameters
[in]suint32_t to write to
[in]dBinary blob to read from
[in,out]offOffset into the blob

Definition at line 132 of file serialize.c.

133{
134 memcpy(s, d + *off, sizeof(uint32_t));
135 (*off) += sizeof(uint32_t);
136}
+ Here is the caller graph for this function:

◆ serial_restore_uint64_t()

void serial_restore_uint64_t ( uint64_t * s,
const unsigned char * d,
int * off )

Unpack an uint64_t from a binary blob.

Parameters
[in]suint64_t to write to
[in]dBinary blob to read from
[in,out]offOffset into the blob

Definition at line 144 of file serialize.c.

145{
146 memcpy(s, d + *off, sizeof(uint64_t));
147 (*off) += sizeof(uint64_t);
148}
+ Here is the caller graph for this function:

◆ serial_restore_parameter()

void serial_restore_parameter ( struct ParameterList * pl,
const unsigned char * d,
int * off,
bool convert )

Unpack a Parameter from a binary blob.

Parameters
[in]plStore the unpacked Parameter here
[in]dBinary blob to read from
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted from utf-8

Definition at line 446 of file serialize.c.

448{
449 unsigned int counter = 0;
450
451 serial_restore_int(&counter, d, off);
452
453 if (counter > SERIAL_MAX_LIST_COUNT)
454 return;
455
456 struct Parameter *np = NULL;
457 while (counter > 0)
458 {
459 np = mutt_param_new();
460 serial_restore_char(&np->attribute, d, off, false);
461 serial_restore_char(&np->value, d, off, convert);
462 TAILQ_INSERT_TAIL(pl, np, entries);
463 counter--;
464 }
465}
struct Parameter * mutt_param_new(void)
Create a new Parameter.
Definition parameter.c:40
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition queue.h:866
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_restore_stailq()

void serial_restore_stailq ( struct ListHead * l,
const unsigned char * d,
int * off,
bool convert )

Unpack a STAILQ from a binary blob.

Parameters
[in]lList to add to
[in]dBinary blob to read from
[in,out]offOffset into the blob
[in]convertIf true, the strings will be converted from utf-8

Definition at line 345 of file serialize.c.

346{
347 unsigned int counter = 0;
348
349 serial_restore_int(&counter, d, off);
350
351 if (counter > SERIAL_MAX_LIST_COUNT)
352 return;
353
354 struct ListNode *np = NULL;
355 while (counter > 0)
356 {
357 np = mutt_list_insert_tail(l, NULL);
358 serial_restore_char(&np->data, d, off, convert);
359 counter--;
360 }
361}
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition list.c:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ lazy_realloc()

void lazy_realloc ( void * ptr,
size_t size )

Reallocate some memory.

Parameters
[in]ptrPointer to resize
[in]sizeMinimum size

The minimum size is 4KiB to avoid repeated resizing.

Definition at line 56 of file serialize.c.

57{
58 void **p = (void **) ptr;
59
60 if (p && (size < 4096))
61 return;
62
63 mutt_mem_realloc(ptr, size);
64}
void mutt_mem_realloc(void *pptr, size_t size)
Resize a block of memory on the heap.
Definition memory.c:146
+ Here is the call graph for this function:
+ Here is the caller graph for this function: