Index: commands.c
===================================================================
--- commands.c	(revision c0a90c2c7ab97b9465c9873757faf312faa0021e)
+++ commands.c	(revision 4211f50b3f182f522a14169eaee7c89c03d9c447)
@@ -2367,6 +2367,4 @@
 char *owl_command_aimlogin(int argc, char **argv, char *buff)
 {
-  int ret;
-  
   if ((argc<2) || (argc>3)) {
     owl_function_makemsg("Wrong number of arguments to aimlogin command");
@@ -2376,15 +2374,11 @@
   /* if we get two arguments, ask for the password */
   if (argc==2) {
-    owl_global_set_buffercommand(&g, buff);
+    owl_global_set_buffercommand(&g, argv[1]);
+    owl_global_set_buffercallback(&g, owl_function_aimlogin);
     owl_function_start_password("AIM Password: ");
     return(NULL);
-  }
-
-  /* clear the buddylist */
-  owl_buddylist_clear(owl_global_get_buddylist(&g));
-
-  /* try to login */
-  ret=owl_aim_login(argv[1], argv[2]);
-  if (ret) owl_function_makemsg("Warning: login for %s failed.\n", argv[1]);
+  } else {
+    owl_function_aimlogin(argv[1], argv[2]);
+  }
 
   /* this is a test */
Index: functions.c
===================================================================
--- functions.c	(revision 1aa2b1a4ff036d9cf91d1f8187b5506c79e8dcc6)
+++ functions.c	(revision 4211f50b3f182f522a14169eaee7c89c03d9c447)
@@ -320,4 +320,5 @@
 
   owl_global_set_buffercommand(&g, line);
+  owl_global_set_buffercallback(&g, &owl_function_zwrite);
 }
 
@@ -350,4 +351,5 @@
 
   owl_global_set_buffercommand(&g, line);
+  owl_global_set_buffercallback(&g, &owl_function_aimwrite);
 }
 
@@ -374,4 +376,5 @@
 
   owl_global_set_buffercommand(&g, "loopwrite");
+  owl_global_set_buffercallback(&g, &owl_function_loopwrite);
 }
 
@@ -483,12 +486,13 @@
 }
 
-void owl_function_aimwrite(char *to)
+void owl_function_aimwrite(char *line, char *msg)
 {
   int ret;
-  char *msg, *format_msg;
+  char *to, *format_msg;
   owl_message *m;
 
+  to = line + 9;
+
   /* make a formatted copy of the message */
-  msg=owl_editwin_get_text(owl_global_get_typwin(&g));
   format_msg=owl_strdup(msg);
   owl_text_wordunwrap(format_msg);
@@ -558,5 +562,5 @@
 }
 
-void owl_function_loopwrite()
+void owl_function_loopwrite(char *line, char *msg)
 {
   owl_message *min, *mout;
@@ -565,9 +569,9 @@
    * an incoming message */
   min=owl_malloc(sizeof(owl_message));
-  owl_message_create_loopback(min, owl_editwin_get_text(owl_global_get_typwin(&g)));
+  owl_message_create_loopback(min, msg);
   owl_message_set_direction_in(min);
   owl_global_messagequeue_addmsg(&g, min);
 
-  mout=owl_function_make_outgoing_loopback(owl_editwin_get_text(owl_global_get_typwin(&g)));
+  mout=owl_function_make_outgoing_loopback(msg);
   owl_log_message(mout);
   if (owl_global_is_displayoutgoing(&g)) {
@@ -928,4 +932,15 @@
     owl_function_error("Error subscribing to login messages from file.");
   }
+}
+
+void owl_function_aimlogin(char *user, char *passwd) {
+  int ret;
+
+  /* clear the buddylist */
+  owl_buddylist_clear(owl_global_get_buddylist(&g));
+
+  /* try to login */
+  ret=owl_aim_login(user, passwd);
+  if (ret) owl_function_makemsg("Warning: login for %s failed.\n", user);
 }
 
@@ -1309,21 +1324,13 @@
 void owl_function_run_buffercommand()
 {
-  char *buff, *ptr;
+  char *buff;
+  void (*cb)(char*, char*);
 
   buff=owl_global_get_buffercommand(&g);
-  if (!strncmp(buff, "zwrite ", 7)) {
-    owl_function_zwrite(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
-  } else if (!strncmp(buff, "zcrypt ", 7)) {
-    owl_function_zcrypt(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
-  } else if (!strncmp(buff, "aimwrite ", 9)) {
-    owl_function_aimwrite(buff+9);
-  } else if (!strncmp(buff, "loopwrite", 9) || !strncmp(buff, "loopwrite ", 10)) {
-    owl_function_loopwrite();
-  } else if (!strncmp(buff, "aimlogin ", 9)) {
-    ptr=owl_sprintf("%s %s", buff, owl_global_get_response(&g));
-    owl_function_command(ptr);
-    owl_free(ptr);
-  } else {
-    owl_function_error("Internal error: invalid buffercommand %s", buff);
+  cb=owl_global_get_buffercallback(&g);
+  if(!cb) {
+    owl_function_error("Internal error: No callback for buffercommand %s", buff);
+  } else {
+    cb(buff, owl_editwin_get_text(owl_global_get_typwin(&g)));
   }
 }
Index: global.c
===================================================================
--- global.c	(revision 176d3443c1ac51ee588037ef4b938c5eba7c2ae5)
+++ global.c	(revision 4211f50b3f182f522a14169eaee7c89c03d9c447)
@@ -250,4 +250,12 @@
 }
 
+void owl_global_set_buffercallback(owl_global *g, void (*cb)(char*,char*)) {
+  g->buffercallback = cb;
+}
+
+void (*owl_global_get_buffercallback(owl_global *g))(char*,char*) {
+  return g->buffercallback;
+}
+
 /* refresh */
 
Index: owl.h
===================================================================
--- owl.h	(revision 1152d45437407d56c72ae3e11e2eb413ac05defd)
+++ owl.h	(revision 4211f50b3f182f522a14169eaee7c89c03d9c447)
@@ -533,4 +533,5 @@
   int config_format;
   char *buffercommand;
+  void (*buffercallback)(char *cmd, char *msg);
   owl_editwin tw;
   owl_viewwin vw;
