diff --git a/src/common/zeroconf/client_zeroconf.py b/src/common/zeroconf/client_zeroconf.py
index c1e550006cd64df0fe437a0bdfe7b5e7e5620595..bf371c1ae0afbb5c6286680aef61911c878e8e01 100644
--- a/src/common/zeroconf/client_zeroconf.py
+++ b/src/common/zeroconf/client_zeroconf.py
@@ -164,10 +164,11 @@ class P2PClient(IdleObject):
 					if on_not_ok:
 						on_not_ok('Connection to host could not be established.')
 					return
-				if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
-					self.conn_holder.number_of_awaiting_messages[self.fd] += 1
+				id = stanza.getThread()
+				if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
+					self.conn_holder.ids_of_awaiting_messages[self.fd].append(id)
 				else:
-					self.conn_holder.number_of_awaiting_messages[self.fd] = 1
+					self.conn_holder.ids_of_awaiting_messages[self.fd] = [id]
 
 	def add_stanza(self, stanza, is_message=False):
 		if self.Connection:
@@ -178,15 +179,16 @@ class P2PClient(IdleObject):
 			self.stanzaqueue.append((stanza, is_message))
 
 		if is_message:
-			if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
-				self.conn_holder.number_of_awaiting_messages[self.fd] += 1
+			id = stanza.getThread()
+			if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
+				self.conn_holder.ids_of_awaiting_messages[self.fd].append(id)
 			else:
-				self.conn_holder.number_of_awaiting_messages[self.fd] = 1
+				self.conn_holder.ids_of_awaiting_messages[self.fd] = [id]
 
 		return True
 
 	def on_message_sent(self, connection_id):
-		self.conn_holder.number_of_awaiting_messages[connection_id] -= 1
+		self.conn_holder.ids_of_awaiting_messages[connection_id].pop(0)
 
 	def on_connect(self, conn):
 		self.Connection = conn
@@ -245,8 +247,8 @@ class P2PClient(IdleObject):
 
 	def on_disconnect(self):
 		if self.conn_holder:
-			if self.conn_holder.number_of_awaiting_messages.has_key(self.fd):
-				del self.conn_holder.number_of_awaiting_messages[self.fd]
+			if self.conn_holder.ids_of_awaiting_messages.has_key(self.fd):
+				del self.conn_holder.ids_of_awaiting_messages[self.fd]
 			self.conn_holder.remove_connection(self.sock_hash)
 		if self.__dict__.has_key('Dispatcher'):
 			self.Dispatcher.PlugOut()
@@ -402,11 +404,11 @@ class P2PConnection(IdleObject, PlugIn):
 		self._plug_idle()
 
 	def read_timeout(self):
-		if self.client.conn_holder.number_of_awaiting_messages.has_key(self.fd) \
-		and self.client.conn_holder.number_of_awaiting_messages[self.fd] > 0:
-			self.client._caller.dispatch('MSGERROR',[unicode(self.client.to), -1,
-				_('Connection to host could not be established: Timeout while sending data.'), None, None])
-			self.client.conn_holder.number_of_awaiting_messages[self.fd] = 0
+		ids = self.client.conn_holder.ids_of_awaiting_messages
+		if self.fd in ids and len(ids[self.fd]) > 0:
+			for id in ids[self.fd]:
+				self._owner.Dispatcher.Event('', DATA_ERROR, (self.client.to, id))
+			ids[self.fd] = []
 		self.pollend()
 
 	def do_connect(self):
@@ -577,7 +579,7 @@ class ClientZeroconf:
 		self.ip_to_hash = {}
 		self.hash_to_port = {}
 		self.listener = None
-		self.number_of_awaiting_messages = {}
+		self.ids_of_awaiting_messages = {}
 
 	def connect(self, show, msg):
 		self.port = self.start_listener(self.caller.port)
diff --git a/src/common/zeroconf/connection_zeroconf.py b/src/common/zeroconf/connection_zeroconf.py
index d89faa3bc103a7c691ef04468b484678c28bff36..d614f90d8603a59559d1d3fb9d9d9c39c9d9eefa 100644
--- a/src/common/zeroconf/connection_zeroconf.py
+++ b/src/common/zeroconf/connection_zeroconf.py
@@ -376,7 +376,9 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
 			return
 
 		if self.status in ('invisible', 'offline'):
-			self.dispatch('MSGERROR', [unicode(jid), '-1', _('You are not connected or not visible to others. Your message could not be sent.'), None, None])
+			self.dispatch('MSGERROR', [unicode(jid), -1,
+				 _('You are not connected or not visible to others. Your message '
+				'could not be sent.'), None, None, session])
 			return
 
 		msgtxt = msg
@@ -475,13 +477,13 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
 
 		def on_send_not_ok(reason):
 			reason += ' ' + _('Your message could not be sent.')
-			self.dispatch('MSGERROR', [jid, '-1', reason, None, None, session])
+			self.dispatch('MSGERROR', [jid, -1, reason, None, None, session])
 
 		ret = self.connection.send(msg_iq, msg is not None, on_ok=on_send_ok,
 			on_not_ok=on_send_not_ok)
 		if ret == -1:
 			# Contact Offline
-			self.dispatch('MSGERROR', [jid, '-1', _('Contact is offline. Your message could not be sent.'), None, None, session])
+			self.dispatch('MSGERROR', [jid, -1, _('Contact is offline. Your message could not be sent.'), None, None, session])
 		return ret
 
 	def send_stanza(self, stanza):
@@ -573,6 +575,13 @@ class ConnectionZeroconf(ConnectionHandlersZeroconf):
 				self.dispatch('STANZA_ARRIVED', unicode(data, errors = 'ignore'))
 			elif event == common.xmpp.transports.DATA_SENT:
 				self.dispatch('STANZA_SENT', unicode(data))
+			elif event == common.xmpp.transports.DATA_ERROR:
+				thread_id = data[1]
+				frm = unicode(data[0])
+				session = self.get_or_create_session(frm, thread_id)
+				self.dispatch('MSGERROR', [frm, -1,
+	            _('Connection to host could not be established: Timeout while '
+					'sending data.'), None, None, session])
 
 # END ConnectionZeroconf
 
diff --git a/src/gajim.py b/src/gajim.py
index 32d58adc2cb6d465c7f777ef0819777177dc7eb5..4d48269724eaf6a4a0155cc031dfff1cd4a98027 100755
--- a/src/gajim.py
+++ b/src/gajim.py
@@ -947,7 +947,8 @@ class Interface:
 		if array[3]:
 			msg = _('error while sending %(message)s ( %(error)s )') % {
 				'message': array[3], 'error': msg}
-		array[5].roster_message(jid, msg, array[4], msg_type='error')
+		if session:
+			session.roster_message(jid, msg, array[4], msg_type='error')
 
 	def handle_event_msgsent(self, account, array):
 		#('MSGSENT', account, (jid, msg, keyID))