NeoMutt  2022-04-29-323-g5fcc6c
Teaching an old dog new tricks
DOXYGEN
Mime Encoder API

Prototype for an encoding function. More...

Functions

static size_t b_encoder (char *str, const char *buf, size_t buflen, const char *tocode)
 Base64 Encode a string - Implements encoder_t -. More...
 
static size_t q_encoder (char *str, const char *buf, size_t buflen, const char *tocode)
 Quoted-printable Encode a string - Implements encoder_t -. More...
 

Detailed Description

Prototype for an encoding function.

Parameters
strString to encode
bufBuffer for result
buflenLength of buffer
tocodeCharacter encoding
Return values
numBytes written to buffer

Function Documentation

◆ b_encoder()

static size_t b_encoder ( char *  str,
const char *  buf,
size_t  buflen,
const char *  tocode 
)
static

Base64 Encode a string - Implements encoder_t -.

Definition at line 69 of file rfc2047.c.

70{
71 char *s0 = str;
72
73 memcpy(str, "=?", 2);
74 str += 2;
75 memcpy(str, tocode, strlen(tocode));
76 str += strlen(tocode);
77 memcpy(str, "?B?", 3);
78 str += 3;
79
80 while (buflen)
81 {
82 char encoded[11] = { 0 };
83 size_t rc;
84 size_t in_len = MIN(3, buflen);
85
86 rc = mutt_b64_encode(buf, in_len, encoded, sizeof(encoded));
87 for (size_t i = 0; i < rc; i++)
88 *str++ = encoded[i];
89
90 buflen -= in_len;
91 buf += in_len;
92 }
93
94 memcpy(str, "?=", 2);
95 str += 2;
96 return str - s0;
97}
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:88
#define MIN(a, b)
Definition: memory.h:31
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ q_encoder()

static size_t q_encoder ( char *  str,
const char *  buf,
size_t  buflen,
const char *  tocode 
)
static

Quoted-printable Encode a string - Implements encoder_t -.

Definition at line 102 of file rfc2047.c.

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