NeoMutt  2024-10-02-37-gfa9146
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
Mime Encoder API

Prototype for an encoding function. More...

Functions

static size_t b_encoder (char *res, const char *src, size_t srclen, const char *tocode)
 Base64 Encode a string - Implements encoder_t -.
 
static size_t q_encoder (char *res, const char *src, size_t srclen, const char *tocode)
 Quoted-printable Encode a string - Implements encoder_t -.
 

Detailed Description

Prototype for an encoding function.

Parameters
resBuffer for the result
srcString to encode
srclenLength of string to encode
tocodeCharacter encoding
Return values
numBytes written to buffer

Function Documentation

◆ b_encoder()

static size_t b_encoder ( char *  res,
const char *  src,
size_t  srclen,
const char *  tocode 
)
static

Base64 Encode a string - Implements encoder_t -.

Definition at line 70 of file rfc2047.c.

71{
72 char *s0 = res;
73
74 memcpy(res, "=?", 2);
75 res += 2;
76 memcpy(res, tocode, strlen(tocode));
77 res += strlen(tocode);
78 memcpy(res, "?B?", 3);
79 res += 3;
80
81 while (srclen)
82 {
83 char encoded[11] = { 0 };
84 size_t rc;
85 size_t in_len = MIN(3, srclen);
86
87 rc = mutt_b64_encode(src, in_len, encoded, sizeof(encoded));
88 for (size_t i = 0; i < rc; i++)
89 *res++ = encoded[i];
90
91 srclen -= in_len;
92 src += in_len;
93 }
94
95 memcpy(res, "?=", 2);
96 res += 2;
97 return res - s0;
98}
size_t mutt_b64_encode(const char *in, size_t inlen, char *out, size_t outlen)
Convert raw bytes to null-terminated base64 string.
Definition: base64.c:87
#define MIN(a, b)
Definition: memory.h:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ q_encoder()

static size_t q_encoder ( char *  res,
const char *  src,
size_t  srclen,
const char *  tocode 
)
static

Quoted-printable Encode a string - Implements encoder_t -.

Definition at line 103 of file rfc2047.c.

104{
105 static const char hex[] = "0123456789ABCDEF";
106 char *s0 = res;
107
108 memcpy(res, "=?", 2);
109 res += 2;
110 memcpy(res, tocode, strlen(tocode));
111 res += strlen(tocode);
112 memcpy(res, "?Q?", 3);
113 res += 3;
114 while (srclen--)
115 {
116 unsigned char c = *src++;
117 if (c == ' ')
118 {
119 *res++ = '_';
120 }
121 else if ((c >= 0x7f) || (c < 0x20) || (c == '_') || strchr(MimeSpecials, c))
122 {
123 *res++ = '=';
124 *res++ = hex[(c & 0xf0) >> 4];
125 *res++ = hex[c & 0x0f];
126 }
127 else
128 {
129 *res++ = c;
130 }
131 }
132 memcpy(res, "?=", 2);
133 res += 2;
134 return res - s0;
135}
const char MimeSpecials[]
Characters that need special treatment in MIME.
Definition: mime.c:67
+ Here is the caller graph for this function: