+/** @brief RFC822 quoting
+ * @param s String to quote
+ * @param force If non-0, always quote
+ * @return Possibly quoted string
+ */
+char *quote822(const char *s, int force) {
+ const char *t;
+ struct dynstr d[1];
+ int c;
+
+ if(!force) {
+ /* See if we need to quote */
+ for(t = s; (c = (unsigned char)*t); ++t) {
+ if(tspecial(c) || http_separator(c) || whitespace(c))
+ break;
+ }
+ if(*t)
+ force = 1;
+ }
+
+ if(!force)
+ return xstrdup(s);
+
+ dynstr_init(d);
+ dynstr_append(d, '"');
+ for(t = s; (c = (unsigned char)*t); ++t) {
+ if(c == '"' || c == '\\')
+ dynstr_append(d, '\\');
+ dynstr_append(d, c);
+ }
+ dynstr_append(d, '"');
+ dynstr_terminate(d);
+ return d->vec;
+}
+