Index: perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm
===================================================================
--- perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm	(revision 87894109aeedcc8ba50bd3b983c0d9558f1e6b32)
+++ perl/modules/Jabber/lib/BarnOwl/Module/Jabber.pm	(revision aa0a0b55489e41bbf85f4613156df3e987972b94)
@@ -285,5 +285,5 @@
         {
             summary => "Send a Jabber Message",
-            usage   => "jwrite <jid> [-t <thread>] [-s <subject>] [-a <account>]"
+            usage   => "jwrite <jid> [-t <thread>] [-s <subject>] [-a <account>] [-m <message>]"
         }
     );
@@ -308,5 +308,6 @@
             description => "jmuc sends Jabber commands related to MUC.\n\n"
               . "The following commands are available\n\n"
-              . "join <muc>  Join a MUC.\n\n"
+              . "join <muc>[/<nick>]\n"
+              . "            Join a MUC (with a given nickname, or otherwise your JID).\n\n"
               . "part <muc>  Part a MUC.\n"
               . "            The MUC is taken from the current message if not supplied.\n\n"
@@ -377,6 +378,5 @@
         my $cjidStr = $conn->baseJIDExists($jidStr);
         if ($cjidStr) {
-            BarnOwl::error("Already logged in as $cjidStr.");
-            return;
+            die("Already logged in as $cjidStr.\n");
         }
     }
@@ -387,11 +387,9 @@
 
     if ( !$uid || !$componentname ) {
-        BarnOwl::error("usage: $cmd JID");
-        return;
+        die("usage: $cmd JID\n");
     }
 
     if ( $conn->jidActive($jidStr) ) {
-        BarnOwl::error("Already logged in as $jidStr.");
-        return;
+        die("Already logged in as $jidStr.\n");
     } elsif ($conn->jidExists($jidStr)) {
         return $conn->tryReconnect($jidStr, 1);
@@ -526,6 +524,5 @@
 sub cmd_jlist {
     if ( !( scalar $conn->getJIDs() ) ) {
-        BarnOwl::error("You are not logged in to Jabber.");
-        return;
+        die("You are not logged in to Jabber.\n");
     }
     BarnOwl::popless_ztext( onGetBuddyList() );
@@ -534,6 +531,5 @@
 sub cmd_jwrite {
     if ( !$conn->connected() ) {
-        BarnOwl::error("You are not logged in to Jabber.");
-        return;
+        die("You are not logged in to Jabber.\n");
     }
 
@@ -543,4 +539,5 @@
     my $jwrite_thread  = "";
     my $jwrite_subject = "";
+    my $jwrite_body;
     my ($to, $from);
     my $jwrite_type    = "chat";
@@ -554,12 +551,11 @@
         'subject=s' => \$jwrite_subject,
         'account=s' => \$from,
-        'id=s'     =>  \$jwrite_sid,
+        'id=s'      => \$jwrite_sid,
+        'message=s' => \$jwrite_body,
     ) or die("Usage: jwrite <jid> [-t <thread>] [-s <subject>] [-a <account>]\n");
     $jwrite_type = 'groupchat' if $gc;
 
     if ( scalar @ARGV != 1 ) {
-        BarnOwl::error(
-            "Usage: jwrite <jid> [-t <thread>] [-s <subject>] [-a <account>]");
-        return;
+        die("Usage: jwrite <jid> [-t <thread>] [-s <subject>] [-a <account>]\n");
     }
     else {
@@ -570,5 +566,5 @@
 
     unless(scalar @candidates) {
-        die("Unable to resolve JID $to");
+        die("Unable to resolve JID $to\n");
     }
 
@@ -577,7 +573,7 @@
     unless(scalar @candidates) {
         if(!$from) {
-            die("You must specify an account with -a");
+            die("You must specify an account with -a\n");
         } else {
-            die("Unable to resolve account $from");
+            die("Unable to resolve account $from\n");
         }
     }
@@ -594,4 +590,9 @@
         type    => $jwrite_type
     };
+
+    if (defined($jwrite_body)) {
+        process_owl_jwrite($jwrite_body);
+        return;
+    }
 
     if(scalar @candidates > 1) {
@@ -631,6 +632,5 @@
     my $func = $jmuc_commands{$cmd};
     if ( !$func ) {
-        BarnOwl::error("jmuc: Unknown command: $cmd");
-        return;
+        die("jmuc: Unknown command: $cmd\n");
     }
 
@@ -654,5 +654,5 @@
         }
         else {
-            BarnOwl::error('You must specify an account with -a <jid>');
+            die("You must specify an account with -a <jid>\n");
         }
         return $func->( $jid, $muc, @ARGV );
@@ -667,5 +667,5 @@
 
     $muc = shift @ARGV
-      or die("Usage: jmuc join <muc> [-p <password>] [-a <account>]");
+      or die("Usage: jmuc join <muc> [-p <password>] [-a <account>]\n");
 
     die("Error: Must specify a fully-qualified MUC name (e.g. barnowl\@conference.mit.edu)\n")
@@ -680,5 +680,5 @@
                                                    MaxChars => 0
                                                   });
-    $completion_jids{$muc} = 1;
+    $completion_jids{$muc->GetJID('base')} = 1;
     return;
 }
@@ -688,10 +688,10 @@
 
     $muc = shift @args if scalar @args;
-    die("Usage: jmuc part [<muc>] [-a <account>]") unless $muc;
+    die("Usage: jmuc part [<muc>] [-a <account>]\n") unless $muc;
 
     if($conn->getConnectionFromJID($jid)->MUCLeave(JID => $muc)) {
         queue_admin_msg("$jid has left $muc.");
     } else {
-        die("Error: Not joined to $muc");
+        die("Error: Not joined to $muc\n");
     }
 }
@@ -703,5 +703,5 @@
     $muc = shift @args if scalar @args;
 
-    die('Usage: jmuc invite <jid> [<muc>] [-a <account>]')
+    die("Usage: jmuc invite <jid> [<muc>] [-a <account>]\n")
       unless $muc && $invite_jid;
 
@@ -718,5 +718,5 @@
     my ( $jid, $muc, @args ) = @_;
     $muc = shift @args if scalar @args;
-    die("Usage: jmuc configure [<muc>]") unless $muc;
+    die("Usage: jmuc configure [<muc>]\n") unless $muc;
     my $iq = Net::Jabber::IQ->new();
     $iq->SetTo($muc);
@@ -759,5 +759,5 @@
 
     $muc = shift @args if scalar @args;
-    die("Usage: jmuc presence [<muc>]") unless $muc;
+    die("Usage: jmuc presence [<muc>]\n") unless $muc;
 
     if ($muc eq '-a') {
@@ -774,5 +774,5 @@
     else {
         my $m = $conn->getConnectionFromJID($jid)->FindMUC(jid => $muc);
-        die("No such muc: $muc") unless $m;
+        die("No such muc: $muc\n") unless $m;
         BarnOwl::popless_ztext(jmuc_presence_single($m));
     }
@@ -801,6 +801,5 @@
     my $func = $jroster_commands{$cmd};
     if ( !$func ) {
-        BarnOwl::error("jroster: Unknown command: $cmd");
-        return;
+        die("jroster: Unknown command: $cmd\n");
     }
 
@@ -825,5 +824,5 @@
         }
         else {
-            BarnOwl::error('You must specify an account with -a <jid>');
+            die("You must specify an account with -a <jid>\n");
         }
         return $func->( $jid, $name, \@groups, $purgeGroups,  @ARGV );
@@ -849,5 +848,5 @@
     }
     else {
-        BarnOwl::error('You must specify an account with -a <jid>');
+        die("You must specify an account with -a <jid>\n");
     }
 
@@ -1234,4 +1233,13 @@
         $completion_jids{$room} = 1;
 
+        my $muc;
+        if ($dir eq 'in') {
+            my $connection = $conn->getConnectionFromSid($props{sid});
+            $muc = $connection->FindMUC(jid => $from);
+        } else {
+            my $connection = $conn->getConnectionFromJID($props{from});
+            $muc = $connection->FindMUC(jid => $to);
+        }
+        $props{from} = $muc->GetFullJID($from) || $nick || $room;
         $props{sender} = $nick || $room;
         $props{recipient} = $room;
@@ -1331,5 +1339,5 @@
         return $givenJIDStr if ($conn->jidExists($givenJIDStr) );
         return resolveConnectedJID($givenJID->GetJID('base')) if $loose;
-        die("Invalid account: $givenJIDStr");
+        die("Invalid account: $givenJIDStr\n");
     }
 
@@ -1384,5 +1392,5 @@
         # Not one of ours.
         else {
-            die("Invalid account: $givenJIDStr");
+            die("Invalid account: $givenJIDStr\n");
         }
 
@@ -1430,5 +1438,5 @@
     if($from) {
         $from_jid = resolveConnectedJID($from, 1);
-        die("Unable to resolve account $from") unless $from_jid;
+        die("Unable to resolve account $from\n") unless $from_jid;
         $to_jid = resolveDestJID($to, $from_jid);
         push @matches, [$from_jid, $to_jid] if $to_jid;
