Wrote a new version of header_fold() that takes a 'force' option and uses
2001-03-04 Jeffrey Stedfast <fejj@ximian.com> * camel-mime-utils.c: Wrote a new version of header_fold() that takes a 'force' option and uses another new function called header_fold_next_space() in place of strchr(inptr, ' ') to get the next whitespace char. The idea of header_fold_next_space() is to not treat spaces between a set of quotes as a space - this way it will be possible to fold (for example) the Content-Type MIME header without worrying about breaking up a boundary string. Note: This code is #if 0'd out until Zucchi approves of the patch. Another Note: We will probably still want to use the "don't fold this header" hash lookup for headers like the Message-Id and possibly a few others. svn path=/trunk/; revision=8552
This commit is contained in:
committed by
Jeffrey Stedfast
parent
6a99ce9981
commit
31cab455ff
@ -1,3 +1,17 @@
|
||||
2001-03-04 Jeffrey Stedfast <fejj@ximian.com>
|
||||
|
||||
* camel-mime-utils.c: Wrote a new version of header_fold() that
|
||||
takes a 'force' option and uses another new function called
|
||||
header_fold_next_space() in place of strchr(inptr, ' ') to get the
|
||||
next whitespace char. The idea of header_fold_next_space() is to
|
||||
not treat spaces between a set of quotes as a space - this way it
|
||||
will be possible to fold (for example) the Content-Type MIME
|
||||
header without worrying about breaking up a boundary string.
|
||||
Note: This code is #if 0'd out until Zucchi approves of the patch.
|
||||
Another Note: We will probably still want to use the "don't fold
|
||||
this header" hash lookup for headers like the Message-Id and
|
||||
possibly a few others.
|
||||
|
||||
2001-03-04 Jeffrey Stedfast <fejj@ximian.com>
|
||||
|
||||
* camel-internet-address.c
|
||||
|
||||
@ -1021,7 +1021,7 @@ static char *
|
||||
header_decode_text (const char *in, int inlen)
|
||||
{
|
||||
GString *out;
|
||||
const char *inptr, *inend, *start;
|
||||
char *inptr, *inend, *start;
|
||||
char *decoded;
|
||||
unsigned char lastc = 0;
|
||||
int wasdword = FALSE;
|
||||
@ -3208,6 +3208,132 @@ header_address_list_format(struct _header_address *a)
|
||||
return ret;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static const char *
|
||||
header_fold_next_space (const char *in)
|
||||
{
|
||||
register const char *inptr = in;
|
||||
gboolean escaped = FALSE;
|
||||
|
||||
if (is_lwsp (*inptr))
|
||||
return inptr;
|
||||
|
||||
do {
|
||||
if (*inptr == '\\') {
|
||||
escaped = TRUE;
|
||||
} else if (*inptr == '"' && !escaped) {
|
||||
/* find the end of this quoted section */
|
||||
for (inptr++; *inptr; inptr++) {
|
||||
if (*inptr == '"' && *(inptr-1) != '\\')
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
escaped = FALSE;
|
||||
}
|
||||
|
||||
inptr++;
|
||||
} while (*inptr && !is_lwsp (*inptr));
|
||||
|
||||
if (*inptr)
|
||||
return inptr;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* I wonder if this might be better for folding headers? */
|
||||
char *
|
||||
header_fold (const char *in, int headerlen, gboolean force)
|
||||
{
|
||||
const char *inptr = in, *space, *p, *n;
|
||||
gboolean needunfold = FALSE;
|
||||
int len, outlen, i;
|
||||
GString *out;
|
||||
char *ret;
|
||||
|
||||
if (in == NULL)
|
||||
return NULL;
|
||||
|
||||
/* first, check to see if we even need to fold */
|
||||
len = headerlen + 2;
|
||||
p = in;
|
||||
while (*p) {
|
||||
n = strchr (p, '\n');
|
||||
if (n == NULL)
|
||||
n = p + strlen (p);
|
||||
else
|
||||
needunfold = TRUE;
|
||||
|
||||
len += n - p;
|
||||
|
||||
if (len >= CAMEL_FOLD_SIZE)
|
||||
break;
|
||||
len = 0;
|
||||
p = n + 1;
|
||||
}
|
||||
|
||||
if (len < CAMEL_FOLD_SIZE)
|
||||
return g_strdup (in);
|
||||
|
||||
/* we need to fold, so first unfold (if we need to), then process */
|
||||
if (needunfold)
|
||||
inptr = in = header_unfold (in);
|
||||
|
||||
out = g_string_new ("");
|
||||
outlen = headerlen + 2;
|
||||
while (*inptr) {
|
||||
if (force)
|
||||
space = strchr (inptr, ' ');
|
||||
else
|
||||
space = header_fold_next_space (inptr);
|
||||
|
||||
if (space) {
|
||||
len = space - inptr + 1;
|
||||
} else {
|
||||
len = strlen (inptr);
|
||||
}
|
||||
|
||||
d(printf ("next word '%.*s'\n", len, inptr));
|
||||
|
||||
if (outlen + len > CAMEL_FOLD_SIZE) {
|
||||
d(printf("outlen = %d wordlen = %d\n", outlen, len));
|
||||
/* strip trailing space */
|
||||
if (out->len > 0 && out->str[out->len-1] == ' ')
|
||||
g_string_truncate (out, out->len-1);
|
||||
g_string_append (out, "\n\t");
|
||||
outlen = 1;
|
||||
|
||||
if (force) {
|
||||
/* check for very long words, just cut them up */
|
||||
while (outlen + len > CAMEL_FOLD_SIZE) {
|
||||
for (i = 0; i < CAMEL_FOLD_SIZE - outlen; i++)
|
||||
g_string_append_c (out, inptr[i]);
|
||||
inptr += CAMEL_FOLD_SIZE - outlen;
|
||||
len -= CAMEL_FOLD_SIZE - outlen;
|
||||
g_string_append (out, "\n\t");
|
||||
outlen = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
outlen += len;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
g_string_append_c (out, inptr[i]);
|
||||
|
||||
inptr += len;
|
||||
}
|
||||
|
||||
ret = out->str;
|
||||
g_string_free (out, FALSE);
|
||||
|
||||
if (needunfold)
|
||||
g_free ((char *)in);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* simple header folding */
|
||||
/* will work even if the header is already folded */
|
||||
char *
|
||||
|
||||
Reference in New Issue
Block a user