Index: filterelement.c
===================================================================
--- filterelement.c	(revision a1d98e491420965088c3ebadc08a0dd3b937b44d)
+++ filterelement.c	(revision d222c44c7a6cab8cd6859100b0c4f22ea74d345a)
@@ -139,13 +139,10 @@
 static void owl_filterelement_print_re(const owl_filterelement *fe, GString *buf)
 {
-  const char *re, *q;
+  const char *re;
   g_string_append(buf, fe->field);
   g_string_append(buf, " ");
 
   re = owl_regex_get_string(&(fe->re));
-  q = owl_getquoting(re);
-  g_string_append(buf, q);
-  g_string_append(buf, re);
-  g_string_append(buf, q);
+  owl_string_append_quoted_arg(buf, re);
 }
 
@@ -153,5 +150,5 @@
 {
   g_string_append(buf, "filter ");
-  g_string_append(buf, fe->field);
+  owl_string_append_quoted_arg(buf, fe->field);
 }
 
@@ -159,5 +156,5 @@
 {
   g_string_append(buf, "perl ");
-  g_string_append(buf, fe->field);
+  owl_string_append_quoted_arg(buf, fe->field);
 }
 
Index: functions.c
===================================================================
--- functions.c	(revision 1279f216fa5354e6309e2c82aecc634431dbfac5)
+++ functions.c	(revision d222c44c7a6cab8cd6859100b0c4f22ea74d345a)
@@ -1632,5 +1632,5 @@
 
   owl_function_popless_text(str->str);
-  g_string_free(str, TRUE);
+  g_string_free(str, true);
 }
 
@@ -2492,7 +2492,8 @@
 static char *owl_function_smartfilter_cc(const owl_message *m) {
   const char *ccs;
+  char *ccs_quoted;
   char *filtname;
-  char *text;
   owl_filter *f;
+  GString *buf;
 
   ccs = owl_message_get_attribute_value(m, "zephyr_ccs");
@@ -2505,13 +2506,15 @@
   }
 
-  text = owl_sprintf("type ^zephyr$ and filter personal and "
-                     "zephyr_ccs ^%s%s%s$",
-                     owl_getquoting(ccs), ccs, owl_getquoting(ccs));
-
-  f = owl_filter_new_fromstring(filtname, text);
+  buf = g_string_new("type ^zephyr$ and filter personal and "
+                     "zephyr_ccs ^");
+  ccs_quoted = owl_text_quote(ccs, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
+  owl_string_append_quoted_arg(buf, ccs_quoted);
+  g_string_append_c(buf, '$');
+  owl_free(ccs_quoted);
+
+  f = owl_filter_new_fromstring(filtname, buf->str);
+  g_string_free(buf, true);
 
   owl_global_add_filter(&g, f);
-
-  owl_free(text);
 
   return filtname;
@@ -2611,6 +2614,6 @@
   const owl_view *v;
   const owl_message *m;
-  const char *cmdprefix, *mclass, *minst;
-  char *cmd;
+  const char *mclass, *minst;
+  GString *buf;
   
   v=owl_global_get_current_view(&g);
@@ -2638,20 +2641,14 @@
 			 mclass, minst);
   } else {
-    cmdprefix = "start-command zpunt ";
-    cmd = owl_malloc(strlen(cmdprefix)+strlen(mclass)+strlen(minst)+10);
-    strcpy(cmd, cmdprefix);
-    strcat(cmd, owl_getquoting(mclass));
-    strcat(cmd, mclass);
-    strcat(cmd, owl_getquoting(mclass));
+    buf = g_string_new("start-command zpunt ");
+    owl_string_append_quoted_arg(buf, mclass);
     if (type) {
-      strcat(cmd, " ");
-      strcat(cmd, owl_getquoting(minst));
-      strcat(cmd, minst);
-      strcat(cmd, owl_getquoting(minst));
+      g_string_append_c(buf, ' ');
+      owl_string_append_quoted_arg(buf, minst);
     } else {
-      strcat(cmd, " *");
-    }
-    owl_function_command(cmd);
-    owl_free(cmd);
+      g_string_append(buf, " *");
+    }
+    owl_function_command(buf->str);
+    g_string_free(buf, true);
   }
 }
Index: global.c
===================================================================
--- global.c	(revision 8510d5b8a92e3c991eff1b503769b5a965d8791e)
+++ global.c	(revision d222c44c7a6cab8cd6859100b0c4f22ea74d345a)
@@ -710,5 +710,4 @@
 {
   char *sn_escaped;
-  const char *quote;
   g->aim_loggedin=1;
   if (g->aim_screenname) owl_free(g->aim_screenname);
@@ -716,6 +715,5 @@
   g->aim_screenname=owl_strdup(screenname);
   sn_escaped = owl_text_quote(screenname, OWL_REGEX_QUOTECHARS, OWL_REGEX_QUOTEWITH);
-  quote = owl_getquoting(sn_escaped);
-  g->aim_screenname_for_filters=owl_sprintf("%s%s%s", quote, sn_escaped, quote);
+  g->aim_screenname_for_filters = owl_arg_quote(sn_escaped);
   owl_free(sn_escaped);
 }
Index: text.c
===================================================================
--- text.c	(revision 72ec874c41ff933b3b6cc8b1873ce0c618623a82)
+++ text.c	(revision d222c44c7a6cab8cd6859100b0c4f22ea74d345a)
@@ -262,13 +262,4 @@
   }
   return(1);
-}
-
-const char *owl_getquoting(const char *line)
-{
-  if (line[0]=='\0') return("'");
-  if (strchr(line, '\'')) return("\"");
-  if (strchr(line, '"')) return("'");
-  if (strcspn(line, "\n\t ") != strlen(line)) return("'");
-  return("");
 }
 
