NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
serialize.h File Reference

Email-object serialiser. More...

#include <stdbool.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 *c, unsigned char *d, int *off, bool convert)
 Pack an Body into a binary blob.
 
unsigned char * serial_dump_tags (const struct TagList *tags, 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 *c, const unsigned char *d, int *off, bool convert)
 Unpack a Body from a binary blob.
 
void serial_restore_tags (struct TagList *tags, 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
  • Thomas Glanzmann
  • Tobias Werth
  • Brian Fundakowski Feldman
  • 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 240 of file serialize.c.

242{
243 unsigned int counter = 0;
244 unsigned int start_off = *off;
245
246 d = serial_dump_int(0xdeadbeef, d, off);
247
248 struct Address *a = NULL;
249 TAILQ_FOREACH(a, al, entries)
250 {
251 d = serial_dump_buffer(a->personal, d, off, convert);
252 d = serial_dump_buffer(a->mailbox, d, off, convert);
253 d = serial_dump_int(a->group, d, off);
254 counter++;
255 }
256
257 memcpy(d + start_off, &counter, sizeof(int));
258
259 return d;
260}
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
unsigned char * serial_dump_int(const unsigned int i, unsigned char *d, int *off)
Pack an integer into a binary blob.
Definition: serialize.c:68
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:360
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 520 of file serialize.c.

521{
522 uint32_t packed = body_pack_flags(b);
523 d = serial_dump_uint32_t(packed, d, off);
524
525 uint64_t big = b->offset;
526 d = serial_dump_uint64_t(big, d, off);
527
528 big = b->length;
529 d = serial_dump_uint64_t(big, d, off);
530
531 d = serial_dump_char(b->xtype, d, off, false);
532 d = serial_dump_char(b->subtype, d, off, false);
533
534 d = serial_dump_parameter(&b->parameter, d, off, convert);
535
536 d = serial_dump_char(b->description, 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:100
static uint32_t body_pack_flags(const struct Body *b)
Pack the Body flags into a uint32_t.
Definition: serialize.c:460
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:407
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:84
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:191
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:61
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
struct ParameterList parameter
Parameters of the content-type.
Definition: body.h:62
char * description
content-description
Definition: body.h:55
char * subtype
content-type subtype
Definition: body.h:60
char * form_name
Content-Disposition form-data name param.
Definition: body.h:59
char * filename
When sending a message, this is the file to which this structure refers.
Definition: body.h:58
+ 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 *  tags,
unsigned char *  d,
int *  off 
)

Pack a TagList into a binary blob.

Parameters
[in]tagsTagList 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 691 of file serialize.c.

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

362{
363 if (buf_is_empty(buf))
364 {
365 d = serial_dump_int(0, d, off);
366 return d;
367 }
368
369 d = serial_dump_int(1, d, off);
370
371 d = serial_dump_char(buf->data, d, off, convert);
372
373 return d;
374}
bool buf_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:303
char * data
Pointer to data.
Definition: buffer.h:35
+ 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 191 of file serialize.c.

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

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

587{
588 d = serial_dump_address(&env->return_path, d, off, convert);
589 d = serial_dump_address(&env->from, d, off, convert);
590 d = serial_dump_address(&env->to, d, off, convert);
591 d = serial_dump_address(&env->cc, d, off, convert);
592 d = serial_dump_address(&env->bcc, d, off, convert);
593 d = serial_dump_address(&env->sender, d, off, convert);
594 d = serial_dump_address(&env->reply_to, d, off, convert);
595 d = serial_dump_address(&env->mail_followup_to, d, off, convert);
596
597 d = serial_dump_char(env->list_post, d, off, convert);
598 d = serial_dump_char(env->list_subscribe, d, off, convert);
599 d = serial_dump_char(env->list_unsubscribe, d, off, convert);
600 d = serial_dump_char(env->subject, d, off, convert);
601
602 if (env->real_subj)
603 d = serial_dump_int(env->real_subj - env->subject, d, off);
604 else
605 d = serial_dump_int(-1, d, off);
606
607 d = serial_dump_char(env->message_id, d, off, false);
608 d = serial_dump_char(env->supersedes, d, off, false);
609 d = serial_dump_char(env->date, d, off, false);
610 d = serial_dump_char(env->x_label, d, off, convert);
611 d = serial_dump_char(env->organization, d, off, convert);
612
613 d = serial_dump_buffer(&env->spam, d, off, convert);
614
615 d = serial_dump_stailq(&env->references, d, off, false);
616 d = serial_dump_stailq(&env->in_reply_to, d, off, false);
617 d = serial_dump_stailq(&env->userhdrs, d, off, convert);
618
619#ifdef USE_NNTP
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#endif
624
625 return d;
626}
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:240
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:310
struct ListHead userhdrs
user defined headers
Definition: envelope.h:87
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
struct AddressList to
Email's 'To' list.
Definition: envelope.h:60
char * followup_to
List of 'followup-to' fields.
Definition: envelope.h:81
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:82
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:85
struct Buffer spam
Spam header.
Definition: envelope.h:84
struct ListHead in_reply_to
in-reply-to header content
Definition: envelope.h:86
char * subject
Email's subject.
Definition: envelope.h:70
struct AddressList bcc
Email's 'Bcc' list.
Definition: envelope.h:62
char * xref
List of cross-references.
Definition: envelope.h:80
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 * date
Sent date.
Definition: envelope.h:75
char * real_subj
Offset of the real subject.
Definition: envelope.h:71
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 68 of file serialize.c.

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

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

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

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

312{
313 unsigned int counter = 0;
314 unsigned int start_off = *off;
315
316 d = serial_dump_int(0xdeadbeef, d, off);
317
318 struct ListNode *np = NULL;
319 STAILQ_FOREACH(np, l, entries)
320 {
321 d = serial_dump_char(np->data, d, off, convert);
322 counter++;
323 }
324
325 memcpy(d + start_off, &counter, sizeof(int));
326
327 return d;
328}
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
+ 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 269 of file serialize.c.

271{
272 unsigned int counter = 0;
273 unsigned int g = 0;
274
275 serial_restore_int(&counter, d, off);
276
277 while (counter)
278 {
279 struct Address *a = mutt_addr_new();
280
281 a->personal = buf_new(NULL);
282 serial_restore_buffer(a->personal, d, off, convert);
283 if (buf_is_empty(a->personal))
284 {
285 buf_free(&a->personal);
286 }
287
288 a->mailbox = buf_new(NULL);
289 serial_restore_buffer(a->mailbox, d, off, false);
290 if (buf_is_empty(a->mailbox))
291 {
292 buf_free(&a->mailbox);
293 }
294
295 serial_restore_int(&g, d, off);
296 a->group = !!g;
298 counter--;
299 }
300}
void mutt_addrlist_append(struct AddressList *al, struct Address *a)
Append an Address to an AddressList.
Definition: address.c:1481
struct Address * mutt_addr_new(void)
Create a new Address.
Definition: address.c:399
void buf_free(struct Buffer **ptr)
Deallocates a buffer.
Definition: buffer.c:331
struct Buffer * buf_new(const char *str)
Allocate a new Buffer.
Definition: buffer.c:316
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:383
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from a binary blob.
Definition: serialize.c:115
+ 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->form_name, d, off, convert);
573 serial_restore_char(&b->filename, d, off, convert);
574 serial_restore_char(&b->d_filename, d, off, convert);
575}
#define TAILQ_INIT(head)
Definition: queue.h:765
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:203
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:139
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:435
static void body_unpack_flags(struct Body *b, uint32_t packed)
Unpack the Body flags from a uint32_t.
Definition: serialize.c:490
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:127
+ 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 *  tags,
const unsigned char *  d,
int *  off 
)

Unpack a TagList from a binary blob.

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

Definition at line 716 of file serialize.c.

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

384{
385 buf_alloc(buf, 1);
386
387 unsigned int used = 0;
388 serial_restore_int(&used, d, off);
389 if (used == 0)
390 return;
391
392 char *str = NULL;
393 serial_restore_char(&str, d, off, convert);
394
395 buf_addstr(buf, str);
396 FREE(&str);
397}
size_t buf_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:238
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:349
+ 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 203 of file serialize.c.

204{
205 unsigned int size = 0;
206 serial_restore_int(&size, d, off);
207
208 if (size == 0)
209 {
210 *c = NULL;
211 return;
212 }
213
214 *c = mutt_mem_malloc(size);
215 memcpy(*c, d + *off, size);
216 if (convert && !mutt_str_is_ascii(*c, size))
217 {
218 char *tmp = mutt_str_dup(*c);
219 if (mutt_ch_convert_string(&tmp, "utf-8", cc_charset(), MUTT_ICONV_NO_FLAGS) == 0)
220 {
221 FREE(c);
222 *c = tmp;
223 }
224 else
225 {
226 FREE(&tmp);
227 }
228 }
229 *off += size;
230}
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
+ 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 635 of file serialize.c.

636{
637 int real_subj_off = 0;
638
639 serial_restore_address(&env->return_path, d, off, convert);
640 serial_restore_address(&env->from, d, off, convert);
641 serial_restore_address(&env->to, d, off, convert);
642 serial_restore_address(&env->cc, d, off, convert);
643 serial_restore_address(&env->bcc, d, off, convert);
644 serial_restore_address(&env->sender, d, off, convert);
645 serial_restore_address(&env->reply_to, d, off, convert);
646 serial_restore_address(&env->mail_followup_to, d, off, convert);
647
648 serial_restore_char(&env->list_post, d, off, convert);
649 serial_restore_char(&env->list_subscribe, d, off, convert);
650 serial_restore_char(&env->list_unsubscribe, d, off, convert);
651
652 const bool c_auto_subscribe = cs_subset_bool(NeoMutt->sub, "auto_subscribe");
653 if (c_auto_subscribe)
655
656 serial_restore_char(&env->subject, d, off, convert);
657 serial_restore_int((unsigned int *) (&real_subj_off), d, off);
658
659 size_t len = mutt_str_len(env->subject);
660 if ((real_subj_off < 0) || (real_subj_off >= len))
661 env->real_subj = NULL;
662 else
663 env->real_subj = env->subject + real_subj_off;
664
665 serial_restore_char(&env->message_id, d, off, false);
666 serial_restore_char(&env->supersedes, d, off, false);
667 serial_restore_char(&env->date, d, off, false);
668 serial_restore_char(&env->x_label, d, off, convert);
669 serial_restore_char(&env->organization, d, off, convert);
670
671 serial_restore_buffer(&env->spam, d, off, convert);
672
673 serial_restore_stailq(&env->references, d, off, false);
674 serial_restore_stailq(&env->in_reply_to, d, off, false);
675 serial_restore_stailq(&env->userhdrs, d, off, convert);
676
677#ifdef USE_NNTP
678 serial_restore_char(&env->xref, d, off, false);
679 serial_restore_char(&env->followup_to, d, off, false);
680 serial_restore_char(&env->x_comment_to, d, off, convert);
681#endif
682}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
void mutt_auto_subscribe(const char *mailto)
Check if user is subscribed to mailing list.
Definition: parse.c:68
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:337
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:269
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ 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 115 of file serialize.c.

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

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

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

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

338{
339 unsigned int counter = 0;
340
341 serial_restore_int(&counter, d, off);
342
343 struct ListNode *np = NULL;
344 while (counter)
345 {
346 np = mutt_list_insert_tail(l, NULL);
347 serial_restore_char(&np->data, d, off, convert);
348 counter--;
349 }
350}
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
+ 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 51 of file serialize.c.

52{
53 void **p = (void **) ptr;
54
55 if (p && (size < 4096))
56 return;
57
58 mutt_mem_realloc(ptr, size);
59}
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
+ Here is the call graph for this function:
+ Here is the caller graph for this function: