diff --git a/src/common/logger.py b/src/common/logger.py
index 85932cb95a3f475702d69fc75c1416808cdd3f77..6a14bbc2bea55ce230e7919416401d3460933610 100644
--- a/src/common/logger.py
+++ b/src/common/logger.py
@@ -228,6 +228,21 @@ class Logger:
 		except sqlite.OperationalError, e:
 			print >> sys.stderr, str(e)
 	
+	def get_um_for_contact(self, jid):
+		''' get unread messages for jid '''
+		if not jid:
+			return
+		jid = jid.lower()
+		jid_id = self.get_jid_id(jid)
+		self.cur.execute('''
+			SELECT message_id, message, time, subject FROM logs , unread_messages 
+			WHERE jid_id = %d AND log_line_id = message_id ORDER BY time ASC 
+			''' % (jid_id)
+			)
+
+		results = self.cur.fetchall()
+		return results
+		
 	def write(self, kind, jid, message = None, show = None, tim = None,
 	subject = None):
 		'''write a row (status, gcstatus, message etc) to logs database
@@ -320,6 +335,7 @@ class Logger:
 			)
 
 		results = self.cur.fetchall()
+		#FIXME: why do we reverse, instead of selecting by ASC order?
 		results.reverse()
 		return results
 	
diff --git a/src/roster_window.py b/src/roster_window.py
index bd87a7728bd862f79ee4605aeda9c0cfffaf2df3..cfaed6074d8a3ad0314e65706b90f61cec0cb24e 100644
--- a/src/roster_window.py
+++ b/src/roster_window.py
@@ -888,7 +888,11 @@ class RosterWindow:
 	def add_account_contacts(self, account):
 		for jid in gajim.contacts.get_jid_list(account):
 			self.add_contact_to_roster(jid, account)
-
+			results = gajim.logger.get_um_for_contact(jid)
+			for result in results:
+				tim = time.localtime(float(result[2]))
+				self.on_message(jid, result[1], tim, account, msg_type= 'chat', msg_id=result[0])
+	
 	def fill_contacts_and_groups_dicts(self, array, account):
 		'''fill gajim.contacts and gajim.groups'''
 		if account not in gajim.contacts.get_accounts():