NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
serialize.c File Reference

Email-object serialiser. More...

#include "config.h"
#include <stdbool.h>
#include <string.h>
#include <sys/types.h>
#include "mutt/lib.h"
#include "address/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "serialize.h"
+ Include dependency graph for serialize.c:

Go to the source code of this file.

Functions

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

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

Function Documentation

◆ lazy_realloc()

void lazy_realloc ( void *  ptr,
size_t  size 
)

Reallocate some memory.

Parameters
ptrPointer to resize
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 *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:

◆ serial_dump_int()

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

Pack an integer into a binary blob.

Parameters
iInteger to save
dBinary blob to add to
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 }
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_uint32_t()

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

Pack a uint32_t into a binary blob.

Parameters
suint32_t to save
dBinary blob to add to
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 }
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_restore_int()

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

Unpack an integer from a binary blob.

Parameters
iInteger to write to
dBinary blob to read from
offOffset into the blob

Definition at line 98 of file serialize.c.

99 {
100  memcpy(i, d + *off, sizeof(int));
101  (*off) += sizeof(int);
102 }
+ 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
suint32_t to write to
dBinary blob to read from
offOffset into the blob

Definition at line 110 of file serialize.c.

111 {
112  memcpy(s, d + *off, sizeof(uint32_t));
113  (*off) += sizeof(uint32_t);
114 }
+ Here is the caller graph for this function:

◆ serial_dump_char_size()

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

Pack a fixed-length string into a binary blob.

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

Definition at line 125 of file serialize.c.

127 {
128  char *p = c;
129 
130  if (!c)
131  {
132  size = 0;
133  d = serial_dump_int(size, d, off);
134  return d;
135  }
136 
137  if (convert && !mutt_str_is_ascii(c, size))
138  {
139  p = mutt_strn_dup(c, size);
140  const char *const c_charset = cs_subset_string(NeoMutt->sub, "charset");
141  if (mutt_ch_convert_string(&p, c_charset, "utf-8", MUTT_ICONV_NO_FLAGS) == 0)
142  {
143  size = mutt_str_len(p) + 1;
144  }
145  }
146 
147  d = serial_dump_int(size, d, off);
148  lazy_realloc(&d, *off + size);
149  memcpy(d + *off, p, size);
150  *off += size;
151 
152  if (p != c)
153  FREE(&p);
154 
155  return d;
156 }
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
Definition: charset.c:758
#define MUTT_ICONV_NO_FLAGS
No flags are set.
Definition: charset.h:71
Container for Accounts, Notifications.
Definition: neomutt.h:36
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
Definition: string.c:548
bool mutt_str_is_ascii(const char *str, size_t len)
Is a string ASCII (7-bit)?
Definition: string.c:981
unsigned char * serial_dump_int(unsigned int i, unsigned char *d, int *off)
Pack an integer into a binary blob.
Definition: serialize.c:67
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
void lazy_realloc(void *ptr, size_t size)
Reallocate some memory.
Definition: serialize.c:50
#define FREE(x)
Definition: memory.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_char()

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

Pack a variable-length string into a binary blob.

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

Definition at line 166 of file serialize.c.

167 {
168  return serial_dump_char_size(c, mutt_str_len(c) + 1, d, off, convert);
169 }
unsigned char * serial_dump_char_size(char *c, ssize_t size, unsigned char *d, int *off, bool convert)
Pack a fixed-length string into a binary blob.
Definition: serialize.c:125
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
+ 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
[out]offOffset into the blob
[in]convertIf true, the strings will be converted to utf-8

Definition at line 178 of file serialize.c.

179 {
180  unsigned int size;
181  serial_restore_int(&size, d, off);
182 
183  if (size == 0)
184  {
185  *c = NULL;
186  return;
187  }
188 
189  *c = mutt_mem_malloc(size);
190  memcpy(*c, d + *off, size);
191  if (convert && !mutt_str_is_ascii(*c, size))
192  {
193  char *tmp = mutt_str_dup(*c);
194  const char *const c_charset = cs_subset_string(NeoMutt->sub, "charset");
195  if (mutt_ch_convert_string(&tmp, "utf-8", c_charset, MUTT_ICONV_NO_FLAGS) == 0)
196  {
197  FREE(c);
198  *c = tmp;
199  }
200  else
201  {
202  FREE(&tmp);
203  }
204  }
205  *off += size;
206 }
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
int mutt_ch_convert_string(char **ps, const char *from, const char *to, uint8_t flags)
Convert a string between encodings.
Definition: charset.c:758
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from a binary blob.
Definition: serialize.c:98
#define MUTT_ICONV_NO_FLAGS
No flags are set.
Definition: charset.h:71
Container for Accounts, Notifications.
Definition: neomutt.h:36
bool mutt_str_is_ascii(const char *str, size_t len)
Is a string ASCII (7-bit)?
Definition: string.c:981
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
#define FREE(x)
Definition: memory.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_address()

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

Pack an Address into a binary blob.

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

Definition at line 216 of file serialize.c.

218 {
219  unsigned int counter = 0;
220  unsigned int start_off = *off;
221 
222  d = serial_dump_int(0xdeadbeef, d, off);
223 
224  struct Address *a = NULL;
225  TAILQ_FOREACH(a, al, entries)
226  {
227  d = serial_dump_char(a->personal, d, off, convert);
228  d = serial_dump_char(a->mailbox, d, off, false);
229  d = serial_dump_int(a->group, d, off);
230  counter++;
231  }
232 
233  memcpy(d + start_off, &counter, sizeof(int));
234 
235  return d;
236 }
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
unsigned char * serial_dump_int(unsigned int i, unsigned char *d, int *off)
Pack an integer into a binary blob.
Definition: serialize.c:67
unsigned char * serial_dump_char(char *c, unsigned char *d, int *off, bool convert)
Pack a variable-length string into a binary blob.
Definition: serialize.c:166
char * personal
Real name of address.
Definition: address.h:37
bool group
Group mailbox?
Definition: address.h:39
+ 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
[out]offOffset into the blob
[in]convertIf true, the strings will be converted from utf-8

Definition at line 245 of file serialize.c.

247 {
248  unsigned int counter = 0;
249  unsigned int g = 0;
250 
251  serial_restore_int(&counter, d, off);
252 
253  while (counter)
254  {
255  struct Address *a = mutt_addr_new();
256  serial_restore_char(&a->personal, d, off, convert);
257  serial_restore_char(&a->mailbox, d, off, false);
258  serial_restore_int(&g, d, off);
259  a->group = !!g;
260  mutt_addrlist_append(al, a);
261  counter--;
262  }
263 }
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:178
struct Address * mutt_addr_new(void)
Create a new Address.
Definition: address.c:385
An email address.
Definition: address.h:35
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from a binary blob.
Definition: serialize.c:98
char * mailbox
Mailbox and host address.
Definition: address.h:38
char * personal
Real name of address.
Definition: address.h:37
bool group
Group mailbox?
Definition: address.h:39
void mutt_addrlist_append(struct AddressList *al, struct Address *a)
Append an Address to an AddressList.
Definition: address.c:1490
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_stailq()

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

Pack a STAILQ into a binary blob.

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

Definition at line 273 of file serialize.c.

274 {
275  unsigned int counter = 0;
276  unsigned int start_off = *off;
277 
278  d = serial_dump_int(0xdeadbeef, d, off);
279 
280  struct ListNode *np = NULL;
281  STAILQ_FOREACH(np, l, entries)
282  {
283  d = serial_dump_char(np->data, d, off, convert);
284  counter++;
285  }
286 
287  memcpy(d + start_off, &counter, sizeof(int));
288 
289  return d;
290 }
unsigned char * serial_dump_int(unsigned int i, unsigned char *d, int *off)
Pack an integer into a binary blob.
Definition: serialize.c:67
unsigned char * serial_dump_char(char *c, unsigned char *d, int *off, bool convert)
Pack a variable-length string into a binary blob.
Definition: serialize.c:166
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
char * data
String.
Definition: list.h:36
A List node for strings.
Definition: list.h:34
+ 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
lList to add to
dBinary blob to read from
offOffset into the blob
convertIf true, the strings will be converted from utf-8

Definition at line 299 of file serialize.c.

300 {
301  unsigned int counter;
302 
303  serial_restore_int(&counter, d, off);
304 
305  struct ListNode *np = NULL;
306  while (counter)
307  {
308  np = mutt_list_insert_tail(l, NULL);
309  serial_restore_char(&np->data, d, off, convert);
310  counter--;
311  }
312 }
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:178
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from a binary blob.
Definition: serialize.c:98
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
char * data
String.
Definition: list.h:36
A List node for strings.
Definition: list.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_buffer()

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

Pack a Buffer into a binary blob.

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

Definition at line 322 of file serialize.c.

323 {
324  if (!buf)
325  {
326  d = serial_dump_int(0, d, off);
327  return d;
328  }
329 
330  d = serial_dump_int(1, d, off);
331 
332  d = serial_dump_char_size(buf->data, buf->dsize + 1, d, off, convert);
333  d = serial_dump_int(buf->dptr - buf->data, d, off);
334  d = serial_dump_int(buf->dsize, d, off);
335 
336  return d;
337 }
size_t dsize
Length of data.
Definition: buffer.h:37
unsigned char * serial_dump_int(unsigned int i, unsigned char *d, int *off)
Pack an integer into a binary blob.
Definition: serialize.c:67
char * dptr
Current read/write position.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:35
unsigned char * serial_dump_char_size(char *c, ssize_t size, unsigned char *d, int *off, bool convert)
Pack a fixed-length string into a binary blob.
Definition: serialize.c:125
+ 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
[out]offOffset into the blob
[in]convertIf true, the strings will be converted from utf-8

Definition at line 346 of file serialize.c.

347 {
348  unsigned int used;
349  unsigned int offset;
350  serial_restore_int(&used, d, off);
351  if (!used)
352  {
353  return;
354  }
355 
356  serial_restore_char(&buf->data, d, off, convert);
357  serial_restore_int(&offset, d, off);
358  mutt_buffer_seek(buf, offset);
359  serial_restore_int(&used, d, off);
360  buf->dsize = used;
361 }
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:178
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from a binary blob.
Definition: serialize.c:98
size_t dsize
Length of data.
Definition: buffer.h:37
char * data
Pointer to data.
Definition: buffer.h:35
void mutt_buffer_seek(struct Buffer *buf, size_t offset)
set current read/write position to offset from beginning
Definition: buffer.c:466
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_parameter()

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

Pack a Parameter into a binary blob.

Parameters
plParameter to pack
dBinary blob to add to
offOffset into the blob
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  unsigned int counter = 0;
375  unsigned int start_off = *off;
376 
377  d = serial_dump_int(0xdeadbeef, d, off);
378 
379  struct Parameter *np = NULL;
380  TAILQ_FOREACH(np, pl, entries)
381  {
382  d = serial_dump_char(np->attribute, d, off, false);
383  d = serial_dump_char(np->value, d, off, convert);
384  counter++;
385  }
386 
387  memcpy(d + start_off, &counter, sizeof(int));
388 
389  return d;
390 }
char * attribute
Parameter name.
Definition: parameter.h:34
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
unsigned char * serial_dump_int(unsigned int i, unsigned char *d, int *off)
Pack an integer into a binary blob.
Definition: serialize.c:67
unsigned char * serial_dump_char(char *c, unsigned char *d, int *off, bool convert)
Pack a variable-length string into a binary blob.
Definition: serialize.c:166
char * value
Parameter value.
Definition: parameter.h:35
Attribute associated with a MIME part.
Definition: parameter.h:32
+ Here is the call graph for this function:
+ 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
plStore the unpacked Parameter here
dBinary blob to read from
offOffset into the blob
convertIf true, the strings will be converted from utf-8

Definition at line 399 of file serialize.c.

401 {
402  unsigned int counter;
403 
404  serial_restore_int(&counter, d, off);
405 
406  struct Parameter *np = NULL;
407  while (counter)
408  {
409  np = mutt_param_new();
410  serial_restore_char(&np->attribute, d, off, false);
411  serial_restore_char(&np->value, d, off, convert);
412  TAILQ_INSERT_TAIL(pl, np, entries);
413  counter--;
414  }
415 }
char * attribute
Parameter name.
Definition: parameter.h:34
struct Parameter * mutt_param_new(void)
Create a new Parameter.
Definition: parameter.c:39
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:178
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from a binary blob.
Definition: serialize.c:98
#define TAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:809
char * value
Parameter value.
Definition: parameter.h:35
Attribute associated with a MIME part.
Definition: parameter.h:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_body()

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

Pack an Body into a binary blob.

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

Definition at line 425 of file serialize.c.

426 {
427  struct Body nb;
428 
429  memcpy(&nb, c, sizeof(struct Body));
430 
431  /* some fields are not safe to cache */
432  nb.content = NULL;
433  nb.charset = NULL;
434  nb.next = NULL;
435  nb.parts = NULL;
436  nb.email = NULL;
437  nb.aptr = NULL;
438  nb.mime_headers = NULL;
439  nb.language = NULL;
440 
441  lazy_realloc(&d, *off + sizeof(struct Body));
442  memcpy(d + *off, &nb, sizeof(struct Body));
443  *off += sizeof(struct Body);
444 
445  d = serial_dump_char(nb.xtype, d, off, false);
446  d = serial_dump_char(nb.subtype, d, off, false);
447 
448  d = serial_dump_parameter(&nb.parameter, d, off, convert);
449 
450  d = serial_dump_char(nb.description, d, off, convert);
451  d = serial_dump_char(nb.form_name, d, off, convert);
452  d = serial_dump_char(nb.filename, d, off, convert);
453  d = serial_dump_char(nb.d_filename, d, off, convert);
454 
455  return d;
456 }
The body of an email.
Definition: body.h:34
unsigned char * serial_dump_char(char *c, unsigned char *d, int *off, bool convert)
Pack a variable-length string into a binary blob.
Definition: serialize.c:166
void lazy_realloc(void *ptr, size_t size)
Reallocate some memory.
Definition: serialize.c:50
unsigned char * serial_dump_parameter(struct ParameterList *pl, unsigned char *d, int *off, bool convert)
Pack a Parameter into a binary blob.
Definition: serialize.c:371
+ 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 c,
const unsigned char *  d,
int *  off,
bool  convert 
)

Unpack a Body from a binary blob.

Parameters
cStore the unpacked Body here
dBinary blob to read from
offOffset into the blob
convertIf true, the strings will be converted from utf-8

Definition at line 465 of file serialize.c.

466 {
467  memcpy(c, d + *off, sizeof(struct Body));
468  *off += sizeof(struct Body);
469  c->language = NULL;
470 
471  serial_restore_char(&c->xtype, d, off, false);
472  serial_restore_char(&c->subtype, d, off, false);
473 
474  TAILQ_INIT(&c->parameter);
475  serial_restore_parameter(&c->parameter, d, off, convert);
476 
477  serial_restore_char(&c->description, d, off, convert);
478  serial_restore_char(&c->form_name, d, off, convert);
479  serial_restore_char(&c->filename, d, off, convert);
480  serial_restore_char(&c->d_filename, d, off, convert);
481 }
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:399
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:46
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:178
char * form_name
Content-Disposition form-data name param.
Definition: body.h:41
The body of an email.
Definition: body.h:34
#define TAILQ_INIT(head)
Definition: queue.h:765
char * subtype
content-type subtype
Definition: body.h:37
char * xtype
content-type if x-unknown
Definition: body.h:36
char * description
content-description
Definition: body.h:40
char * language
content-language (RFC8255)
Definition: body.h:38
char * d_filename
filename to be used for the content-disposition header.
Definition: body.h:47
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ serial_dump_envelope()

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

Pack an Envelope into a binary blob.

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

Definition at line 491 of file serialize.c.

493 {
494  d = serial_dump_address(&env->return_path, d, off, convert);
495  d = serial_dump_address(&env->from, d, off, convert);
496  d = serial_dump_address(&env->to, d, off, convert);
497  d = serial_dump_address(&env->cc, d, off, convert);
498  d = serial_dump_address(&env->bcc, d, off, convert);
499  d = serial_dump_address(&env->sender, d, off, convert);
500  d = serial_dump_address(&env->reply_to, d, off, convert);
501  d = serial_dump_address(&env->mail_followup_to, d, off, convert);
502 
503  d = serial_dump_char(env->list_post, d, off, convert);
504  d = serial_dump_char(env->subject, d, off, convert);
505 
506  if (env->real_subj)
507  d = serial_dump_int(env->real_subj - env->subject, d, off);
508  else
509  d = serial_dump_int(-1, d, off);
510 
511  d = serial_dump_char(env->message_id, d, off, false);
512  d = serial_dump_char(env->supersedes, d, off, false);
513  d = serial_dump_char(env->date, d, off, false);
514  d = serial_dump_char(env->x_label, d, off, convert);
515  d = serial_dump_char(env->organization, d, off, convert);
516 
517  d = serial_dump_buffer(&env->spam, d, off, convert);
518 
519  d = serial_dump_stailq(&env->references, d, off, false);
520  d = serial_dump_stailq(&env->in_reply_to, d, off, false);
521  d = serial_dump_stailq(&env->userhdrs, d, off, convert);
522 
523 #ifdef USE_NNTP
524  d = serial_dump_char(env->xref, d, off, false);
525  d = serial_dump_char(env->followup_to, d, off, false);
526  d = serial_dump_char(env->x_comment_to, d, off, convert);
527 #endif
528 
529  return d;
530 }
struct AddressList mail_followup_to
Email&#39;s &#39;mail-followup-to&#39;.
Definition: envelope.h:63
struct AddressList reply_to
Email&#39;s &#39;reply-to&#39;.
Definition: envelope.h:62
char * supersedes
Supersedes header.
Definition: envelope.h:70
struct AddressList bcc
Email&#39;s &#39;Bcc&#39; list.
Definition: envelope.h:60
char * xref
List of cross-references.
Definition: envelope.h:76
char * date
Sent date.
Definition: envelope.h:71
unsigned char * serial_dump_address(struct AddressList *al, unsigned char *d, int *off, bool convert)
Pack an Address into a binary blob.
Definition: serialize.c:216
unsigned char * serial_dump_buffer(struct Buffer *buf, unsigned char *d, int *off, bool convert)
Pack a Buffer into a binary blob.
Definition: serialize.c:322
struct ListHead userhdrs
user defined headers
Definition: envelope.h:83
char * real_subj
Offset of the real subject.
Definition: envelope.h:67
struct ListHead in_reply_to
in-reply-to header content
Definition: envelope.h:82
char * message_id
Message ID.
Definition: envelope.h:69
unsigned char * serial_dump_stailq(struct ListHead *l, unsigned char *d, int *off, bool convert)
Pack a STAILQ into a binary blob.
Definition: serialize.c:273
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
struct AddressList cc
Email&#39;s &#39;Cc&#39; list.
Definition: envelope.h:59
char * x_comment_to
List of &#39;X-comment-to&#39; fields.
Definition: envelope.h:78
unsigned char * serial_dump_int(unsigned int i, unsigned char *d, int *off)
Pack an integer into a binary blob.
Definition: serialize.c:67
unsigned char * serial_dump_char(char *c, unsigned char *d, int *off, bool convert)
Pack a variable-length string into a binary blob.
Definition: serialize.c:166
char * list_post
This stores a mailto URL, or nothing.
Definition: envelope.h:65
char * subject
Email&#39;s subject.
Definition: envelope.h:66
struct AddressList return_path
Return path for the Email.
Definition: envelope.h:56
char * followup_to
List of &#39;followup-to&#39; fields.
Definition: envelope.h:77
char * organization
Organisation header.
Definition: envelope.h:73
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
struct AddressList sender
Email&#39;s sender.
Definition: envelope.h:61
struct ListHead references
message references (in reverse order)
Definition: envelope.h:81
char * x_label
X-Label.
Definition: envelope.h:72
struct Buffer spam
Spam header.
Definition: envelope.h:80
+ 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
envStore the unpacked Envelope here
dBinary blob to read from
offOffset into the blob
convertIf true, the strings will be converted from utf-8

Definition at line 539 of file serialize.c.

540 {
541  int real_subj_off;
542 
543  serial_restore_address(&env->return_path, d, off, convert);
544  serial_restore_address(&env->from, d, off, convert);
545  serial_restore_address(&env->to, d, off, convert);
546  serial_restore_address(&env->cc, d, off, convert);
547  serial_restore_address(&env->bcc, d, off, convert);
548  serial_restore_address(&env->sender, d, off, convert);
549  serial_restore_address(&env->reply_to, d, off, convert);
550  serial_restore_address(&env->mail_followup_to, d, off, convert);
551 
552  serial_restore_char(&env->list_post, d, off, convert);
553 
554  const bool c_auto_subscribe = cs_subset_bool(NeoMutt->sub, "auto_subscribe");
555  if (c_auto_subscribe)
557 
558  serial_restore_char(&env->subject, d, off, convert);
559  serial_restore_int((unsigned int *) (&real_subj_off), d, off);
560 
561  if (real_subj_off >= 0)
562  env->real_subj = env->subject + real_subj_off;
563  else
564  env->real_subj = NULL;
565 
566  serial_restore_char(&env->message_id, d, off, false);
567  serial_restore_char(&env->supersedes, d, off, false);
568  serial_restore_char(&env->date, d, off, false);
569  serial_restore_char(&env->x_label, d, off, convert);
570  serial_restore_char(&env->organization, d, off, convert);
571 
572  serial_restore_buffer(&env->spam, d, off, convert);
573 
574  serial_restore_stailq(&env->references, d, off, false);
575  serial_restore_stailq(&env->in_reply_to, d, off, false);
576  serial_restore_stailq(&env->userhdrs, d, off, convert);
577 
578 #ifdef USE_NNTP
579  serial_restore_char(&env->xref, d, off, false);
580  serial_restore_char(&env->followup_to, d, off, false);
581  serial_restore_char(&env->x_comment_to, d, off, convert);
582 #endif
583 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
struct AddressList mail_followup_to
Email&#39;s &#39;mail-followup-to&#39;.
Definition: envelope.h:63
struct AddressList reply_to
Email&#39;s &#39;reply-to&#39;.
Definition: envelope.h:62
char * supersedes
Supersedes header.
Definition: envelope.h:70
struct AddressList bcc
Email&#39;s &#39;Bcc&#39; list.
Definition: envelope.h:60
char * xref
List of cross-references.
Definition: envelope.h:76
char * date
Sent date.
Definition: envelope.h:71
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:178
struct ListHead userhdrs
user defined headers
Definition: envelope.h:83
char * real_subj
Offset of the real subject.
Definition: envelope.h:67
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from a binary blob.
Definition: serialize.c:98
Container for Accounts, Notifications.
Definition: neomutt.h:36
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:346
struct ListHead in_reply_to
in-reply-to header content
Definition: envelope.h:82
char * message_id
Message ID.
Definition: envelope.h:69
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
struct AddressList cc
Email&#39;s &#39;Cc&#39; list.
Definition: envelope.h:59
char * x_comment_to
List of &#39;X-comment-to&#39; fields.
Definition: envelope.h:78
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:245
char * list_post
This stores a mailto URL, or nothing.
Definition: envelope.h:65
char * subject
Email&#39;s subject.
Definition: envelope.h:66
struct AddressList return_path
Return path for the Email.
Definition: envelope.h:56
char * followup_to
List of &#39;followup-to&#39; fields.
Definition: envelope.h:77
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:299
char * organization
Organisation header.
Definition: envelope.h:73
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
struct AddressList sender
Email&#39;s sender.
Definition: envelope.h:61
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct ListHead references
message references (in reverse order)
Definition: envelope.h:81
char * x_label
X-Label.
Definition: envelope.h:72
struct Buffer spam
Spam header.
Definition: envelope.h:80
void mutt_auto_subscribe(const char *mailto)
Check if user is subscribed to mailing list.
Definition: parse.c:69
+ 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
tagsTagList to pack
dBinary blob to add to
offOffset into the blob
Return values
ptrEnd of the newly packed binary

Definition at line 592 of file serialize.c.

593 {
594  unsigned int counter = 0;
595  unsigned int start_off = *off;
596 
597  d = serial_dump_int(0xdeadbeef, d, off);
598 
599  struct Tag *t = NULL;
600  STAILQ_FOREACH(t, tags, entries)
601  {
602  d = serial_dump_char(t->name, d, off, false);
603  counter++;
604  }
605 
606  memcpy(d + start_off, &counter, sizeof(int));
607 
608  return d;
609 }
LinkedList Tag Element.
Definition: tags.h:37
char * name
Tag name.
Definition: tags.h:39
unsigned char * serial_dump_int(unsigned int i, unsigned char *d, int *off)
Pack an integer into a binary blob.
Definition: serialize.c:67
unsigned char * serial_dump_char(char *c, unsigned char *d, int *off, bool convert)
Pack a variable-length string into a binary blob.
Definition: serialize.c:166
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
+ 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
tagsTagList to unpack
dBinary blob to add to
offOffset into the blob

Definition at line 617 of file serialize.c.

618 {
619  unsigned int counter = 0;
620 
621  serial_restore_int(&counter, d, off);
622 
623  while (counter)
624  {
625  char *name = NULL;
626  serial_restore_char(&name, d, off, false);
627  driver_tags_add(tags, name);
628  counter--;
629  }
630 }
void driver_tags_add(struct TagList *list, char *new_tag)
Add a tag to header.
Definition: tags.c:81
char * name
Tag name.
Definition: tags.h:39
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:178
void serial_restore_int(unsigned int *i, const unsigned char *d, int *off)
Unpack an integer from a binary blob.
Definition: serialize.c:98
+ Here is the call graph for this function:
+ Here is the caller graph for this function: