]> diplodocus.org Git - nmh/blob - sbr/unquote.c
uip/mhcachesbr.c: Move exported symbols to existing h/mhcachesbr.h.
[nmh] / sbr / unquote.c
1 /* unquote.c -- Handle quote removal and quoted-pair strings on
2 * RFC 2822-5322 atoms.
3 *
4 * This code is Copyright (c) 2013, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
7 */
8
9 #include <h/mh.h>
10
11 /*
12 * Remove quotes (and handle escape strings) from RFC 5322 quoted-strings.
13 *
14 * Since we never add characters to the string, the output buffer is assumed
15 * to have at least as many characters as the input string.
16 *
17 */
18
19 void
20 unquote_string(const char *input, char *output)
21 {
22 int n = 0; /* n is the position in the input buffer */
23 int m = 0; /* m is the position in the output buffer */
24
25 while ( input[n] != '\0') {
26 switch ( input[n] ) {
27 case '\\':
28 n++;
29 if ( input[n] != '\0')
30 output[m++] = input[n++];
31 break;
32 case '"':
33 n++;
34 break;
35 default:
36 output[m++] = input[n++];
37 break;
38 }
39 }
40
41 output[m] = '\0';
42 }