ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
encode_qp.c
Go to the documentation of this file.
1#include "errtxt.h"
2#include "mime.h"
3#include "idx.h"
4#include "logmsg.h"
5
6#define WHO "encode_qp"
7
16
17static const char hexchar[16] = "0123456789ABCDEF";
18
19static void die_nomem() { logmsg(WHO,111,FATAL,ERR_NOMEM); }
20
21void encode_qp(const char *indata,unsigned int n,stralloc *outdata)
22{
23 char *cpout;
24 char ch;
25 unsigned int i;
26 const char *cpin;
27
28 cpin = indata;
29 i = 0;
30 /* max 3 outchars per inchar & 2 char newline per 72 chars */
31 if (!stralloc_copys(outdata,"")) die_nomem();
32 if (!stralloc_ready(outdata,n * 3 + n/36)) die_nomem(); /* worst case */
33 cpout = outdata->s;
34 while (n--) {
35 ch = *cpin++;
36 if (ch != ' ' && ch != '\n' && ch != '\t' &&
37 (ch > 126 || ch < 33 || ch == 61)) {
38 *(cpout++) = '=';
39 *(cpout++) = hexchar[(ch >> 4) & 0xf];
40 *(cpout++) = hexchar[ch & 0xf];
41 i += 3;
42 } else {
43 if (ch == '\n')
44 i = 0;
45 *(cpout++) = ch;
46 }
47 if (i >= 72) {
48 *(cpout++) = '=';
49 *(cpout++) = '\n';
50 i = 0;
51 }
52 }
53 outdata->len = (unsigned int) (cpout - outdata->s);
54}
Error messages. If you translate these, I would urge you to keep the English version as well....
#define ERR_NOMEM
Definition errtxt.h:14
void die_nomem()
Definition getconf.c:17
#define WHO
Definition author.c:1
void encode_qp(const char *indata, unsigned int n, stralloc *outdata)
Definition encode_qp.c:21
#define outdata
Definition makehash.c:46
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:32