Index: ChangeLog
===================================================================
--- ChangeLog	(revision 2adaf1d136a6e763b2295b4b954b714981c669fd)
+++ ChangeLog	(revision b45293f130eb8f835b655248eb10214a0ce070b7)
@@ -1,4 +1,7 @@
 $Id$
 
+1.2.7
+	Outgoing messages now go through the config for formatting
+	
 1.2.6
 	Started adding code for newmsgproc.  It doesn't fully work yet!
Index: functions.c
===================================================================
--- functions.c	(revision 2adaf1d136a6e763b2295b4b954b714981c669fd)
+++ functions.c	(revision b45293f130eb8f835b655248eb10214a0ce070b7)
@@ -82,9 +82,8 @@
 }
 
-void owl_function_make_outgoing_zephyr(char *header, char *body, char *zwriteline, char *zsig) {
+void owl_function_make_outgoing_zephyr(char *body, char *zwriteline, char *zsig) {
   owl_message *m;
   int followlast;
   owl_zwrite z;
-  char *tobuff, *recip;
   
   followlast=owl_global_should_followlast(&g);
@@ -93,27 +92,7 @@
   owl_zwrite_create_from_line(&z, zwriteline);
 
-  /* in 'tobuff' place the "Message sent to foo" string.
-   * Right now this only works for one recipient */
-  tobuff=owl_malloc(strlen(owl_zwrite_get_recip_n(&z, 0))+100);
-  sprintf(tobuff, "Zephyr sent to %s  (Zsig: %s)", owl_zwrite_get_recip_n(&z, 0), zsig);
-
   /* create the message */
   m=owl_malloc(sizeof(owl_message));
-  owl_message_create(m,  tobuff, body);
-  owl_message_set_direction_out(m);
-  owl_message_set_type_zephyr(m);
-
-  /* set zwriteline */
-  owl_message_set_zwriteline(m, zwriteline);
-
-  owl_message_set_class(m, owl_zwrite_get_class(&z));
-  owl_message_set_instance(m, owl_zwrite_get_instance(&z));
-  owl_message_set_opcode(m, owl_zwrite_get_opcode(&z));
-  owl_message_set_realm(m, owl_zwrite_get_realm(&z));
-  owl_message_set_sender(m, ZGetSender());
-  /* this only gets the first recipient for now, must fix */
-  recip=long_zuser(owl_zwrite_get_recip_n(&z, 0));
-  owl_message_set_recipient(m, recip);
-  owl_free(recip);
+  owl_message_create_from_zwriteline(m, zwriteline, body, zsig);
 
   /* add it to the global list */
@@ -130,5 +109,4 @@
   wnoutrefresh(owl_global_get_curs_recwin(&g));
   owl_global_set_needrefresh(&g);
-  owl_free(tobuff);
   owl_zwrite_free(&z);
 }
@@ -176,5 +154,5 @@
 
 void owl_function_zwrite(char *line) {
-  char *tmpbuff, buff[1024];
+  char buff[1024];
   owl_zwrite z;
   int i, j;
@@ -188,7 +166,5 @@
   if (owl_global_is_displayoutgoing(&g) && owl_zwrite_is_personal(&z)) {
     owl_zwrite_get_recipstr(&z, buff);
-    tmpbuff = owl_sprintf("Message sent to %s", buff);
-    owl_function_make_outgoing_zephyr(tmpbuff, owl_editwin_get_text(owl_global_get_typwin(&g)), line, owl_zwrite_get_zsig(&z));
-    owl_free(tmpbuff);
+    owl_function_make_outgoing_zephyr(owl_editwin_get_text(owl_global_get_typwin(&g)), line, owl_zwrite_get_zsig(&z));
   }
 
@@ -953,4 +929,5 @@
   if (owl_global_is_bell(&g)) {
     beep();
+    owl_global_set_needrefresh(&g); /* do we really need this? */
   }
 }
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) {
Index: owl.c
===================================================================
--- owl.c	(revision 55a4578c949354da1589d1fce5b3577a51f19d9e)
+++ owl.c	(revision b45293f130eb8f835b655248eb10214a0ce070b7)
@@ -32,12 +32,9 @@
   owl_editwin *tw;
   owl_popwin *pw;
-  int j, ret, initialsubs, debug, newzephyrs, argcsave, followlast;
+  int j, ret, initialsubs, debug, newzephyrs, argcsave, followlast, nexttimediff;
   struct sigaction sigact;
-  char *configfile, *tty, *perlout;
-  char buff[LINE], startupmsg[LINE];
-  char **argvsave;
+  char *configfile, *tty, *perlout, **argvsave, buff[LINE], startupmsg[LINE];
   owl_filter *f;
   time_t nexttime;
-  int nexttimediff;
 
   argcsave=argc;
@@ -139,5 +136,5 @@
   /* setup the default filters */
   f=malloc(sizeof(owl_filter));
-  owl_filter_init_fromstring(f, "personal", "class ^message$ and instance ^personal$ and ( recipient ^%me%$ or sender ^%me%$ )"); /* fix to use admintype */
+  owl_filter_init_fromstring(f, "personal", "class ^message$ and instance ^personal$ and ( recipient ^%me%$ or sender ^%me%$ )");
   owl_list_append_element(owl_global_get_filterlist(&g), f);
 
@@ -189,5 +186,4 @@
   sepwin=owl_global_get_curs_sepwin(&g);
   typwin=owl_global_get_curs_typwin(&g);
-
   tw=owl_global_get_typwin(&g);
 
@@ -279,5 +275,5 @@
       /* create the new message */
       m=owl_malloc(sizeof(owl_message));
-      owl_message_create_from_zephyr(m, &notice);
+      owl_message_create_from_znotice(m, &notice);
       
       /* if it's on the puntlist then, nuke it and continue */
@@ -305,5 +301,4 @@
       if (owl_global_is_personalbell(&g) && owl_message_is_personal(m)) {
 	owl_function_beep();
-	owl_global_set_needrefresh(&g);
       }
 
Index: owl.h
===================================================================
--- owl.h	(revision 88736cb6dc62a13c37d12bfe5204281765daf5ab)
+++ owl.h	(revision b45293f130eb8f835b655248eb10214a0ce070b7)
@@ -12,6 +12,6 @@
 static const char owl_h_fileIdent[] = "$Id$";
 
-#define OWL_VERSION         1.2.6
-#define OWL_VERSION_STRING "1.2.6"
+#define OWL_VERSION         1.2.7
+#define OWL_VERSION_STRING "1.2.7"
 
 #define OWL_DEBUG 0
@@ -242,4 +242,5 @@
   char *body;
   char *zwriteline;
+  char *zsig;
 } owl_message;
 
Index: readconfig.c
===================================================================
--- readconfig.c	(revision 4b464a43720ec7191ae97a55c10c3e66721ed93f)
+++ readconfig.c	(revision b45293f130eb8f835b655248eb10214a0ce070b7)
@@ -62,4 +62,6 @@
   /* create variables */
   perl_get_sv("owl::id", TRUE);
+  perl_get_sv("owl::type", TRUE);
+  perl_get_sv("owl::direction", TRUE);
   perl_get_sv("owl::class", TRUE);
   perl_get_sv("owl::instance", TRUE);
@@ -127,11 +129,10 @@
   int i, j, len;
   char *ptr, *ptr2;
-  ZNotice_t *n;
 
   if (!owl_global_have_config(&g)) return("");
 
   /* set owl::msg */
-  n=owl_message_get_notice(m);
-  ptr=owl_zephyr_get_message(n, &len);
+  ptr=owl_message_get_body(m);
+  len=strlen(ptr);
   ptr2=owl_malloc(len+20);
   memcpy(ptr2, ptr, len);
@@ -144,5 +145,6 @@
 
   /* set owl::zsig */
-  ptr=owl_zephyr_get_zsig(n, &len);
+  ptr=owl_message_get_zsig(m);
+  len=strlen(ptr);
   if (len>0) {
     ptr2=owl_malloc(len+20);
@@ -165,4 +167,15 @@
   } else {
     sv_setpv(perl_get_sv("owl::type", TRUE), "unknown");
+  }
+
+  /* set owl::direction */
+  if (owl_message_is_direction_in(m)) {
+    sv_setpv(perl_get_sv("owl::direction", TRUE), "in");
+  } else if (owl_message_is_direction_out(m)) {
+    sv_setpv(perl_get_sv("owl::direction", TRUE), "out");
+  } else if (owl_message_is_direction_none(m)) {
+    sv_setpv(perl_get_sv("owl::direction", TRUE), "none");
+  } else {
+    sv_setpv(perl_get_sv("owl::direction", TRUE), "unknown");
   }
 
@@ -189,25 +202,29 @@
 
   /* set owl::fields */
-  av_clear(perl_get_av("owl::fields", TRUE));
-  j=owl_zephyr_get_num_fields(n);
-  for (i=0; i<j; i++) {
-    ptr=owl_zephyr_get_field(n, i+1, &len);
-    ptr2=owl_malloc(len+10);
-    memcpy(ptr2, ptr, len);
-    ptr2[len]='\0';
-    av_push(perl_get_av("owl::fields", TRUE), newSVpvn(ptr2, len));
-    owl_free(ptr2);
+  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
+    av_clear(perl_get_av("owl::fields", TRUE));
+    j=owl_zephyr_get_num_fields(owl_message_get_notice(m));
+    for (i=0; i<j; i++) {
+      ptr=owl_zephyr_get_field(owl_message_get_notice(m), i+1, &len);
+      ptr2=owl_malloc(len+10);
+      memcpy(ptr2, ptr, len);
+      ptr2[len]='\0';
+      av_push(perl_get_av("owl::fields", TRUE), newSVpvn(ptr2, len));
+      owl_free(ptr2);
+    }
   }
 
   /* for backwards compatibilty, because I'm an idiot */
-  av_clear(perl_get_av("fields", TRUE));
-  j=owl_zephyr_get_num_fields(n);
-  for (i=0; i<j; i++) {
-    ptr=owl_zephyr_get_field(n, i+1, &len);
-    ptr2=owl_malloc(len+10);
-    memcpy(ptr2, ptr, len);
-    ptr2[len]='\0';
-    av_push(perl_get_av("fields", TRUE), newSVpvn(ptr2, len));
-    owl_free(ptr2);
+  if (owl_message_is_type_zephyr(m) && owl_message_is_direction_in(m)) {
+    av_clear(perl_get_av("fields", TRUE));
+    j=owl_zephyr_get_num_fields(owl_message_get_notice(m));
+    for (i=0; i<j; i++) {
+      ptr=owl_zephyr_get_field(owl_message_get_notice(m), i+1, &len);
+      ptr2=owl_malloc(len+10);
+      memcpy(ptr2, ptr, len);
+      ptr2[len]='\0';
+      av_push(perl_get_av("fields", TRUE), newSVpvn(ptr2, len));
+      owl_free(ptr2);
+    }
   }
 
