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