Index: commands.c
===================================================================
--- commands.c	(revision 89ce40586b5d15cd89537d88aaa0c7c2aceb2146)
+++ commands.c	(revision 987cf3f48057443b84ecf140854129cf1a6cbbdc)
@@ -136,5 +136,5 @@
 	      "Send a local message.\n"),
 
-  OWLCMD_ARGS("zcrypt", owl_command_zcrypt, OWL_CTX_INTERACTIVE,
+  OWLCMD_ARGS("zcrypt", owl_command_zwrite, OWL_CTX_INTERACTIVE,
 	      "send an encrypted zephyr",
 	      "zcrypt [-n] [-C] [-c class] [-i instance] [-r realm] [-O opcode] [-m <message...>]\n",
@@ -1914,5 +1914,5 @@
 char *owl_command_zwrite(int argc, const char *const *argv, const char *buff)
 {
-  owl_zwrite z;
+  owl_zwrite *z;
 
   if (!owl_global_is_havezephyr(&g)) {
@@ -1921,16 +1921,21 @@
   }
   /* check for a zwrite -m */
-  owl_zwrite_create_from_line(&z, buff);
-  if (owl_zwrite_is_message_set(&z)) {
-    owl_function_zwrite(buff, NULL);
-    owl_zwrite_cleanup(&z);
-    return (NULL);
-  }
-  owl_zwrite_cleanup(&z);
+  z = owl_zwrite_new(buff);
+  if (!z) {
+    owl_function_error("Error in zwrite arguments");
+    return NULL;
+  }
+
+  if (owl_zwrite_is_message_set(z)) {
+    owl_function_zwrite(z, NULL);
+    owl_zwrite_delete(z);
+    return NULL;
+  }
 
   if (argc < 2) {
+    owl_zwrite_delete(z);
     owl_function_makemsg("Not enough arguments to the zwrite command.");
   } else {
-    owl_function_zwrite_setup(buff);
+    owl_function_zwrite_setup(z);
   }
   return(NULL);
@@ -2019,29 +2024,4 @@
 {
   owl_function_loopwrite_setup();
-  return(NULL);
-}
-
-char *owl_command_zcrypt(int argc, const char *const *argv, const char *buff)
-{
-  owl_zwrite z;
-
-  if (!owl_global_is_havezephyr(&g)) {
-    owl_function_makemsg("Zephyr is not available");
-    return(NULL);
-  }
-  /* check for a zcrypt -m */
-  owl_zwrite_create_from_line(&z, buff);
-  if (owl_zwrite_is_message_set(&z)) {
-    owl_function_zcrypt(buff, NULL);
-    owl_zwrite_cleanup(&z);
-    return (NULL);
-  }
-  owl_zwrite_cleanup(&z);
-
-  if (argc < 2) {
-    owl_function_makemsg("Not enough arguments to the zcrypt command.");
-  } else {
-    owl_function_zwrite_setup(buff);
-  }
   return(NULL);
 }
Index: functions.c
===================================================================
--- functions.c	(revision 13ebf929c89a2f68717a74de950e3479e82546c6)
+++ functions.c	(revision 987cf3f48057443b84ecf140854129cf1a6cbbdc)
@@ -223,17 +223,11 @@
  * that.
  */
-owl_message *owl_function_make_outgoing_zephyr(const char *body, const char *zwriteline, const char *zsig)
+owl_message *owl_function_make_outgoing_zephyr(const owl_zwrite *z)
 {
   owl_message *m;
-  owl_zwrite zw;
-
-  owl_zwrite_create_from_line(&zw, zwriteline);
-  owl_zwrite_set_zsig(&zw, zsig);
 
   /* create the message */
   m=owl_malloc(sizeof(owl_message));
-  
-  owl_message_create_from_zwrite(m, &zw, body);
-  owl_zwrite_cleanup(&zw);
+  owl_message_create_from_zwrite(m, z, owl_zwrite_get_message(z));
 
   return(m);
@@ -296,5 +290,5 @@
 }
 
-static void owl_function_write_setup(const char *line, const char *noun, void (*callback)(owl_editwin *))
+static void owl_function_write_setup(const char *noun)
 {
 
@@ -307,46 +301,41 @@
 			 "End with a dot on a line by itself.  ^C will quit.",
 			 noun);
-
-  owl_function_start_edit_win(line, callback,
+}
+
+void owl_function_zwrite_setup(owl_zwrite *z)
+{
+  /* send a ping if necessary */
+  if (owl_global_is_txping(&g)) {
+    owl_zwrite_send_ping(z);
+  }
+
+
+  owl_function_write_setup("zephyr");
+  owl_function_start_edit_win(z->zwriteline,
+                              &owl_callback_zwrite,
+                              z, (void(*)(void*))owl_zwrite_delete);
+}
+
+void owl_function_aimwrite_setup(const char *line)
+{
+  owl_function_write_setup("message");
+  owl_function_start_edit_win(line,
+                              &owl_callback_aimwrite,
                               owl_strdup(line),
                               owl_free);
-}
-
-void owl_function_zwrite_setup(const char *line)
-{
-  owl_zwrite z;
-  int ret;
-
-  /* check the arguments */
-  ret=owl_zwrite_create_from_line(&z, line);
-  if (ret) {
-    owl_function_error("Error in zwrite arguments");
-    owl_zwrite_cleanup(&z);
-    return;
-  }
-
-  /* send a ping if necessary */
-  if (owl_global_is_txping(&g)) {
-    owl_zwrite_send_ping(&z);
-  }
-  owl_zwrite_cleanup(&z);
-
-  owl_function_write_setup(line, "zephyr", &owl_callback_zwrite);
-}
-
-void owl_function_aimwrite_setup(const char *line)
-{
-  owl_function_write_setup(line, "message", &owl_callback_aimwrite);
+
 }
 
 void owl_function_loopwrite_setup(void)
 {
-  owl_function_write_setup("loopwrite", "message", owl_callback_loopwrite);
+  owl_function_write_setup("message");
+  owl_function_start_edit_win("loopwrite",
+                              &owl_callback_loopwrite,
+                              "loopwrite", NULL);
 }
 
 void owl_callback_zwrite(owl_editwin *e) {
-  char *command = owl_editwin_get_cbdata(e);
-  owl_function_zwrite(command,
-                      owl_editwin_get_text(e));
+  owl_zwrite *z = owl_editwin_get_cbdata(e);
+  owl_function_zwrite(z, owl_editwin_get_text(e));
 }
 
@@ -354,29 +343,25 @@
  * the message is expected to be set from the zwrite line itself
  */
-void owl_function_zwrite(const char *line, const char *msg)
-{
-  owl_zwrite z;
-  const char *mymsg;
+void owl_function_zwrite(owl_zwrite *z, const char *msg)
+{
   owl_message *m;
 
-  if(!strncmp(line, "zcrypt", strlen("zcrypt"))) {
-    owl_function_zcrypt(line, msg);
+  if(strcmp(z->cmd, "zcrypt") == 0) {
+    owl_function_zcrypt(z, msg);
     return;
   }
 
   /* create the zwrite and send the message */
-  owl_zwrite_create_from_line(&z, line);
-  owl_zwrite_populate_zsig(&z);
+  owl_zwrite_populate_zsig(z);
   if (msg) {
-    owl_zwrite_set_message(&z, msg);
-  }
-  owl_zwrite_send_message(&z);
+    owl_zwrite_set_message(z, msg);
+  }
+  owl_zwrite_send_message(z);
   owl_function_makemsg("Waiting for ack...");
 
   /* If it's personal */
-  if (owl_zwrite_is_personal(&z)) {
+  if (owl_zwrite_is_personal(z)) {
     /* create the outgoing message */
-    mymsg=owl_zwrite_get_message(&z);
-    m=owl_function_make_outgoing_zephyr(mymsg, line, owl_zwrite_get_zsig(&z));
+    m=owl_function_make_outgoing_zephyr(z);
 
     if (m) {
@@ -386,7 +371,4 @@
     }
   }
-
-  /* free the zwrite */
-  owl_zwrite_cleanup(&z);
 }
 
@@ -394,8 +376,6 @@
  * the message is expected to be set from the zwrite line itself
  */
-void owl_function_zcrypt(const char *line, const char *msg)
-{
-  owl_zwrite z;
-  const char *mymsg;
+void owl_function_zcrypt(owl_zwrite *z, const char *msg)
+{
   char *cryptmsg;
   owl_message *m;
@@ -405,20 +385,18 @@
 
   /* create the zwrite and send the message */
-  owl_zwrite_create_from_line(&z, line);
-  owl_zwrite_populate_zsig(&z);
+  owl_zwrite_populate_zsig(z);
   if (msg) {
-    owl_zwrite_set_message(&z, msg);
-  }
-
-  mymsg=owl_zwrite_get_message(&z);
+    owl_zwrite_set_message(z, msg);
+  }
+
 
   zcrypt = owl_sprintf("%s/zcrypt", owl_get_bindir());
   argv[0] = "zcrypt";
   argv[1] = "-E";
-  argv[2] = "-c"; argv[3] = owl_zwrite_get_class(&z);
-  argv[4] = "-i"; argv[5] = owl_zwrite_get_instance(&z);
+  argv[2] = "-c"; argv[3] = owl_zwrite_get_class(z);
+  argv[4] = "-i"; argv[5] = owl_zwrite_get_instance(z);
   argv[6] = NULL;
 
-  rv = call_filter(zcrypt, argv, mymsg, &cryptmsg, &status);
+  rv = call_filter(zcrypt, argv, owl_zwrite_get_message(z), &cryptmsg, &status);
 
   owl_free(zcrypt);
@@ -428,19 +406,17 @@
     owl_function_error("Error in zcrypt, possibly no key found.  Message not sent.");
     owl_function_beep();
-    owl_zwrite_cleanup(&z);
     return;
   }
 
-  owl_zwrite_set_message(&z, cryptmsg);
-  owl_zwrite_set_opcode(&z, "crypt");
+  owl_zwrite_set_message(z, cryptmsg);
+  owl_zwrite_set_opcode(z, "crypt");
     
-  owl_zwrite_send_message(&z);
+  owl_zwrite_send_message(z);
   owl_function_makemsg("Waiting for ack...");
 
   /* If it's personal */
-  if (owl_zwrite_is_personal(&z)) {
+  if (owl_zwrite_is_personal(z)) {
     /* create the outgoing message */
-    mymsg=owl_zwrite_get_message(&z);
-    m=owl_function_make_outgoing_zephyr(mymsg, line, owl_zwrite_get_zsig(&z));
+    m=owl_function_make_outgoing_zephyr(z);
     if (m) {
       owl_global_messagequeue_addmsg(&g, m);
@@ -452,5 +428,4 @@
   /* free the zwrite */
   owl_free(cryptmsg);
-  owl_zwrite_cleanup(&z);
 }
 
Index: owl.h
===================================================================
--- owl.h	(revision 68e5464454e6b10711aea47efecf242cd3c3ef2a)
+++ owl.h	(revision 987cf3f48057443b84ecf140854129cf1a6cbbdc)
@@ -344,4 +344,5 @@
 
 typedef struct _owl_zwrite {
+  char *cmd;
   char *zwriteline;
   char *class;
Index: zephyr.c
===================================================================
--- zephyr.c	(revision 922f5890c367ee59369356b3b41d2399001bbf05)
+++ zephyr.c	(revision 987cf3f48057443b84ecf140854129cf1a6cbbdc)
@@ -852,4 +852,5 @@
   char *tmpbuff, *myuser, *to;
   owl_message *mout;
+  owl_zwrite *z;
   
   /* bail if it doesn't look like a message we should reply to.  Some
@@ -887,8 +888,13 @@
   owl_free(to);
 
+  z = owl_zwrite_new(tmpbuff);
+  owl_zwrite_set_message(z, owl_global_get_zaway_msg(&g));
+  owl_zwrite_set_zsig(z, "Automated reply:");
+
   /* display the message as an admin message in the receive window */
-  mout=owl_function_make_outgoing_zephyr(owl_global_get_zaway_msg(&g), tmpbuff, "Automated reply:");
+  mout=owl_function_make_outgoing_zephyr(z);
   owl_global_messagequeue_addmsg(&g, mout);
   owl_free(tmpbuff);
+  owl_zwrite_delete(z);
 #endif
 }
Index: zwrite.c
===================================================================
--- zwrite.c	(revision c230bc1b418cbace9d748df62640c26a59aa1622)
+++ zwrite.c	(revision 987cf3f48057443b84ecf140854129cf1a6cbbdc)
@@ -5,4 +5,14 @@
 #include "owl.h"
 
+owl_zwrite *owl_zwrite_new(const char *line)
+{
+  owl_zwrite *z = owl_malloc(sizeof *z);
+  if (owl_zwrite_create_from_line(z, line) < 0) {
+    owl_zwrite_delete(z);
+    return NULL;
+  }
+  return z;
+}
+
 int owl_zwrite_create_from_line(owl_zwrite *z, const char *line)
 {
@@ -15,4 +25,5 @@
   
   /* start with null entries */
+  z->cmd=NULL;
   z->realm=NULL;
   z->class=NULL;
@@ -35,4 +46,5 @@
   myargc=argc;
   if (myargc && *(myargv[0])!='-') {
+    z->cmd=owl_strdup(myargv[0]);
     myargc--;
     myargv++;
@@ -350,4 +362,10 @@
 }
 
+void owl_zwrite_delete(owl_zwrite *z)
+{
+  owl_zwrite_cleanup(z);
+  owl_free(z);
+}
+
 void owl_zwrite_cleanup(owl_zwrite *z)
 {
