Index: protocols/jabber/io.c
===================================================================
--- protocols/jabber/io.c	(revision af7f046b85694db45d670054e28960e4a0d79232)
+++ protocols/jabber/io.c	(revision 8fb1263325c6839b792c352283abac3f63142fa2)
@@ -375,36 +375,20 @@
 	
 	if( ( c = xt_find_node( node->children, "bind" ) ) )
-	{
-		reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( &ic->acc->set, "resource" ), NULL ) );
-		xt_add_attr( reply, "xmlns", XMLNS_BIND );
-		reply = jabber_make_packet( "iq", "set", NULL, reply );
-		jabber_cache_add( ic, reply, jabber_pkt_bind_sess );
-		
-		if( !jabber_write_packet( ic, reply ) )
-			return XT_ABORT;
-		
-		jd->flags |= JFLAG_WAIT_BIND;
-	}
+		jd->flags |= JFLAG_WANT_BIND;
 	
 	if( ( c = xt_find_node( node->children, "session" ) ) )
-	{
-		reply = xt_new_node( "session", NULL, NULL );
-		xt_add_attr( reply, "xmlns", XMLNS_SESSION );
-		reply = jabber_make_packet( "iq", "set", NULL, reply );
-		jabber_cache_add( ic, reply, jabber_pkt_bind_sess );
-		
-		if( !jabber_write_packet( ic, reply ) )
-			return XT_ABORT;
-		
-		jd->flags |= JFLAG_WAIT_SESSION;
-	}
+		jd->flags |= JFLAG_WANT_SESSION;
 	
 	/* This flag is already set if we authenticated via SASL, so now
 	   we can resume the session in the new stream, if we don't have
 	   to bind/initialize the session. */
-	if( jd->flags & JFLAG_AUTHENTICATED && ( jd->flags & ( JFLAG_WAIT_BIND | JFLAG_WAIT_SESSION ) ) == 0 )
+	if( jd->flags & JFLAG_AUTHENTICATED && ( jd->flags & ( JFLAG_WANT_BIND | JFLAG_WANT_SESSION ) ) == 0 )
 	{
 		if( !jabber_get_roster( ic ) )
 			return XT_ABORT;
+	}
+	else if( jd->flags & JFLAG_AUTHENTICATED )
+	{
+		return jabber_pkt_bind_sess( ic, NULL, NULL );
 	}
 	
Index: protocols/jabber/iq.c
===================================================================
--- protocols/jabber/iq.c	(revision af7f046b85694db45d670054e28960e4a0d79232)
+++ protocols/jabber/iq.c	(revision 8fb1263325c6839b792c352283abac3f63142fa2)
@@ -298,8 +298,8 @@
 {
 	struct jabber_data *jd = ic->proto_data;
-	struct xt_node *c;
+	struct xt_node *c, *reply = NULL;
 	char *s;
 	
-	if( ( c = xt_find_node( node->children, "bind" ) ) )
+	if( node && ( c = xt_find_node( node->children, "bind" ) ) )
 	{
 		c = xt_find_node( c->children, "jid" );
@@ -308,12 +308,31 @@
 			imcb_log( ic, "Server changed session resource string to `%s'", s + 1 );
 		
-		jd->flags &= ~JFLAG_WAIT_BIND;
-	}
-	else
-	{
-		jd->flags &= ~JFLAG_WAIT_SESSION;
-	}
-	
-	if( ( jd->flags & ( JFLAG_WAIT_BIND | JFLAG_WAIT_SESSION ) ) == 0 )
+		jd->flags &= ~JFLAG_WANT_BIND;
+	}
+	else if( node && ( c = xt_find_node( node->children, "session" ) ) )
+	{
+		jd->flags &= ~JFLAG_WANT_SESSION;
+	}
+	
+	if( jd->flags & JFLAG_WANT_BIND )
+	{
+		reply = xt_new_node( "bind", NULL, xt_new_node( "resource", set_getstr( &ic->acc->set, "resource" ), NULL ) );
+		xt_add_attr( reply, "xmlns", XMLNS_BIND );
+	}
+	else if( jd->flags & JFLAG_WANT_SESSION )
+	{
+		reply = xt_new_node( "session", NULL, NULL );
+		xt_add_attr( reply, "xmlns", XMLNS_SESSION );
+	}
+	
+	if( reply != NULL )
+	{
+		reply = jabber_make_packet( "iq", "set", NULL, reply );
+		jabber_cache_add( ic, reply, jabber_pkt_bind_sess );
+		
+		if( !jabber_write_packet( ic, reply ) )
+			return XT_ABORT;
+	}
+	else if( ( jd->flags & ( JFLAG_WANT_BIND | JFLAG_WANT_SESSION ) ) == 0 )
 	{
 		if( !jabber_get_roster( ic ) )
Index: protocols/jabber/jabber.h
===================================================================
--- protocols/jabber/jabber.h	(revision af7f046b85694db45d670054e28960e4a0d79232)
+++ protocols/jabber/jabber.h	(revision 8fb1263325c6839b792c352283abac3f63142fa2)
@@ -40,7 +40,7 @@
 	JFLAG_STREAM_RESTART = 4,       /* Set when we want to restart the stream (after
 	                                   SASL or TLS). */
-	JFLAG_WAIT_SESSION = 8,	        /* Set if we sent a <session> tag and need a reply
+	JFLAG_WANT_SESSION = 8,	        /* Set if the server wants a <session/> tag
 	                                   before we continue. */
-	JFLAG_WAIT_BIND = 16,           /* ... for <bind> tag. */
+	JFLAG_WANT_BIND = 16,           /* ... for <bind> tag. */
 	JFLAG_WANT_TYPING = 32,         /* Set if we ever sent a typing notification, this
 	                                   activates all XEP-85 related code. */
