ezmlmx 0.68
ezmlmx
Loading...
Searching...
No Matches
decode_hdr.c
Go to the documentation of this file.
1#include "stralloc.h"
2#include "error.h"
3#include "case.h"
4#include "byte.h"
5#include "uint_t.h"
6#include "mime.h"
7#include "errtxt.h"
8#include "idx.h"
9#include "logmsg.h"
10
11#define WHO "decode_hdr"
12
21
22static void die_nomem() { logmsg(WHO,111,FATAL,ERR_NOMEM); }
23
24void decode_hdr(const char *indata,unsigned int n,stralloc *outdata)
25{
26 unsigned int pos;
27 const char *cp,*cpnext,*cpstart,*cpenc,*cptxt,*cpend,*cpafter;
28
29 cpnext = indata;
30 cpafter = cpnext + n;
31 cpstart = cpnext;
32 if (!stralloc_copys(outdata,"")) die_nomem();
33 if (!stralloc_ready(outdata,n)) die_nomem();
34 for (;;) {
35 cpstart = cpstart + byte_chr(cpstart,cpafter-cpstart,'=');
36 if (cpstart == cpafter)
37 break;
38 ++cpstart;
39 if (*cpstart != '?') continue;
40 ++cpstart;
41 cpenc = cpstart + byte_chr(cpstart,cpafter-cpstart,'?');
42 if (cpenc == cpafter) continue;
43 cpenc++;
44 cptxt = cpenc + byte_chr(cpenc,cpafter-cpenc,'?');
45 if (cptxt == cpafter) continue;
46 cptxt++;
47 cpend = cptxt + byte_chr(cptxt,cpafter-cptxt,'?');
48 if (cpend == cpafter || *(cpend + 1) != '=') continue;
49
50 /* We'll decode anything. On lists with many charsets, this may */
51 /* result in unreadable subjects, but that's the case even if */
52 /* no decoding is done. This way, the subject will be optimal */
53 /* for threading, but charset info is lost. We aim to correctly */
54 /* decode us-ascii and all iso-8859/2022 charsets. Exacly how */
55 /* these will be displayed depends on dir/charset. */
56
57 cp = cpnext;
58 /* scrap lwsp between coded strings */
59 while (*cp == ' ' || *cp == '\t')
60 cp++;
61 if (cp != cpstart - 2)
62 if (!stralloc_catb(outdata,cpnext,cpstart - cpnext - 2)) die_nomem();
63 cpnext = cp + 1;
64 cpstart = cpnext;
65 switch (*cpenc) {
66 case 'b': case 'B':
67 pos = outdata->len;
68 decode_b64(cptxt,cpend-cptxt,outdata);
69 cpnext = cpend + 2;
70 cpstart = cpnext;
71 break;
72 case 'q': case 'Q':
73 decode_qp(cptxt,cpend-cptxt,outdata);
74 cpnext = cpend + 2;
75 cpstart = cpnext;
76 break;
77 default: /* shouldn't happen, but let's be reasonable */
78 cpstart = cpend + 2;
79 break;
80 }
81 }
82 if (!stralloc_catb(outdata,cpnext,indata-cpnext+n)) die_nomem();
83}
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 decode_b64(const char *cpfrom, unsigned int n, stralloc *outdata)
Definition decode_b64.c:33
#define outdata
Definition makehash.c:46
const char * cp
Definition ezmlm-cron.c:76
void decode_hdr(const char *indata, unsigned int n, stralloc *outdata)
Definition decode_hdr.c:24
void decode_qp(const char *cpfrom, unsigned int n, stralloc *outdata)
Definition decode_qp.c:35
const char * logmsg(const char *dir, unsigned long num, unsigned long listno, unsigned long subs, int done)
Definition loginfo.c:32