ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
decode_qp.c
Go to the documentation of this file.
1#include "stralloc.h"
2#include "errtxt.h"
3#include "mime.h"
4#include "idx.h"
5#include "logmsg.h"
6
7#define WHO "decode_qp"
8
19
20static const char char16table[128] = {
21 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
22 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
23 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
24 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1, -1,-1,-1,-1,
25 -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1,
26 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1,
27 -1,10,11,12, 13,14,15,-1, -1,-1,-1,-1, -1,-1,-1,-1,
28 -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1, -1,-1,-1,-1
29};
30
31#define char16enc(c) (((c) & 0x80) ? -1 : char16table[(int)(c)])
32
33static void die_nomem() { logmsg(WHO,111,FATAL,ERR_NOMEM); }
34
35void decode_qp(const char *cpfrom,unsigned int n,stralloc *outdata)
36{
37 const char *cp,*cpnext;
38 char ch1, ch2; /* need to be signed */
39 char ch;
40
41 cp = cpfrom;
42 cpnext = cp + n;
43 if (!stralloc_readyplus(outdata,n)) die_nomem();
44
45 while (cp < cpnext) {
46 ch = *cp++;
47 if (ch == '_') ch = ' '; /* '_' -> space */
48 if (ch == '=') { /* "=F8" -> '\xF8' */
49 if (*cp == '\n') { /* skip soft line break */
50 ++cp;
51 continue;
52 }
53 ch1 = char16enc(*cp); ++cp;
54 if (cp >= cpnext) break;
55 ch2 = char16enc(*cp); ++cp;
56 if (ch1 >= 0 && ch2 >= 0) { /* ignore illegals */
57 ch = (ch1 << 4 | ch2) & 0xff;
58 }
59 }
60 if (!stralloc_append(outdata,&ch)) die_nomem();
61 }
62}
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
#define outdata
Definition makehash.c:46
const char * cp
Definition ezmlm-cron.c:76
void decode_qp(const char *cpfrom, unsigned int n, stralloc *outdata)
Definition decode_qp.c:35
#define char16enc(c)
Definition decode_qp.c:31
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:32