- /* Quote and escape name that contains any specials, as necessary. */
- if (strpbrk("\"(),.:;<>@[\\]", name)) {
+ char *specials = "\"(),.:;<>@[\\]";
+ escape_component (name, namesize, specials);
+}
+
+
+void
+escape_local_part (char *name, size_t namesize) {
+ /* wsp (whitespace) is horizontal tab or space, according to
+ RFC 5234. */
+ char *specials_less_dot_plus_wsp = " \"(),:;<>@[\\]";
+ escape_component (name, namesize, specials_less_dot_plus_wsp);
+}
+
+
+/* Escape an address component, hopefully per RFC 5322. Assumes
+ one-byte characters. The char array pointed to by the name
+ argument is modified in place. Its size is specified by the
+ namesize argument. The need_escape argument is a string of
+ characters that require that name be escaped. */
+void
+escape_component (char *name, size_t namesize, char *chars_to_escape) {
+ /* If name contains any chars_to_escape:
+ 1) enclose it in ""
+ 2) escape any embedded "
+ */
+ if (strpbrk(name, chars_to_escape)) {