Index: message.c
===================================================================
--- message.c	(revision 3a2daac2dddd32e805373d81642d45a0943dd05c)
+++ message.c	(revision b45293f130eb8f835b655248eb10214a0ce070b7)
@@ -1,4 +1,5 @@
 #include <zephyr/zephyr.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <string.h>
 #include <sys/socket.h>
@@ -26,4 +27,5 @@
   m->opcode=owl_strdup("");
   m->realm=owl_strdup("");
+  m->zsig=owl_strdup("");
   strcpy(m->hostname, "");
   m->zwriteline=strdup("");
@@ -65,4 +67,13 @@
 char *owl_message_get_sender(owl_message *m) {
   return(m->sender);
+}
+
+void owl_message_set_zsig(owl_message *m, char *zsig) {
+  if (m->zsig) owl_free(m->zsig);
+  m->zsig=owl_strdup(zsig);
+}
+
+char *owl_message_get_zsig(owl_message *m) {
+  return(m->zsig);
 }
 
@@ -347,5 +358,5 @@
 }
 
-void owl_message_create_from_zephyr(owl_message *m, ZNotice_t *n) {
+void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n) {
   struct hostent *hent;
   int k;
@@ -374,4 +385,5 @@
     n->z_opcode=owl_strdup("");
   }
+  m->zsig=owl_strdup(n->z_message);
 
   if ((ptr=strchr(n->z_recipient, '@'))!=NULL) {
@@ -383,4 +395,5 @@
   m->zwriteline=strdup("");
 
+  /* set the body */
   ptr=owl_zephyr_get_message(n, &k);
   m->body=owl_malloc(k+10);
@@ -412,4 +425,44 @@
 }
 
+void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig) {
+  owl_zwrite z;
+  int ret;
+  
+  owl_message_init_raw(m);
+
+  /* create a zwrite for the purpose of filling in other message fields */
+  owl_zwrite_create_from_line(&z, line);
+
+  /* set things */
+  owl_message_set_direction_out(m);
+  owl_message_set_type_zephyr(m);
+  m->sender=owl_strdup(ZGetSender());
+  m->class=owl_strdup(owl_zwrite_get_class(&z));
+  m->inst=owl_strdup(owl_zwrite_get_instance(&z));
+  m->recip=long_zuser(owl_zwrite_get_recip_n(&z, 0)); /* only gets the first user, must fix */
+  owl_zwrite_get_recipstr(&z, m->recip);
+  m->opcode=owl_strdup(owl_zwrite_get_opcode(&z));
+  m->realm=owl_strdup(owl_zwrite_get_realm(&z)); /* also a hack, but not here */
+  m->zwriteline=owl_strdup(line);
+  m->body=owl_strdup(body);
+  m->zsig=owl_strdup(zsig);
+  
+  /* save the hostname */
+  ret=gethostname(m->hostname, MAXHOSTNAMELEN);
+  if (ret) {
+    strcpy(m->hostname, "localhost");
+  }
+
+  /* create the formatted message */
+  if (owl_global_is_config_format(&g)) {
+    _owl_message_make_text_from_config(m);
+  } else if (owl_global_is_userclue(&g, OWL_USERCLUE_CLASSES)) {
+    _owl_message_make_text_from_zwriteline_standard(m);
+  } else {
+    _owl_message_make_text_from_zwriteline_simple(m);
+  }
+
+  owl_zwrite_free(&z);
+}
 
 void _owl_message_make_text_from_config(owl_message *m) {
@@ -432,8 +485,38 @@
 }
 
+void _owl_message_make_text_from_zwriteline_standard(owl_message *m) {
+  char *indent, *text, *zsigbuff;
+
+  text=owl_message_get_body(m);
+
+  indent=owl_malloc(strlen(text)+owl_text_num_lines(text)*OWL_MSGTAB+10);
+  owl_text_indent(indent, text, OWL_MSGTAB);
+  owl_fmtext_init_null(&(m->fmtext));
+  owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
+  owl_fmtext_append_normal(&(m->fmtext), "Zephyr sent to ");
+  owl_fmtext_append_normal(&(m->fmtext), owl_message_get_recipient(m));
+  owl_fmtext_append_normal(&(m->fmtext), "  (Zsig: ");
+
+  zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m)));
+  owl_message_pretty_zsig(m, zsigbuff);
+  owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
+  owl_free(zsigbuff);
+  
+  owl_fmtext_append_normal(&(m->fmtext), ")");
+  owl_fmtext_append_normal(&(m->fmtext), "\n");
+  owl_fmtext_append_ztext(&(m->fmtext), indent);
+  if (text[strlen(text)-1]!='\n') {
+    owl_fmtext_append_normal(&(m->fmtext), "\n");
+  }
+
+  owl_free(indent);
+}
+
+void _owl_message_make_text_from_zwriteline_simple(owl_message *m) {
+  _owl_message_make_text_from_zwriteline_standard(m);
+}
+
 void _owl_message_make_text_from_notice_standard(owl_message *m) {
-  char *body, *indent, *ptr;
-  char frombuff[1024];
-  char zsigbuff[LINE];
+  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
   ZNotice_t *n;
   int len;
@@ -514,11 +597,13 @@
 
     /* stick on the zsig */
-    _owl_message_get_zsig(m, zsigbuff, LINE);
-    if (zsigbuff[0]!='\0') {
-      owl_fmtext_append_normal(&(m->fmtext), "    (");
-      owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
-      owl_fmtext_append_normal(&(m->fmtext), ")");
-    }
-    owl_fmtext_append_normal(&(m->fmtext), "\n");
+    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m)));
+    owl_message_pretty_zsig(m, zsigbuff);
+    owl_fmtext_append_normal(&(m->fmtext), "    (");
+    owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
+    owl_fmtext_append_normal(&(m->fmtext), ")");
+    owl_fmtext_append_normal(&(m->fmtext), "\n");
+    owl_free(zsigbuff);
+
+    /* then the indented message */
     owl_fmtext_append_ztext(&(m->fmtext), indent);
 
@@ -536,7 +621,5 @@
 
 void _owl_message_make_text_from_notice_simple(owl_message *m) {
-  char *body, *indent, *ptr;
-  char frombuff[1024];
-  char zsigbuff[LINE];
+  char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
   ZNotice_t *n;
   int len;
@@ -616,11 +699,13 @@
 
     /* stick on the zsig */
-    _owl_message_get_zsig(m, zsigbuff, LINE);
-    if (zsigbuff[0]!='\0') {
-      owl_fmtext_append_normal(&(m->fmtext), "    (");
-      owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
-      owl_fmtext_append_normal(&(m->fmtext), ")");
-    }
-    owl_fmtext_append_normal(&(m->fmtext), "\n");
+    zsigbuff=owl_malloc(strlen(owl_message_get_zsig(m)));
+    owl_message_pretty_zsig(m, zsigbuff);
+    owl_fmtext_append_normal(&(m->fmtext), "    (");
+    owl_fmtext_append_ztext(&(m->fmtext), zsigbuff);
+    owl_fmtext_append_normal(&(m->fmtext), ")");
+    owl_fmtext_append_normal(&(m->fmtext), "\n");
+    owl_free(zsigbuff);
+
+    /* then the indented message */
     owl_fmtext_append_ztext(&(m->fmtext), indent);
 
@@ -637,36 +722,12 @@
 }
 
-void _owl_message_get_zsig(owl_message *m, char *buff, int size) {
+void owl_message_pretty_zsig(owl_message *m, char *buff) {
+  /* stick a one line version of the zsig in buff */
   char *ptr;
-  ZNotice_t n;
-  int len;
-  /* just a hackish thing for now.  We'll only present the first line
-     or the first 'size'. characters.  If the message is not
-     appropriate for having a zsig we'll return an empty string */
-  n=m->notice;
-
-
-  /* bail if it shouldn't have a zsig */
-  buff[0]='\0';
-  if (!strcasecmp(n.z_opcode, "ping")) {
-    return;
-  }
-
-  /* find the right length to copy */
-  len=strlen(n.z_message);
-  if (size < len) {
-    len=size;
-  }
-  if ((ptr=strchr(n.z_message, '\n'))!=NULL) {
-    if ((ptr-n.z_message) < len) {
-      len=ptr-n.z_message;
-    }
-  }
-
-  /* copy */
-  strncpy(buff, n.z_message, len);
-  buff[len]='\0';
-}
-
+
+  strcpy(buff, m->zsig);
+  ptr=strchr(buff, '\n');
+  if (ptr) ptr[0]='\0';
+}
 
 void owl_message_free(owl_message *m) {
