NeoMutt  2024-12-12-14-g7b49f7
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 239 of file serialize.c.

241{
242 unsigned int counter = 0;
243 unsigned int start_off = *off;
244
245 d = serial_dump_int(0xdeadbeef, d, off);
246
247 struct Address *a = NULL;
248 TAILQ_FOREACH(a, al, entries)
249 {
250 d = serial_dump_buffer(a->personal, d, off, convert);
251 d = serial_dump_buffer(a->mailbox, d, off, convert);
252 d = serial_dump_int(a->group, d, off);
253 counter++;
254 }
255
256 memcpy(d + start_off, &counter, sizeof(int));
257
258 return d;
259}
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:743
unsigned char * serial_dump_int(const unsigned int i, unsigned char *d, int *off)
Pack an integer into a binary blob.
Definition: serialize.c:67
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:359
An email address.
Definition: address.h:36
struct Buffer * personal
Real name of address.
Definition: address.h:37
bool group
Group mailbox?
Definition: address.h:39
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
+ 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 519 of file serialize.c.

520{
521 uint32_t packed = body_pack_flags(b);
522 d = serial_dump_uint32_t(packed, d, off);
523
524 uint64_t big = b->offset;
525 d = serial_dump_uint64_t(big, d, off);
526
527 big = b->length;
528 d = serial_dump_uint64_t(big, d, off);
529
530 d = serial_dump_char(b->xtype, d, off, false);
531 d = serial_dump_char(b->subtype, d, off, false);
532
533 d = serial_dump_parameter(&b->parameter, d, off, convert);
534
535 d = serial_dump_char(b->description, d, off, convert);
536 d = serial_dump_char(b->content_id, d, off, convert);
537 d = serial_dump_char(b->form_name, d, off, convert);
538 d = serial_dump_char(b->filename, d, off, convert);
539 d = serial_dump_char(b->d_filename, d, off, convert);
540
541 return d;
542}
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:99
static uint32_t body_pack_flags(const struct Body *b)
Pack the Body flags into a uint32_t.
Definition: serialize.c:459
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:406
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:83
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:190
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 688 of file serialize.c.

689{
690 unsigned int counter = 0;
691 unsigned int start_off = *off;
692
693 d = serial_dump_int(0xdeadbeef, d, off);
694
695 struct Tag *tag = NULL;
696 STAILQ_FOREACH(tag, tl, entries)
697 {
698 d = serial_dump_char(tag->name, d, off, false);
699 counter++;
700 }
701
702 memcpy(d + start_off, &counter, sizeof(int));
703
704 return d;
705}
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
LinkedList Tag Element.
Definition: tags.h:42
char * name
Tag name.
Definition: tags.h:43
+ 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 359 of file serialize.c.

361{
362 if (buf_is_empty(buf))
363 {
364 d = serial_dump_int(0, d, off);
365 return d;
366 }
367
368 d = serial_dump_int(1, d, off);
369
370 d = serial_dump_char(buf->data, d, off, convert);
371
372 return d;
373}
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 190 of file serialize.c.

191{
192 return serial_dump_char_size(c, mutt_str_len(c) + 1, d, off, convert);
193}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
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:153
+ 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 153 of file serialize.c.

155{
156 char *p = NULL;
157
158 if (!c || (*c == '\0') || (size == 0))
159 {
160 return serial_dump_int(0, d, off);
161 }
162
163 if (convert && !mutt_str_is_ascii(c, size))
164 {
165 p = mutt_strn_dup(c, size);
166 if (mutt_ch_convert_string(&p, cc_charset(), "utf-8", MUTT_ICONV_NO_FLAGS) == 0)
167 {
168 size = mutt_str_len(p) + 1;
169 }
170 }
171
172 d = serial_dump_int(size, d, off);
173 lazy_realloc(&d, *off + size);
174 memcpy(d + *off, p ? p : c, size);
175 *off += size;
176
177 FREE(&p);
178
179 return d;
180}
const char * cc_charset(void)
Get the cached value of $charset.
Definition: config_cache.c:116
#define FREE(x)
Definition: memory.h:55
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
Definition: charset.c:831
#define MUTT_ICONV_NO_FLAGS
No flags are set.
Definition: charset.h:64
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
Definition: string.c:380
bool mutt_str_is_ascii(const char *str, size_t len)
Is a string ASCII (7-bit)?
Definition: string.c:683
void lazy_realloc(void *ptr, size_t size)
Reallocate some memory.
Definition: serialize.c:50
+ 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 586 of file serialize.c.

588{
589 d = serial_dump_address(&env->return_path, d, off, convert);
590 d = serial_dump_address(&env->from, d, off, convert);
591 d = serial_dump_address(&env->to, d, off, convert);
592 d = serial_dump_address(&env->cc, d, off, convert);
593 d = serial_dump_address(&env->bcc, d, off, convert);
594 d = serial_dump_address(&env->sender, d, off, convert);
595 d = serial_dump_address(&env->reply_to, d, off, convert);
596 d = serial_dump_address(&env->mail_followup_to, d, off, convert);
597
598 d = serial_dump_char(env->list_post, d, off, convert);
599 d = serial_dump_char(env->list_subscribe, d, off, convert);
600 d = serial_dump_char(env->list_unsubscribe, d, off, convert);
601 d = serial_dump_char(env->subject, d, off, convert);
602
603 if (env->real_subj)
604 d = serial_dump_int(env->real_subj - env->subject, d, off);
605 else
606 d = serial_dump_int(-1, d, off);
607
608 d = serial_dump_char(env->message_id, d, off, false);
609 d = serial_dump_char(env->supersedes, d, off, false);
610 d = serial_dump_char(env->date, d, off, false);
611 d = serial_dump_char(env->x_label, d, off, convert);
612 d = serial_dump_char(env->organization, d, off, convert);
613
614 d = serial_dump_buffer(&env->spam, d, off, convert);
615
616 d = serial_dump_stailq(&env->references, d, off, false);
617 d = serial_dump_stailq(&env->in_reply_to, d, off, false);
618 d = serial_dump_stailq(&env->userhdrs, d, off, convert);
619
620 d = serial_dump_char(env->xref, d, off, false);
621 d = serial_dump_char(env->followup_to, d, off, false);
622 d = serial_dump_char(env->x_comment_to, d, off, convert);
623
624 return d;
625}
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:239
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:309
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 67 of file serialize.c.

68{
69 lazy_realloc(&d, *off + sizeof(int));
70 memcpy(d + *off, &i, sizeof(int));
71 (*off) += sizeof(int);
72
73 return d;
74}
+ 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 83 of file serialize.c.

84{
85 lazy_realloc(&d, *off + sizeof(uint32_t));
86 memcpy(d + *off, &s, sizeof(uint32_t));
87 (*off) += sizeof(uint32_t);
88
89 return d;
90}
+ 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 99 of file serialize.c.

100{
101 lazy_realloc(&d, *off + sizeof(uint64_t));
102 memcpy(d + *off, &s, sizeof(uint64_t));
103 (*off) += sizeof(uint64_t);
104
105 return d;
106}
+ 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 406 of file serialize.c.

408{
409 unsigned int counter = 0;
410 unsigned int start_off = *off;
411
412 d = serial_dump_int(0xdeadbeef, d, off);
413
414 struct Parameter *np = NULL;
415 TAILQ_FOREACH(np, pl, entries)
416 {
417 d = serial_dump_char(np->attribute, d, off, false);
418 d = serial_dump_char(np->value, d, off, convert);
419 counter++;
420 }
421
422 memcpy(d + start_off, &counter, sizeof(int));
423
424 return d;
425}
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 309 of file serialize.c.

311{
312 unsigned int counter = 0;
313 unsigned int start_off = *off;
314
315 d = serial_dump_int(0xdeadbeef, d, off);
316
317 struct ListNode *np = NULL;
318 STAILQ_FOREACH(np, l, entries)
319 {
320 d = serial_dump_char(np->data, d, off, convert);
321 counter++;
322 }
323
324 memcpy(d + start_off, &counter, sizeof(int));
325
326 return d;
327}
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 268 of file serialize.c.

270{
271 unsigned int counter = 0;
272 unsigned int g = 0;
273
274 serial_restore_int(&counter, d, off);
275
276 while (counter > 0)
277 {
278 struct Address *a = mutt_addr_new();
279
280 a->personal = buf_new(NULL);
281 serial_restore_buffer(a->personal, d, off, convert);
282 if (buf_is_empty(a->personal))
283 {
284 buf_free(&a->personal);
285 }
286
287 a->mailbox = buf_new(NULL);
288 serial_restore_buffer(a->mailbox, d, off, false);
289 if (buf_is_empty(a->mailbox))
290 {
291 buf_free(&a->mailbox);
292 }
293
294 serial_restore_int(&g, d, off);
295 a->group = !!g;
297 counter--;
298 }
299}
void mutt_addrlist_append(struct AddressList *al, struct Address *a)
Append an Address to an AddressList.
Definition: address.c:1480
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:382
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from a binary blob.
Definition: serialize.c:114
+ 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 551 of file serialize.c.

552{
553 uint32_t packed = 0;
554 serial_restore_uint32_t(&packed, d, off);
555 body_unpack_flags(b, packed);
556
557 uint64_t big = 0;
558 serial_restore_uint64_t(&big, d, off);
559 b->offset = big;
560
561 big = 0;
562 serial_restore_uint64_t(&big, d, off);
563 b->length = big;
564
565 serial_restore_char(&b->xtype, d, off, false);
566 serial_restore_char(&b->subtype, d, off, false);
567
569 serial_restore_parameter(&b->parameter, d, off, convert);
570
571 serial_restore_char(&b->description, d, off, convert);
572 serial_restore_char(&b->content_id, d, off, convert);
573 serial_restore_char(&b->form_name, d, off, convert);
574 serial_restore_char(&b->filename, d, off, convert);
575 serial_restore_char(&b->d_filename, d, off, convert);
576}
#define TAILQ_INIT(head)
Definition: queue.h:783
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:202
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:138
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:434
static void body_unpack_flags(struct Body *b, uint32_t packed)
Unpack the Body flags from a uint32_t.
Definition: serialize.c:489
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:126
+ 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 713 of file serialize.c.

714{
715 unsigned int counter = 0;
716
717 serial_restore_int(&counter, d, off);
718
719 while (counter > 0)
720 {
721 char *name = NULL;
722 serial_restore_char(&name, d, off, false);
723 driver_tags_add(tl, name);
724 counter--;
725 }
726}
void driver_tags_add(struct TagList *tl, char *new_tag)
Add a tag to header.
Definition: tags.c:107
+ 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 382 of file serialize.c.

383{
384 buf_alloc(buf, 1);
385
386 unsigned int used = 0;
387 serial_restore_int(&used, d, off);
388 if (used == 0)
389 return;
390
391 char *str = NULL;
392 serial_restore_char(&str, d, off, convert);
393
394 buf_addstr(buf, str);
395 FREE(&str);
396}
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 202 of file serialize.c.

203{
204 unsigned int size = 0;
205 serial_restore_int(&size, d, off);
206
207 if (size == 0)
208 {
209 *c = NULL;
210 return;
211 }
212
213 *c = MUTT_MEM_MALLOC(size, char);
214 memcpy(*c, d + *off, size);
215 if (convert && !mutt_str_is_ascii(*c, size))
216 {
217 char *tmp = mutt_str_dup(*c);
218 if (mutt_ch_convert_string(&tmp, "utf-8", cc_charset(), MUTT_ICONV_NO_FLAGS) == 0)
219 {
220 FREE(c);
221 *c = tmp;
222 }
223 else
224 {
225 FREE(&tmp);
226 }
227 }
228 *off += size;
229}
#define MUTT_MEM_MALLOC(n, type)
Definition: memory.h:41
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
+ 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 634 of file serialize.c.

635{
636 int real_subj_off = 0;
637
638 serial_restore_address(&env->return_path, d, off, convert);
639 serial_restore_address(&env->from, d, off, convert);
640 serial_restore_address(&env->to, d, off, convert);
641 serial_restore_address(&env->cc, d, off, convert);
642 serial_restore_address(&env->bcc, d, off, convert);
643 serial_restore_address(&env->sender, d, off, convert);
644 serial_restore_address(&env->reply_to, d, off, convert);
645 serial_restore_address(&env->mail_followup_to, d, off, convert);
646
647 serial_restore_char(&env->list_post, d, off, convert);
648 serial_restore_char(&env->list_subscribe, d, off, convert);
649 serial_restore_char(&env->list_unsubscribe, d, off, convert);
650
651 const bool c_auto_subscribe = cs_subset_bool(NeoMutt->sub, "auto_subscribe");
652 if (c_auto_subscribe)
654
655 serial_restore_char((char **) &env->subject, d, off, convert);
656 serial_restore_int((unsigned int *) (&real_subj_off), d, off);
657
658 size_t len = mutt_str_len(env->subject);
659 if ((real_subj_off < 0) || (real_subj_off >= len))
660 *(char **) &env->real_subj = NULL;
661 else
662 *(char **) &env->real_subj = env->subject + real_subj_off;
663
664 serial_restore_char(&env->message_id, d, off, false);
665 serial_restore_char(&env->supersedes, d, off, false);
666 serial_restore_char(&env->date, d, off, false);
667 serial_restore_char(&env->x_label, d, off, convert);
668 serial_restore_char(&env->organization, d, off, convert);
669
670 serial_restore_buffer(&env->spam, d, off, convert);
671
672 serial_restore_stailq(&env->references, d, off, false);
673 serial_restore_stailq(&env->in_reply_to, d, off, false);
674 serial_restore_stailq(&env->userhdrs, d, off, convert);
675
676 serial_restore_char(&env->xref, d, off, false);
677 serial_restore_char(&env->followup_to, d, off, false);
678 serial_restore_char(&env->x_comment_to, d, off, convert);
679}
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:109
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:336
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:268
Container for Accounts, Notifications.
Definition: neomutt.h:42
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
+ 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 114 of file serialize.c.

115{
116 memcpy(i, d + *off, sizeof(int));
117 (*off) += sizeof(int);
118}
+ 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 126 of file serialize.c.

127{
128 memcpy(s, d + *off, sizeof(uint32_t));
129 (*off) += sizeof(uint32_t);
130}
+ 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 138 of file serialize.c.

139{
140 memcpy(s, d + *off, sizeof(uint64_t));
141 (*off) += sizeof(uint64_t);
142}
+ 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 434 of file serialize.c.

436{
437 unsigned int counter = 0;
438
439 serial_restore_int(&counter, d, off);
440
441 struct Parameter *np = NULL;
442 while (counter > 0)
443 {
444 np = mutt_param_new();
445 serial_restore_char(&np->attribute, d, off, false);
446 serial_restore_char(&np->value, d, off, convert);
447 TAILQ_INSERT_TAIL(pl, np, entries);
448 counter--;
449 }
450}
struct Parameter * mutt_param_new(void)
Create a new Parameter.
Definition: parameter.c:40
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:827
+ 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 336 of file serialize.c.

337{
338 unsigned int counter = 0;
339
340 serial_restore_int(&counter, d, off);
341
342 struct ListNode *np = NULL;
343 while (counter > 0)
344 {
345 np = mutt_list_insert_tail(l, NULL);
346 serial_restore_char(&np->data, d, off, convert);
347 counter--;
348 }
349}
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 50 of file serialize.c.

51{
52 void **p = (void **) ptr;
53
54 if (p && (size < 4096))
55 return;
56
57 mutt_mem_realloc(ptr, size);
58}
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: