X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Funquote.c;h=aa40a0cc84aca85925a1d95fae48dd2f8775bf6c;hp=f9fa9112fccfd9f6fab7ab566ee04babda9d077c;hb=5d690daafbcd4ed26d19610fcc017999ee5af892;hpb=55ca5bf643035fd37cf0568e5ea73c1a8636b9a6 diff --git a/sbr/unquote.c b/sbr/unquote.c index f9fa911..aa40a0c 100644 --- a/sbr/unquote.c +++ b/sbr/unquote.c @@ -1,45 +1,48 @@ /* - * 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. - */ +** 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. - * - */ - +** Remove quotes and quoted-pair sequences from RFC-5322 atoms. +** +** Currently the actual algorithm is simpler than it technically should +** be: any quotes are simply eaten, unless they're preceded by the escape +** character (\). This seems to be sufficient for our needs for now. +** +** Arguments: +** +** input - The input string +** output - The output string; is assumed to have at least as much +** room as the input string. At worst the output string will +** be the same size as the input string; it might be smaller. +*/ 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 */ + int inpos = 0; + int outpos = 0; - 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; + while (input[inpos] != '\0') { + switch (input[inpos]) { + case '\\': + inpos++; + if (input[inpos] != '\0') + output[outpos++] = input[inpos++]; + break; + case '"': + inpos++; + break; + default: + output[outpos++] = input[inpos++]; + break; + } } - } - - output[m] = '\0'; - - return; + output[outpos] = '\0'; }