]> diplodocus.org Git - nmh/blob - sbr/encode_rfc2047.c
ff77ff52a0c419730f92cc67c40cdbbdeb938a29
[nmh] / sbr / encode_rfc2047.c
1 /*
2 * Routines to encode message headers using RFC 2047-encoding.
3 *
4 * This code is Copyright (c) 2002, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
7 */
8
9 #include <h/mh.h>
10
11 /*
12 * Encode a message header using RFC 2047 encoding. We make the assumption
13 * that all characters < 128 are ASCII and as a consequence don't need any
14 * encoding.
15 */
16
17 int
18 encode_rfc2047(const char *name, char **value, int encoding,
19 const char *charset)
20 {
21 char *p;
22
23 /*
24 * First, check to see if we even need to encode the header
25 */
26
27 for (p = *value; *p != '\0'; p++) {
28 if (! isascii((int) *p)
29 goto encode;
30 }
31
32 return 0;
33
34 encode:
35 /*
36 * Some rules from RFC 2047:
37 *
38 * - Encoded words cannot be more than 75 characters long
39 * - Multiple "long" encoded words must be on new lines.
40 *
41 * Also, we're not permitted to encode email addresses, so
42 * we need to actually _parse_ email addresses and only encode
43 * the right bits.