Use the same mh_hostname() function from test/common.h in mhsign(1)
[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 quoted-pair sequences from RFC-5322 atoms.
14 **
15 ** Currently the actual algorithm is simpler than it technically should
16 ** be: any quotes are simply eaten, unless they're preceded by the escape
17 ** character (\).  This seems to be sufficient for our needs for now.
18 **
19 ** Arguments:
20 **
21 ** input      - The input string
22 ** output     - The output string; is assumed to have at least as much
23 **              room as the input string.  At worst the output string will
24 **              be the same size as the input string; it might be smaller.
25 */
26 void
27 unquote_string(const char *input, char *output)
28 {
29         int inpos = 0;
30         int outpos = 0;
31
32         while (input[inpos] != '\0') {
33                 switch (input[inpos]) {
34                 case '\\':
35                         inpos++;
36                         if (input[inpos] != '\0')
37                                 output[outpos++] = input[inpos++];
38                         break;
39                 case '"':
40                         inpos++;
41                         break;
42                 default:
43                         output[outpos++] = input[inpos++];
44                         break;
45                 }
46         }
47         output[outpos] = '\0';
48 }