X-Git-Url: http://git.marmaro.de/?a=blobdiff_plain;f=sbr%2Funquote.c;fp=sbr%2Funquote.c;h=f9fa9112fccfd9f6fab7ab566ee04babda9d077c;hb=4c30d368bca8b3f108a7e86a5b890e33470cdebf;hp=0000000000000000000000000000000000000000;hpb=f16ae6eedeacce086d513e10461938c1650e265e;p=mmh diff --git a/sbr/unquote.c b/sbr/unquote.c new file mode 100644 index 0000000..f9fa911 --- /dev/null +++ b/sbr/unquote.c @@ -0,0 +1,45 @@ +/* + * unquote.c: Handle quote removal and quoted-pair strings on + * RFC 2822-5322 atoms. + * + * This code is Copyright (c) 2013, by the authors of nmh. See the + * COPYRIGHT file in the root directory of the nmh distribution for + * complete copyright information. + */ + +#include + +/* + * Remove quotes (and handle escape strings) from RFC 5322 quoted-strings. + * + * Since we never add characters to the string, the output buffer is assumed + * to have at least as many characters as the input string. + * + */ + +void +unquote_string(const char *input, char *output) +{ + int n = 0; /* n is the position in the input buffer */ + int m = 0; /* m is the position in the output buffer */ + + while ( input[n] != '\0') { + switch ( input[n] ) { + case '\\': + n++; + if ( input[n] != '\0') + output[m++] = input[n++]; + break; + case '"': + n++; + break; + default: + output[m++] = input[n++]; + break; + } + } + + output[m] = '\0'; + + return; +}