Index: aim.c
===================================================================
--- aim.c	(revision ae4cd1243d47da8a85df9cfef60d918a6db8a0a4)
+++ aim.c	(revision d559df97bd8fe22559fdadb8b64e5166521fa4b2)
@@ -1277,5 +1277,10 @@
   nz_screenname=owl_aim_normalize_screenname(userinfo->sn);
   m=owl_malloc(sizeof(owl_message));
-  owl_message_create_incoming_aim(m, nz_screenname, owl_global_get_aim_screenname(&g), stripmsg);
+  owl_message_create_aim(m,
+			 nz_screenname,
+			 owl_global_get_aim_screenname(&g),
+			 stripmsg,
+			 OWL_MESSAGE_DIRECTION_IN,
+			 0);
   owl_global_messagequeue_addmsg(&g, m);
   owl_free(stripmsg);
Index: buddylist.c
===================================================================
--- buddylist.c	(revision 38cf544c320814f53070c768b4974c2786a024f4)
+++ buddylist.c	(revision d559df97bd8fe22559fdadb8b64e5166521fa4b2)
@@ -28,5 +28,10 @@
 
     m=owl_malloc(sizeof(owl_message));
-    owl_message_create_aim_login(m, 0, screenname);
+    owl_message_create_aim(m,
+			   screenname,
+			   owl_global_get_aim_screenname(&g),
+			   "",
+			   OWL_MESSAGE_DIRECTION_IN,
+			   1);
     owl_global_messagequeue_addmsg(&g, m);
   }
@@ -56,5 +61,11 @@
   if (found) {
     m=owl_malloc(sizeof(owl_message));
-    owl_message_create_aim_login(m, 1, screenname);
+    owl_message_create_aim(m,
+			   screenname,
+			   owl_global_get_aim_screenname(&g),
+			   "",
+			   OWL_MESSAGE_DIRECTION_IN,
+			   -1);
+
     owl_global_messagequeue_addmsg(&g, m);
   }
Index: fmtext.c
===================================================================
--- fmtext.c	(revision 578923063811aaac872c32fbf07dfbbde5cf868f)
+++ fmtext.c	(revision d559df97bd8fe22559fdadb8b64e5166521fa4b2)
@@ -457,13 +457,11 @@
 }
 
-
+  
+/* the first column is column 0 */
+/* the message is expected to end in a new line for now */
 void owl_fmtext_truncate_cols(owl_fmtext *in, int acol, int bcol, owl_fmtext *out)
 {
   char *ptr1, *ptr2, *last;
   int len, offset;
-  
-  /* the first column is column 0 */
-
-  /* the message is expected to end in a new line for now */
 
   last=in->textbuff+in->textlen-1;
@@ -485,10 +483,13 @@
     len=bcol-acol;
     if (len > (ptr2-(ptr1+acol))) {
+      /* the whole line fits with room to spare, don't take a full 'len' */
       len=ptr2-(ptr1+acol);
     }
     if (len>last-ptr1) {
+      /* the whole rest of the text fits with room to spare, adjust for it */
       len-=(last-ptr1);
     }
     if (len<=0) {
+      /* saftey check */
       owl_fmtext_append_normal(out, "\n");
       ptr1=ptr2+1;
Index: functions.c
===================================================================
--- functions.c	(revision 378fa145d992195cad4c271818e9d091467c9b61)
+++ functions.c	(revision d559df97bd8fe22559fdadb8b64e5166521fa4b2)
@@ -139,5 +139,10 @@
   /* create the message */
   m=owl_malloc(sizeof(owl_message));
-  owl_message_create_outgoing_aim(m, owl_global_get_aim_screenname(&g), to, body);
+  owl_message_create_aim(m,
+			 owl_global_get_aim_screenname(&g),
+			 to,
+			 body,
+			 OWL_MESSAGE_DIRECTION_OUT,
+			 0);
 
   /* add it to the global list and current view */
Index: logging.c
===================================================================
--- logging.c	(revision aac889a55d28c6586a8ad7d7dbd397a6870a211e)
+++ logging.c	(revision d559df97bd8fe22559fdadb8b64e5166521fa4b2)
@@ -57,5 +57,5 @@
   FILE *file;
   char filename[MAXPATHLEN], *logpath;
-  char *tobuff, *ptr;
+  char *tobuff;
 
   tobuff=owl_sprintf("aim:%s", to);
Index: message.c
===================================================================
--- message.c	(revision 578923063811aaac872c32fbf07dfbbde5cf868f)
+++ message.c	(revision d559df97bd8fe22559fdadb8b64e5166521fa4b2)
@@ -219,7 +219,13 @@
 
 
-void owl_message_set_isloginout(owl_message *m)
-{
-  owl_message_set_attribute(m, "isloginout", "");
+void owl_message_set_islogin(owl_message *m)
+{
+  owl_message_set_attribute(m, "loginout", "login");
+}
+
+
+void owl_message_set_islogout(owl_message *m)
+{
+  owl_message_set_attribute(m, "loginout", "logout");
 }
 
@@ -228,7 +234,28 @@
   char *res;
 
-  res=owl_message_get_attribute_value(m, "isloginout");
+  res=owl_message_get_attribute_value(m, "loginout");
   if (!res) return(0);
   return(1);
+}
+
+int owl_message_is_login(owl_message *m)
+{
+  char *res;
+
+  res=owl_message_get_attribute_value(m, "loginout");
+  if (!res) return(0);
+  if (!strcmp(res, "login")) return(1);
+  return(0);
+}
+
+
+int owl_message_is_logout(owl_message *m)
+{
+  char *res;
+
+  res=owl_message_get_attribute_value(m, "loginout");
+  if (!res) return(0);
+  if (!strcmp(res, "logout")) return(1);
+  return(0);
 }
 
@@ -541,8 +568,10 @@
 }
 
-void owl_message_create_incoming_aim(owl_message *m, char *sender, char *recipient, char *text)
-{
-  char *indent;
-
+/* if loginout == -1 it's a logout message
+ *                 0 it's not a login/logout message
+ *                 1 it's a login message
+ */
+void owl_message_create_aim(owl_message *m, char *sender, char *recipient, char *text, int direction, int loginout)
+{
   owl_message_init(m);
   owl_message_set_body(m, text);
@@ -550,74 +579,72 @@
   owl_message_set_recipient(m, recipient);
   owl_message_set_type_aim(m);
-  owl_message_set_direction_in(m);
-
-  /* for now, all AIM messages are private messages since we don't do chat rooms */
-  owl_message_set_isprivate(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_bold(&(m->fmtext), OWL_TABSTR);
-  owl_fmtext_append_bold(&(m->fmtext), "AIM from ");
-  owl_fmtext_append_bold(&(m->fmtext), sender);
-  owl_fmtext_append_bold(&(m->fmtext), "\n");
-  owl_fmtext_append_bold(&(m->fmtext), indent);
-  if (text[strlen(text)-1]!='\n') {
+
+  if (direction==OWL_MESSAGE_DIRECTION_IN) {
+    owl_message_set_direction_in(m);
+  } else if (direction==OWL_MESSAGE_DIRECTION_OUT) {
+    owl_message_set_direction_out(m);
+  }
+
+  /* for now all messages that aren't loginout are private */
+  if (!loginout) {
+    owl_message_set_isprivate(m);
+  }
+
+  if (loginout==-1) {
+    owl_message_set_islogout(m);
+  } else if (loginout==1) {
+    owl_message_set_islogin(m);
+  }
+
+  /* create the formatted message */
+  if (owl_global_is_config_format(&g)) {
+    _owl_message_make_text_from_config(m);
+  } else {
+    _owl_message_make_text_from_aim(m);
+  }
+}
+
+void _owl_message_make_text_from_aim(owl_message *m)
+{
+  char *indent;
+
+  if (owl_message_is_loginout(m)) {
+    owl_fmtext_init_null(&(m->fmtext));
+    owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
+    if (owl_message_is_login(m)) {
+      owl_fmtext_append_bold(&(m->fmtext), "AIM LOGIN");
+    } else {
+      owl_fmtext_append_bold(&(m->fmtext), "AIM LOGOUT");
+    }
+    owl_fmtext_append_normal(&(m->fmtext), " for ");
+    owl_fmtext_append_normal(&(m->fmtext), owl_message_get_sender(m));
+    owl_fmtext_append_normal(&(m->fmtext), "\n");
+  } else if (owl_message_is_direction_in(m)) {
+    indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
+    owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
+    owl_fmtext_init_null(&(m->fmtext));
+    owl_fmtext_append_bold(&(m->fmtext), OWL_TABSTR);
+    owl_fmtext_append_bold(&(m->fmtext), "AIM from ");
+    owl_fmtext_append_bold(&(m->fmtext), owl_message_get_sender(m));
     owl_fmtext_append_bold(&(m->fmtext), "\n");
-  }
-  
-  owl_free(indent);
-}
-
-void owl_message_create_outgoing_aim(owl_message *m, char *sender, char *recipient, char *text)
-{
-  char *indent;
-
-  owl_message_init(m);
-  owl_message_set_body(m, text);
-  owl_message_set_sender(m, sender);
-  owl_message_set_recipient(m, recipient);
-  owl_message_set_type_aim(m);
-  owl_message_set_direction_out(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), "AIM sent to ");
-  owl_fmtext_append_normal(&(m->fmtext), recipient);
-  owl_fmtext_append_normal(&(m->fmtext), "\n");
-  owl_fmtext_append_ztext(&(m->fmtext), indent);
-  if (text[strlen(text)-1]!='\n') {
+    owl_fmtext_append_bold(&(m->fmtext), indent);
+    if (indent[strlen(indent)-1]!='\n') {
+      owl_fmtext_append_normal(&(m->fmtext), "\n");
+    }
+    owl_free(indent);
+  } else if (owl_message_is_direction_out(m)) {
+    indent=owl_malloc(strlen(owl_message_get_body(m))+owl_text_num_lines(owl_message_get_body(m))*OWL_MSGTAB+10);
+    owl_text_indent(indent, owl_message_get_body(m), OWL_MSGTAB);
+    owl_fmtext_init_null(&(m->fmtext));
+    owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
+    owl_fmtext_append_normal(&(m->fmtext), "AIM sent to ");
+    owl_fmtext_append_normal(&(m->fmtext), owl_message_get_recipient(m));
     owl_fmtext_append_normal(&(m->fmtext), "\n");
-  }
-  
-  owl_free(indent);
-}
-
-/* For login direction == 0
- * For logout direction == 1
- */
-void owl_message_create_aim_login(owl_message *m, int direction, char *screenname)
-{
-  owl_message_init(m);
-  owl_message_set_body(m, "");
-  owl_message_set_sender(m, screenname);
-  owl_message_set_recipient(m, owl_global_get_aim_screenname(&g));
-  owl_message_set_type_aim(m);
-  owl_message_set_direction_in(m);
-
-  owl_message_set_isloginout(m);
-
-  owl_fmtext_init_null(&(m->fmtext));
-  owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
-  if (direction==0) {
-    owl_fmtext_append_bold(&(m->fmtext), "AIM LOGIN");
-  } else if (direction==1) {
-    owl_fmtext_append_bold(&(m->fmtext), "AIM LOGOUT");
-  }
-  owl_fmtext_append_normal(&(m->fmtext), " for ");
-  owl_fmtext_append_normal(&(m->fmtext), screenname);
-  owl_fmtext_append_normal(&(m->fmtext), "\n");
+    owl_fmtext_append_ztext(&(m->fmtext), indent);
+    if (indent[strlen(indent)-1]!='\n') {
+      owl_fmtext_append_normal(&(m->fmtext), "\n");
+    }
+    owl_free(indent);
+  }
 }
 
@@ -687,5 +714,9 @@
   /* Set the "isloginout" attribute if it's a login message */
   if (!strcasecmp(n->z_class, "login")) {
-    owl_message_set_isloginout(m);
+    if (!strcasecmp(n->z_opcode, "user_login")) {
+      owl_message_set_islogin(m);
+    } else if (!strcasecmp(n->z_opcode, "user_logout")) {
+      owl_message_set_islogout(m);
+    }
   }
 
Index: readconfig.c
===================================================================
--- readconfig.c	(revision ac70242984535359cfe3077777a7067de6dfef19)
+++ readconfig.c	(revision d559df97bd8fe22559fdadb8b64e5166521fa4b2)
@@ -173,11 +173,5 @@
 
   /* set owl::type */
-  if (owl_message_is_type_zephyr(m)) {
-    sv_setpv(perl_get_sv("owl::type", TRUE), "zephyr");
-  } else if (owl_message_is_type_admin(m)) {
-    sv_setpv(perl_get_sv("owl::type", TRUE), "admin");
-  } else {
-    sv_setpv(perl_get_sv("owl::type", TRUE), "unknown");
-  }
+  sv_setpv(perl_get_sv("owl::type", TRUE), owl_message_type_to_string(m));
 
   /* set owl::direction */
