Index: message.c
===================================================================
--- message.c	(revision 440ce0128879af680216691261571cf7a278f993)
+++ message.c	(revision 0ff8fb572754799e77ac2cf2d386b7699f995257)
@@ -14,5 +14,6 @@
 static const char fileIdent[] = "$Id$";
 
-void owl_message_init(owl_message *m) {
+void owl_message_init(owl_message *m)
+{
   time_t t;
 
@@ -32,5 +33,6 @@
 }
 
-void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue) {
+void owl_message_set_attribute(owl_message *m, char *attrname, char *attrvalue)
+{
   /* add the named attribute to the message.  If an attribute with the
      name already exists, replace the old value with the new value */
@@ -58,5 +60,6 @@
 }
 
-char *owl_message_get_attribute_value(owl_message *m, char *attrname) {
+char *owl_message_get_attribute_value(owl_message *m, char *attrname)
+{
   /* return the value associated with the named attribute, or NULL if
      the attribute does not exist */
@@ -76,13 +79,16 @@
 
 
-owl_fmtext *owl_message_get_fmtext(owl_message *m) {
+owl_fmtext *owl_message_get_fmtext(owl_message *m)
+{
   return(&(m->fmtext));
 }
 
-void owl_message_set_class(owl_message *m, char *class) {
+void owl_message_set_class(owl_message *m, char *class)
+{
   owl_message_set_attribute(m, "class", class);
 }
 
-char *owl_message_get_class(owl_message *m) {
+char *owl_message_get_class(owl_message *m)
+{
   char *class;
 
@@ -92,9 +98,11 @@
 }
 
-void owl_message_set_instance(owl_message *m, char *inst) {
+void owl_message_set_instance(owl_message *m, char *inst)
+{
   owl_message_set_attribute(m, "instance", inst);
 }
 
-char *owl_message_get_instance(owl_message *m) {
+char *owl_message_get_instance(owl_message *m)
+{
   char *instance;
 
@@ -104,9 +112,11 @@
 }
 
-void owl_message_set_sender(owl_message *m, char *sender) {
+void owl_message_set_sender(owl_message *m, char *sender)
+{
   owl_message_set_attribute(m, "sender", sender);
 }
 
-char *owl_message_get_sender(owl_message *m) {
+char *owl_message_get_sender(owl_message *m)
+{
   char *sender;
 
@@ -116,9 +126,11 @@
 }
 
-void owl_message_set_zsig(owl_message *m, char *zsig) {
+void owl_message_set_zsig(owl_message *m, char *zsig)
+{
   owl_message_set_attribute(m, "zsig", zsig);
 }
 
-char *owl_message_get_zsig(owl_message *m) {
+char *owl_message_get_zsig(owl_message *m)
+{
   char *zsig;
 
@@ -128,29 +140,27 @@
 }
 
-void owl_message_set_recipient(owl_message *m, char *recip) {
+void owl_message_set_recipient(owl_message *m, char *recip)
+{
   owl_message_set_attribute(m, "recipient", recip);
 }
 
-char *owl_message_get_recipient(owl_message *m) {
+char *owl_message_get_recipient(owl_message *m)
+{
   /* this is stupid for outgoing messages, we need to fix it. */
 
   char *recip;
-     
-  if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) {
-    recip=owl_message_get_attribute_value(m, "recipient");
-  } else if (owl_message_is_direction_out(m)) {
-    recip=m->zwriteline;
-  } else {
-    recip=owl_message_get_attribute_value(m, "recipient");
-  }
+
+  recip=owl_message_get_attribute_value(m, "recipient");
   if (!recip) return("");
   return(recip);
 }
 
-void owl_message_set_realm(owl_message *m, char *realm) {
+void owl_message_set_realm(owl_message *m, char *realm)
+{
   owl_message_set_attribute(m, "realm", realm);
 }
 
-char *owl_message_get_realm(owl_message *m) {
+char *owl_message_get_realm(owl_message *m)
+{
   char *realm;
   
@@ -160,9 +170,11 @@
 }
 
-void owl_message_set_body(owl_message *m, char *body) {
+void owl_message_set_body(owl_message *m, char *body)
+{
   owl_message_set_attribute(m, "body", body);
 }
 
-char *owl_message_get_body(owl_message *m) {
+char *owl_message_get_body(owl_message *m)
+{
   char *body;
 
@@ -173,9 +185,11 @@
 
 
-void owl_message_set_opcode(owl_message *m, char *opcode) {
+void owl_message_set_opcode(owl_message *m, char *opcode)
+{
   owl_message_set_attribute(m, "opcode", opcode);
 }
 
-char *owl_message_get_opcode(owl_message *m) {
+char *owl_message_get_opcode(owl_message *m)
+{
   char *opcode;
 
@@ -185,95 +199,116 @@
 }
 
-char *owl_message_get_timestr(owl_message *m) {
+char *owl_message_get_timestr(owl_message *m)
+{
   return(m->time);
 }
 
-void owl_message_set_type_admin(owl_message *m) {
+void owl_message_set_type_admin(owl_message *m)
+{
   m->type=OWL_MESSAGE_TYPE_ADMIN;
 }
 
-void owl_message_set_type_zephyr(owl_message *m) {
+void owl_message_set_type_zephyr(owl_message *m)
+{
   m->type=OWL_MESSAGE_TYPE_ZEPHYR;
 }
 
-void owl_message_set_type_aim(owl_message *m) {
+void owl_message_set_type_aim(owl_message *m)
+{
   m->type=OWL_MESSAGE_TYPE_AIM;
 }
 						
-int owl_message_is_type_admin(owl_message *m) {
+int owl_message_is_type_admin(owl_message *m)
+{
   if (m->type==OWL_MESSAGE_TYPE_ADMIN) return(1);
   return(0);
 }
 
-int owl_message_is_type_zephyr(owl_message *m) {
+int owl_message_is_type_zephyr(owl_message *m)
+{
   if (m->type==OWL_MESSAGE_TYPE_ZEPHYR) return(1);
   return(0);
 }
 
-int owl_message_is_type_aim(owl_message *m) {
+int owl_message_is_type_aim(owl_message *m)
+{
   if (m->type==OWL_MESSAGE_TYPE_AIM) return(1);
   return(0);
 }
 
-int owl_message_is_type_generic(owl_message *m) {
+int owl_message_is_type_generic(owl_message *m)
+{
   if (m->type==OWL_MESSAGE_TYPE_GENERIC) return(1);
   return(0);
 }
 
-char *owl_message_get_text(owl_message *m) {
+char *owl_message_get_text(owl_message *m)
+{
   return(owl_fmtext_get_text(&(m->fmtext)));
 }
 
-void owl_message_set_direction_in(owl_message *m) {
+void owl_message_set_direction_in(owl_message *m)
+{
   m->direction=OWL_MESSAGE_DIRECTION_IN;
 }
 
-void owl_message_set_direction_out(owl_message *m) {
+void owl_message_set_direction_out(owl_message *m)
+{
   m->direction=OWL_MESSAGE_DIRECTION_OUT;
 }
 
-void owl_message_set_direction_none(owl_message *m) {
+void owl_message_set_direction_none(owl_message *m)
+{
   m->direction=OWL_MESSAGE_DIRECTION_NONE;
 }
 
-int owl_message_is_direction_in(owl_message *m) {
+int owl_message_is_direction_in(owl_message *m)
+{
   if (m->direction==OWL_MESSAGE_DIRECTION_IN) return(1);
   return(0);
 }
 
-int owl_message_is_direction_out(owl_message *m) {
+int owl_message_is_direction_out(owl_message *m)
+{
   if (m->direction==OWL_MESSAGE_DIRECTION_OUT) return(1);
   return(0);
 }
 
-int owl_message_is_direction_none(owl_message *m) {
+int owl_message_is_direction_none(owl_message *m)
+{
   if (m->direction==OWL_MESSAGE_DIRECTION_NONE) return(1);
   return(0);
 }
 
-int owl_message_get_numlines(owl_message *m) {
+int owl_message_get_numlines(owl_message *m)
+{
   if (m == NULL) return(0);
   return(owl_fmtext_num_lines(&(m->fmtext)));
 }
 
-void owl_message_mark_delete(owl_message *m) {
+void owl_message_mark_delete(owl_message *m)
+{
   if (m == NULL) return;
   m->delete=1;
 }
 
-void owl_message_unmark_delete(owl_message *m) {
+void owl_message_unmark_delete(owl_message *m)
+{
   if (m == NULL) return;
   m->delete=0;
 }
 
-char *owl_message_get_zwriteline(owl_message *m) {
+char *owl_message_get_zwriteline(owl_message *m)
+{
   return(m->zwriteline);
 }
 
-void owl_message_set_zwriteline(owl_message *m, char *line) {
+void owl_message_set_zwriteline(owl_message *m, char *line)
+{
   m->zwriteline=strdup(line);
 }
 
-int owl_message_is_delete(owl_message *m) {
+int owl_message_is_delete(owl_message *m)
+{
   if (m == NULL) return(0);
   if (m->delete==1) return(1);
@@ -281,14 +316,17 @@
 }
 
-ZNotice_t *owl_message_get_notice(owl_message *m) {
+ZNotice_t *owl_message_get_notice(owl_message *m)
+{
   return(&(m->notice));
 }
 
-char *owl_message_get_hostname(owl_message *m) {
+char *owl_message_get_hostname(owl_message *m)
+{
   return(m->hostname);
 }
 
 
-void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color) {
+void owl_message_curs_waddstr(owl_message *m, WINDOW *win, int aline, int bline, int acol, int bcol, int color)
+{
   owl_fmtext a, b;
 
@@ -312,21 +350,30 @@
 }
 
-int owl_message_is_personal(owl_message *m) {
-  if (strcasecmp(owl_message_get_class(m), "message")) return(0);
-  if (strcasecmp(owl_message_get_instance(m), "personal")) return(0);
-  if (!strcasecmp(owl_message_get_recipient(m), ZGetSender()) ||
-      !strcasecmp(owl_message_get_sender(m), ZGetSender())) {
+int owl_message_is_personal(owl_message *m)
+{
+  if (owl_message_is_type_zephyr(m)) {
+    if (strcasecmp(owl_message_get_class(m), "message")) return(0);
+    if (strcasecmp(owl_message_get_instance(m), "personal")) return(0);
+    if (!strcasecmp(owl_message_get_recipient(m), ZGetSender()) ||
+	!strcasecmp(owl_message_get_sender(m), ZGetSender())) {
+      return(1);
+    }
+  }
+  return(0);
+}
+
+/* true if the message is only intended for one recipient (me) */
+int owl_message_is_to_me(owl_message *m)
+{
+  if (owl_message_is_type_zephyr(m)) {
+    if (!strcasecmp(owl_message_get_recipient(m), ZGetSender())) {
+      return(1);
+    } else {
+      return(0);
+    }
+  } else if (owl_message_is_type_aim(m)) {
+    /* right now we don't support chat rooms */
     return(1);
-  }
-  return(0);
-}
-
-int owl_message_is_private(owl_message *m) {
-  if (!strcasecmp(owl_message_get_recipient(m), ZGetSender())) return(1);
-  return(0);
-}
-
-int owl_message_is_mail(owl_message *m) {
-  if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_private(m)) {
+  } else if (owl_message_is_type_admin(m)) {
     return(1);
   }
@@ -334,26 +381,82 @@
 }
 
-int owl_message_is_ping(owl_message *m) {
-  if (!strcasecmp(owl_message_get_opcode(m), "ping")) return(1);
-  return(0);
-}
-
-int owl_message_is_login(owl_message *m) {
-  if (!strcasecmp(owl_message_get_class(m), "login")) return(1);
-  return(0);
-  /* is this good enough? */
-}
-
-int owl_message_is_burningears(owl_message *m) {
+
+int owl_message_is_from_me(owl_message *m)
+{
+  if (owl_message_is_type_zephyr(m)) {
+    if (!strcasecmp(owl_message_get_sender(m), ZGetSender())) {
+      return(1);
+    } else {
+      return(0);
+    }
+  } else if (owl_message_is_type_aim(m)) {
+    if (!strcasecmp(owl_message_get_sender(m), owl_global_get_aim_screenname(&g))) {
+      return(1);
+    } else {
+      return(0);
+    }
+  } else if (owl_message_is_type_admin(m)) {
+    return(0);
+  }
+  return(0);
+}
+
+int owl_message_is_mail(owl_message *m)
+{
+  if (owl_message_is_type_zephyr(m)) {
+    if (!strcasecmp(owl_message_get_class(m), "mail") && owl_message_is_to_me(m)) {
+      return(1);
+    } else {
+      return(0);
+    }
+  }
+  return(0);
+}
+
+int owl_message_is_ping(owl_message *m)
+{
+  if (owl_message_is_type_zephyr(m)) {
+    if (!strcasecmp(owl_message_get_opcode(m), "ping")) {
+      return(1);
+    } else {
+      return(0);
+    }
+  }
+  return(0);
+}
+
+int owl_message_is_login(owl_message *m)
+{
+  if (owl_message_is_type_zephyr(m)) {
+    if (!strcasecmp(owl_message_get_class(m), "login")) {
+      return(1);
+    } else {
+      return(0);
+    }
+  } else if (owl_message_is_type_aim(m)) {
+    /* deal with this once we can use buddy lists */
+    return(0);
+  }
+       
+  return(0);
+}
+
+int owl_message_is_burningears(owl_message *m)
+{
   /* we should add a global to cache the short zsender */
   char sender[LINE], *ptr;
 
   /* if the message is from us or to us, it doesn't count */
-  if (!strcasecmp(ZGetSender(), owl_message_get_sender(m))) return(0);
-  if (!strcasecmp(ZGetSender(), owl_message_get_recipient(m))) return(0);
-
-  strcpy(sender, ZGetSender());
-  ptr=strchr(sender, '@');
-  if (ptr) *ptr='\0';
+  if (owl_message_is_from_me(m) || owl_message_is_to_me(m)) return(0);
+
+  if (owl_message_is_type_zephyr(m)) {
+    strcpy(sender, ZGetSender());
+    ptr=strchr(sender, '@');
+    if (ptr) *ptr='\0';
+  } else if (owl_message_is_type_aim(m)) {
+    strcpy(sender, owl_global_get_aim_screenname(&g));
+  } else {
+    return(0);
+  }
 
   if (stristr(owl_message_get_body(m), sender)) {
@@ -364,5 +467,6 @@
 
 /* caller must free return value. */
-char *owl_message_get_cc(owl_message *m) {
+char *owl_message_get_cc(owl_message *m)
+{
   char *cur, *out, *end;
 
@@ -378,9 +482,11 @@
 }
 
-int owl_message_get_id(owl_message *m) {
+int owl_message_get_id(owl_message *m)
+{
   return(m->id);
 }
 					
-int owl_message_search(owl_message *m, char *string) {
+int owl_message_search(owl_message *m, char *string)
+{
   /* return 1 if the message contains "string", 0 otherwise.  This is
    * case insensitive because the functions it uses are */
@@ -389,5 +495,6 @@
 }
 
-void owl_message_create(owl_message *m, char *header, char *text) {
+void owl_message_create(owl_message *m, char *header, char *text)
+{
   char *indent;
 
@@ -409,5 +516,6 @@
 }
 
-void owl_message_create_aim(owl_message *m, char *sender, char *recipient, char *text) {
+void owl_message_create_aim(owl_message *m, char *sender, char *recipient, char *text)
+{
   char *indent;
 
@@ -435,5 +543,6 @@
 }
 
-void owl_message_create_admin(owl_message *m, char *header, char *text) {
+void owl_message_create_admin(owl_message *m, char *header, char *text)
+{
   char *indent;
 
@@ -460,5 +569,6 @@
 }
 
-void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n) {
+void owl_message_create_from_znotice(owl_message *m, ZNotice_t *n)
+{
   struct hostent *hent;
   int k;
@@ -552,5 +662,6 @@
 }
 
-void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig) {
+void owl_message_create_from_zwriteline(owl_message *m, char *line, char *body, char *zsig)
+{
   owl_zwrite z;
   int ret;
@@ -593,5 +704,6 @@
 }
 
-void _owl_message_make_text_from_config(owl_message *m) {
+void _owl_message_make_text_from_config(owl_message *m)
+{
   char *body, *indent;
 
@@ -612,5 +724,6 @@
 }
 
-void _owl_message_make_text_from_zwriteline_standard(owl_message *m) {
+void _owl_message_make_text_from_zwriteline_standard(owl_message *m)
+{
   char *indent, *text, *zsigbuff, *foo;
 
@@ -642,5 +755,6 @@
 }
 
-void _owl_message_make_text_from_zwriteline_simple(owl_message *m) {
+void _owl_message_make_text_from_zwriteline_simple(owl_message *m)
+{
   char *indent, *text, *zsigbuff, *foo;
 
@@ -672,5 +786,6 @@
 }
 
-void _owl_message_make_text_from_notice_standard(owl_message *m) {
+void _owl_message_make_text_from_notice_standard(owl_message *m)
+{
   char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
   ZNotice_t *n;
@@ -702,5 +817,5 @@
   owl_fmtext_append_normal(&(m->fmtext), OWL_TABSTR);
 
-  if (!strcasecmp(owl_message_get_opcode(m), "ping") && owl_message_is_private(m)) {
+  if (!strcasecmp(owl_message_get_opcode(m), "ping") && owl_message_is_to_me(m)) {
     owl_fmtext_append_bold(&(m->fmtext), "PING");
     owl_fmtext_append_normal(&(m->fmtext), " from ");
@@ -773,5 +888,6 @@
 }
 
-void _owl_message_make_text_from_notice_simple(owl_message *m) {
+void _owl_message_make_text_from_notice_simple(owl_message *m)
+{
   char *body, *indent, *ptr, *zsigbuff, frombuff[LINE];
   ZNotice_t *n;
@@ -873,5 +989,6 @@
 }
 
-void owl_message_pretty_zsig(owl_message *m, char *buff) {
+void owl_message_pretty_zsig(owl_message *m, char *buff)
+{
   /* stick a one line version of the zsig in buff */
   char *ptr;
@@ -882,5 +999,6 @@
 }
 
-void owl_message_free(owl_message *m) {
+void owl_message_free(owl_message *m)
+{
   int i, j;
   owl_pair *p;
