1 /*$Id: decodeHDR.c,v 1.2 1998/02/28 19:03:02 lindberg Exp $*/
2 /*$Name: ezmlm-idx-040 $*/
13 static void die_nomem(fatal
)
16 strerr_die2x(111,fatal
,ERR_NOMEM
);
19 void decodeHDR(indata
,n
,outdata
,charset
,fatal
)
26 /* decodes indata depending on charset. May put '\n' and '\0' into out */
27 /* data and can take them as indata. */
30 char *cp
,*cpnext
,*cpstart
,*cpenc
,*cptxt
,*cpend
,*cpafter
;
35 if (!stralloc_copys(outdata
,"")) die_nomem(fatal
);
36 if (!stralloc_ready(outdata
,n
)) die_nomem(fatal
);
38 cpstart
= cpstart
+ byte_chr(cpstart
,cpafter
-cpstart
,'=');
39 if (cpstart
== cpafter
)
45 cpenc
= cpstart
+ byte_chr(cpstart
,cpafter
-cpstart
,'?');
49 cptxt
= cpenc
+ byte_chr(cpenc
,cpafter
-cpenc
,'?');
53 cpend
= cptxt
+ byte_chr(cptxt
,cpafter
-cptxt
,'?');
54 if (cpend
== cpafter
|| *(cpend
+ 1) != '=')
56 /* We'll decode anything. On lists with many charsets, this may */
57 /* result in unreadable subjects, but that's the case even if */
58 /* no decoding is done. This way, the subject will be optimal */
59 /* for threading, but charset info is lost. We aim to correctly */
60 /* decode us-ascii and all iso-8859/2022 charsets. Exacly how */
61 /* these will be displayed depends on dir/charset. */
63 /* scrap lwsp between coded strings */
64 while (*cp
== ' ' || *cp
== '\t')
66 if (cp
!= cpstart
- 2)
67 if (!stralloc_catb(outdata
,cpnext
, cpstart
- cpnext
- 2))
75 decodeB(cptxt
,cpend
-cptxt
,outdata
,2,fatal
);
81 decodeQ(cptxt
,cpend
-cptxt
,outdata
,fatal
);
85 default: /* shouldn't happen, but let's be reasonable */
90 if (!stralloc_catb(outdata
,cpnext
,indata
-cpnext
+n
)) die_nomem(fatal
);